[Midnightbsd-cvs] src [10184] trunk/sys/boot/uboot: sync with freebsd 10
laffer1 at midnightbsd.org
laffer1 at midnightbsd.org
Fri Jun 1 19:20:45 EDT 2018
Revision: 10184
http://svnweb.midnightbsd.org/src/?rev=10184
Author: laffer1
Date: 2018-06-01 19:20:45 -0400 (Fri, 01 Jun 2018)
Log Message:
-----------
sync with freebsd 10
Modified Paths:
--------------
trunk/sys/boot/uboot/Makefile
trunk/sys/boot/uboot/Makefile.inc
trunk/sys/boot/uboot/common/main.c
trunk/sys/boot/uboot/common/metadata.c
trunk/sys/boot/uboot/lib/Makefile
trunk/sys/boot/uboot/lib/api_public.h
trunk/sys/boot/uboot/lib/console.c
trunk/sys/boot/uboot/lib/copy.c
trunk/sys/boot/uboot/lib/devicename.c
trunk/sys/boot/uboot/lib/disk.c
trunk/sys/boot/uboot/lib/elf_freebsd.c
trunk/sys/boot/uboot/lib/glue.c
trunk/sys/boot/uboot/lib/glue.h
trunk/sys/boot/uboot/lib/libuboot.h
trunk/sys/boot/uboot/lib/module.c
trunk/sys/boot/uboot/lib/net.c
trunk/sys/boot/uboot/lib/reboot.c
trunk/sys/boot/uboot/lib/time.c
Added Paths:
-----------
trunk/sys/boot/uboot/fdt/
trunk/sys/boot/uboot/fdt/Makefile
trunk/sys/boot/uboot/fdt/uboot_fdt.c
Property Changed:
----------------
trunk/sys/boot/uboot/Makefile.inc
trunk/sys/boot/uboot/common/Makefile.inc
Modified: trunk/sys/boot/uboot/Makefile
===================================================================
--- trunk/sys/boot/uboot/Makefile 2018-06-01 23:17:30 UTC (rev 10183)
+++ trunk/sys/boot/uboot/Makefile 2018-06-01 23:20:45 UTC (rev 10184)
@@ -1,5 +1,12 @@
# $MidnightBSD$
+# $FreeBSD: stable/10/sys/boot/uboot/Makefile 275763 2014-12-14 15:33:45Z andrew $
+.include <bsd.own.mk>
+
SUBDIR= lib
+.if ${MK_FDT} != "no"
+SUBDIR+=fdt
+.endif
+
.include <bsd.subdir.mk>
Modified: trunk/sys/boot/uboot/Makefile.inc
===================================================================
--- trunk/sys/boot/uboot/Makefile.inc 2018-06-01 23:17:30 UTC (rev 10183)
+++ trunk/sys/boot/uboot/Makefile.inc 2018-06-01 23:20:45 UTC (rev 10184)
@@ -2,7 +2,7 @@
.if ${MACHINE_ARCH} == "powerpc64"
CFLAGS+= -m32 -mcpu=powerpc
-LDFLAGS+= -m elf32ppc
+LDFLAGS+= -m elf32ppc_fbsd
.endif
.include "../Makefile.inc"
Property changes on: trunk/sys/boot/uboot/Makefile.inc
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Index: trunk/sys/boot/uboot/common/Makefile.inc
===================================================================
--- trunk/sys/boot/uboot/common/Makefile.inc 2018-06-01 23:17:30 UTC (rev 10183)
+++ trunk/sys/boot/uboot/common/Makefile.inc 2018-06-01 23:20:45 UTC (rev 10184)
Property changes on: trunk/sys/boot/uboot/common/Makefile.inc
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Modified: trunk/sys/boot/uboot/common/main.c
===================================================================
--- trunk/sys/boot/uboot/common/main.c 2018-06-01 23:17:30 UTC (rev 10183)
+++ trunk/sys/boot/uboot/common/main.c 2018-06-01 23:20:45 UTC (rev 10184)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*-
* Copyright (c) 2000 Benno Rice <benno at jeamland.net>
* Copyright (c) 2000 Stephane Potvin <sepotvin at videotron.ca>
@@ -27,7 +28,8 @@
*/
#include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/boot/uboot/common/main.c 294346 2016-01-19 21:42:19Z ian $");
+#include <sys/param.h>
#include <stand.h>
@@ -36,10 +38,30 @@
#include "glue.h"
#include "libuboot.h"
+#ifndef nitems
+#define nitems(x) (sizeof((x)) / sizeof((x)[0]))
+#endif
+
struct uboot_devdesc currdev;
struct arch_switch archsw; /* MI/MD interface boundary */
int devs_no;
+uintptr_t uboot_heap_start;
+uintptr_t uboot_heap_end;
+
+struct device_type {
+ const char *name;
+ int type;
+} device_types[] = {
+ { "disk", DEV_TYP_STOR },
+ { "ide", DEV_TYP_STOR | DT_STOR_IDE },
+ { "mmc", DEV_TYP_STOR | DT_STOR_MMC },
+ { "sata", DEV_TYP_STOR | DT_STOR_SATA },
+ { "scsi", DEV_TYP_STOR | DT_STOR_SCSI },
+ { "usb", DEV_TYP_STOR | DT_STOR_USB },
+ { "net", DEV_TYP_NET }
+};
+
extern char end[];
extern char bootprog_name[];
extern char bootprog_rev[];
@@ -111,27 +133,283 @@
for (i = 0; i < 3; i++) {
size = memsize(si, t[i]);
if (size > 0)
- printf("%s:\t %lldMB\n", ub_mem_type(t[i]),
+ printf("%s: %lldMB\n", ub_mem_type(t[i]),
size / 1024 / 1024);
}
}
+static const char *
+get_device_type(const char *devstr, int *devtype)
+{
+ int i;
+ int namelen;
+ struct device_type *dt;
+
+ if (devstr) {
+ for (i = 0; i < nitems(device_types); i++) {
+ dt = &device_types[i];
+ namelen = strlen(dt->name);
+ if (strncmp(dt->name, devstr, namelen) == 0) {
+ *devtype = dt->type;
+ return (devstr + namelen);
+ }
+ }
+ printf("Unknown device type '%s'\n", devstr);
+ }
+
+ *devtype = -1;
+ return (NULL);
+}
+
+static const char *
+device_typename(int type)
+{
+ int i;
+
+ for (i = 0; i < nitems(device_types); i++)
+ if (device_types[i].type == type)
+ return (device_types[i].name);
+
+ return ("<unknown>");
+}
+
+/*
+ * Parse a device string into type, unit, slice and partition numbers. A
+ * returned value of -1 for type indicates a search should be done for the
+ * first loadable device, otherwise a returned value of -1 for unit
+ * indicates a search should be done for the first loadable device of the
+ * given type.
+ *
+ * The returned values for slice and partition are interpreted by
+ * disk_open().
+ *
+ * Valid device strings: For device types:
+ *
+ * <type_name> DEV_TYP_STOR, DEV_TYP_NET
+ * <type_name><unit> DEV_TYP_STOR, DEV_TYP_NET
+ * <type_name><unit>: DEV_TYP_STOR, DEV_TYP_NET
+ * <type_name><unit>:<slice> DEV_TYP_STOR
+ * <type_name><unit>:<slice>. DEV_TYP_STOR
+ * <type_name><unit>:<slice>.<partition> DEV_TYP_STOR
+ *
+ * For valid type names, see the device_types array, above.
+ *
+ * Slice numbers are 1-based. 0 is a wildcard.
+ */
+static void
+get_load_device(int *type, int *unit, int *slice, int *partition)
+{
+ char *devstr;
+ const char *p;
+ char *endp;
+
+ *type = -1;
+ *unit = -1;
+ *slice = 0;
+ *partition = -1;
+
+ devstr = ub_env_get("loaderdev");
+ if (devstr == NULL) {
+ printf("U-Boot env: loaderdev not set, will probe all devices.\n");
+ return;
+ }
+ printf("U-Boot env: loaderdev='%s'\n", devstr);
+
+ p = get_device_type(devstr, type);
+
+ /* Ignore optional spaces after the device name. */
+ while (*p == ' ')
+ p++;
+
+ /* Unknown device name, or a known name without unit number. */
+ if ((*type == -1) || (*p == '\0')) {
+ return;
+ }
+
+ /* Malformed unit number. */
+ if (!isdigit(*p)) {
+ *type = -1;
+ return;
+ }
+
+ /* Guaranteed to extract a number from the string, as *p is a digit. */
+ *unit = strtol(p, &endp, 10);
+ p = endp;
+
+ /* Known device name with unit number and nothing else. */
+ if (*p == '\0') {
+ return;
+ }
+
+ /* Device string is malformed beyond unit number. */
+ if (*p != ':') {
+ *type = -1;
+ *unit = -1;
+ return;
+ }
+
+ p++;
+
+ /* No slice and partition specification. */
+ if ('\0' == *p )
+ return;
+
+ /* Only DEV_TYP_STOR devices can have a slice specification. */
+ if (!(*type & DEV_TYP_STOR)) {
+ *type = -1;
+ *unit = -1;
+ return;
+ }
+
+ *slice = strtoul(p, &endp, 10);
+
+ /* Malformed slice number. */
+ if (p == endp) {
+ *type = -1;
+ *unit = -1;
+ *slice = 0;
+ return;
+ }
+
+ p = endp;
+
+ /* No partition specification. */
+ if (*p == '\0')
+ return;
+
+ /* Device string is malformed beyond slice number. */
+ if (*p != '.') {
+ *type = -1;
+ *unit = -1;
+ *slice = 0;
+ return;
+ }
+
+ p++;
+
+ /* No partition specification. */
+ if (*p == '\0')
+ return;
+
+ *partition = strtol(p, &endp, 10);
+ p = endp;
+
+ /* Full, valid device string. */
+ if (*endp == '\0')
+ return;
+
+ /* Junk beyond partition number. */
+ *type = -1;
+ *unit = -1;
+ *slice = 0;
+ *partition = -1;
+}
+
+static void
+print_disk_probe_info()
+{
+ char slice[32];
+ char partition[32];
+
+ if (currdev.d_disk.slice > 0)
+ sprintf(slice, "%d", currdev.d_disk.slice);
+ else
+ strcpy(slice, "<auto>");
+
+ if (currdev.d_disk.partition >= 0)
+ sprintf(partition, "%d", currdev.d_disk.partition);
+ else
+ strcpy(partition, "<auto>");
+
+ printf(" Checking unit=%d slice=%s partition=%s...",
+ currdev.d_unit, slice, partition);
+
+}
+
+static int
+probe_disks(int devidx, int load_type, int load_unit, int load_slice,
+ int load_partition)
+{
+ int open_result, unit;
+ struct open_file f;
+
+ currdev.d_disk.slice = load_slice;
+ currdev.d_disk.partition = load_partition;
+
+ f.f_devdata = &currdev;
+ open_result = -1;
+
+ if (load_type == -1) {
+ printf(" Probing all disk devices...\n");
+ /* Try each disk in succession until one works. */
+ for (currdev.d_unit = 0; currdev.d_unit < UB_MAX_DEV;
+ currdev.d_unit++) {
+ print_disk_probe_info();
+ open_result = devsw[devidx]->dv_open(&f, &currdev);
+ if (open_result == 0) {
+ printf(" good.\n");
+ return (0);
+ }
+ printf("\n");
+ }
+ return (-1);
+ }
+
+ if (load_unit == -1) {
+ printf(" Probing all %s devices...\n", device_typename(load_type));
+ /* Try each disk of given type in succession until one works. */
+ for (unit = 0; unit < UB_MAX_DEV; unit++) {
+ currdev.d_unit = uboot_diskgetunit(load_type, unit);
+ if (currdev.d_unit == -1)
+ break;
+ print_disk_probe_info();
+ open_result = devsw[devidx]->dv_open(&f, &currdev);
+ if (open_result == 0) {
+ printf(" good.\n");
+ return (0);
+ }
+ printf("\n");
+ }
+ return (-1);
+ }
+
+ if ((currdev.d_unit = uboot_diskgetunit(load_type, load_unit)) != -1) {
+ print_disk_probe_info();
+ open_result = devsw[devidx]->dv_open(&f,&currdev);
+ if (open_result == 0) {
+ printf(" good.\n");
+ return (0);
+ }
+ printf("\n");
+ }
+
+ printf(" Requested disk type/unit/slice/partition not found\n");
+ return (-1);
+}
+
int
main(void)
{
struct api_signature *sig = NULL;
+ int load_type, load_unit, load_slice, load_partition;
int i;
- struct open_file f;
+ const char *ldev;
+ /*
+ * If we can't find the magic signature and related info, exit with a
+ * unique error code that U-Boot reports as "## Application terminated,
+ * rc = 0xnnbadab1". Hopefully 'badab1' looks enough like "bad api" to
+ * provide a clue. It's better than 0xffffffff anyway.
+ */
if (!api_search_sig(&sig))
- return (-1);
+ return (0x01badab1);
syscall_ptr = sig->syscall;
if (syscall_ptr == NULL)
- return (-2);
+ return (0x02badab1);
if (sig->version > API_SIG_VERSION)
- return (-3);
+ return (0x03badab1);
/* Clear BSS sections */
bzero(__sbss_start, __sbss_end - __sbss_start);
@@ -138,21 +416,28 @@
bzero(__bss_start, _end - __bss_start);
/*
- * Set up console.
- */
+ * Initialise the heap as early as possible. Once this is done,
+ * alloc() is usable. The stack is buried inside us, so this is safe.
+ */
+ uboot_heap_start = round_page((uintptr_t)end);
+ uboot_heap_end = uboot_heap_start + 512 * 1024;
+ setheap((void *)uboot_heap_start, (void *)uboot_heap_end);
+
+ /*
+ * Set up console.
+ */
cons_probe();
+ printf("Compatible U-Boot API signature found @%x\n", (uint32_t)sig);
- printf("Compatible API signature found @%x\n", (uint32_t)sig);
+ printf("\n");
+ printf("%s, Revision %s\n", bootprog_name, bootprog_rev);
+ printf("(%s, %s)\n", bootprog_maker, bootprog_date);
+ printf("\n");
dump_sig(sig);
dump_addr_info();
- /*
- * Initialise the heap as early as possible. Once this is done,
- * alloc() is usable. The stack is buried inside us, so this is
- * safe.
- */
- setheap((void *)end, (void *)(end + 512 * 1024));
+ meminfo();
/*
* Enumerate U-Boot devices
@@ -161,10 +446,7 @@
panic("no U-Boot devices found");
printf("Number of U-Boot devices: %d\n", devs_no);
- printf("\n");
- printf("%s, Revision %s\n", bootprog_name, bootprog_rev);
- printf("(%s, %s)\n", bootprog_maker, bootprog_date);
- meminfo();
+ get_load_device(&load_type, &load_unit, &load_slice, &load_partition);
/*
* March through the device switch probing for things.
@@ -176,36 +458,43 @@
if ((devsw[i]->dv_init)() != 0)
continue;
- printf("\nDevice: %s\n", devsw[i]->dv_name);
+ printf("Found U-Boot device: %s\n", devsw[i]->dv_name);
currdev.d_dev = devsw[i];
currdev.d_type = currdev.d_dev->dv_type;
currdev.d_unit = 0;
- if (strncmp(devsw[i]->dv_name, "disk",
- strlen(devsw[i]->dv_name)) == 0) {
- f.f_devdata = &currdev;
- currdev.d_disk.slice = 0;
- if (devsw[i]->dv_open(&f,&currdev) == 0)
+ if ((load_type == -1 || (load_type & DEV_TYP_STOR)) &&
+ strcmp(devsw[i]->dv_name, "disk") == 0) {
+ if (probe_disks(i, load_type, load_unit, load_slice,
+ load_partition) == 0)
break;
}
- if (strncmp(devsw[i]->dv_name, "net",
- strlen(devsw[i]->dv_name)) == 0)
+ if ((load_type == -1 || (load_type & DEV_TYP_NET)) &&
+ strcmp(devsw[i]->dv_name, "net") == 0)
break;
}
- if (devsw[i] == NULL)
- panic("No boot device found!");
+ /*
+ * If we couldn't find a boot device, return an error to u-boot.
+ * U-boot may be running a boot script that can try something different
+ * so returning an error is better than forcing a reboot.
+ */
+ if (devsw[i] == NULL) {
+ printf("No boot device found!\n");
+ return (0xbadef1ce);
+ }
- env_setenv("currdev", EV_VOLATILE, uboot_fmtdev(&currdev),
- uboot_setcurrdev, env_nounset);
- env_setenv("loaddev", EV_VOLATILE, uboot_fmtdev(&currdev),
- env_noset, env_nounset);
+ ldev = uboot_fmtdev(&currdev);
+ env_setenv("currdev", EV_VOLATILE, ldev, uboot_setcurrdev, env_nounset);
+ env_setenv("loaddev", EV_VOLATILE, ldev, env_noset, env_nounset);
+ printf("Booting from %s\n", ldev);
setenv("LINES", "24", 1); /* optional */
setenv("prompt", "loader>", 1);
+ archsw.arch_loadaddr = uboot_loadaddr;
archsw.arch_getdev = uboot_getdev;
archsw.arch_copyin = uboot_copyin;
archsw.arch_copyout = uboot_copyout;
@@ -276,6 +565,104 @@
return (CMD_OK);
}
+enum ubenv_action {
+ UBENV_UNKNOWN,
+ UBENV_SHOW,
+ UBENV_IMPORT
+};
+
+static void
+handle_uboot_env_var(enum ubenv_action action, const char * var)
+{
+ char ldvar[128];
+ const char *val;
+ char *wrk;
+ int len;
+
+ /*
+ * On an import with the variable name formatted as ldname=ubname,
+ * import the uboot variable ubname into the loader variable ldname,
+ * otherwise the historical behavior is to import to uboot.ubname.
+ */
+ if (action == UBENV_IMPORT) {
+ len = strcspn(var, "=");
+ if (len == 0) {
+ printf("name cannot start with '=': '%s'\n", var);
+ return;
+ }
+ if (var[len] == 0) {
+ strcpy(ldvar, "uboot.");
+ strncat(ldvar, var, sizeof(ldvar) - 7);
+ } else {
+ len = MIN(len, sizeof(ldvar) - 1);
+ strncpy(ldvar, var, len);
+ ldvar[len] = 0;
+ var = &var[len + 1];
+ }
+ }
+
+ /*
+ * If the user prepended "uboot." (which is how they usually see these
+ * names) strip it off as a convenience.
+ */
+ if (strncmp(var, "uboot.", 6) == 0) {
+ var = &var[6];
+ }
+
+ /* If there is no variable name left, punt. */
+ if (var[0] == 0) {
+ printf("empty variable name\n");
+ return;
+ }
+
+ val = ub_env_get(var);
+ if (action == UBENV_SHOW) {
+ if (val == NULL)
+ printf("uboot.%s is not set\n", var);
+ else
+ printf("uboot.%s=%s\n", var, val);
+ } else if (action == UBENV_IMPORT) {
+ if (val != NULL) {
+ setenv(ldvar, val, 1);
+ }
+ }
+}
+
+static int
+command_ubenv(int argc, char *argv[])
+{
+ enum ubenv_action action;
+ const char *var;
+ int i;
+
+ action = UBENV_UNKNOWN;
+ if (argc > 1) {
+ if (strcasecmp(argv[1], "import") == 0)
+ action = UBENV_IMPORT;
+ else if (strcasecmp(argv[1], "show") == 0)
+ action = UBENV_SHOW;
+ }
+ if (action == UBENV_UNKNOWN) {
+ command_errmsg = "usage: 'ubenv <import|show> [var ...]";
+ return (CMD_ERROR);
+ }
+
+ if (argc > 2) {
+ for (i = 2; i < argc; i++)
+ handle_uboot_env_var(action, argv[i]);
+ } else {
+ var = NULL;
+ for (;;) {
+ if ((var = ub_env_enum(var)) == NULL)
+ break;
+ handle_uboot_env_var(action, var);
+ }
+ }
+
+ return (CMD_OK);
+}
+COMMAND_SET(ubenv, "ubenv", "show or import U-Boot env vars", command_ubenv);
+
#ifdef LOADER_FDT_SUPPORT
/*
* Since proper fdt command handling function is defined in fdt_loader_cmd.c,
Modified: trunk/sys/boot/uboot/common/metadata.c
===================================================================
--- trunk/sys/boot/uboot/common/metadata.c 2018-06-01 23:17:30 UTC (rev 10183)
+++ trunk/sys/boot/uboot/common/metadata.c 2018-06-01 23:20:45 UTC (rev 10184)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*-
* Copyright (c) 1998 Michael Smith <msmith at freebsd.org>
* Copyright (C) 2006 Semihalf, Piotr Kruszynski <ppk at semihalf.com>
@@ -27,12 +28,13 @@
*/
#include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/boot/uboot/common/metadata.c 275763 2014-12-14 15:33:45Z andrew $");
#include <stand.h>
#include <sys/param.h>
#include <sys/reboot.h>
#include <sys/linker.h>
+#include <sys/boot.h>
#include <machine/elf.h>
#include <machine/metadata.h>
@@ -42,36 +44,14 @@
#include "glue.h"
#if defined(LOADER_FDT_SUPPORT)
-extern int fdt_fixup(void);
+#include <fdt_platform.h>
#endif
-/*
- * Return a 'boothowto' value corresponding to the kernel arguments in
- * (kargs) and any relevant environment variables.
- */
-static struct
-{
- const char *ev;
- int mask;
-} howto_names[] = {
- {"boot_askname", RB_ASKNAME},
- {"boot_cdrom", RB_CDROM},
- {"boot_ddb", RB_KDB},
- {"boot_dfltroot", RB_DFLTROOT},
- {"boot_gdb", RB_GDB},
- {"boot_multicons", RB_MULTIPLE},
- {"boot_mute", RB_MUTE},
- {"boot_pause", RB_PAUSE},
- {"boot_serial", RB_SERIAL},
- {"boot_single", RB_SINGLE},
- {"boot_verbose", RB_VERBOSE},
- {NULL, 0}
-};
-
static int
md_getboothowto(char *kargs)
{
char *cp;
+ char *p;
int howto;
int active;
int i;
@@ -132,10 +112,12 @@
if (getenv(howto_names[i].ev) != NULL)
howto |= howto_names[i].mask;
}
- if (!strcmp(getenv("console"), "comconsole"))
- howto |= RB_SERIAL;
- if (!strcmp(getenv("console"), "nullconsole"))
- howto |= RB_MUTE;
+ if ((p = getenv("console"))) {
+ if (!strcmp(p, "comconsole"))
+ howto |= RB_SERIAL;
+ if (!strcmp(p, "nullconsole"))
+ howto |= RB_MUTE;
+ }
return(howto);
}
@@ -276,7 +258,10 @@
vm_offset_t envp;
vm_offset_t size;
vm_offset_t vaddr;
+#if defined(LOADER_FDT_SUPPORT)
vm_offset_t dtbp;
+ int dtb_size;
+#endif
char *rootdevname;
int howto;
int i;
@@ -322,6 +307,16 @@
/* Pad to a page boundary */
addr = roundup(addr, PAGE_SIZE);
+#if defined(LOADER_FDT_SUPPORT)
+ /* Handle device tree blob */
+ dtbp = addr;
+ dtb_size = fdt_copy(addr);
+
+ /* Pad to a page boundary */
+ if (dtb_size)
+ addr += roundup(dtb_size, PAGE_SIZE);
+#endif
+
kernend = 0;
kfp = file_findfile(NULL, "elf32 kernel");
if (kfp == NULL)
@@ -332,9 +327,7 @@
file_addmetadata(kfp, MODINFOMD_ENVP, sizeof envp, &envp);
#if defined(LOADER_FDT_SUPPORT)
- /* Handle device tree blob */
- dtbp = fdt_fixup();
- if (dtbp != (vm_offset_t)NULL)
+ if (dtb_size)
file_addmetadata(kfp, MODINFOMD_DTBP, sizeof dtbp, &dtbp);
else
pager_output("WARNING! Trying to fire up the kernel, but no "
@@ -355,12 +348,15 @@
/* Convert addresses to the final VA */
*modulep -= __elfN(relocation_offset);
- for (i = 0; i < sizeof mdt / sizeof mdt[0]; i++) {
- md = file_findmetadata(kfp, mdt[i]);
- if (md) {
- bcopy(md->md_data, &vaddr, sizeof vaddr);
- vaddr -= __elfN(relocation_offset);
- bcopy(&vaddr, md->md_data, sizeof vaddr);
+ /* Do relocation fixup on metadata of each module. */
+ for (xp = file_findfile(NULL, NULL); xp != NULL; xp = xp->f_next) {
+ for (i = 0; i < sizeof mdt / sizeof mdt[0]; i++) {
+ md = file_findmetadata(xp, mdt[i]);
+ if (md) {
+ bcopy(md->md_data, &vaddr, sizeof vaddr);
+ vaddr -= __elfN(relocation_offset);
+ bcopy(&vaddr, md->md_data, sizeof vaddr);
+ }
}
}
Added: trunk/sys/boot/uboot/fdt/Makefile
===================================================================
--- trunk/sys/boot/uboot/fdt/Makefile (rev 0)
+++ trunk/sys/boot/uboot/fdt/Makefile 2018-06-01 23:20:45 UTC (rev 10184)
@@ -0,0 +1,34 @@
+# $MidnightBSD$
+# $FreeBSD: stable/10/sys/boot/uboot/fdt/Makefile 275763 2014-12-14 15:33:45Z andrew $
+
+.include <bsd.own.mk>
+
+.PATH: ${.CURDIR}/../../common
+
+LIB= uboot_fdt
+INTERNALLIB=
+WARNS?= 2
+
+SRCS= uboot_fdt.c
+
+CFLAGS+= -ffreestanding -msoft-float
+
+CFLAGS+= -I${.CURDIR}/../../../../lib/libstand/
+
+# U-Boot library headers
+CFLAGS+= -I${.CURDIR}/../lib
+
+# libfdt headers
+CFLAGS+= -I${.CURDIR}/../../fdt
+
+# Pick up the bootstrap header for some interface items
+CFLAGS+= -I${.CURDIR}/../../common -I${.CURDIR}/../../.. -I.
+
+machine:
+ ln -sf ${.CURDIR}/../../../${MACHINE_CPUARCH}/include machine
+
+CLEANFILES+= machine
+
+.include <bsd.lib.mk>
+
+beforedepend ${OBJS}: machine
Property changes on: trunk/sys/boot/uboot/fdt/Makefile
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: trunk/sys/boot/uboot/fdt/uboot_fdt.c
===================================================================
--- trunk/sys/boot/uboot/fdt/uboot_fdt.c (rev 0)
+++ trunk/sys/boot/uboot/fdt/uboot_fdt.c 2018-06-01 23:20:45 UTC (rev 10184)
@@ -0,0 +1,180 @@
+/* $MidnightBSD$ */
+/*-
+ * Copyright (c) 2009-2010 The FreeBSD Foundation
+ * All rights reserved.
+ *
+ * This software was developed by Semihalf under sponsorship from
+ * the FreeBSD Foundation.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: stable/10/sys/boot/uboot/fdt/uboot_fdt.c 283409 2015-05-24 15:29:56Z ian $");
+
+#include <sys/param.h>
+#include <stand.h>
+#include <fdt_platform.h>
+
+#include "glue.h"
+
+#define STR(number) #number
+#define STRINGIFY(number) STR(number)
+
+int
+fdt_platform_load_dtb(void)
+{
+ struct fdt_header *hdr;
+ const char *s;
+ char *p;
+
+ /*
+ * If the U-boot environment contains a variable giving the address of a
+ * valid blob in memory, use it. The U-boot README says the right
+ * variable for fdt data loaded into ram is fdt_addr_r, so try that
+ * first. Board vendors also use both fdtaddr and fdt_addr names.
+ */
+ s = ub_env_get("fdt_addr_r");
+ if (s == NULL)
+ s = ub_env_get("fdtaddr");
+ if (s == NULL)
+ s = ub_env_get("fdt_addr");
+ if (s != NULL && *s != '\0') {
+ hdr = (struct fdt_header *)strtoul(s, &p, 16);
+ if (*p == '\0') {
+ if (fdt_load_dtb_addr(hdr) == 0) {
+ printf("Using DTB provided by U-Boot at "
+ "address %p.\n", hdr);
+ return (0);
+ }
+ }
+ }
+
+ /*
+ * If the U-boot environment contains a variable giving the name of a
+ * file, use it if we can load and validate it.
+ */
+ s = ub_env_get("fdtfile");
+ if (s == NULL)
+ s = ub_env_get("fdt_file");
+ if (s != NULL && *s != '\0') {
+ if (fdt_load_dtb_file(s) == 0) {
+ printf("Loaded DTB from file '%s'.\n", s);
+ return (0);
+ }
+ }
+
+ return (1);
+}
+
+void
+fdt_platform_fixups(void)
+{
+ static struct fdt_mem_region regions[UB_MAX_MR];
+ const char *env, *str;
+ char *end, *ethstr;
+ int eth_no, i, len, n;
+ struct sys_info *si;
+
+ env = NULL;
+ eth_no = 0;
+ ethstr = NULL;
+
+ /* Acquire sys_info */
+ si = ub_get_sys_info();
+
+ while ((env = ub_env_enum(env)) != NULL) {
+ if (strncmp(env, "eth", 3) == 0 &&
+ strncmp(env + (strlen(env) - 4), "addr", 4) == 0) {
+ /*
+ * Handle Ethernet addrs: parse uboot env eth%daddr
+ */
+
+ if (!eth_no) {
+ /*
+ * Check how many chars we will need to store
+ * maximal eth iface number.
+ */
+ len = strlen(STRINGIFY(TMP_MAX_ETH)) +
+ strlen("ethernet") + 1;
+
+ /*
+ * Reserve mem for string "ethernet" and len
+ * chars for iface no.
+ */
+ ethstr = (char *)malloc(len * sizeof(char));
+ bzero(ethstr, len * sizeof(char));
+ strcpy(ethstr, "ethernet0");
+ }
+
+ /* Extract interface number */
+ i = strtol(env + 3, &end, 10);
+ if (end == (env + 3))
+ /* 'ethaddr' means interface 0 address */
+ n = 0;
+ else
+ n = i;
+
+ if (n > TMP_MAX_ETH)
+ continue;
+
+ str = ub_env_get(env);
+
+ if (n != 0) {
+ /*
+ * Find the lenght of the interface id by
+ * taking in to account the first 3 and
+ * last 4 characters.
+ */
+ i = strlen(env) - 7;
+ strncpy(ethstr + 8, env + 3, i);
+ }
+
+ /* Modify blob */
+ fdt_fixup_ethernet(str, ethstr, len);
+
+ /* Clear ethernet..XXXX.. string */
+ bzero(ethstr + 8, len - 8);
+
+ if (n + 1 > eth_no)
+ eth_no = n + 1;
+ } else if (strcmp(env, "consoledev") == 0) {
+ str = ub_env_get(env);
+ fdt_fixup_stdout(str);
+ }
+ }
+
+ /* Modify cpu(s) and bus clock frequenties in /cpus node [Hz] */
+ fdt_fixup_cpubusfreqs(si->clk_cpu, si->clk_bus);
+
+ /* Extract the DRAM regions into fdt_mem_region format. */
+ for (i = 0, n = 0; i < si->mr_no && n < nitems(regions); i++) {
+ if (si->mr[i].flags == MR_ATTR_DRAM) {
+ regions[n].start = si->mr[i].start;
+ regions[n].size = si->mr[i].size;
+ n++;
+ }
+ }
+
+ /* Fixup memory regions */
+ fdt_fixup_memory(regions, n);
+}
Property changes on: trunk/sys/boot/uboot/fdt/uboot_fdt.c
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Modified: trunk/sys/boot/uboot/lib/Makefile
===================================================================
--- trunk/sys/boot/uboot/lib/Makefile 2018-06-01 23:17:30 UTC (rev 10183)
+++ trunk/sys/boot/uboot/lib/Makefile 2018-06-01 23:20:45 UTC (rev 10184)
@@ -1,5 +1,8 @@
# $MidnightBSD$
+# $FreeBSD: stable/10/sys/boot/uboot/lib/Makefile 275763 2014-12-14 15:33:45Z andrew $
+.include <bsd.own.mk>
+
.PATH: ${.CURDIR}/../../common
LIB= uboot
@@ -18,6 +21,16 @@
CFLAGS+= -DLOADER_DISK_SUPPORT
.endif
+.if ${MK_FDT} != "no"
+LOADER_FDT_SUPPORT= yes
+.else
+LOADER_FDT_SUPPORT= no
+.endif
+
+.if ${LOADER_FDT_SUPPORT} == "yes"
+CFLAGS+= -DLOADER_FDT_SUPPORT -I${.CURDIR}/../../fdt
+.endif
+
# Pick up FDT includes
CFLAGS+= -I${.CURDIR}/../../../../sys/contrib/libfdt/
Modified: trunk/sys/boot/uboot/lib/api_public.h
===================================================================
--- trunk/sys/boot/uboot/lib/api_public.h 2018-06-01 23:17:30 UTC (rev 10183)
+++ trunk/sys/boot/uboot/lib/api_public.h 2018-06-01 23:20:45 UTC (rev 10184)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*
* (C) Copyright 2007-2008 Semihalf
*
@@ -48,7 +49,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/boot/uboot/lib/api_public.h 265071 2014-04-29 00:45:42Z ian $
*
* This file needs to be kept in sync with U-Boot reference:
* http://www.denx.de/cgi-bin/gitweb.cgi?p=u-boot.git;a=blob;f=include/api_public.h
@@ -132,6 +133,7 @@
#define DT_STOR_SCSI 0x0020
#define DT_STOR_USB 0x0040
#define DT_STOR_MMC 0x0080
+#define DT_STOR_SATA 0x0100
#define DEV_STA_CLOSED 0x0000 /* invalid, closed */
#define DEV_STA_OPEN 0x0001 /* open i.e. active */
Modified: trunk/sys/boot/uboot/lib/console.c
===================================================================
--- trunk/sys/boot/uboot/lib/console.c 2018-06-01 23:17:30 UTC (rev 10183)
+++ trunk/sys/boot/uboot/lib/console.c 2018-06-01 23:20:45 UTC (rev 10184)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*-
* Copyright (c) 2007 Semihalf, Rafal Jaworowski <raj at semihalf.com>
* All rights reserved.
@@ -25,7 +26,7 @@
*/
#include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/boot/uboot/lib/console.c 182723 2008-09-03 15:39:50Z raj $");
#include <stand.h>
#include "bootstrap.h"
Modified: trunk/sys/boot/uboot/lib/copy.c
===================================================================
--- trunk/sys/boot/uboot/lib/copy.c 2018-06-01 23:17:30 UTC (rev 10183)
+++ trunk/sys/boot/uboot/lib/copy.c 2018-06-01 23:20:45 UTC (rev 10184)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*-
* Copyright (c) 1998 Michael Smith <msmith at freebsd.org>
* Copyright (c) 2007 Semihalf, Rafal Jaworowski <raj at semihalf.com>
@@ -26,20 +27,121 @@
*/
#include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/boot/uboot/lib/copy.c 294685 2016-01-24 22:00:36Z ian $");
+#include <sys/param.h>
#include <stand.h>
+#include <stdint.h>
+#include "api_public.h"
+#include "glue.h"
+#include "libuboot.h"
+
/*
* MD primitives supporting placement of module data
+ */
+
+#ifdef __arm__
+#define KERN_ALIGN (2 * 1024 * 1024)
+#else
+#define KERN_ALIGN PAGE_SIZE
+#endif
+
+/*
+ * Avoid low memory, u-boot puts things like args and dtb blobs there.
+ */
+#define KERN_MINADDR max(KERN_ALIGN, (1024 * 1024))
+
+extern void _start(void); /* ubldr entry point address. */
+
+/*
+ * This is called for every object loaded (kernel, module, dtb file, etc). The
+ * expected return value is the next address at or after the given addr which is
+ * appropriate for loading the given object described by type and data. On each
+ * call the addr is the next address following the previously loaded object.
*
- * XXX should check load address/size against memory top.
+ * The first call is for loading the kernel, and the addr argument will be zero,
+ * and we search for a big block of ram to load the kernel and modules.
+ *
+ * On subsequent calls the addr will be non-zero, and we just round it up so
+ * that each object begins on a page boundary.
*/
+uint64_t
+uboot_loadaddr(u_int type, void *data, uint64_t addr)
+{
+ struct sys_info *si;
+ uint64_t sblock, eblock, subldr, eubldr;
+ uint64_t biggest_block, this_block;
+ uint64_t biggest_size, this_size;
+ int i;
+ char *envstr;
+ if (addr == 0) {
+ /*
+ * If the loader_kernaddr environment variable is set, blindly
+ * honor it. It had better be right. We force interpretation
+ * of the value in base-16 regardless of any leading 0x prefix,
+ * because that's the U-Boot convention.
+ */
+ envstr = ub_env_get("loader_kernaddr");
+ if (envstr != NULL)
+ return (strtoul(envstr, NULL, 16));
+
+ /*
+ * Find addr/size of largest DRAM block. Carve our own address
+ * range out of the block, because loading the kernel over the
+ * top ourself is a poor memory-conservation strategy. Avoid
+ * memory at beginning of the first block of physical ram,
+ * since u-boot likes to pass args and data there. Assume that
+ * u-boot has moved itself to the very top of ram and
+ * optimistically assume that we won't run into it up there.
+ */
+ if ((si = ub_get_sys_info()) == NULL)
+ panic("could not retrieve system info");
+
+ biggest_block = 0;
+ biggest_size = 0;
+ subldr = rounddown2((uintptr_t)_start, KERN_ALIGN);
+ eubldr = roundup2((uint64_t)uboot_heap_end, KERN_ALIGN);
+ for (i = 0; i < si->mr_no; i++) {
+ if (si->mr[i].flags != MR_ATTR_DRAM)
+ continue;
+ sblock = roundup2((uint64_t)si->mr[i].start,
+ KERN_ALIGN);
+ eblock = rounddown2((uint64_t)si->mr[i].start +
+ si->mr[i].size, KERN_ALIGN);
+ if (biggest_size == 0)
+ sblock += KERN_MINADDR;
+ if (subldr >= sblock && subldr < eblock) {
+ if (subldr - sblock > eblock - eubldr) {
+ this_block = sblock;
+ this_size = subldr - sblock;
+ } else {
+ this_block = eubldr;
+ this_size = eblock - eubldr;
+ }
+ }
+ if (biggest_size < this_size) {
+ biggest_block = this_block;
+ biggest_size = this_size;
+ }
+ }
+ if (biggest_size == 0)
+ panic("Not enough DRAM to load kernel\n");
+#if 0
+ printf("Loading kernel into region 0x%08jx-0x%08jx (%ju MiB)\n",
+ (uintmax_t)biggest_block,
+ (uintmax_t)biggest_block + biggest_size - 1,
+ (uintmax_t)biggest_size / 1024 / 1024);
+#endif
+ return (biggest_block);
+ }
+ return roundup2(addr, PAGE_SIZE);
+}
+
ssize_t
uboot_copyin(const void *src, vm_offset_t dest, const size_t len)
{
-
bcopy(src, (void *)dest, len);
return (len);
}
@@ -47,7 +149,6 @@
ssize_t
uboot_copyout(const vm_offset_t src, void *dest, const size_t len)
{
-
bcopy((void *)src, dest, len);
return (len);
}
@@ -55,6 +156,5 @@
ssize_t
uboot_readin(const int fd, vm_offset_t dest, const size_t len)
{
-
- return (read(fd, (void *) dest, len));
+ return (read(fd, (void *)dest, len));
}
Modified: trunk/sys/boot/uboot/lib/devicename.c
===================================================================
--- trunk/sys/boot/uboot/lib/devicename.c 2018-06-01 23:17:30 UTC (rev 10183)
+++ trunk/sys/boot/uboot/lib/devicename.c 2018-06-01 23:20:45 UTC (rev 10184)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*-
* Copyright (c) 1998 Michael Smith <msmith at freebsd.org>
* All rights reserved.
@@ -25,7 +26,7 @@
*/
#include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/boot/uboot/lib/devicename.c 240273 2012-09-09 11:32:06Z ae $");
#include <stand.h>
#include <string.h>
Modified: trunk/sys/boot/uboot/lib/disk.c
===================================================================
--- trunk/sys/boot/uboot/lib/disk.c 2018-06-01 23:17:30 UTC (rev 10183)
+++ trunk/sys/boot/uboot/lib/disk.c 2018-06-01 23:20:45 UTC (rev 10184)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*-
* Copyright (c) 2008 Semihalf, Rafal Jaworowski
* Copyright (c) 2009 Semihalf, Piotr Ziecik
@@ -32,7 +33,7 @@
*/
#include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/boot/uboot/lib/disk.c 265071 2014-04-29 00:45:42Z ian $");
#include <sys/param.h>
#include <sys/disk.h>
@@ -45,9 +46,6 @@
#include "glue.h"
#include "libuboot.h"
-#define DEBUG
-#undef DEBUG
-
#define stor_printf(fmt, args...) do { \
printf("%s%d: ", dev->d_dev->dv_name, dev->d_unit); \
printf(fmt, ##args); \
@@ -281,3 +279,26 @@
return (0);
}
+
+/*
+ * Return the device unit number for the given type and type-relative unit
+ * number.
+ */
+int
+uboot_diskgetunit(int type, int type_unit)
+{
+ int local_type_unit;
+ int i;
+
+ local_type_unit = 0;
+ for (i = 0; i < stor_info_no; i++) {
+ if ((stor_info[i].type & type) == type) {
+ if (local_type_unit == type_unit) {
+ return (i);
+ }
+ local_type_unit++;
+ }
+ }
+
+ return (-1);
+}
Modified: trunk/sys/boot/uboot/lib/elf_freebsd.c
===================================================================
--- trunk/sys/boot/uboot/lib/elf_freebsd.c 2018-06-01 23:17:30 UTC (rev 10183)
+++ trunk/sys/boot/uboot/lib/elf_freebsd.c 2018-06-01 23:20:45 UTC (rev 10184)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*-
* Copyright (c) 2001 Benno Rice <benno at FreeBSD.org>
* Copyright (c) 2007 Semihalf, Rafal Jaworowski <raj at semihalf.com>
@@ -26,7 +27,7 @@
*/
#include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/boot/uboot/lib/elf_freebsd.c 283505 2015-05-25 01:06:55Z ian $");
#include <sys/param.h>
#include <sys/linker.h>
@@ -38,6 +39,7 @@
#include <stand.h>
#include "bootstrap.h"
+#include "libuboot.h"
extern vm_offset_t md_load(char *, vm_offset_t *);
@@ -69,6 +71,7 @@
vm_offset_t mdp;
Elf_Ehdr *e;
int error;
+ void (*entry)(void *);
if ((fmp = file_findmetadata(fp, MODINFOMD_ELFHDR)) == NULL)
return (EFTYPE);
@@ -78,11 +81,13 @@
if ((error = md_load(fp->f_args, &mdp)) != 0)
return (error);
- printf("Kernel entry at 0x%x ...\n", e->e_entry);
+ entry = (void *)e->e_entry;
+ printf("Kernel entry at 0x%x...\n", (unsigned)entry);
dev_cleanup();
+ printf("Kernel args: %s\n", fp->f_args);
- (*(void (*)())e->e_entry)((void *)mdp);
+ (*entry)((void *)mdp);
panic("exec returned");
}
Modified: trunk/sys/boot/uboot/lib/glue.c
===================================================================
--- trunk/sys/boot/uboot/lib/glue.c 2018-06-01 23:17:30 UTC (rev 10183)
+++ trunk/sys/boot/uboot/lib/glue.c 2018-06-01 23:20:45 UTC (rev 10184)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*-
* Copyright (c) 2007-2008 Semihalf, Rafal Jaworowski <raj at semihalf.com>
* All rights reserved.
@@ -25,7 +26,7 @@
*/
#include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/boot/uboot/lib/glue.c 265071 2014-04-29 00:45:42Z ian $");
#include <sys/types.h>
@@ -34,9 +35,6 @@
#include "api_public.h"
#include "glue.h"
-#define DEBUG
-#undef DEBUG
-
#ifdef DEBUG
#define debugf(fmt, args...) do { printf("%s(): ", __func__); printf(fmt,##args); } while (0)
#else
@@ -407,6 +405,9 @@
if (type & DT_STOR_MMC)
return ("MMC");
+ if (type & DT_STOR_SATA)
+ return ("SATA");
+
return ("Unknown");
}
Modified: trunk/sys/boot/uboot/lib/glue.h
===================================================================
--- trunk/sys/boot/uboot/lib/glue.h 2018-06-01 23:17:30 UTC (rev 10183)
+++ trunk/sys/boot/uboot/lib/glue.h 2018-06-01 23:20:45 UTC (rev 10184)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*-
* Copyright (c) 2008 Semihalf, Rafal Jaworowski <raj at semihalf.com>
* All rights reserved.
@@ -23,7 +24,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/boot/uboot/lib/glue.h 283409 2015-05-24 15:29:56Z ian $
*/
/*
@@ -40,7 +41,7 @@
int api_search_sig(struct api_signature **sig);
-#define UB_MAX_MR 5 /* max mem regions number */
+#define UB_MAX_MR 16 /* max mem regions number */
#define UB_MAX_DEV 6 /* max devices number */
/*
Modified: trunk/sys/boot/uboot/lib/libuboot.h
===================================================================
--- trunk/sys/boot/uboot/lib/libuboot.h 2018-06-01 23:17:30 UTC (rev 10183)
+++ trunk/sys/boot/uboot/lib/libuboot.h 2018-06-01 23:20:45 UTC (rev 10184)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*-
* Copyright (C) 2000 Benno Rice.
* Copyright (C) 2007 Semihalf, Rafal Jaworowski <raj at semihalf.com>
@@ -24,7 +25,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/boot/uboot/lib/libuboot.h 283505 2015-05-25 01:06:55Z ian $
*/
struct uboot_devdesc
@@ -32,9 +33,9 @@
struct devsw *d_dev;
int d_type;
int d_unit;
+ void *d_opendata;
union {
struct {
- void *data;
int slice;
int partition;
off_t offset;
@@ -57,6 +58,10 @@
extern struct netif_driver uboot_net;
extern struct devsw uboot_storage;
+extern uintptr_t uboot_heap_start;
+extern uintptr_t uboot_heap_end;
+
+uint64_t uboot_loadaddr(u_int type, void *data, uint64_t addr);
ssize_t uboot_copyin(const void *src, vm_offset_t dest, const size_t len);
ssize_t uboot_copyout(const vm_offset_t src, void *dest, const size_t len);
ssize_t uboot_readin(const int fd, vm_offset_t dest, const size_t len);
@@ -68,3 +73,6 @@
extern struct file_format uboot_elf;
void reboot(void);
+
+int uboot_diskgetunit(int type, int type_unit);
+
Modified: trunk/sys/boot/uboot/lib/module.c
===================================================================
--- trunk/sys/boot/uboot/lib/module.c 2018-06-01 23:17:30 UTC (rev 10183)
+++ trunk/sys/boot/uboot/lib/module.c 2018-06-01 23:20:45 UTC (rev 10184)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*-
* Copyright (c) 1998 Michael Smith <msmith at freebsd.org>
* All rights reserved.
@@ -25,23 +26,31 @@
*/
#include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/boot/uboot/lib/module.c 275763 2014-12-14 15:33:45Z andrew $");
/*
* U-Boot-specific module functionality.
- *
- * XXX not much for now...
- *
*/
#include <stand.h>
#include <string.h>
+#if defined(LOADER_FDT_SUPPORT)
+#include <fdt_platform.h>
+#endif
+
#include "bootstrap.h"
+#include "libuboot.h"
int
uboot_autoload(void)
{
+#if defined(LOADER_FDT_SUPPORT)
+ int err;
+ if ((err = fdt_setup_fdtp()) != 0)
+ return (err);
+#endif
+
return(0);
}
Modified: trunk/sys/boot/uboot/lib/net.c
===================================================================
--- trunk/sys/boot/uboot/lib/net.c 2018-06-01 23:17:30 UTC (rev 10183)
+++ trunk/sys/boot/uboot/lib/net.c 2018-06-01 23:20:45 UTC (rev 10184)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*-
* Copyright (c) 2000-2001 Benno Rice
* Copyright (c) 2007 Semihalf, Rafal Jaworowski <raj at semihalf.com>
@@ -26,7 +27,7 @@
*/
#include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/boot/uboot/lib/net.c 283510 2015-05-25 01:29:45Z ian $");
#include <sys/param.h>
#include <sys/types.h>
@@ -45,6 +46,7 @@
#include "api_public.h"
#include "glue.h"
#include "libuboot.h"
+#include "dev_net.h"
static int net_probe(struct netif *, void *);
static int net_match(struct netif *, void *);
@@ -84,6 +86,109 @@
static struct uboot_softc uboot_softc;
+/*
+ * get_env_net_params()
+ *
+ * Attempt to obtain all the parms we need for netbooting from the U-Boot
+ * environment. If we fail to obtain the values it may still be possible to
+ * netboot; the net_dev code will attempt to get the values from bootp, rarp,
+ * and other such sources.
+ *
+ * If rootip.s_addr is non-zero net_dev assumes the required global variables
+ * are set and skips the bootp inquiry. For that reason, we don't set rootip
+ * until we've verified that we have at least the minimum required info.
+ *
+ * This is called from netif_init() which can result in it getting called
+ * multiple times, by design. The network code at higher layers zeroes out
+ * rootip when it closes a network interface, so if it gets opened again we have
+ * to obtain all this info again.
+ */
+static void
+get_env_net_params()
+{
+ char *envstr;
+ in_addr_t rootaddr, serveraddr;
+
+ /* Silently get out right away if we don't have rootpath. */
+ if (ub_env_get("rootpath") == NULL)
+ return;
+
+ /*
+ * Our own IP address must be valid. Silently get out if it's not set,
+ * but whine if it's there and we can't parse it.
+ */
+ if ((envstr = ub_env_get("ipaddr")) == NULL)
+ return;
+ if ((myip.s_addr = inet_addr(envstr)) == INADDR_NONE) {
+ printf("Could not parse ipaddr '%s'\n", envstr);
+ return;
+ }
+
+ /*
+ * Netmask is optional, default to the "natural" netmask for our IP, but
+ * whine if it was provided and we couldn't parse it.
+ */
+ if ((envstr = ub_env_get("netmask")) != NULL &&
+ (netmask = inet_addr(envstr)) == INADDR_NONE) {
+ printf("Could not parse netmask '%s'\n", envstr);
+ }
+ if (netmask == INADDR_NONE) {
+ if (IN_CLASSA(myip.s_addr))
+ netmask = IN_CLASSA_NET;
+ else if (IN_CLASSB(myip.s_addr))
+ netmask = IN_CLASSB_NET;
+ else
+ netmask = IN_CLASSC_NET;
+ }
+
+ /*
+ * Get optional serverip before rootpath; the latter can override it.
+ * Whine only if it's present but can't be parsed.
+ */
+ serveraddr = INADDR_NONE;
+ if ((envstr = ub_env_get("serverip")) != NULL) {
+ if ((serveraddr = inet_addr(envstr)) == INADDR_NONE)
+ printf("Could not parse serverip '%s'\n", envstr);
+ }
+
+ /*
+ * There must be a rootpath. It may be ip:/path or it may be just the
+ * path in which case the ip needs to be in serverip.
+ */
+ if ((envstr = ub_env_get("rootpath")) == NULL)
+ return;
+ strncpy(rootpath, envstr, sizeof(rootpath) - 1);
+ rootaddr = net_parse_rootpath();
+ if (rootaddr == INADDR_NONE)
+ rootaddr = serveraddr;
+ if (rootaddr == INADDR_NONE) {
+ printf("No server address for rootpath '%s'\n", envstr);
+ return;
+ }
+ rootip.s_addr = rootaddr;
+
+ /*
+ * Gateway IP is optional unless rootip is on a different net in which
+ * case whine if it's missing or we can't parse it, and set rootip addr
+ * to zero, which signals to other network code that network params
+ * aren't set (so it will try dhcp, bootp, etc).
+ */
+ envstr = ub_env_get("gatewayip");
+ if (!SAMENET(myip, rootip, netmask)) {
+ if (envstr == NULL) {
+ printf("Need gatewayip for a root server on a "
+ "different network.\n");
+ rootip.s_addr = 0;
+ return;
+ }
+ if ((gateip.s_addr = inet_addr(envstr) == INADDR_NONE)) {
+ printf("Could not parse gatewayip '%s'\n", envstr);
+ rootip.s_addr = 0;
+ return;
+ }
+ }
+}
+
static int
net_match(struct netif *nif, void *machdep_hint)
{
@@ -222,6 +327,11 @@
nif->nif_driver->netif_bname, nif->nif_unit);
}
+ /* Attempt to get netboot params from the u-boot env. */
+ get_env_net_params();
+ if (myip.s_addr != 0)
+ desc->myip = myip;
+
#if defined(NETIF_DEBUG)
printf("network: %s%d attached to %s\n", nif->nif_driver->netif_bname,
nif->nif_unit, ether_sprintf(desc->myea));
Modified: trunk/sys/boot/uboot/lib/reboot.c
===================================================================
--- trunk/sys/boot/uboot/lib/reboot.c 2018-06-01 23:17:30 UTC (rev 10183)
+++ trunk/sys/boot/uboot/lib/reboot.c 2018-06-01 23:20:45 UTC (rev 10184)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*-
* Copyright (c) 2007 Semihalf, Rafal Jaworowski <raj at semihalf.com>
* All rights reserved.
@@ -25,7 +26,7 @@
*/
#include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/boot/uboot/lib/reboot.c 182723 2008-09-03 15:39:50Z raj $");
#include <stand.h>
#include "glue.h"
Modified: trunk/sys/boot/uboot/lib/time.c
===================================================================
--- trunk/sys/boot/uboot/lib/time.c 2018-06-01 23:17:30 UTC (rev 10183)
+++ trunk/sys/boot/uboot/lib/time.c 2018-06-01 23:20:45 UTC (rev 10184)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*-
* Copyright (c) 2000 Benno Rice
* Copyright (c) 2007 Semihalf, Rafal Jaworowski <raj at semihalf.com>
@@ -26,7 +27,7 @@
*/
#include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/boot/uboot/lib/time.c 204318 2010-02-25 15:30:26Z raj $");
#include <stand.h>
More information about the Midnightbsd-cvs
mailing list