Sync usage with man page.
[netbsd-mini2440.git] / sys / arch / sandpoint / stand / netboot / main.c
blobc52e521deb41010cf26b8bd7e7c0e2059f4eb0e6
1 /* $NetBSD: main.c,v 1.22 2009/06/12 00:24:33 nisimura Exp $ */
3 /*-
4 * Copyright (c) 2007 The NetBSD Foundation, Inc.
5 * All rights reserved.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Tohru Nishimura.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
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>
41 #include "globals.h"
43 void *bootinfo; /* low memory reserved to pass bootinfo structures */
44 int bi_size; /* BOOTINFO_MAXSIZE */
45 char *bi_next;
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() */
51 void main(void);
52 void bi_init(void *);
53 void bi_add(void *, int, int);
55 extern char bootprog_rev[], bootprog_maker[], bootprog_date[];
57 int brdtype;
58 char *consname = CONSNAME;
59 int consport = CONSPORT;
60 int consspeed = CONSSPEED;
61 int ticks_per_sec = TICKS_PER_SEC;
63 void
64 main(void)
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();
79 printf("\n");
80 printf(">> NetBSD/sandpoint Boot, Revision %s\n", bootprog_rev);
81 printf(">> (%s, %s)\n", bootprog_maker, bootprog_date);
82 switch (brdtype) {
83 case BRD_SANDPOINTX3:
84 printf("Sandpoint X3"); break;
85 case BRD_ENCOREPP1:
86 printf("Encore PP1"); break;
88 printf(", %dMB SDRAM\n", memsize >> 20);
90 n = pcilookup(PCI_CLASS_IDE, lata, sizeof(lata)/sizeof(lata[0]));
91 if (n == 0)
92 printf("no IDE found\n");
93 else {
94 tag = lata[0][1];
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]),
98 b, d, f);
101 n = pcilookup(PCI_CLASS_ETH, lnif, sizeof(lnif)/sizeof(lnif[0]));
102 if (n == 0) {
103 tag = ~0;
104 printf("no NIC found\n");
106 else {
107 tag = lnif[0][1];
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]),
111 b, d, f);
114 pcisetup();
115 pcifixup();
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");
124 _rtt();
127 howto = RB_SINGLE | AB_VERBOSE;
128 #ifdef START_DDB_SESSION
129 howto |= RB_KDB;
130 #endif
132 bootinfo = (void *)0x4000;
133 bi_init(bootinfo);
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");
163 _rtt();
166 void
167 bi_init(void *addr)
169 struct btinfo_magic bi_magic;
171 memset(addr, 0, BOOTINFO_MAXSIZE);
172 bi_next = (char *)addr;
173 bi_size = 0;
175 bi_magic.magic = BOOTINFO_MAGIC;
176 bi_add(&bi_magic, BTINFO_MAGIC, sizeof(bi_magic));
179 void
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? */
187 bi = new;
188 bi->next = size;
189 bi->type = type;
190 memcpy(bi_next, new, size);
191 bi_next += size;
194 #if 0
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"
200 void
201 mkatagparams(unsigned addr, char *kcmd)
203 struct tag {
204 unsigned siz;
205 unsigned tag;
206 unsigned val[1];
208 struct tag *p;
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;
218 p->tag = ATAG_CORE;
219 p->siz = tagsize(3);
220 p->val[0] = 0; /* flags */
221 p->val[1] = 0; /* pagesize */
222 p->val[2] = 0; /* rootdev */
223 p = tagnext(p);
224 p->tag = ATAG_MEM;
225 p->siz = tagsize(2);
226 p->val[0] = 64 * 1024 * 1024;
227 p->val[1] = 0; /* start */
228 p = tagnext(p);
229 if (kcmd != NULL) {
230 p = tagnext(p);
231 p->tag = ATAG_CMDLINE;
232 p->siz = tagsize((strlen(kcmd) + 1 + 3) >> 2);
233 strcpy((void *)p->val, kcmd);
235 p = tagnext(p);
236 p->tag = ATAG_NONE;
237 p->siz = 0;
239 #endif