patchset3 - legacy code refactoring
cover patchset3 - legacy code refactoring
This is the third patch-set of the new uImage format work. It concludes the phase of clean-up and reorganization of the old format code, preparing the ground for adding the code implementing the new format.
All the new uImage patches sent to the list so far, as well as updates resulting from the feedback received, will be soon available from the new-image branch of the u-boot-testing repository (there will be a separate announcement).
The completion of the clean-up phase is a good moment to review the patches posted to date, and help with testing. This work affects all architectures and operating systems, so it would be much appreciated if people could give u-boot-testing#new-image a try and report back. So far, the changes were tested on a lite5200b board and successfully built for ppc, arm, mips and coldfire targets.
Work is now ongoing on adding support for the new format, results will be posted to the list, and also available from u-boot-testing#new-image. Once the implementation is complete, and the code is reviewed and tested, it will be merged to the master.
Marian Balakowicz (6):
[new uImage] Move kernel data find code to get_kernel() routine [new uImage] Cleanup FDT handling in PPC do_boot_linux() [new uImage] Cleanup PPC and M68K do_bootm_linux() boot allocations [new uImage] Move PPC and M68K ramdisk loading to a common routine [new uImage] Removed dead ramdisk code on microblaze architecture [new uImage] Factor out common image_get_ramdisk() routine
Cheers,
m.
PATCH 1/6 Factor out common image_get_ramdisk() routine
Architecture specific do_bootm_linux() routines share common ramdisk image processing code. Move this code to a common helper routine.
---
common/image.c | 203 +++++++++++++++++++++++++++++++++++++++++++++++- include/image.h | 10 ++ lib_arm/bootm.c | 114 --------------------------- lib_avr32/bootm.c | 72 ----------------- lib_i386/bootm.c | 76 +----------------- lib_m68k/bootm.c | 89 ++------------------- lib_microblaze/bootm.c | 85 -------------------- lib_mips/bootm.c | 84 -------------------- lib_ppc/bootm.c | 94 ++-------------------- 9 files changed, 239 insertions(+), 588 deletions(-)
common/image.c +200 -3
@@ -23,10 +23,20 @@* MA 02111-1307 USA */ #ifndef USE_HOSTCC -# include <common.h> -# include <watchdog.h> +#include <common.h> +#include <watchdog.h> + +#ifdef CONFIG_SHOW_BOOT_PROGRESS +#include <status_led.h> +#endif + +#ifdef CONFIG_HAS_DATAFLASH +#include <dataflash.h> +#endif + +extern int do_reset (cmd_tbl_t *cmdtp,int flag,int argc,char *argv[]);#else -# include "mkimage.h" +#include "mkimage.h" #endif #include <image.h>
@@ -280,4 +290,191 @@ const char* image_get_comp_name (uint8_t comp) return name; } + +/** +* image_get_ramdisk - get and verify ramdisk image +* @cmdtp: command table pointer +* @flag: command flag +* @argc: command argument count +* @argv: command argument list +* @rd_addr: ramdisk image start address +* @arch: expected ramdisk architecture +* @verify: checksum verification flag +* +* image_get_ramdisk() returns a pointer to the verified ramdisk image +* header. Routine receives image start address and expected architecture +* flag. Verification done covers data and header integrity and os/type/arch +* fields checking. +* +* If dataflash support is enabled routine checks for dataflash addresses +* and handles required dataflash reads. +* +* returns: +* pointer to a ramdisk image header, if image was found and valid +* otherwise, board is reset +*/ +image_header_t *image_get_ramdisk (cmd_tbl_t *cmdtp,int flag, +int argc,char *argv[], +ulong rd_addr,uint8_t arch,int verify) +{ +image_header_t *rd_hdr; + +show_boot_progress (9 ); + +#ifdef CONFIG_HAS_DATAFLASH +if (addr_dataflash (rd_addr)) { + rd_hdr = (image_header_t *)CFG_LOAD_ADDR ; +debug (" Reading Ramdisk image header from dataflash address " +"%08lx to %08lx\n" , rd_addr, (ulong )rd_hdr); +read_dataflash (rd_addr,image_get_header_size (), + (char *)rd_hdr); + } else +#endif + rd_hdr = (image_header_t *)rd_addr; + +if (!image_check_magic (rd_hdr)) { +puts ("Bad Magic Number\n" ); +show_boot_progress (-10 ); +do_reset (cmdtp, flag, argc, argv); + } + +if (!image_check_hcrc (rd_hdr)) { +puts ("Bad Header Checksum\n" ); +show_boot_progress (-11 ); +do_reset (cmdtp, flag, argc, argv); + } + +show_boot_progress (10 ); +print_image_hdr (rd_hdr); + +#ifdef CONFIG_HAS_DATAFLASH +if (addr_dataflash (rd_addr)) { +debug (" Reading Ramdisk image data from dataflash address " +"%08lx to %08lx\n" , rd_addr + image_get_header_size, + (ulong )image_get_data (rd_hdr)); + +read_dataflash (rd_addr +image_get_header_size (), +image_get_data_size (rd_hdr), + (char *)image_get_data (rd_hdr)); + }#endif + +if (verify) { +puts (" Verifying Checksum ... " ); +if (!image_check_dcrc_wd (rd_hdr,CHUNKSZ )) { +puts ("Bad Data CRC\n" ); +show_boot_progress (-12 ); +do_reset (cmdtp, flag, argc, argv); + } +puts ("OK\n" ); + } + +show_boot_progress (11 ); + +if (!image_check_os (rd_hdr,IH_OS_LINUX ) || + !image_check_arch (rd_hdr, arch) || + !image_check_type (rd_hdr,IH_TYPE_RAMDISK )) { +printf ("No Linux %s Ramdisk Image\n" , +image_get_arch_name (arch)); +show_boot_progress (-13 ); +do_reset (cmdtp, flag, argc, argv); + } + +return rd_hdr; +} + +/** +* get_ramdisk - main ramdisk handling routine +* @cmdtp: command table pointer +* @flag: command flag +* @argc: command argument count +* @argv: command argument list +* @hdr: pointer to the posiibly multi componet kernel image +* @verify: checksum verification flag +* @arch: expected ramdisk architecture +* @rd_start: pointer to a ulong variable, will hold ramdisk start address +* @rd_end: pointer to a ulong variable, will hold ramdisk end +* +* get_ramdisk() is responsible for finding a valid ramdisk image. +* Curently supported are the following ramdisk sources: +* - multicomponent kernel/ramdisk image, +* - commandline provided address of decicated ramdisk image. +* +* returns: +* rd_start and rd_end are set to ramdisk start/end addresses if +* ramdisk image is found and valid +* rd_start and rd_end are set to 0 if no ramdisk exists +* board is reset if ramdisk image is found but corrupted +*/ +void get_ramdisk (cmd_tbl_t *cmdtp,int flag,int argc,char *argv[], +image_header_t *hdr,int verify,uint8_t arch, +ulong *rd_start,ulong *rd_end) +{ +ulong rd_addr; +ulong rd_data, rd_len; +image_header_t *rd_hdr; + +if (argc >=3 ) { +/* +* Look for a '-' which indicates to ignore the +* ramdisk argument +*/ +if (strcmp (argv[2 ],"-" ) ==0 ) { +debug ("## Skipping init Ramdisk\n" ); + rd_len = rd_data =0 ; + }else { +/* +* Check if there is an initrd image at the +* address provided in the second bootm argument +*/ + rd_addr =simple_strtoul (argv[2 ],NULL ,16 ); +printf ("## Loading init Ramdisk Image at %08lx ...\n" , + rd_addr); + + rd_hdr =image_get_ramdisk (cmdtp, flag, argc, argv, + rd_addr, arch, verify); + + rd_data =image_get_data (rd_hdr); + rd_len =image_get_data_size (rd_hdr); + +#if defined(CONFIG_B2 ) || defined(CONFIG_EVB4510 ) || defined(CONFIG_ARMADILLO ) +/* +*we need to copy the ramdisk to SRAM to let Linux boot +*/ +memmove ((void *)image_get_load (rd_hdr), + (uchar *)rd_data, rd_len); + + rd_data =image_get_load (rd_hdr); +#endif /* CONFIG_B2 || CONFIG_EVB4510 || CONFIG_ARMADILLO */ + } + + }else if (image_check_type (hdr,IH_TYPE_MULTI )) { +/* +* Now check if we have a multifile image +* Get second entry data start address and len +*/ +show_boot_progress (13 ); +printf ("## Loading init Ramdisk from multi component " +"Image at %08lx ...\n" , (ulong )hdr); +image_multi_getimg (hdr,1 , &rd_data, &rd_len); + }else { +/* +* no initrd image +*/ +show_boot_progress (14 ); + rd_len = rd_data =0 ; + } + +if (!rd_data) { +debug ("## No init Ramdisk\n" ); + *rd_start =0 ; + *rd_end =0 ; + }else { + *rd_start = rd_data; + *rd_end = rd_data + rd_len; + } +debug (" ramdisk start = 0x%08lx, ramdisk end = 0x%08lx\n" , + *rd_start, *rd_end); +} +#endif /* USE_HOSTCC */ +
include/image.h +10 -0
@@ -34,6 +34,7 @@#define __IMAGE_H__#include <asm/byteorder.h> +#include <command.h> #ifndef USE_HOSTCC #include <linux/string.h> #endif
@@ -331,6 +332,15 @@ const char* image_get_os_name (uint8_t os);const char *image_get_arch_name (uint8_t arch);const char *image_get_type_name (uint8_t type);const char *image_get_comp_name (uint8_t comp); + +image_header_t *image_get_ramdisk (cmd_tbl_t *cmdtp,int flag, +int argc,char *argv[], +ulong rd_addr,uint8_t arch,int verify); + +void get_ramdisk (cmd_tbl_t *cmdtp,int flag,int argc,char *argv[], +image_header_t *hdr,int verify,uint8_t arch, +ulong *rd_start,ulong *rd_end);#endif /* USE_HOSTCCa */ +#endif /* __IMAGE_H__ */
lib_arm/bootm.c +2 -112
136 lines not on this page · raw message
lib_avr32/bootm.c +2 -70
91 lines not on this page · raw message
lib_i386/bootm.c +3 -73
90 lines not on this page · raw message
lib_m68k/bootm.c +9 -80
123 lines not on this page · raw message
lib_microblaze/bootm.c +2 -83
101 lines not on this page · raw message
lib_mips/bootm.c +2 -82
103 lines not on this page · raw message
lib_ppc/bootm.c +9 -85
126 lines not on this page · raw message
PATCH 2/6 Removed dead ramdisk code on microblaze architecture
In reply to Marian BalakowiczMicroblaze do_bootm_linux() includes ramdisk processing code but the ramdisk does not get used anywhere later on.
---
lib_microblaze/bootm.c | 5 ----- 1 files changed, 0 insertions(+), 5 deletions(-)
lib_microblaze/bootm.c +0 -5
@@ -35,17 +35,12 @@ DECLARE_GLOBAL_DATA_PTR;void do_bootm_linux (cmd_tbl_t * cmdtp,int flag,int argc,char *argv[],image_header_t *hdr,int verify) { -ulong initrd_start, initrd_end; -/* First parameter is mapped to $r5 for kernel boot args */ void (*theKernel) (char *);char *commandline =getenv ("bootargs" ); theKernel = (void (*)(char *))image_get_ep (hdr); -get_ramdisk (cmdtp, flag, argc, argv, hdr, verify, -IH_ARCH_MICROBLAZE , &initrd_start, &initrd_end); -show_boot_progress (15 );#ifdef DEBUG
PATCH 2/6 Removed dead ramdisk code on microblaze architecture
Hi Marian,
do you have git repository with your changes?
I would like to see what is changed from previous state. I have some changes in my internal repository which modified linux booting with using ramdisk too.
Regards,
Michal Simek
Quoted 32 lines
Microblaze
do_bootm_linux()includes ramdisk processing code but the ramdisk does not get used anywhere later on.Signed-off-by Marian Balakowicz <[email protected]>---
lib_microblaze/bootm.c | 5 ----- 1 files changed, 0 insertions(+), 5 deletions(-)lib_microblaze/bootm.c +0
-5@@ -35,17 +35,12 @@ DECLARE_GLOBAL_DATA_PTR;void do_bootm_linux (cmd_tbl_t * cmdtp,int flag,int argc,char *argv[],image_header_t *hdr,int verify) { -ulong initrd_start, initrd_end; -/* First parameter is mapped to $r5 for kernel boot args */ void (*theKernel) (char *);char *commandline =getenv ("bootargs" ); theKernel = (void (*)(char *))image_get_ep (hdr); -get_ramdisk (cmdtp, flag, argc, argv, hdr, verify, -IH_ARCH_MICROBLAZE , &initrd_start, &initrd_end); -show_boot_progress (15 );#ifdef DEBUG
PATCH 2/6 Removed dead ramdisk code on microblaze architecture
Quoted 3 lines · Michal Simek
Hi Marian,
do you have git repository with your changes?
Hi Michal,
Let me answer this, as Marian is out of office. Yes, the changes are available form the new-image branch of the u-boot-testing repo. For more details, please see my email to the list announcing it, sent a while ago ([U-Boot-Users] [new uImage] Code available on new-image branch of u-boot-testing repo).
Quoted 3 lines
I would like to see what is changed from previous state. I have some changes in my internal repository which modified linux booting with using ramdisk too.
It would be very good to have a look at your changes -- could you post them (preferably using the new-image branch as a baseline :).
Thanks,
Bartlomiej
PATCH 2/6 Removed dead ramdisk code on microblaze architecture
Hi Bartolomiej,
Quoted 11 lines
Quoted 3 lines
Hi Marian,
do you have git repository with your changes?
Hi Michal,
Let me answer this, as Marian is out of office. Yes, the changes are available form the new-image branch of the u-boot-testing repo. For more details, please see my email to the list announcing it, sent a while ago ([U-Boot-Users] [new uImage] Code available on new-image branch of u-boot-testing repo).
Thanks.
Quoted 6 lines
Quoted 3 lines
I would like to see what is changed from previous state. I have some changes in my internal repository which modified linux booting with using ramdisk too.
It would be very good to have a look at your changes -- could you post them (preferably using the new-image branch as a baseline :).
Microblaze linux bootm function will be simpler powerpc bootm function. Microblaze supports FDT and Ramdisk now.
I'll check it soon and I'll send my changes.
Regards,
Michal Simek
PATCH 3/6 Move PPC and M68K ramdisk loading to a common routine
In reply to Marian BalakowiczRamdisk loading code, including initrd_high variable handling, was duplicated for PPC and M68K platforms. This patch creates common helper routine that is being called from both platforms' do_bootm_linux() routines.
---
common/image.c | 113 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ include/image.h | 7 +++ lib_m68k/bootm.c | 114 ++++++++++++------------------------------------------ lib_ppc/bootm.c | 112 ++++++++++++----------------------------------------- 4 files changed, 171 insertions(+), 175 deletions(-)
common/image.c +113 -0
@@ -22,6 +22,9 @@* Foundation, Inc., 59 Temple Place, Suite 330, Boston, * MA 02111-1307 USA */ + +#define DEBUG +#ifndef USE_HOSTCC #include <common.h> #include <watchdog.h>
@@ -34,6 +37,10 @@#include <dataflash.h> #endif +#ifdef CONFIG_LOGBUFFER +#include <logbuff.h> +#endif +extern int do_reset (cmd_tbl_t *cmdtp,int flag,int argc,char *argv[]);#else #include "mkimage.h"
@@ -476,5 +483,111 @@ void get_ramdisk (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],debug (" ramdisk start = 0x%08lx, ramdisk end = 0x%08lx\n" , *rd_start, *rd_end); } + +#if defined(CONFIG_PPC ) || defined(CONFIG_M68K ) +/** +* ramdisk_high - relocate init ramdisk +* @rd_data: ramdisk data start address +* @rd_len: ramdisk data length +* @kbd: kernel board info copy (within BOOTMAPSZ boundary) +* @sp_limit: stack pointer limit (including BOOTMAPSZ) +* @sp: current stack pointer +* @initrd_start: pointer to a ulong variable, will hold final init ramdisk +* start address (after possible relocation) +* @initrd_end: pointer to a ulong variable, will hold final init ramdisk +* end address (after possible relocation) +* +* ramdisk_high() takes a relocation hint from "initrd_high" environement +* variable and if requested ramdisk data is moved to a specified location. +* +* returns: +* initrd_start and initrd_end are set to final (after relocation) ramdisk +* start/end addresses if ramdisk image start and len were provided +* otherwise set initrd_start and initrd_end to zeros +* +*/ +void ramdisk_high (ulong rd_data,ulong rd_len,bd_t *kbd,ulong sp_limit, +ulong sp,ulong *initrd_start,ulong *initrd_end) +{ +char *s; +ulong initrd_high; +int initrd_copy_to_ram =1 ; + +if ((s =getenv ("initrd_high" )) !=NULL ) { +/* a value of "no" or a similar string will act like 0, +* turning the "load high" feature off. This is intentional. +*/ + initrd_high =simple_strtoul (s,NULL ,16 ); +if (initrd_high == ~0 ) + initrd_copy_to_ram =0 ; + }else { +/* not set, no restrictions to load high */ + initrd_high = ~0 ; + } + +#ifdef CONFIG_LOGBUFFER +/* Prevent initrd from overwriting logbuffer */ +if (initrd_high < (kbd->bi_memsize -LOGBUFF_LEN -LOGBUFF_OVERHEAD )) + initrd_high = kbd->bi_memsize -LOGBUFF_LEN -LOGBUFF_OVERHEAD ; +debug ("## Logbuffer at 0x%08lx " , kbd->bi_memsize -LOGBUFF_LEN ); +#endif +debug ("## initrd_high = 0x%08lx, copy_to_ram = %d\n" , + initrd_high, initrd_copy_to_ram); + +if (rd_data) { +if (!initrd_copy_to_ram) {/* zero-copy ramdisk support */ +debug (" in-place initrd\n" ); + *initrd_start = rd_data; + *initrd_end = rd_data + rd_len; + }else { + *initrd_start = (ulong )kbd - rd_len; + *initrd_start &= ~(4096 -1 );/* align on page */ + +if (initrd_high) { +ulong nsp; + +/* +* the inital ramdisk does not need to be within +* CFG_BOOTMAPSZ as it is not accessed until after +* the mm system is initialised. +* +* do the stack bottom calculation again and see if +* the initrd will fit just below the monitor stack +* bottom without overwriting the area allocated +* for command line args and board info. +*/ + nsp = sp; + nsp -=2048 ;/* just to be sure */ + nsp &= ~0xF ; + +if (nsp > initrd_high)/* limit as specified */ + nsp = initrd_high; + + nsp -= rd_len; + nsp &= ~(4096 -1 );/* align on page */ + +if (nsp >= sp_limit) + *initrd_start = nsp; + } + +show_boot_progress (12 ); + + *initrd_end = *initrd_start + rd_len; +printf (" Loading Ramdisk to %08lx, end %08lx ... " , + *initrd_start, *initrd_end); + +memmove_wd ((void *)*initrd_start, + (void *)rd_data, rd_len,CHUNKSZ ); + +puts ("OK\n" ); + } + }else { + *initrd_start =0 ; + *initrd_end =0 ; + } +debug (" ramdisk load start = 0x%08lx, ramdisk load end = 0x%08lx\n" , + *initrd_start, *initrd_end); +} +#endif /* CONFIG_PPC || CONFIG_M68K */ #endif /* USE_HOSTCC */
include/image.h +6 -1
@@ -37,6 +37,7 @@#include <command.h> #ifndef USE_HOSTCC #include <linux/string.h> +#include <asm/u-boot.h> #endif /*
@@ -340,7 +341,11 @@ image_header_t* image_get_ramdisk (cmd_tbl_t *cmdtp, int flag,void get_ramdisk (cmd_tbl_t *cmdtp,int flag,int argc,char *argv[],image_header_t *hdr,int verify,uint8_t arch,ulong *rd_start,ulong *rd_end); -#endif /* USE_HOSTCCa */ +#if defined(CONFIG_PPC ) || defined(CONFIG_M68K ) +void ramdisk_high (ulong rd_data_start,ulong rd_len,bd_t *kbd,ulong sp_limit, +ulong sp,ulong *initrd_start,ulong *initrd_end); +#endif /* CONFIG_PPC || CONFIG_M68K */ +#endif /* USE_HOSTCC */ #endif /* __IMAGE_H__ */
lib_m68k/bootm.c +26 -88
158 lines not on this page · raw message
lib_ppc/bootm.c +26 -86
178 lines not on this page · raw message
PATCH 4/6 Cleanup PPC and M68K do_bootm_linux() boot allocations
In reply to Marian BalakowiczThis patch moves common pre-boot allocation steps shared between PPC and M68K to a helper routines:
common:
- get_boot_sp_limit()
- get_boot_cmline()
- get_boot_kbd()
platform:
- set_clocks_in_mhz()
---
common/image.c | 118 ++++++++++++++++++++++++++++++++++++++++++++++++++---- include/image.h | 10 ++++- lib_m68k/bootm.c | 72 +++++++++++++-------------------- lib_ppc/bootm.c | 106 ++++++++++++++++++++----------------------------- 4 files changed, 189 insertions(+), 117 deletions(-)
common/image.c +109 -9
@@ -42,9 +42,15 @@#endif extern int do_reset (cmd_tbl_t *cmdtp,int flag,int argc,char *argv[]); + +#ifdef CONFIG_CMD_BDI +extern int do_bdinfo (cmd_tbl_t *cmdtp,int flag,int argc,char *argv[]); +#endif + +DECLARE_GLOBAL_DATA_PTR ;#else #include "mkimage.h" -#endif +#endif /* USE_HOSTCC*/ #include <image.h>
@@ -501,17 +507,19 @@ void get_ramdisk (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],* variable and if requested ramdisk data is moved to a specified location. * * returns: -* initrd_start and initrd_end are set to final (after relocation) ramdisk +* - initrd_start and initrd_end are set to final (after relocation) ramdisk * start/end addresses if ramdisk image start and len were provided -* otherwise set initrd_start and initrd_end to zeros -* +* otherwise set initrd_start and initrd_end set to zeros +* - returns new allc_current, next free address below BOOTMAPSZ */ -void ramdisk_high (ulong rd_data,ulong rd_len,bd_t *kbd,ulong sp_limit, -ulong sp,ulong *initrd_start,ulong *initrd_end) +ulong ramdisk_high (ulong alloc_current,ulong rd_data,ulong rd_len, +bd_t *kbd,ulong sp_limit,ulong sp, +ulong *initrd_start,ulong *initrd_end) {char *s;ulong initrd_high;int initrd_copy_to_ram =1 ; +ulong new_alloc_current = alloc_current;if ((s =getenv ("initrd_high" )) !=NULL ) {/* a value of "no" or a similar string will act like 0,
@@ -540,7 +548,8 @@ void ramdisk_high (ulong rd_data, ulong rd_len, bd_t *kbd, ulong sp_limit, *initrd_start = rd_data; *initrd_end = rd_data + rd_len; }else { - *initrd_start = (ulong )kbd - rd_len; + new_alloc_current = alloc_current - rd_len; + *initrd_start = new_alloc_current; *initrd_start &= ~(4096 -1 );/* align on page */ if (initrd_high) {
@@ -566,8 +575,10 @@ void ramdisk_high (ulong rd_data, ulong rd_len, bd_t *kbd, ulong sp_limit, nsp -= rd_len; nsp &= ~(4096 -1 );/* align on page */ -if (nsp >= sp_limit) +if (nsp >= sp_limit) { *initrd_start = nsp; + new_alloc_current = alloc_current; + } }show_boot_progress (12 );
@@ -587,7 +598,96 @@ void ramdisk_high (ulong rd_data, ulong rd_len, bd_t *kbd, ulong sp_limit, }debug (" ramdisk load start = 0x%08lx, ramdisk load end = 0x%08lx\n" , *initrd_start, *initrd_end); + +return new_alloc_current; +} + +/** +* get_boot_sp_limit - calculate stack pointer limit +* @sp: current stack pointer +* +* get_boot_sp_limit() takes current stack pointer adrress and calculates +* stack pointer limit, below which kernel boot data (cmdline, board info, +* etc.) will be allocated. +* +* returns: +* stack pointer limit +*/ +ulong get_boot_sp_limit (ulong sp) +{ +ulong sp_limit = sp; + + sp_limit -=2048 ;/* just to be sure */ + +/* make sure sp_limit is within kernel mapped space */ +if (sp_limit >CFG_BOOTMAPSZ ) + sp_limit =CFG_BOOTMAPSZ ; + sp_limit &= ~0xF ; + +return sp_limit; +} + +/** +* get_boot_cmdline - allocate and initialize kernel cmdline +* @alloc_current: current boot allocation address (counting down +* from sp_limit) +* @cmd_start: pointer to a ulong variable, will hold cmdline start +* @cmd_end: pointer to a ulong variable, will hold cmdline end +* +* get_boot_cmdline() allocates space for kernel command line below +* provided alloc_current address. If "bootargs" U-boot environemnt +* variable is present its contents is copied to allocated kernel +* command line. +* +* returns: +* alloc_current after cmdline allocation +*/ +ulong get_boot_cmdline (ulong alloc_current,ulong *cmd_start,ulong *cmd_end) +{ +char *cmdline; +char *s; + + cmdline = (char *)((alloc_current -CFG_BARGSIZE ) & ~0xF ); + +if ((s =getenv ("bootargs" )) ==NULL ) + s ="" ; + +strcpy (cmdline, s); + + *cmd_start = (ulong) & cmdline[0 ]; + *cmd_end = *cmd_start +strlen (cmdline); + +debug ("## cmdline at 0x%08lx ... 0x%08lx\n" , *cmd_start, *cmd_end); + +return (ulong )cmdline; +} + +/** +* get_boot_kbd - allocate and initialize kernel copy of board info +* @alloc_current: current boot allocation address (counting down +* from sp_limit) +* @kbd: double pointer to board info data +* +* get_boot_kbd() - allocates space for kernel copy of board info data. +* Space is allocated below provided alloc_current address and kernel +* board info is initialized with the current u-boot board info data. +* +* returns: +* alloc_current after kbd allocation +*/ +ulong get_boot_kbd (ulong alloc_current,bd_t **kbd) +{ + *kbd = (bd_t *) (((ulong )alloc_current -sizeof (bd_t)) & ~0xF ); + **kbd = *(gd->bd); + +debug ("## kernel board info at 0x%08lx\n" , (ulong)*kbd); + +#if defined(DEBUG ) && defined(CONFIG_CMD_BDI ) +do_bdinfo (NULL ,0 ,0 ,NULL ); +#endif + +return (ulong)*kbd; }#endif /* CONFIG_PPC || CONFIG_M68K */ -#endif /* USE_HOSTCC */ +#endif /* USE_HOSTCC */
include/image.h +8 -2
@@ -343,9 +343,15 @@ void get_ramdisk (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[], ulong *rd_start, ulong *rd_end);#if defined(CONFIG_PPC ) || defined(CONFIG_M68K ) -void ramdisk_high (ulong rd_data_start,ulong rd_len,bd_t *kbd,ulong sp_limit, -ulong sp,ulong *initrd_start,ulong *initrd_end); +ulong ramdisk_high (ulong alloc_current,ulong rd_data,ulong rd_len, +bd_t *kbd,ulong sp_limit,ulong sp, +ulong *initrd_start,ulong *initrd_end); + +ulong get_boot_sp_limit (ulong sp); +ulong get_boot_cmdline (ulong alloc_current,ulong *cmd_start,ulong *cmd_end); +ulong get_boot_kbd (ulong alloc_current,bd_t **kbd);#endif /* CONFIG_PPC || CONFIG_M68K */ +#endif /* USE_HOSTCC */ #endif /* __IMAGE_H__ */
lib_m68k/bootm.c +28 -44
118 lines not on this page · raw message
lib_ppc/bootm.c +44 -62
149 lines not on this page · raw message
PATCH 5/6 Cleanup FDT handling in PPC do_boot_linux()
In reply to Marian BalakowiczMove FDT blob finding and relocation to a dedicated get_fdt() routine. It increases code readability and will make adding support for new uImage format easier.
---
lib_ppc/bootm.c | 285 ++++++++++++++++++++++++++++++------------------------- 1 files changed, 158 insertions(+), 127 deletions(-)
lib_ppc/bootm.c +158 -127
@@ -41,6 +41,9 @@#include <fdt_support.h> static void fdt_error (const char *msg); +static ulong get_fdt (ulong alloc_current,cmd_tbl_t *cmdtp,int flag, +int argc,char *argv[], +image_header_t *hdr,char **of_flat_tree);#endif #ifdef CFG_INIT_RAM_LOCK
@@ -69,9 +72,7 @@ do_bootm_linux(cmd_tbl_t *cmdtp, int flag,void (*kernel)(bd_t *,ulong ,ulong ,ulong ,ulong );#if defined(CONFIG_OF_LIBFDT ) -image_header_t *fdt_hdr; -char *of_flat_tree =NULL ; -ulong of_data =0 ; +char *of_flat_tree;#endif /*
@@ -111,131 +112,9 @@ do_bootm_linux(cmd_tbl_t *cmdtp, int flag,#if defined(CONFIG_OF_LIBFDT )/* find flattened device tree */ -if (argc >3 ) { - of_flat_tree = (char *)simple_strtoul (argv[3 ],NULL ,16 ); - fdt_hdr = (image_header_t *)of_flat_tree; - -if (fdt_check_header (of_flat_tree) ==0 ) { -#ifndef CFG_NO_FLASH -if (addr2info ((ulong )of_flat_tree) !=NULL ) - of_data = (ulong )of_flat_tree; -#endif - }else if (image_check_magic (fdt_hdr)) { -ulong image_start, image_end; -ulong load_start, load_end; - -printf ("## Flat Device Tree at %08lX\n" , fdt_hdr); -print_image_hdr (fdt_hdr); - - image_start = (ulong )fdt_hdr; - image_end =image_get_image_end (fdt_hdr); - - load_start =image_get_load (fdt_hdr); - load_end = load_start +image_get_data_size (fdt_hdr); - -if ((load_start < image_end) && (load_end > image_start)) { -fdt_error ("fdt overwritten" ); -do_reset (cmdtp, flag, argc, argv); - } - -puts (" Verifying Checksum ... " ); -if (!image_check_hcrc (fdt_hdr)) { -fdt_error ("fdt header checksum invalid" ); -do_reset (cmdtp, flag, argc, argv); - } - -if (!image_check_dcrc (fdt_hdr)) { -fdt_error ("fdt checksum invalid" ); -do_reset (cmdtp, flag, argc, argv); - } -puts ("OK\n" ); - -if (!image_check_type (fdt_hdr,IH_TYPE_FLATDT )) { -fdt_error ("uImage is not a fdt" ); -do_reset (cmdtp, flag, argc, argv); - } -if (image_get_comp (fdt_hdr) !=IH_COMP_NONE ) { -fdt_error ("uImage is compressed" ); -do_reset (cmdtp, flag, argc, argv); - } -if (fdt_check_header (of_flat_tree +image_get_header_size ()) !=0 ) { -fdt_error ("uImage data is not a fdt" ); -do_reset (cmdtp, flag, argc, argv); - } - -memmove ((void *)image_get_load (fdt_hdr), - (void *)(of_flat_tree +image_get_header_size ()), -image_get_data_size (fdt_hdr)); - - of_flat_tree = (char *)image_get_load (fdt_hdr); - }else { -fdt_error ("Did not find a Flattened Device Tree" ); -do_reset (cmdtp, flag, argc, argv); - } -printf (" Booting using the fdt at 0x%x\n" , - of_flat_tree); - }else if (image_check_type (hdr,IH_TYPE_MULTI )) { -ulong fdt_data, fdt_len; - -image_multi_getimg (hdr,2 , &fdt_data, &fdt_len); -if (fdt_len) { - - of_flat_tree = (char *)fdt_data; - -#ifndef CFG_NO_FLASH -/* move the blob if it is in flash (set of_data to !null) */ -if (addr2info ((ulong )of_flat_tree) !=NULL ) - of_data = (ulong )of_flat_tree; -#endif - -if (fdt_check_header (of_flat_tree) !=0 ) { -fdt_error ("image is not a fdt" ); -do_reset (cmdtp, flag, argc, argv); - } - -if (be32_to_cpu (fdt_totalsize (of_flat_tree)) != fdt_len) { -fdt_error ("fdt size != image size" ); -do_reset (cmdtp, flag, argc, argv); - } - } - } -#endif - - -#if defined(CONFIG_OF_LIBFDT ) - -#ifdef CFG_BOOTMAPSZ -/* -* The blob must be within CFG_BOOTMAPSZ, -* so we flag it to be copied if it is not. -*/ -if (of_flat_tree >= (char *)CFG_BOOTMAPSZ ) - of_data = (ulong )of_flat_tree; -#endif - -/* move of_flat_tree if needed */ -if (of_data) { -int err; -ulong of_start, of_len; - - of_len =be32_to_cpu (fdt_totalsize (of_data)); - -/* position on a 4K boundary before the alloc_current */ - of_start = alloc_current - of_len; - of_start &= ~(4096 -1 );/* align on page */ -debug ("## device tree at 0x%08lX ... 0x%08lX (len=%ld=0x%lX)\n" , - of_data, of_data + of_len -1 , of_len, of_len); + alloc_current =get_fdt (alloc_current, + cmdtp, flag, argc, argv, hdr, &of_flat_tree); - of_flat_tree = (char *)of_start; -printf (" Loading Device Tree to %08lx, end %08lx ... " , - of_start, of_start + of_len -1 ); - err =fdt_open_into ((void *)of_data, (void *)of_start, of_len); -if (err !=0 ) { -fdt_error ("fdt move failed" ); -do_reset (cmdtp, flag, argc, argv); - } -puts ("OK\n" ); - }/* * Add the chosen node if it doesn't exist, add the env and bd_t * if the user wants it (the logic is in the subroutines).
@@ -342,4 +221,156 @@ static void fdt_error (const char *msg)puts (msg);puts (" - must RESET the board to recover.\n" ); } + +static ulong get_fdt (ulong alloc_current, +cmd_tbl_t *cmdtp,int flag, +int argc,char *argv[], +image_header_t *hdr,char **of_flat_tree) +{ +image_header_t *fdt_hdr; +ulong fdt_relocate =0 ; +char *fdt =NULL ; +ulong new_alloc_current; + +if (argc >3 ) { + fdt = (char *)simple_strtoul (argv[3 ],NULL ,16 ); + fdt_hdr = (image_header_t *)fdt; + +if (fdt_check_header (fdt) ==0 ) { +printf ("## Flattened Device Tree blob at %08lx\n" , fdt); +#ifndef CFG_NO_FLASH +if (addr2info ((ulong )fdt) !=NULL ) + fdt_relocate =1 ; +#endif + }else if (image_check_magic (fdt_hdr)) { +ulong image_start, image_end; +ulong load_start, load_end; + +printf ("## Flattened Device Tree Image at %08lx\n" , + fdt_hdr); + +print_image_hdr (fdt_hdr); + + image_start = (ulong )fdt_hdr; + image_end =image_get_image_end (fdt_hdr); + + load_start =image_get_load (fdt_hdr); + load_end = load_start +image_get_data_size (fdt_hdr); + +if ((load_start < image_end) && (load_end > image_start)) { +fdt_error ("fdt overwritten" ); +do_reset (cmdtp, flag, argc, argv); + } + +puts (" Verifying Checksum ... " ); +if (!image_check_hcrc (fdt_hdr)) { +fdt_error ("fdt header checksum invalid" ); +do_reset (cmdtp, flag, argc, argv); + } + +if (!image_check_dcrc (fdt_hdr)) { +fdt_error ("fdt checksum invalid" ); +do_reset (cmdtp, flag, argc, argv); + } +puts ("OK\n" ); + +if (!image_check_type (fdt_hdr,IH_TYPE_FLATDT )) { +fdt_error ("uImage is not a fdt" ); +do_reset (cmdtp, flag, argc, argv); + } +if (image_get_comp (fdt_hdr) !=IH_COMP_NONE ) { +fdt_error ("uImage is compressed" ); +do_reset (cmdtp, flag, argc, argv); + } +if (fdt_check_header ((char *)image_get_data (fdt_hdr)) !=0 ) { +fdt_error ("uImage data is not a fdt" ); +do_reset (cmdtp, flag, argc, argv); + } + +memmove ((void *)image_get_load (fdt_hdr), + (void *)image_get_data (fdt_hdr), +image_get_data_size (fdt_hdr)); + + fdt = (char *)image_get_load (fdt_hdr); + }else { +fdt_error ("Did not find a Flattened Device Tree" ); +do_reset (cmdtp, flag, argc, argv); + } +printf (" Booting using the fdt at 0x%x\n" , + fdt); + }else if (image_check_type (hdr,IH_TYPE_MULTI )) { +ulong fdt_data, fdt_len; + +printf ("## Flattened Device Tree from multi " +"component Image at %08lX\n" , (ulong )hdr); + +image_multi_getimg (hdr,2 , &fdt_data, &fdt_len); +if (fdt_len) { + + fdt = (char *)fdt_data; +printf (" Booting using the fdt at 0x%x\n" , fdt); + +#ifndef CFG_NO_FLASH +/* move the blob if it is in flash (set of_relocte) */ +if (addr2info ((ulong )fdt) !=NULL ) + fdt_relocate =1 ; +#endif + +if (fdt_check_header (fdt) !=0 ) { +fdt_error ("image is not a fdt" ); +do_reset (cmdtp, flag, argc, argv); + } + +if (be32_to_cpu (fdt_totalsize (fdt)) != fdt_len) { +fdt_error ("fdt size != image size" ); +do_reset (cmdtp, flag, argc, argv); + } + }else { +debug (" Did not find a Flattened Device Tree" ); + } + } + +#ifdef CFG_BOOTMAPSZ +/* +* The blob must be within CFG_BOOTMAPSZ, +* so we flag it to be copied if it is not. +*/ +if (fdt >= (char *)CFG_BOOTMAPSZ ) + fdt_relocate =1 ; +#endif + +/* move flattend device tree if needed */ +if (fdt_relocate) { +int err; +ulong of_start, of_len; + + of_len =be32_to_cpu (fdt_totalsize (fdt)); + +/* position on a 4K boundary before the alloc_current */ + of_start = alloc_current - of_len; + of_start &= ~(4096 -1 );/* align on page */ + +debug ("## device tree at 0x%08lX ... 0x%08lX (len=%ld=0x%lX)\n" , + (ulong )fdt, (ulong )fdt + of_len -1 , + of_len, of_len); + +printf (" Loading Device Tree to %08lx, end %08lx ... " , + of_start, of_start + of_len -1 ); + + err =fdt_open_into (fdt, (void *)of_start, of_len); +if (err !=0 ) { +fdt_error ("fdt move failed" ); +do_reset (cmdtp, flag, argc, argv); + } +puts ("OK\n" ); + + *of_flat_tree = (char *)of_start; + new_alloc_current = of_start; + }else { + *of_flat_tree = fdt; + new_alloc_current = alloc_current; + } + +return new_alloc_current; +}#endif
PATCH 6/6 Move kernel data find code to get_kernel() routine
In reply to Marian BalakowiczVerification of the kernel image (in old format) and finding kernel data is moved to a dedicated routine. The routine will also hold support for, to be added, new image format.
---
common/cmd_bootm.c | 181 +++++++++++++++++++++++++++++++--------------------- 1 files changed, 107 insertions(+), 74 deletions(-)
common/cmd_bootm.c +107 -74
@@ -74,6 +74,9 @@ static void fixup_silent_linux (void);#endif static void print_type (image_header_t *hdr); +static image_header_t *get_kernel (cmd_tbl_t *cmdtp,int flag, +int argc,char *argv[],int verify, +ulong *os_data,ulong *os_len);extern int do_reset (cmd_tbl_t *cmdtp,int flag,int argc,char *argv[]);/*
@@ -121,85 +124,17 @@ int do_bootm (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])int verify =getenv_verify ();image_header_t *hdr; -ulong img_addr;ulong os_data, os_len;ulong image_start, image_end;ulong load_start, load_end; - -if (argc <2 ) { - img_addr = load_addr; - }else { - img_addr =simple_strtoul (argv[1 ],NULL ,16 ); - } - -show_boot_progress (1 ); -printf ("## Booting image@%08lx ...\n" , img_addr); - -#ifdef CONFIG_HAS_DATAFLASH -if (addr_dataflash (img_addr)){ - hdr = (image_header_t *)CFG_LOAD_ADDR ; -read_dataflash (img_addr,image_get_header_size (), (char *)hdr); - } else -#endif - hdr = (image_header_t *)img_addr; - -if (!image_check_magic (hdr)) { -puts ("Bad Magic Number\n" ); -show_boot_progress (-1 ); -return 1 ; - } -show_boot_progress (2 ); - -if (!image_check_hcrc (hdr)) { -puts ("Bad Header Checksum\n" ); -show_boot_progress (-2 ); +/* get kernel image header, start address and length */ + hdr =get_kernel (cmdtp, flag, argc, argv, verify, + &os_data, &os_len); +if (hdr ==NULL )return 1 ; - } -show_boot_progress (3 ); -#ifdef CONFIG_HAS_DATAFLASH -if (addr_dataflash (img_addr)) -read_dataflash (img_addr +image_get_header_size (), -image_get_data_size (hdr), - (char *)image_get_data (hdr)); -#endif - -/* uImage is in a system RAM, pointed to by hdr */ -print_image_hdr (hdr); - -if (verify) { -puts (" Verifying Checksum ... " ); -if (!image_check_dcrc (hdr)) { -printf ("Bad Data CRC\n" ); -show_boot_progress (-3 ); -return 1 ; - } -puts ("OK\n" ); - } -show_boot_progress (4 ); - -if (!image_check_target_arch (hdr)) { -printf ("Unsupported Architecture 0x%x\n" ,image_get_arch (hdr)); -show_boot_progress (-4 ); -return 1 ; - } -show_boot_progress (5 ); - -switch (image_get_type (hdr)) { -case IH_TYPE_KERNEL : - os_data =image_get_data (hdr); - os_len =image_get_data_size (hdr); -break ; -case IH_TYPE_MULTI : -image_multi_getimg (hdr,0 , &os_data, &os_len); -break ; -default : -printf ("Wrong Image Type for %s command\n" , cmdtp->name); -show_boot_progress (-5 ); -return 1 ; - }show_boot_progress (6 );/*
@@ -229,7 +164,7 @@ int do_bootm (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])switch (image_get_comp (hdr)) {case IH_COMP_NONE : -if (image_get_load (hdr) == img_addr) { +if (image_get_load (hdr) == (ulong )hdr) {printf (" XIP %s ... " , type_name); }else {printf (" Loading %s ... " , type_name);
@@ -280,6 +215,7 @@ int do_bootm (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])return 1 ; }puts ("OK\n" ); +debug (" kernel loaded at 0x%08lx, end = 0x%08lx\n" , load_start, load_end);show_boot_progress (7 );if ((load_start < image_end) && (load_end > image_start)) {
@@ -340,6 +276,103 @@ int do_bootm (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])return 1 ; } +/** +* get_kernel - find kernel image +* @os_data: pointer to a ulong variable, will hold os data start address +* @os_len: pointer to a ulong variable, will hold os data length +* +* get_kernel() tries to find a kernel image, verifies its integrity +* and locates kernel data. +* +* returns: +* pointer to image header if valid image was found, plus kernel start +* address and length, otherwise NULL +*/ +static image_header_t *get_kernel (cmd_tbl_t *cmdtp,int flag, +int argc,char *argv[],int verify, +ulong *os_data,ulong *os_len) +{ +image_header_t *hdr; +ulong img_addr; + +if (argc <2 ) { + img_addr = load_addr; + }else { + img_addr =simple_strtoul (argv[1 ],NULL ,16 ); + } + +show_boot_progress (1 ); +printf ("## Booting image@%08lx ...\n" , img_addr); + +#ifdef CONFIG_HAS_DATAFLASH +if (addr_dataflash (img_addr)){ + hdr = (image_header_t *)CFG_LOAD_ADDR ; +read_dataflash (img_addr,image_get_header_size (), (char *)hdr); + } else +#endif + hdr = (image_header_t *)img_addr; + +if (!image_check_magic (hdr)) { +puts ("Bad Magic Number\n" ); +show_boot_progress (-1 ); +return NULL ; + } +show_boot_progress (2 ); + +if (!image_check_hcrc (hdr)) { +puts ("Bad Header Checksum\n" ); +show_boot_progress (-2 ); +return NULL ; + } +show_boot_progress (3 ); + +#ifdef CONFIG_HAS_DATAFLASH +if (addr_dataflash (img_addr)) +read_dataflash (img_addr +image_get_header_size (), +image_get_data_size (hdr), + (char *)image_get_data (hdr)); +#endif + +/* uImage is in a system RAM, pointed to by hdr */ +print_image_hdr (hdr); + +if (verify) { +puts (" Verifying Checksum ... " ); +if (!image_check_dcrc (hdr)) { +printf ("Bad Data CRC\n" ); +show_boot_progress (-3 ); +return NULL ; + } +puts ("OK\n" ); + } +show_boot_progress (4 ); + +if (!image_check_target_arch (hdr)) { +printf ("Unsupported Architecture 0x%x\n" ,image_get_arch (hdr)); +show_boot_progress (-4 ); +return NULL ; + } +show_boot_progress (5 ); + +switch (image_get_type (hdr)) { +case IH_TYPE_KERNEL : + *os_data =image_get_data (hdr); + *os_len =image_get_data_size (hdr); +break ; +case IH_TYPE_MULTI : +image_multi_getimg (hdr,0 , os_data, os_len); +break ; +default : +printf ("Wrong Image Type for %s command\n" , cmdtp->name); +show_boot_progress (-5 ); +return NULL ; + } +debug (" kernel data at 0x%08lx, end = 0x%08lx\n" , + *os_data, *os_data + *os_len); + +return hdr; +} + U_BOOT_CMD( bootm, CFG_MAXARGS, 1, do_bootm, "bootm - boot application image from memory\n",
@@ -502,7 +535,7 @@ U_BOOT_CMD(#endif /*******************************************************************/ -/* */ +/* helper routines */ /*******************************************************************/ void print_image_hdr (image_header_t *hdr) {
cover patchset3 - legacy code refactoring
In reply to Marian BalakowiczQuoted 33 lines · Marian Balakowicz
This is the third patch-set of the new uImage format work. It concludes the
phase of clean-up and reorganization of the old format code, preparing the
ground for adding the code implementing the new format.All the new uImage patches sent to the list so far, as well as updates resulting from the feedback received, will be soon available from the new-image
branch of the u-boot-testing repository (there will be a separate announcement).The completion of the clean-up phase is a good moment to review the patches
posted to date, and help with testing. This work affects all architectures and
operating systems, so it would be much appreciated if people could give
u-boot-testing#new-image a try and report back. So far, the changes were tested
on a lite5200b board and successfully built for ppc, arm, mips and coldfire
targets.Work is now ongoing on adding support for the new format, results will be
posted to the list, and also available from u-boot-testing#new- image. Once the
implementation is complete, and the code is reviewed and tested, it will be
merged to the master.
Quoted 10 lines
Marian Balakowicz (6):
[new uImage] Move kernel data find code toget_kernel()routine [new uImage] Cleanup FDT handling in PPCdo_boot_linux()[new uImage] Cleanup PPC and M68Kdo_bootm_linux()boot
allocations
[new uImage] Move PPC and M68K ramdisk loading to a common
routine
[new uImage] Removed dead ramdisk code on microblaze architecture [new uImage] Factor out commonimage_get_ramdisk()routine
Have you thought about passing load_end into the do_bootm_* commands. I think this will help us do better allocation/memory management in bootm.
- k