2 * Copyright (c) 2000 Benno Rice <benno@jeamland.net>
3 * Copyright (c) 2000 Stephane Potvin <sepotvin@videotron.ca>
4 * Copyright (c) 2007-2008 Semihalf, Rafal Jaworowski <raj@semihalf.com>
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 #include <sys/cdefs.h>
30 __FBSDID("$FreeBSD$");
34 #include "api_public.h"
35 #include "bootstrap.h"
39 struct uboot_devdesc currdev;
40 struct arch_switch archsw; /* MI/MD interface boundary */
44 extern char bootprog_name[];
45 extern char bootprog_rev[];
46 extern char bootprog_date[];
47 extern char bootprog_maker[];
49 extern unsigned char _etext[];
50 extern unsigned char _edata[];
51 extern unsigned char __bss_start[];
52 extern unsigned char __sbss_start[];
53 extern unsigned char __sbss_end[];
54 extern unsigned char _end[];
57 dump_sig(struct api_signature *sig)
60 printf("signature:\n");
61 printf(" version\t= %d\n", sig->version);
62 printf(" checksum\t= 0x%08x\n", sig->checksum);
63 printf(" sc entry\t= 0x%08x\n", sig->syscall);
71 printf("\naddresses info:\n");
72 printf(" _etext (sdata) = 0x%08x\n", (uint32_t)_etext);
73 printf(" _edata = 0x%08x\n", (uint32_t)_edata);
74 printf(" __sbss_start = 0x%08x\n", (uint32_t)__sbss_start);
75 printf(" __sbss_end = 0x%08x\n", (uint32_t)__sbss_end);
76 printf(" __sbss_start = 0x%08x\n", (uint32_t)__bss_start);
77 printf(" _end = 0x%08x\n", (uint32_t)_end);
78 printf(" syscall entry = 0x%08x\n", (uint32_t)syscall_ptr);
83 memsize(struct sys_info *si, int flags)
89 for (i = 0; i < si->mr_no; i++)
90 if (si->mr[i].flags == flags && si->mr[i].size)
91 size += (si->mr[i].size);
101 int t[3] = { MR_ATTR_DRAM, MR_ATTR_FLASH, MR_ATTR_SRAM };
104 if ((si = ub_get_sys_info()) == NULL)
105 panic("could not retrieve system info");
107 for (i = 0; i < 3; i++) {
108 size = memsize(si, t[i]);
110 printf("%s:\t %lldMB\n", ub_mem_type(t[i]),
118 struct api_signature *sig = NULL;
121 if (!api_search_sig(&sig))
124 syscall_ptr = sig->syscall;
125 if (syscall_ptr == NULL)
128 if (sig->version > API_SIG_VERSION)
131 /* Clear BSS sections */
132 bzero(__sbss_start, __sbss_end - __sbss_start);
133 bzero(__bss_start, _end - __bss_start);
140 printf("Compatible API signature found @%x\n", (uint32_t)sig);
146 * Initialise the heap as early as possible. Once this is done,
147 * alloc() is usable. The stack is buried inside us, so this is
150 setheap((void *)end, (void *)(end + 512 * 1024));
153 * Enumerate U-Boot devices
155 if ((devs_no = ub_dev_enum()) == 0)
156 panic("no U-Boot devices found");
157 printf("Number of U-Boot devices: %d\n", devs_no);
160 * March through the device switch probing for things.
162 for (i = 0; devsw[i] != NULL; i++)
163 if (devsw[i]->dv_init != NULL)
164 (devsw[i]->dv_init)();
167 printf("%s, Revision %s\n", bootprog_name, bootprog_rev);
168 printf("(%s, %s)\n", bootprog_maker, bootprog_date);
171 /* XXX only support netbooting for now */
172 for (i = 0; devsw[i] != NULL; i++)
173 if (strncmp(devsw[i]->dv_name, "net",
174 strlen(devsw[i]->dv_name)) == 0)
177 if (devsw[i] == NULL)
178 panic("no network devices?!");
180 currdev.d_dev = devsw[i];
181 currdev.d_type = currdev.d_dev->dv_type;
184 env_setenv("currdev", EV_VOLATILE, uboot_fmtdev(&currdev),
185 uboot_setcurrdev, env_nounset);
186 env_setenv("loaddev", EV_VOLATILE, uboot_fmtdev(&currdev),
187 env_noset, env_nounset);
189 setenv("LINES", "24", 1); /* optional */
190 setenv("prompt", "loader>", 1);
192 archsw.arch_getdev = uboot_getdev;
193 archsw.arch_copyin = uboot_copyin;
194 archsw.arch_copyout = uboot_copyout;
195 archsw.arch_readin = uboot_readin;
196 archsw.arch_autoload = uboot_autoload;
198 interact(); /* doesn't return */
204 COMMAND_SET(heap, "heap", "show heap usage", command_heap);
206 command_heap(int argc, char *argv[])
209 printf("heap base at %p, top at %p, used %d\n", end, sbrk(0),
215 COMMAND_SET(reboot, "reboot", "reboot the system", command_reboot);
217 command_reboot(int argc, char *argv[])
220 printf("Resetting...\n");
223 printf("Reset failed!\n");
227 COMMAND_SET(devinfo, "devinfo", "show U-Boot devices", command_devinfo);
229 command_devinfo(int argc, char *argv[])
233 if ((devs_no = ub_dev_enum()) == 0) {
234 command_errmsg = "no U-Boot devices found!?";
238 printf("U-Boot devices:\n");
239 for (i = 0; i < devs_no; i++) {
246 COMMAND_SET(sysinfo, "sysinfo", "show U-Boot system info", command_sysinfo);
248 command_sysinfo(int argc, char *argv[])
252 if ((si = ub_get_sys_info()) == NULL) {
253 command_errmsg = "could not retrieve U-Boot sys info!?";
257 printf("U-Boot system info:\n");