summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Dearman <chris.dearman@imgtec.com>2014-09-20 08:53:09 +0400
committerMatt Redfearn <matt.redfearn@imgtec.com>2015-08-26 11:51:27 +0300
commit9b23a9375e8808b8907b749e054acadf49f83c05 (patch)
tree9e382d25cb2e05480b8aedd3d9ebc8c02eaca09c
parentc993210476acb3855a49f78496f22cbc94f6c4b2 (diff)
downloadCI20_u-boot-9b23a9375e8808b8907b749e054acadf49f83c05.tar.xz
Make boota more functional
* Use the kernel & ramdisk destinations specified in the header if they look sensible * Use the kernel command line options from the boot image to initialise the kernel arguments Change-Id: I964e9bd9abeaff89b62299772d8d053bbf473258
-rw-r--r--arch/mips/lib/bootm.c88
-rwxr-xr-xcommon/cmd_boota.c40
2 files changed, 59 insertions, 69 deletions
diff --git a/arch/mips/lib/bootm.c b/arch/mips/lib/bootm.c
index 985f6d06e..de52ef0b9 100644
--- a/arch/mips/lib/bootm.c
+++ b/arch/mips/lib/bootm.c
@@ -260,80 +260,74 @@ int do_bootm_linux(int flag, int argc, char * const argv[],
extern void flush_cache_all(void);
-// TODO: This is a bunch of cruft from X-Boot. All these things
-// should be replaced with either U-Boot definitions, or the values
-// should be calculated at run time. I suspect that the correct place
-// to get this stuff from is the boot.img header.
-//
-// In the case of CFG_KERNEL_DST, it seems that the corresponding
-// address from the the uImage file used to build boot.img is
-// 0x80010000:
-//
-// $ file uImage
-// uImage: u-boot legacy uImage, Linux-3.0.8-gb006f40, Linux/MIPS,
-// OS Kernel Image (gzip), 3762679 bytes, Thu Aug 7 16:22:16 2014,
-// Load Address: 0x80010000, Entry Point: 0x805FF400,
-// Header CRC: 0xC31FEAAA, Data CRC: 0xABB89D18
-//
-// Don't yet have a guess about what should replace CFG_RAMDISK_DST.
-#define CFG_KERNEL_DST 0x80f00000 /* Load Linux kernel to this addr */
-#define CFG_RAMDISK_DST 0x81a00000 /* initrd address */
-
-bootm_headers_t images; /* pointers to os/initrd/fdt images */
-
-void do_boota_linux(bootm_headers_t * images, const char *addr,
+void do_boota_linux(bootm_headers_t * images,
struct fastboot_boot_img_hdr *fb_hdr)
{
unsigned page_mask;
unsigned kernel_actual;
- unsigned ramdisk_actual;
- char initrd_param[64];
+ const void *kernel_src_addr, *ramdisk_src_addr;
+ void *kernel_dst_addr, *ramdisk_dst_addr;
char cmdline[256];
- void (*kernel) (int, char **, char **, ulong);
/* init kernel, ramdisk and prepare parameters */
page_mask = fb_hdr->page_size - 1;
kernel_actual = (fb_hdr->kernel_size + page_mask) & (~page_mask);
- ramdisk_actual = (fb_hdr->ramdisk_size + page_mask) & (~page_mask);
- fb_hdr->kernel_addr = (unsigned int)(addr + fb_hdr->page_size);
- fb_hdr->ramdisk_addr = fb_hdr->kernel_addr + kernel_actual;
-
-#ifdef DEBUG
+ kernel_src_addr =
+ (const void *)((unsigned int)fb_hdr + fb_hdr->page_size);
+ kernel_dst_addr = (void *)fb_hdr->kernel_addr;
+ ramdisk_src_addr =
+ (const void *)(((unsigned int)kernel_src_addr) + kernel_actual);
+ ramdisk_dst_addr = (void *)fb_hdr->ramdisk_addr;
+
+ // The default kernel load address used by mkbootimg.c is 0x10000000
+ // If the load address specified in the header appears invalid make
+ // a guess about where to load it. The default zImage execution address
+ // is 0x80f00000
+ if (kernel_dst_addr < (void *)0x80000000)
+ kernel_dst_addr = (void *)0x80f00000;
+
+ // For the ramdisk we just make a SWAG
+ // maybe it would be possible to just leave it where it is?
+ if (kernel_dst_addr < (void *)0x80000000)
+ kernel_dst_addr = (void *)0x81f00000;
+
+#ifdef DEBUG
printf(" page_mask: 0x%x\n", page_mask);
printf(" kernel size: 0x%x\n", kernel_actual);
- printf(" kernel address: 0x%x\n", fb_hdr->kernel_addr);
- printf(" ramdisk size: 0x%x\n", ramdisk_actual);
- printf("ramdisk address: 0x%x\n", fb_hdr->ramdisk_addr);
+ printf(" kernel srcaddr: %p\n", kernel_src_addr);
+ printf(" kernel dstaddr: %p\n", kernel_dst_addr);
+ printf("ramdisk srcaddr: %p\n", ramdisk_src_addr);
+ printf("ramdisk dstaddr: %p\n", ramdisk_dst_addr);
#endif /* DEBUG */
- memcpy((char *)CFG_KERNEL_DST, (char *)fb_hdr->kernel_addr,
- fb_hdr->kernel_size);
+ memcpy(kernel_dst_addr, kernel_src_addr, fb_hdr->kernel_size);
+ memcpy(ramdisk_dst_addr, ramdisk_src_addr, fb_hdr->ramdisk_size);
- memcpy((char *)CFG_RAMDISK_DST, (char *)fb_hdr->ramdisk_addr,
- fb_hdr->ramdisk_size);
+ boot_cmdline_linux(NULL);
- sprintf(initrd_param, " rd_start=0x%X rd_size=0x%X",
- CFG_RAMDISK_DST, fb_hdr->ramdisk_size);
-#ifdef DEBUG
- printf("initrd_param: \"%s\"\n", initrd_param);
-#endif /* DEBUG */
+ // Include any kernel command line options from boot.img
+ const char *bcmdline = (const char *)fb_hdr->cmdline;
+ linux_cmdline_set(bcmdline, strlen(bcmdline));
- boot_cmdline_linux(NULL);
// TODO: These extra lines are being added to support old
// kernels which expect these two parameters to be included
// on the command line.
- sprintf(cmdline, "rd_start=0x%X", CFG_RAMDISK_DST);
+ sprintf(cmdline, "rd_start=0x%0X", (unsigned int)ramdisk_dst_addr);
linux_cmdline_set(cmdline, strlen(cmdline));
sprintf(cmdline, "rd_size=0x%X", fb_hdr->ramdisk_size);
linux_cmdline_set(cmdline, strlen(cmdline));
+#ifdef DEBUG
+ printf("rd_start=0x%X rd_size=0x%X\n",
+ (unsigned int)ramdisk_dst_addr, fb_hdr->ramdisk_size);
+#endif /* DEBUG */
boot_prep_linux(images);
- kernel = (void (*)(int, char **, char **))CFG_KERNEL_DST;
-
// TODO: Replace with boot_jump_linux(images)?
flush_cache_all();
- (*kernel) (linux_argc, linux_argv, linux_env, 0ul);
+ typedef void __noreturn(*kernel_entry_t) (int, ulong, ulong, ulong);
+ kernel_entry_t kernel = (kernel_entry_t) kernel_dst_addr;
+ (*kernel) (linux_argc, (ulong) linux_argv, (ulong) linux_env, 0ul);
}
#endif /* CONFIG_CMD_BOOTA */
diff --git a/common/cmd_boota.c b/common/cmd_boota.c
index 83b09cc8e..3af751f28 100755
--- a/common/cmd_boota.c
+++ b/common/cmd_boota.c
@@ -39,8 +39,7 @@ DECLARE_GLOBAL_DATA_PTR;
#include <fastboot.h>
-void do_boota_linux(bootm_headers_t *, const char *,
- struct fastboot_boot_img_hdr *);
+void do_boota_linux(bootm_headers_t *, struct fastboot_boot_img_hdr *);
/*
* If everything is successful, this function will never return because
@@ -50,54 +49,51 @@ void do_boota_linux(bootm_headers_t *, const char *,
int do_boota(cmd_tbl_t * cmdtp, int flag, int argc, char *const argv[])
{
ulong addr;
+ struct fastboot_boot_img_hdr *fb_hdr;
if (argc < 2)
return cmd_usage(cmdtp);
addr = simple_strtoul(argv[1], NULL, 16);
- // This logic stolen from init_boot_linux() in
- // boot/usb/jz4780_poll.c from the X-Boot code for urboard.
- struct fastboot_boot_img_hdr fb_hdr;
- memcpy(&fb_hdr, (struct fastboot_boot_img_hdr *)addr,
- sizeof(struct fastboot_boot_img_hdr));
+ fb_hdr = (struct fastboot_boot_img_hdr *)addr;
- if (memcmp(fb_hdr.magic, FASTBOOT_BOOT_MAGIC, 8)) {
+ if (memcmp(fb_hdr->magic, FASTBOOT_BOOT_MAGIC, 8)) {
puts("boota: bad boot image magic, maybe not a boot.img?\n");
return 1;
}
#ifdef DEBUG
printf("---------------------\n");
- printf("kernel_size: 0x%x\n", fb_hdr.kernel_size);
- printf("kernel_addr: 0x%x\n\n", fb_hdr.kernel_addr);
+ printf("kernel_size: 0x%x\n", fb_hdr->kernel_size);
+ printf("kernel_addr: 0x%x\n\n", fb_hdr->kernel_addr);
- printf("ramdisk_size: 0x%x\n", fb_hdr.ramdisk_size);
- printf("ramdisk_addr: 0x%x\n\n", fb_hdr.ramdisk_addr);
+ printf("ramdisk_size: 0x%x\n", fb_hdr->ramdisk_size);
+ printf("ramdisk_addr: 0x%x\n\n", fb_hdr->ramdisk_addr);
- printf("second_size: 0x%x\n", fb_hdr.second_size);
- printf("second_addr: 0x%x\n\n", fb_hdr.second_addr);
+ printf("second_size: 0x%x\n", fb_hdr->second_size);
+ printf("second_addr: 0x%x\n\n", fb_hdr->second_addr);
- printf("tags_addr: 0x%x\n\n", fb_hdr.tags_addr);
+ printf("tags_addr: 0x%x\n\n", fb_hdr->tags_addr);
- printf("page_size: 0x%x\n\n", fb_hdr.page_size);
+ printf("page_size: 0x%x\n\n", fb_hdr->page_size);
- if (fb_hdr.unused[0] || fb_hdr.unused[1]) {
+ if (fb_hdr->unused[0] || fb_hdr->unused[1]) {
printf("***** ERROR unused: 0x%x 0x%x\n",
- fb_hdr.unused[0], fb_hdr.unused[1]);
+ fb_hdr->unused[0], fb_hdr->unused[1]);
return 1;
}
- printf("name: \"%s\"\n\n", fb_hdr.name);
+ printf("name: \"%s\"\n\n", fb_hdr->name);
- printf("cmdline: \"%s\"\n", fb_hdr.cmdline);
+ printf("cmdline: \"%s\"\n", fb_hdr->cmdline);
#endif /* DEBUG */
// TODO: Need to incorporate more code from do_bootm() to
- // initialize 'images'. Eventually, I expect the call to
+ // initialize 'images'. Eventually, I expect the call to
// do_boota_linx() to mirror the call to do_bootm_linux().
/* init kernel, ramdisk and prepare parameters */
- do_boota_linux(&images, (char *)addr, &fb_hdr);
+ do_boota_linux(&images, fb_hdr);
printf("%s, %d: We should not come here ... \n", __FILE__, __LINE__);