1 /* $NetBSD: main.c,v 1.22 2009/06/12 00:24:33 nisimura Exp $ */
4 * Copyright (c) 2007 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
32 #include <sys/param.h>
33 #include <sys/reboot.h>
35 #include <lib/libsa/stand.h>
36 #include <lib/libsa/loadfile.h>
37 #include <lib/libkern/libkern.h>
39 #include <machine/bootinfo.h>
43 void *bootinfo
; /* low memory reserved to pass bootinfo structures */
44 int bi_size
; /* BOOTINFO_MAXSIZE */
47 extern char bootfile
[]; /* filled by DHCP */
48 char rootdev
[4]; /* NIF nickname, filled by netif_init() */
49 uint8_t en
[6]; /* NIC macaddr, fill by netif_init() */
53 void bi_add(void *, int, int);
55 extern char bootprog_rev
[], bootprog_maker
[], bootprog_date
[];
58 char *consname
= CONSNAME
;
59 int consport
= CONSPORT
;
60 int consspeed
= CONSSPEED
;
61 int ticks_per_sec
= TICKS_PER_SEC
;
66 int n
, b
, d
, f
, howto
;
67 unsigned memsize
, tag
;
68 unsigned long marks
[MARK_MAX
];
69 struct btinfo_memory bi_mem
;
70 struct btinfo_console bi_cons
;
71 struct btinfo_clock bi_clk
;
72 struct btinfo_bootpath bi_path
;
73 struct btinfo_rootdevice bi_rdev
;
74 unsigned lnif
[1][2], lata
[1][2];
76 /* determine SDRAM size */
77 memsize
= mpc107memsize();
80 printf(">> NetBSD/sandpoint Boot, Revision %s\n", bootprog_rev
);
81 printf(">> (%s, %s)\n", bootprog_maker
, bootprog_date
);
84 printf("Sandpoint X3"); break;
86 printf("Encore PP1"); break;
88 printf(", %dMB SDRAM\n", memsize
>> 20);
90 n
= pcilookup(PCI_CLASS_IDE
, lata
, sizeof(lata
)/sizeof(lata
[0]));
92 printf("no IDE found\n");
95 pcidecomposetag(tag
, &b
, &d
, &f
);
96 printf("%04x.%04x IDE %02d:%02d:%02d\n",
97 PCI_VENDOR(lata
[0][0]), PCI_PRODUCT(lata
[0][0]),
101 n
= pcilookup(PCI_CLASS_ETH
, lnif
, sizeof(lnif
)/sizeof(lnif
[0]));
104 printf("no NIC found\n");
108 pcidecomposetag(tag
, &b
, &d
, &f
);
109 printf("%04x.%04x NIC %02d:%02d:%02d\n",
110 PCI_VENDOR(lnif
[0][0]), PCI_PRODUCT(lnif
[0][0]),
117 if (netif_init(tag
) == 0)
118 printf("no NIC device driver is found\n");
120 printf("Try NFS load /netbsd\n");
121 marks
[MARK_START
] = 0;
122 if (loadfile("net:", marks
, LOAD_KERNEL
) < 0) {
123 printf("load failed. Restarting...\n");
127 howto
= RB_SINGLE
| AB_VERBOSE
;
128 #ifdef START_DDB_SESSION
132 bootinfo
= (void *)0x4000;
135 bi_mem
.memsize
= memsize
;
136 snprintf(bi_cons
.devname
, sizeof(bi_cons
.devname
), consname
);
137 bi_cons
.addr
= consport
;
138 bi_cons
.speed
= consspeed
;
139 bi_clk
.ticks_per_sec
= ticks_per_sec
;
140 snprintf(bi_path
.bootpath
, sizeof(bi_path
.bootpath
), bootfile
);
141 snprintf(bi_rdev
.devname
, sizeof(bi_rdev
.devname
), rootdev
);
142 bi_rdev
.cookie
= tag
; /* PCI tag for fxp netboot case */
144 bi_add(&bi_cons
, BTINFO_CONSOLE
, sizeof(bi_cons
));
145 bi_add(&bi_mem
, BTINFO_MEMORY
, sizeof(bi_mem
));
146 bi_add(&bi_clk
, BTINFO_CLOCK
, sizeof(bi_clk
));
147 bi_add(&bi_path
, BTINFO_BOOTPATH
, sizeof(bi_path
));
148 bi_add(&bi_rdev
, BTINFO_ROOTDEVICE
, sizeof(bi_rdev
));
150 printf("entry=%p, ssym=%p, esym=%p\n",
151 (void *)marks
[MARK_ENTRY
],
152 (void *)marks
[MARK_SYM
],
153 (void *)marks
[MARK_END
]);
155 __syncicache((void *)marks
[MARK_ENTRY
],
156 (u_int
)marks
[MARK_SYM
] - (u_int
)marks
[MARK_ENTRY
]);
158 run((void *)marks
[MARK_SYM
], (void *)marks
[MARK_END
],
159 (void *)howto
, bootinfo
, (void *)marks
[MARK_ENTRY
]);
161 /* should never come here */
162 printf("exec returned. Restarting...\n");
169 struct btinfo_magic bi_magic
;
171 memset(addr
, 0, BOOTINFO_MAXSIZE
);
172 bi_next
= (char *)addr
;
175 bi_magic
.magic
= BOOTINFO_MAGIC
;
176 bi_add(&bi_magic
, BTINFO_MAGIC
, sizeof(bi_magic
));
180 bi_add(void *new, int type
, int size
)
182 struct btinfo_common
*bi
;
184 if (bi_size
+ size
> BOOTINFO_MAXSIZE
)
185 return; /* XXX error? */
190 memcpy(bi_next
, new, size
);
195 static const char *cmdln
[] = {
196 "console=ttyS0,115200 root=/dev/sda1 rw initrd=0x200000,2M",
197 "console=ttyS0,115200 root=/dev/nfs ip=dhcp"
201 mkatagparams(unsigned addr
, char *kcmd
)
209 #define ATAG_CORE 0x54410001
210 #define ATAG_MEM 0x54410002
211 #define ATAG_INITRD 0x54410005
212 #define ATAG_CMDLINE 0x54410009
213 #define ATAG_NONE 0x00000000
214 #define tagnext(p) (struct tag *)((unsigned *)(p) + (p)->siz)
215 #define tagsize(n) (2 + (n))
217 p
= (struct tag
*)addr
;
220 p
->val
[0] = 0; /* flags */
221 p
->val
[1] = 0; /* pagesize */
222 p
->val
[2] = 0; /* rootdev */
226 p
->val
[0] = 64 * 1024 * 1024;
227 p
->val
[1] = 0; /* start */
231 p
->tag
= ATAG_CMDLINE
;
232 p
->siz
= tagsize((strlen(kcmd
) + 1 + 3) >> 2);
233 strcpy((void *)p
->val
, kcmd
);