2008-02-16 22:13:11 +00:00
|
|
|
/*-
|
|
|
|
* Copyright (c) 2000 Benno Rice <benno@jeamland.net>
|
|
|
|
* Copyright (c) 2000 Stephane Potvin <sepotvin@videotron.ca>
|
2008-09-03 17:48:41 +00:00
|
|
|
* Copyright (c) 2007-2008 Semihalf, Rafal Jaworowski <raj@semihalf.com>
|
2008-02-16 22:13:11 +00:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* 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 AUTHORS 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$");
|
An ARM kernel can be loaded at any 2MB boundary, make ubldr aware of that.
Previously, ubldr would use the virtual addresses in the elf headers by
masking off the high bits and assuming the result was a physical address
where the kernel should be loaded. That would sometimes discard
significant bits of the physical address, but the effects of that were
undone by archsw copy code that would find a large block of memory and
apply an offset to the source/dest copy addresses. The result was that
things were loaded at a different physical address than requested by the
higher code layers, but that worked because other adjustments were applied
later (such as when jumping to the entry point). Very confusing, and
somewhat fragile.
Now the archsw copy routines are just simple copies, and instead
archsw.arch_loadaddr is implemented to choose a load address. The new
routine uses some of the code from the old offset-translation routine to
find the largest block of ram, but it excludes ubldr itself from that
range, and also excludes If ubldr splits the largest block of ram in
two, the kernel is loaded into the bottom of whichever resulting block is
larger.
As part of eliminating ubldr itself from the ram ranges, export the heap
start/end addresses in a pair of new global variables.
This change means that the virtual addresses in the arm kernel elf headers
now have no meaning at all, except for the entry point address. There is
an implicit assumption that the entry point is in the first text page, and
that the address in the the header can be turned into an offset by masking
it with PAGE_MASK. In the future we can link all arm kernels at a virtual
address of 0xC0000000 with no need to use any low-order part of the
address to influence where in ram the kernel gets loaded.
2015-05-17 19:59:05 +00:00
|
|
|
#include <sys/param.h>
|
2008-02-16 22:13:11 +00:00
|
|
|
|
|
|
|
#include <stand.h>
|
|
|
|
|
|
|
|
#include "api_public.h"
|
2008-02-23 17:58:12 +00:00
|
|
|
#include "bootstrap.h"
|
|
|
|
#include "glue.h"
|
|
|
|
#include "libuboot.h"
|
2008-02-16 22:13:11 +00:00
|
|
|
|
2014-03-11 22:02:49 +00:00
|
|
|
#ifndef nitems
|
|
|
|
#define nitems(x) (sizeof((x)) / sizeof((x)[0]))
|
|
|
|
#endif
|
|
|
|
|
2008-09-03 17:48:41 +00:00
|
|
|
struct uboot_devdesc currdev;
|
|
|
|
struct arch_switch archsw; /* MI/MD interface boundary */
|
|
|
|
int devs_no;
|
2008-02-16 22:13:11 +00:00
|
|
|
|
An ARM kernel can be loaded at any 2MB boundary, make ubldr aware of that.
Previously, ubldr would use the virtual addresses in the elf headers by
masking off the high bits and assuming the result was a physical address
where the kernel should be loaded. That would sometimes discard
significant bits of the physical address, but the effects of that were
undone by archsw copy code that would find a large block of memory and
apply an offset to the source/dest copy addresses. The result was that
things were loaded at a different physical address than requested by the
higher code layers, but that worked because other adjustments were applied
later (such as when jumping to the entry point). Very confusing, and
somewhat fragile.
Now the archsw copy routines are just simple copies, and instead
archsw.arch_loadaddr is implemented to choose a load address. The new
routine uses some of the code from the old offset-translation routine to
find the largest block of ram, but it excludes ubldr itself from that
range, and also excludes If ubldr splits the largest block of ram in
two, the kernel is loaded into the bottom of whichever resulting block is
larger.
As part of eliminating ubldr itself from the ram ranges, export the heap
start/end addresses in a pair of new global variables.
This change means that the virtual addresses in the arm kernel elf headers
now have no meaning at all, except for the entry point address. There is
an implicit assumption that the entry point is in the first text page, and
that the address in the the header can be turned into an offset by masking
it with PAGE_MASK. In the future we can link all arm kernels at a virtual
address of 0xC0000000 with no need to use any low-order part of the
address to influence where in ram the kernel gets loaded.
2015-05-17 19:59:05 +00:00
|
|
|
uintptr_t uboot_heap_start;
|
|
|
|
uintptr_t uboot_heap_end;
|
|
|
|
|
2014-03-11 22:02:49 +00:00
|
|
|
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 }
|
|
|
|
};
|
|
|
|
|
2008-02-16 22:13:11 +00:00
|
|
|
extern char end[];
|
|
|
|
extern char bootprog_name[];
|
|
|
|
extern char bootprog_rev[];
|
|
|
|
extern char bootprog_date[];
|
|
|
|
extern char bootprog_maker[];
|
|
|
|
|
|
|
|
extern unsigned char _etext[];
|
|
|
|
extern unsigned char _edata[];
|
|
|
|
extern unsigned char __bss_start[];
|
|
|
|
extern unsigned char __sbss_start[];
|
|
|
|
extern unsigned char __sbss_end[];
|
|
|
|
extern unsigned char _end[];
|
|
|
|
|
2010-05-25 15:21:39 +00:00
|
|
|
#ifdef LOADER_FDT_SUPPORT
|
|
|
|
extern int command_fdt_internal(int argc, char *argv[]);
|
|
|
|
#endif
|
|
|
|
|
2008-09-03 17:48:41 +00:00
|
|
|
static void
|
|
|
|
dump_sig(struct api_signature *sig)
|
2008-02-16 22:13:11 +00:00
|
|
|
{
|
|
|
|
#ifdef DEBUG
|
|
|
|
printf("signature:\n");
|
|
|
|
printf(" version\t= %d\n", sig->version);
|
|
|
|
printf(" checksum\t= 0x%08x\n", sig->checksum);
|
|
|
|
printf(" sc entry\t= 0x%08x\n", sig->syscall);
|
|
|
|
#endif
|
|
|
|
}
|
2008-09-03 17:48:41 +00:00
|
|
|
|
2008-02-16 22:13:11 +00:00
|
|
|
static void
|
|
|
|
dump_addr_info(void)
|
|
|
|
{
|
|
|
|
#ifdef DEBUG
|
|
|
|
printf("\naddresses info:\n");
|
2008-09-03 17:48:41 +00:00
|
|
|
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);
|
2008-02-16 22:13:11 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
static uint64_t
|
2008-09-03 17:48:41 +00:00
|
|
|
memsize(struct sys_info *si, int flags)
|
2008-02-16 22:13:11 +00:00
|
|
|
{
|
2008-09-03 17:48:41 +00:00
|
|
|
uint64_t size;
|
|
|
|
int i;
|
2008-02-23 17:58:12 +00:00
|
|
|
|
|
|
|
size = 0;
|
2008-02-16 22:13:11 +00:00
|
|
|
for (i = 0; i < si->mr_no; i++)
|
|
|
|
if (si->mr[i].flags == flags && si->mr[i].size)
|
2008-02-23 17:58:12 +00:00
|
|
|
size += (si->mr[i].size);
|
2008-02-16 22:13:11 +00:00
|
|
|
|
2008-02-23 17:58:12 +00:00
|
|
|
return (size);
|
2008-02-16 22:13:11 +00:00
|
|
|
}
|
|
|
|
|
2008-09-03 17:48:41 +00:00
|
|
|
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)
|
2014-03-17 16:10:42 +00:00
|
|
|
printf("%s: %lldMB\n", ub_mem_type(t[i]),
|
2008-09-03 17:48:41 +00:00
|
|
|
size / 1024 / 1024);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-11 22:02:49 +00:00
|
|
|
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;
|
|
|
|
|
2014-03-17 16:10:42 +00:00
|
|
|
*type = -1;
|
2014-03-11 22:02:49 +00:00
|
|
|
*unit = -1;
|
|
|
|
*slice = 0;
|
|
|
|
*partition = -1;
|
|
|
|
|
2014-03-17 16:10:42 +00:00
|
|
|
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);
|
|
|
|
|
2014-12-21 17:10:24 +00:00
|
|
|
/* Ignore optional spaces after the device name. */
|
|
|
|
while (*p == ' ')
|
|
|
|
p++;
|
|
|
|
|
|
|
|
/* Unknown device name, or a known name without unit number. */
|
2014-03-11 22:02:49 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2014-03-17 16:10:42 +00:00
|
|
|
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>");
|
|
|
|
|
2015-11-22 20:38:50 +00:00
|
|
|
if (currdev.d_disk.partition >= 0)
|
2014-03-17 16:10:42 +00:00
|
|
|
sprintf(partition, "%d", currdev.d_disk.partition);
|
|
|
|
else
|
|
|
|
strcpy(partition, "<auto>");
|
|
|
|
|
|
|
|
printf(" Checking unit=%d slice=%s partition=%s...",
|
|
|
|
currdev.d_unit, slice, partition);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-03-11 22:02:49 +00:00
|
|
|
static int
|
2014-03-14 00:49:02 +00:00
|
|
|
probe_disks(int devidx, int load_type, int load_unit, int load_slice,
|
|
|
|
int load_partition)
|
2014-03-11 22:02:49 +00:00
|
|
|
{
|
2014-03-14 00:49:02 +00:00
|
|
|
int open_result, unit;
|
2014-03-11 22:02:49 +00:00
|
|
|
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) {
|
2014-03-17 16:10:42 +00:00
|
|
|
printf(" Probing all disk devices...\n");
|
2014-03-11 22:02:49 +00:00
|
|
|
/* Try each disk in succession until one works. */
|
|
|
|
for (currdev.d_unit = 0; currdev.d_unit < UB_MAX_DEV;
|
|
|
|
currdev.d_unit++) {
|
2014-03-17 16:10:42 +00:00
|
|
|
print_disk_probe_info();
|
2014-03-14 00:49:02 +00:00
|
|
|
open_result = devsw[devidx]->dv_open(&f, &currdev);
|
2014-03-11 22:02:49 +00:00
|
|
|
if (open_result == 0) {
|
|
|
|
printf(" good.\n");
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (load_unit == -1) {
|
2014-03-17 16:10:42 +00:00
|
|
|
printf(" Probing all %s devices...\n", device_typename(load_type));
|
2014-03-11 22:02:49 +00:00
|
|
|
/* 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;
|
2014-03-17 16:10:42 +00:00
|
|
|
print_disk_probe_info();
|
2014-03-14 00:49:02 +00:00
|
|
|
open_result = devsw[devidx]->dv_open(&f, &currdev);
|
2014-03-11 22:02:49 +00:00
|
|
|
if (open_result == 0) {
|
|
|
|
printf(" good.\n");
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((currdev.d_unit = uboot_diskgetunit(load_type, load_unit)) != -1) {
|
2014-03-17 16:10:42 +00:00
|
|
|
print_disk_probe_info();
|
2014-03-14 00:49:02 +00:00
|
|
|
open_result = devsw[devidx]->dv_open(&f,&currdev);
|
2014-03-11 22:02:49 +00:00
|
|
|
if (open_result == 0) {
|
2014-03-17 16:10:42 +00:00
|
|
|
printf(" good.\n");
|
2014-03-11 22:02:49 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
|
2015-11-22 20:38:50 +00:00
|
|
|
printf(" Requested disk type/unit/slice/partition not found\n");
|
2014-03-11 22:02:49 +00:00
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
2008-02-16 22:13:11 +00:00
|
|
|
int
|
|
|
|
main(void)
|
|
|
|
{
|
|
|
|
struct api_signature *sig = NULL;
|
2014-03-11 22:02:49 +00:00
|
|
|
int load_type, load_unit, load_slice, load_partition;
|
|
|
|
int i;
|
2015-11-22 20:38:50 +00:00
|
|
|
const char *ldev;
|
2008-02-16 22:13:11 +00:00
|
|
|
|
2014-03-01 19:25:23 +00:00
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
2008-02-16 22:13:11 +00:00
|
|
|
if (!api_search_sig(&sig))
|
2014-03-01 19:25:23 +00:00
|
|
|
return (0x01badab1);
|
2008-02-16 22:13:11 +00:00
|
|
|
|
|
|
|
syscall_ptr = sig->syscall;
|
|
|
|
if (syscall_ptr == NULL)
|
2014-03-01 19:25:23 +00:00
|
|
|
return (0x02badab1);
|
2008-02-16 22:13:11 +00:00
|
|
|
|
|
|
|
if (sig->version > API_SIG_VERSION)
|
2014-03-01 19:25:23 +00:00
|
|
|
return (0x03badab1);
|
2008-02-16 22:13:11 +00:00
|
|
|
|
|
|
|
/* Clear BSS sections */
|
|
|
|
bzero(__sbss_start, __sbss_end - __sbss_start);
|
|
|
|
bzero(__bss_start, _end - __bss_start);
|
|
|
|
|
|
|
|
/*
|
2014-03-17 16:10:42 +00:00
|
|
|
* Initialise the heap as early as possible. Once this is done,
|
|
|
|
* alloc() is usable. The stack is buried inside us, so this is safe.
|
|
|
|
*/
|
An ARM kernel can be loaded at any 2MB boundary, make ubldr aware of that.
Previously, ubldr would use the virtual addresses in the elf headers by
masking off the high bits and assuming the result was a physical address
where the kernel should be loaded. That would sometimes discard
significant bits of the physical address, but the effects of that were
undone by archsw copy code that would find a large block of memory and
apply an offset to the source/dest copy addresses. The result was that
things were loaded at a different physical address than requested by the
higher code layers, but that worked because other adjustments were applied
later (such as when jumping to the entry point). Very confusing, and
somewhat fragile.
Now the archsw copy routines are just simple copies, and instead
archsw.arch_loadaddr is implemented to choose a load address. The new
routine uses some of the code from the old offset-translation routine to
find the largest block of ram, but it excludes ubldr itself from that
range, and also excludes If ubldr splits the largest block of ram in
two, the kernel is loaded into the bottom of whichever resulting block is
larger.
As part of eliminating ubldr itself from the ram ranges, export the heap
start/end addresses in a pair of new global variables.
This change means that the virtual addresses in the arm kernel elf headers
now have no meaning at all, except for the entry point address. There is
an implicit assumption that the entry point is in the first text page, and
that the address in the the header can be turned into an offset by masking
it with PAGE_MASK. In the future we can link all arm kernels at a virtual
address of 0xC0000000 with no need to use any low-order part of the
address to influence where in ram the kernel gets loaded.
2015-05-17 19:59:05 +00:00
|
|
|
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);
|
2014-03-17 16:10:42 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Set up console.
|
|
|
|
*/
|
2008-02-16 22:13:11 +00:00
|
|
|
cons_probe();
|
2014-03-17 16:10:42 +00:00
|
|
|
printf("Compatible U-Boot API signature found @%x\n", (uint32_t)sig);
|
2008-02-16 22:13:11 +00:00
|
|
|
|
2014-03-17 16:10:42 +00:00
|
|
|
printf("\n");
|
|
|
|
printf("%s, Revision %s\n", bootprog_name, bootprog_rev);
|
|
|
|
printf("(%s, %s)\n", bootprog_maker, bootprog_date);
|
|
|
|
printf("\n");
|
2008-02-16 22:13:11 +00:00
|
|
|
|
|
|
|
dump_sig(sig);
|
|
|
|
dump_addr_info();
|
|
|
|
|
2014-03-17 16:10:42 +00:00
|
|
|
meminfo();
|
2008-02-16 22:13:11 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Enumerate U-Boot devices
|
|
|
|
*/
|
|
|
|
if ((devs_no = ub_dev_enum()) == 0)
|
2008-09-03 17:48:41 +00:00
|
|
|
panic("no U-Boot devices found");
|
|
|
|
printf("Number of U-Boot devices: %d\n", devs_no);
|
2008-02-16 22:13:11 +00:00
|
|
|
|
2014-03-11 22:02:49 +00:00
|
|
|
get_load_device(&load_type, &load_unit, &load_slice, &load_partition);
|
|
|
|
|
2010-05-25 09:59:53 +00:00
|
|
|
/*
|
2014-03-11 22:02:49 +00:00
|
|
|
* March through the device switch probing for things.
|
2010-05-25 09:59:53 +00:00
|
|
|
*/
|
2010-02-25 15:27:13 +00:00
|
|
|
for (i = 0; devsw[i] != NULL; i++) {
|
2010-05-25 09:59:53 +00:00
|
|
|
|
|
|
|
if (devsw[i]->dv_init == NULL)
|
|
|
|
continue;
|
|
|
|
if ((devsw[i]->dv_init)() != 0)
|
|
|
|
continue;
|
|
|
|
|
2014-03-11 22:02:49 +00:00
|
|
|
printf("Found U-Boot device: %s\n", devsw[i]->dv_name);
|
2008-02-16 22:13:11 +00:00
|
|
|
|
2014-03-11 22:02:49 +00:00
|
|
|
currdev.d_dev = devsw[i];
|
|
|
|
currdev.d_type = currdev.d_dev->dv_type;
|
|
|
|
currdev.d_unit = 0;
|
2014-02-22 17:51:10 +00:00
|
|
|
|
2014-03-11 22:02:49 +00:00
|
|
|
if ((load_type == -1 || (load_type & DEV_TYP_STOR)) &&
|
|
|
|
strcmp(devsw[i]->dv_name, "disk") == 0) {
|
2014-03-14 00:49:02 +00:00
|
|
|
if (probe_disks(i, load_type, load_unit, load_slice,
|
2014-03-11 22:02:49 +00:00
|
|
|
load_partition) == 0)
|
|
|
|
break;
|
|
|
|
}
|
2014-02-22 17:51:10 +00:00
|
|
|
|
2014-03-17 13:54:53 +00:00
|
|
|
if ((load_type == -1 || (load_type & DEV_TYP_NET)) &&
|
|
|
|
strcmp(devsw[i]->dv_name, "net") == 0)
|
2014-03-11 22:02:49 +00:00
|
|
|
break;
|
|
|
|
}
|
2014-02-22 17:51:10 +00:00
|
|
|
|
2014-03-11 22:02:49 +00:00
|
|
|
/*
|
|
|
|
* 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);
|
|
|
|
}
|
2008-02-16 22:13:11 +00:00
|
|
|
|
2015-11-22 20:38:50 +00:00
|
|
|
ldev = uboot_fmtdev(&currdev);
|
|
|
|
env_setenv("currdev", EV_VOLATILE, ldev, uboot_setcurrdev, env_nounset);
|
|
|
|
env_setenv("loaddev", EV_VOLATILE, ldev, env_noset, env_nounset);
|
2015-12-05 23:59:30 +00:00
|
|
|
printf("Booting from %s\n", ldev);
|
2008-02-16 22:13:11 +00:00
|
|
|
|
|
|
|
setenv("LINES", "24", 1); /* optional */
|
|
|
|
setenv("prompt", "loader>", 1);
|
|
|
|
|
An ARM kernel can be loaded at any 2MB boundary, make ubldr aware of that.
Previously, ubldr would use the virtual addresses in the elf headers by
masking off the high bits and assuming the result was a physical address
where the kernel should be loaded. That would sometimes discard
significant bits of the physical address, but the effects of that were
undone by archsw copy code that would find a large block of memory and
apply an offset to the source/dest copy addresses. The result was that
things were loaded at a different physical address than requested by the
higher code layers, but that worked because other adjustments were applied
later (such as when jumping to the entry point). Very confusing, and
somewhat fragile.
Now the archsw copy routines are just simple copies, and instead
archsw.arch_loadaddr is implemented to choose a load address. The new
routine uses some of the code from the old offset-translation routine to
find the largest block of ram, but it excludes ubldr itself from that
range, and also excludes If ubldr splits the largest block of ram in
two, the kernel is loaded into the bottom of whichever resulting block is
larger.
As part of eliminating ubldr itself from the ram ranges, export the heap
start/end addresses in a pair of new global variables.
This change means that the virtual addresses in the arm kernel elf headers
now have no meaning at all, except for the entry point address. There is
an implicit assumption that the entry point is in the first text page, and
that the address in the the header can be turned into an offset by masking
it with PAGE_MASK. In the future we can link all arm kernels at a virtual
address of 0xC0000000 with no need to use any low-order part of the
address to influence where in ram the kernel gets loaded.
2015-05-17 19:59:05 +00:00
|
|
|
archsw.arch_loadaddr = uboot_loadaddr;
|
2008-02-16 22:13:11 +00:00
|
|
|
archsw.arch_getdev = uboot_getdev;
|
|
|
|
archsw.arch_copyin = uboot_copyin;
|
|
|
|
archsw.arch_copyout = uboot_copyout;
|
|
|
|
archsw.arch_readin = uboot_readin;
|
|
|
|
archsw.arch_autoload = uboot_autoload;
|
|
|
|
|
2014-07-27 16:12:51 +00:00
|
|
|
interact(NULL); /* doesn't return */
|
2008-02-16 22:13:11 +00:00
|
|
|
|
2008-09-03 17:48:41 +00:00
|
|
|
return (0);
|
2008-02-16 22:13:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
COMMAND_SET(heap, "heap", "show heap usage", command_heap);
|
|
|
|
static int
|
|
|
|
command_heap(int argc, char *argv[])
|
|
|
|
{
|
2008-09-03 15:39:50 +00:00
|
|
|
|
|
|
|
printf("heap base at %p, top at %p, used %d\n", end, sbrk(0),
|
2008-03-13 17:54:21 +00:00
|
|
|
sbrk(0) - end);
|
2008-02-16 22:13:11 +00:00
|
|
|
|
2008-09-03 17:48:41 +00:00
|
|
|
return (CMD_OK);
|
2008-02-16 22:13:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
COMMAND_SET(reboot, "reboot", "reboot the system", command_reboot);
|
|
|
|
static int
|
|
|
|
command_reboot(int argc, char *argv[])
|
|
|
|
{
|
2008-12-17 15:58:07 +00:00
|
|
|
|
2008-02-16 22:13:11 +00:00
|
|
|
printf("Resetting...\n");
|
|
|
|
ub_reset();
|
|
|
|
|
|
|
|
printf("Reset failed!\n");
|
|
|
|
while(1);
|
|
|
|
}
|
2008-09-03 17:48:41 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
2010-05-25 15:21:39 +00:00
|
|
|
|
2014-09-08 19:19:10 +00:00
|
|
|
enum ubenv_action {
|
|
|
|
UBENV_UNKNOWN,
|
|
|
|
UBENV_SHOW,
|
|
|
|
UBENV_IMPORT
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
handle_uboot_env_var(enum ubenv_action action, const char * var)
|
|
|
|
{
|
2015-12-14 22:00:46 +00:00
|
|
|
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 (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];
|
|
|
|
}
|
|
|
|
}
|
2014-09-08 19:19:10 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 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) {
|
2015-12-14 22:00:46 +00:00
|
|
|
var = &var[6];
|
2014-09-08 19:19:10 +00:00
|
|
|
}
|
2015-12-14 22:00:46 +00:00
|
|
|
|
|
|
|
/* If ldvar is malformed or there's no variable name left, punt. */
|
|
|
|
if (ldvar[0] == 0 || var[0] == 0)
|
|
|
|
return;
|
|
|
|
|
2014-09-08 19:19:10 +00:00
|
|
|
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) {
|
2015-12-14 22:00:46 +00:00
|
|
|
setenv(ldvar, val, 1);
|
2014-09-08 19:19:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
2010-05-25 15:21:39 +00:00
|
|
|
#ifdef LOADER_FDT_SUPPORT
|
|
|
|
/*
|
|
|
|
* Since proper fdt command handling function is defined in fdt_loader_cmd.c,
|
|
|
|
* and declaring it as extern is in contradiction with COMMAND_SET() macro
|
|
|
|
* (which uses static pointer), we're defining wrapper function, which
|
|
|
|
* calls the proper fdt handling routine.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
command_fdt(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
|
|
|
|
return (command_fdt_internal(argc, argv));
|
|
|
|
}
|
|
|
|
|
|
|
|
COMMAND_SET(fdt, "fdt", "flattened device tree handling", command_fdt);
|
|
|
|
#endif
|