summaryrefslogtreecommitdiffstats
path: root/sys/boot
diff options
context:
space:
mode:
authorraj <raj@FreeBSD.org>2008-09-03 17:48:41 +0000
committerraj <raj@FreeBSD.org>2008-09-03 17:48:41 +0000
commit6997451f836d8272f2757d753e07ca8db038cdab (patch)
tree9f80471a654432e5c01c980e48859aa9f7411fe9 /sys/boot
parent1a861ba7af7797b7aa5777c8ab85ee5dd31063cc (diff)
downloadFreeBSD-src-6997451f836d8272f2757d753e07ca8db038cdab.zip
FreeBSD-src-6997451f836d8272f2757d753e07ca8db038cdab.tar.gz
Improve loader support for U-Boot.
- add new diag commands: devinfo, sysinfo for U-Boot-style details about the system configuration - better memory info summary - style corrections Obtained from: Semihalf
Diffstat (limited to 'sys/boot')
-rw-r--r--sys/boot/uboot/common/main.c119
-rw-r--r--sys/boot/uboot/lib/glue.c92
-rw-r--r--sys/boot/uboot/lib/glue.h42
3 files changed, 188 insertions, 65 deletions
diff --git a/sys/boot/uboot/common/main.c b/sys/boot/uboot/common/main.c
index 7498c76..f7a0745 100644
--- a/sys/boot/uboot/common/main.c
+++ b/sys/boot/uboot/common/main.c
@@ -1,7 +1,7 @@
/*-
* Copyright (c) 2000 Benno Rice <benno@jeamland.net>
* Copyright (c) 2000 Stephane Potvin <sepotvin@videotron.ca>
- * Copyright (c) 2007 Semihalf, Rafal Jaworowski <raj@semihalf.com>
+ * Copyright (c) 2007-2008 Semihalf, Rafal Jaworowski <raj@semihalf.com>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -36,9 +36,9 @@ __FBSDID("$FreeBSD$");
#include "glue.h"
#include "libuboot.h"
-struct uboot_devdesc currdev;
-struct arch_switch archsw; /* MI/MD interface boundary */
-int devs_no;
+struct uboot_devdesc currdev;
+struct arch_switch archsw; /* MI/MD interface boundary */
+int devs_no;
extern char end[];
extern char bootprog_name[];
@@ -53,17 +53,8 @@ extern unsigned char __sbss_start[];
extern unsigned char __sbss_end[];
extern unsigned char _end[];
-void dump_si(struct sys_info *si)
-{
-#ifdef DEBUG
- printf("sys info:\n");
- printf(" clkbus\t= 0x%08x\n", si->clk_bus);
- printf(" clkcpu\t= 0x%08x\n", si->clk_cpu);
- printf(" bar\t\t= 0x%08x\n", si->bar);
-#endif
-}
-
-static void dump_sig(struct api_signature *sig)
+static void
+dump_sig(struct api_signature *sig)
{
#ifdef DEBUG
printf("signature:\n");
@@ -72,30 +63,27 @@ static void dump_sig(struct api_signature *sig)
printf(" sc entry\t= 0x%08x\n", sig->syscall);
#endif
}
+
static void
dump_addr_info(void)
{
#ifdef DEBUG
printf("\naddresses info:\n");
- printf(" _etext (sdata) = 0x%08x\n", (u_int32_t)_etext);
- printf(" _edata = 0x%08x\n", (u_int32_t)_edata);
- printf(" __sbss_start = 0x%08x\n", (u_int32_t)__sbss_start);
- printf(" __sbss_end = 0x%08x\n", (u_int32_t)__sbss_end);
- printf(" __sbss_start = 0x%08x\n", (u_int32_t)__bss_start);
- printf(" _end = 0x%08x\n", (u_int32_t)_end);
- printf(" syscall entry = 0x%08x\n", (u_int32_t)syscall_ptr);
+ printf(" _etext (sdata) = 0x%08x\n", (uint32_t)_etext);
+ printf(" _edata = 0x%08x\n", (uint32_t)_edata);
+ printf(" __sbss_start = 0x%08x\n", (uint32_t)__sbss_start);
+ printf(" __sbss_end = 0x%08x\n", (uint32_t)__sbss_end);
+ printf(" __sbss_start = 0x%08x\n", (uint32_t)__bss_start);
+ printf(" _end = 0x%08x\n", (uint32_t)_end);
+ printf(" syscall entry = 0x%08x\n", (uint32_t)syscall_ptr);
#endif
}
static uint64_t
-memsize(int flags)
+memsize(struct sys_info *si, int flags)
{
- int i;
- struct sys_info *si;
- uint64_t size;
-
- if ((si = ub_get_sys_info()) == NULL)
- return 0;
+ uint64_t size;
+ int i;
size = 0;
for (i = 0; i < si->mr_no; i++)
@@ -105,6 +93,25 @@ memsize(int flags)
return (size);
}
+static void
+meminfo(void)
+{
+ uint64_t size;
+ struct sys_info *si;
+ int t[3] = { MR_ATTR_DRAM, MR_ATTR_FLASH, MR_ATTR_SRAM };
+ int i;
+
+ if ((si = ub_get_sys_info()) == NULL)
+ panic("could not retrieve system info");
+
+ for (i = 0; i < 3; i++) {
+ size = memsize(si, t[i]);
+ if (size > 0)
+ printf("%s:\t %lldMB\n", ub_mem_type(t[i]),
+ size / 1024 / 1024);
+ }
+}
+
int
main(void)
{
@@ -112,14 +119,14 @@ main(void)
int i;
if (!api_search_sig(&sig))
- return -1;
+ return (-1);
syscall_ptr = sig->syscall;
if (syscall_ptr == NULL)
- return -2;
+ return (-2);
if (sig->version > API_SIG_VERSION)
- return -3;
+ return (-3);
/* Clear BSS sections */
bzero(__sbss_start, __sbss_end - __sbss_start);
@@ -146,10 +153,9 @@ main(void)
* Enumerate U-Boot devices
*/
if ((devs_no = ub_dev_enum()) == 0)
- panic("no devices found");
- printf("Number of U-Boot devices found %d\n", devs_no);
+ panic("no U-Boot devices found");
+ printf("Number of U-Boot devices: %d\n", devs_no);
- /* XXX all our dv_init()s currently don't do anything... */
/*
* March through the device switch probing for things.
*/
@@ -160,9 +166,7 @@ main(void)
printf("\n");
printf("%s, Revision %s\n", bootprog_name, bootprog_rev);
printf("(%s, %s)\n", bootprog_maker, bootprog_date);
- printf("Memory: %lldMB\n", memsize(MR_ATTR_DRAM) / 1024 / 1024);
- printf("FLASH: %lldMB\n", memsize(MR_ATTR_FLASH) / 1024 / 1024);
-// printf("SRAM: %lldMB\n", memsize(MR_ATTR_SRAM) / 1024 / 1024);
+ meminfo();
/* XXX only support netbooting for now */
for (i = 0; devsw[i] != NULL; i++)
@@ -193,7 +197,7 @@ main(void)
interact(); /* doesn't return */
- return 0;
+ return (0);
}
@@ -205,7 +209,7 @@ command_heap(int argc, char *argv[])
printf("heap base at %p, top at %p, used %d\n", end, sbrk(0),
sbrk(0) - end);
- return(CMD_OK);
+ return (CMD_OK);
}
COMMAND_SET(reboot, "reboot", "reboot the system", command_reboot);
@@ -218,3 +222,38 @@ command_reboot(int argc, char *argv[])
printf("Reset failed!\n");
while(1);
}
+
+COMMAND_SET(devinfo, "devinfo", "show U-Boot devices", command_devinfo);
+static int
+command_devinfo(int argc, char *argv[])
+{
+ int i;
+
+ if ((devs_no = ub_dev_enum()) == 0) {
+ command_errmsg = "no U-Boot devices found!?";
+ return (CMD_ERROR);
+ }
+
+ printf("U-Boot devices:\n");
+ for (i = 0; i < devs_no; i++) {
+ ub_dump_di(i);
+ printf("\n");
+ }
+ return (CMD_OK);
+}
+
+COMMAND_SET(sysinfo, "sysinfo", "show U-Boot system info", command_sysinfo);
+static int
+command_sysinfo(int argc, char *argv[])
+{
+ struct sys_info *si;
+
+ if ((si = ub_get_sys_info()) == NULL) {
+ command_errmsg = "could not retrieve U-Boot sys info!?";
+ return (CMD_ERROR);
+ }
+
+ printf("U-Boot system info:\n");
+ ub_dump_si(si);
+ return (CMD_OK);
+}
diff --git a/sys/boot/uboot/lib/glue.c b/sys/boot/uboot/lib/glue.c
index fe982d6..0aca89c 100644
--- a/sys/boot/uboot/lib/glue.c
+++ b/sys/boot/uboot/lib/glue.c
@@ -1,5 +1,5 @@
/*-
- * Copyright (c) 2007 Semihalf, Rafal Jaworowski <raj@semihalf.com>
+ * Copyright (c) 2007-2008 Semihalf, Rafal Jaworowski <raj@semihalf.com>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -41,7 +41,7 @@ __FBSDID("$FreeBSD$");
#endif
/* Some random address used by U-Boot. */
-extern long uboot_address;
+extern long uboot_address;
/* crc32 stuff stolen from lib/libdisk/write_ia64_disk.c */
static uint32_t crc32_tab[] = {
@@ -138,7 +138,6 @@ valid_sig(struct api_signature *sig)
int
api_search_sig(struct api_signature **sig)
{
-
unsigned char *sp, *spend;
if (sig == NULL)
@@ -176,7 +175,7 @@ ub_getc(void)
if (!syscall(API_GETC, NULL, (uint32_t)&c))
return (-1);
- return c;
+ return (c);
}
int
@@ -187,7 +186,7 @@ ub_tstc(void)
if (!syscall(API_TSTC, NULL, (uint32_t)&t))
return (-1);
- return t;
+ return (t);
}
void
@@ -313,7 +312,7 @@ ub_dev_enum(void)
di->cookie = devices[n - 1].cookie;
if (!syscall(API_DEV_ENUM, NULL, di))
- return 0;
+ return (0);
}
return (n);
@@ -461,6 +460,87 @@ ub_dev_send(int handle, void *buf, int len)
return (err);
}
+static char *
+ub_stor_type(int type)
+{
+
+ if (type & DT_STOR_IDE)
+ return ("IDE");
+
+ if (type & DT_STOR_SCSI)
+ return ("SCSI");
+
+ if (type & DT_STOR_USB)
+ return ("USB");
+
+ if (type & DT_STOR_MMC);
+ return ("MMC");
+
+ return ("Unknown");
+}
+
+char *
+ub_mem_type(int flags)
+{
+
+ switch(flags & 0x000F) {
+ case MR_ATTR_FLASH:
+ return ("FLASH");
+ case MR_ATTR_DRAM:
+ return ("DRAM");
+ case MR_ATTR_SRAM:
+ return ("SRAM");
+ default:
+ return ("Unknown");
+ }
+}
+
+void
+ub_dump_di(int handle)
+{
+ struct device_info *di = ub_dev_get(handle);
+ int i;
+
+ printf("device info (%d):\n", handle);
+ printf(" cookie\t= 0x%08x\n", (uint32_t)di->cookie);
+ printf(" type\t\t= 0x%08x\n", di->type);
+
+ if (di->type == DEV_TYP_NET) {
+ printf(" hwaddr\t= ");
+ for (i = 0; i < 6; i++)
+ printf("%02x ", di->di_net.hwaddr[i]);
+
+ printf("\n");
+
+ } else if (di->type & DEV_TYP_STOR) {
+ printf(" type\t\t= %s\n", ub_stor_type(di->type));
+ printf(" blk size\t\t= %ld\n", di->di_stor.block_size);
+ printf(" blk count\t\t= %ld\n", di->di_stor.block_count);
+ }
+}
+
+void
+ub_dump_si(struct sys_info *si)
+{
+ int i;
+
+ printf("sys info:\n");
+ printf(" clkbus\t= %ld MHz\n", si->clk_bus / 1000 / 1000);
+ printf(" clkcpu\t= %ld MHz\n", si->clk_cpu / 1000 / 1000);
+ printf(" bar\t\t= 0x%08lx\n", si->bar);
+
+ printf("---\n");
+ for (i = 0; i < si->mr_no; i++) {
+ if (si->mr[i].flags == 0)
+ break;
+
+ printf(" start\t= 0x%08lx\n", si->mr[i].start);
+ printf(" size\t= 0x%08lx\n", si->mr[i].size);
+ printf(" type\t= %s\n", ub_mem_type(si->mr[i].flags));
+ printf("---\n");
+ }
+}
+
/****************************************
*
* env vars
diff --git a/sys/boot/uboot/lib/glue.h b/sys/boot/uboot/lib/glue.h
index 72aff3b..06944b2 100644
--- a/sys/boot/uboot/lib/glue.h
+++ b/sys/boot/uboot/lib/glue.h
@@ -35,10 +35,10 @@
#include "api_public.h"
-int syscall(int, int *, ...);
-void *syscall_ptr;
+int syscall(int, int *, ...);
+void *syscall_ptr;
-int api_search_sig(struct api_signature **sig);
+int api_search_sig(struct api_signature **sig);
/*
* The ub_ library calls are part of the application, not U-Boot code! They
@@ -48,32 +48,36 @@ int api_search_sig(struct api_signature **sig);
*/
/* console */
-int ub_getc(void);
-int ub_tstc(void);
-void ub_putc(char c);
-void ub_puts(const char *s);
+int ub_getc(void);
+int ub_tstc(void);
+void ub_putc(char c);
+void ub_puts(const char *s);
/* system */
-void ub_reset(void);
+void ub_reset(void);
struct sys_info *ub_get_sys_info(void);
/* time */
-void ub_udelay(unsigned long);
-unsigned long ub_get_timer(unsigned long);
+void ub_udelay(unsigned long);
+unsigned long ub_get_timer(unsigned long);
/* env vars */
-char *ub_env_get(const char *name);
-void ub_env_set(const char *name, char *value);
-const char *ub_env_enum(const char *last);
+char *ub_env_get(const char *name);
+void ub_env_set(const char *name, char *value);
+const char *ub_env_enum(const char *last);
/* devices */
-int ub_dev_enum(void);
-int ub_dev_open(int handle);
-int ub_dev_close(int handle);
-int ub_dev_read(int handle, void *buf, lbasize_t len, lbastart_t start);
-int ub_dev_send(int handle, void *buf, int len);
-int ub_dev_recv(int handle, void *buf, int len);
+int ub_dev_enum(void);
+int ub_dev_open(int handle);
+int ub_dev_close(int handle);
+int ub_dev_read(int handle, void *buf, lbasize_t len, lbastart_t start);
+int ub_dev_send(int handle, void *buf, int len);
+int ub_dev_recv(int handle, void *buf, int len);
struct device_info * ub_dev_get(int);
+void ub_dump_di(int);
+void ub_dump_si(struct sys_info *);
+char *ub_mem_type(int);
+
#endif /* _API_GLUE_H_ */
OpenPOWER on IntegriCloud