bootm: refactor to prepare multiple initrd support
Subsystems (3)
cover bootm: refactor to prepare multiple initrd support
Linux can transparently handle concatenated individually compressed CPIOs just fine, but so far, the concantenation needed to happen before bootm is called.
This series prepares for supporting initrd concatenation by refactoring the bootm code to make it easier to extend in a follow-up series.
No functional change intended.
Ahmad Fatoum (10):
bootm: set image_data::initrd_res at a single place
bootm: fit: split support into dedicated file
bootm: uimage: split support into dedicated file
filetype: introduce filetype_fit
bootm: refactor for readability and extensibility
memory: move release_sdram_region into header
resource: make NULL in release_[sdram_]region a no-op
common: elf: use release_region unconditionally
memory: always print errors on request_sdram_region failure
memory: drop now duplicate request_sdram_region error messages
arch/arm/cpu/armv7r-mpu.c | 6 +- arch/arm/cpu/bootm-fip.c | 11 +- arch/arm/cpu/mmu_32.c | 4 +- arch/arm/lib32/bootm.c | 13 +- arch/arm/lib32/bootz.c | 7 +- common/Makefile | 2 + common/bootm-fit.c | 176 ++++++++++++++++++ common/bootm-uimage.c | 176 ++++++++++++++++++ common/bootm.c | 376 ++++++-------------------------------- common/elf.c | 11 +- common/filetype.c | 1 + common/image-fit.c | 11 +- common/memory.c | 25 +-- common/resource.c | 2 + common/uimage.c | 12 +- fs/pstore/ram_core.c | 7 +- include/bootm-fit.h | 70 +++++++ include/bootm-uimage.h | 57 ++++++ include/filetype.h | 7 + include/memory.h | 45 ++++- lib/libfile.c | 5 +- 21 files changed, 625 insertions(+), 399 deletions(-) create mode 100644 common/bootm-fit.c create mode 100644 common/bootm-uimage.c create mode 100644 include/bootm-fit.h create mode 100644 include/bootm-uimage.h
Signature · 1 line
2.47.3
PATCH 1/10 bootm: set image_data::initrd_res at a single place
We are going to substantially rework this function, so make it easier to reason about by setting the externally visible image_data->initrd_res only at the end.
--- common/bootm.c | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-)
common/bootm.c +10 -12
@@ -339,6 +339,7 @@ static int bootm_open_initrd_uimage(struct image_data *data)const struct resource *bootm_load_initrd (struct image_data *data,unsigned long load_address) { +struct resource *res;enum filetype type;int ret;
@@ -362,10 +363,9 @@ bootm_load_initrd(struct image_data *data, unsigned long load_address) ERR_PTR(ret));return ERR_PTR (ret); } - data->initrd_res =request_sdram_region ("initrd" , - load_address, initrd_size, -MEMTYPE_LOADER_DATA ,MEMATTRS_RW ); -if (!data->initrd_res) { + res =request_sdram_region ("initrd" , load_address, initrd_size, +MEMTYPE_LOADER_DATA ,MEMATTRS_RW ); +if (!res) { pr_err("unable to request SDRAM region for initrd at" " 0x%08llx-0x%08llx\n", (unsigned long long)load_address,
@@ -397,16 +397,15 @@ bootm_load_initrd(struct image_data *data, unsigned long load_address) num =uimage_part_num (data->initrd_part); - data->initrd_res =uimage_load_to_sdram (data->initrd, - num, load_address); -if (!data->initrd_res) + res =uimage_load_to_sdram (data->initrd, num, load_address); +if (!res)return ERR_PTR (-ENOMEM ); goto done; } - data->initrd_res =file_to_sdram (data->initrd_file, load_address,MEMTYPE_LOADER_DATA ); -if (!data->initrd_res) + res =file_to_sdram (data->initrd_file, load_address,MEMTYPE_LOADER_DATA ); +if (!res)return ERR_PTR (-ENOMEM ); done:
@@ -417,10 +416,9 @@ bootm_load_initrd(struct image_data *data, unsigned long load_address)pr_info (", multifile image %s" , data->initrd_part);pr_info ("\n" ); done1: -pr_info ("initrd is at %pa-%pa\n" , - &data->initrd_res->start, - &data->initrd_res->end); +pr_info ("initrd is at %pa-%pa\n" , &res->start, &res->end); + data->initrd_res = res;return data->initrd_res; }
Signature · 1 line
2.47.3
PATCH 2/10 bootm: fit: split support into dedicated file
In reply to Ahmad FatoumInterleaving the FIT handling with the generic bootm code makes the generic code harder to follow. Let's factor it out into a dedicated file.
--- common/Makefile | 1 + common/bootm-fit.c | 185 ++++++++++++++++++++++++++++++++++++++++++++ common/bootm.c | 156 ++++--------------------------------- include/bootm-fit.h | 70 +++++++++++++++++ 4 files changed, 271 insertions(+), 141 deletions(-) create mode 100644 common/bootm-fit.c create mode 100644 include/bootm-fit.h
common/Makefile +1 -0
@@ -71,6 +71,7 @@ obj-$(CONFIG_RATP) += ratp/ obj-$(CONFIG_BOOTCHOOSER) += bootchooser.o obj-$(CONFIG_UIMAGE) += uimage_types.o uimage.o obj-$(CONFIG_FITIMAGE) += image-fit.o +obj-$(CONFIG_BOOTM_FITIMAGE) += bootm-fit.o obj-$(CONFIG_MENUTREE) += menutree.o lwl-$(CONFIG_IMD) += imd-barebox.o obj-$(CONFIG_IMD) += imd.o
common/bootm-fit.c new file +185 -0
185 lines not on this page · raw message
common/bootm.c +15 -141
215 lines not on this page · raw message
include/bootm-fit.h new file +70 -0
70 lines not on this page · raw message
Signature · 1 line
2.47.3
PATCH 3/10 bootm: uimage: split support into dedicated file
In reply to Ahmad FatoumInterleaving the uImage handling with the generic bootm code makes the generic code harder to follow. Let's factor it out into a dedicated file.
--- common/Makefile | 1 + common/bootm-uimage.c | 176 +++++++++++++++++++++++++++++++++++++++++ common/bootm.c | 143 +++------------------------------ include/bootm-uimage.h | 57 +++++++++++++ 4 files changed, 243 insertions(+), 134 deletions(-) create mode 100644 common/bootm-uimage.c create mode 100644 include/bootm-uimage.h
common/Makefile +1 -0
@@ -70,6 +70,7 @@ obj-$(CONFIG_TLV) += tlv/ obj-$(CONFIG_RATP) += ratp/ obj-$(CONFIG_BOOTCHOOSER) += bootchooser.o obj-$(CONFIG_UIMAGE) += uimage_types.o uimage.o +obj-$(CONFIG_BOOTM_UIMAGE) += bootm-uimage.o obj-$(CONFIG_FITIMAGE) += image-fit.o obj-$(CONFIG_BOOTM_FITIMAGE) += bootm-fit.o obj-$(CONFIG_MENUTREE) += menutree.o
common/bootm-uimage.c new file +176 -0
176 lines not on this page · raw message
common/bootm.c +9 -134
191 lines not on this page · raw message
include/bootm-uimage.h new file +57 -0
57 lines not on this page · raw message
Signature · 1 line
2.47.3
PATCH 4/10 filetype: introduce filetype_fit
In reply to Ahmad FatoumIt's not possible to differentiate a flattened device tree from a FIT image without parsing it for top-level /images and /configurations node.
We thus have some checks that check for filetype_oftree instead of filetype_fit, which is confusing. Let's introduce filetype_fit and handle it at the boot layer to allow for slightly more readable code.
This will pay off some more when we start making use of it in a later commit.
--- common/bootm.c | 7 +++---- common/filetype.c | 1 + common/image-fit.c | 11 ++++++++++- include/filetype.h | 7 +++++++ 4 files changed, 21 insertions(+), 5 deletions(-)
common/bootm.c +3 -4
@@ -571,7 +571,7 @@ int bootm_boot(struct bootm_data *bootm_data)if (size <PAGE_SIZE ) goto err_out; - os_type = data->os_type =file_detect_type (data->os_header,PAGE_SIZE ); + os_type = data->os_type =file_detect_boot_image_type (data->os_header,PAGE_SIZE );if (!data->force && os_type == filetype_unknown) {pr_err ("Unknown OS filetype (try -f)\n" );
@@ -589,7 +589,7 @@ int bootm_boot(struct bootm_data *bootm_data) data->oftree_file =NULL ; data->initrd_file =NULL ; data->tee_file =NULL ; -if (os_type != filetype_oftree) { +if (os_type != filetype_fit) {pr_err ("Signed boot and image is no FIT image, aborting\n" ); ret = -EINVAL ; goto err_out;
@@ -599,10 +599,9 @@ int bootm_boot(struct bootm_data *bootm_data) os_type_str =file_type_to_short_string (os_type);switch (os_type) { -case filetype_oftree: +case filetype_fit: ret =bootm_open_fit (data); os_type =file_detect_type (data->fit_kernel, data->fit_kernel_size); - os_type_str ="FIT" ;break ;case filetype_uimage: ret =bootm_open_uimage (data);
common/filetype.c +1 -0
@@ -42,6 +42,7 @@ static const struct filetype_str filetype_str[] = { [filetype_gzip] = { "GZIP compressed", "gzip" }, [filetype_bzip2] = { "BZIP2 compressed", "bzip2" }, [filetype_oftree] = { "open firmware Device Tree flattened Binary", "dtb" }, + [filetype_fit] = { "Flattened Image Tree", "FIT" }, [filetype_aimage] = { "android boot image", "android" }, [filetype_sh] = { "bourne SHell", "sh" }, [filetype_mips_barebox] = { "MIPS barebox image", "mips-barebox" },
common/image-fit.c +10 -1
@@ -1081,10 +1081,19 @@ static int do_bootm_fit(struct image_data *data)return -EINVAL ; } +static bool fitimage_check (struct image_handler *handler, +struct image_data *data, +enum filetype detected_filetype) +{ +return detected_filetype == filetype_oftree || + detected_filetype == filetype_fit; +} +static struct image_handler fit_handler = { .name ="FIT image" , .bootm = do_bootm_fit, - .filetype = filetype_oftree, + .filetype = filetype_fit, + .check_image = fitimage_check, };static int bootm_fit_register (void )
include/filetype.h +7 -0
@@ -24,6 +24,7 @@ enum filetype { filetype_gzip, filetype_bzip2, filetype_oftree, + filetype_fit, filetype_aimage, filetype_sh, filetype_mips_barebox,
@@ -108,6 +109,12 @@ static inline bool file_is_compressed_file(enum filetype ft) } } +static inline enum filetype file_detect_boot_image_type (const void *_buf,size_t bufsize) +{ +enum filetype ft =file_detect_type (_buf, bufsize); +return ft == filetype_oftree ? filetype_fit : ft; +} +#define ARM_HEAD_SIZE 0x30#define ARM_HEAD_MAGICWORD_OFFSET 0x20#define ARM_HEAD_SIZE_OFFSET 0x2C
Signature · 1 line
2.47.3
PATCH 5/10 bootm: refactor for readability and extensibility
In reply to Ahmad FatoumThe code is hard to follow with the gotos and the organically grown ordering. Let's refactor it, so we can start putting a loop around it.
--- common/bootm.c | 71 +++++++++++++++++++++++--------------------------- 1 file changed, 32 insertions(+), 39 deletions(-)
common/bootm.c +32 -39
@@ -280,61 +280,54 @@ int bootm_load_os(struct image_data *data, unsigned long load_address)const struct resource *bootm_load_initrd (struct image_data *data,unsigned long load_address) { -struct resource *res; -enum filetype type; +struct resource *res =NULL ; +const char *initrd, *initrd_part =NULL ; +enum filetype type = filetype_unknown;int ret;if (!IS_ENABLED (CONFIG_BOOTM_INITRD ))return NULL ; -if (bootm_get_override (&data->initrd_file, bootm_overrides.initrd_file)) - goto initrd_file; - -if (data->initrd_res) +/* TODO: This should not be set anywhere, but in case it is, let's print +* a warning to find out if we need this +*/ +if (WARN_ON (data->initrd_res))return data->initrd_res; -if (data->os_fit) { - res =bootm_load_fit_initrd (data, load_address); -if (IS_ERR (res)) -return res; -if (res) -pr_info ("Loaded initrd from FIT image\n" ); +bootm_get_override (&data->initrd_file, bootm_overrides.initrd_file); - goto done1; - } - -initrd_file: -if (!data->initrd_file) -return NULL ; - - ret =file_name_detect_type (data->initrd_file, &type); -if (ret) { -pr_err ("could not open initrd \"%s\": %pe\n" , data->initrd_file,ERR_PTR (ret)); -return ERR_PTR (ret); + initrd = data->initrd_file; +if (initrd) { + ret =file_name_detect_type (initrd, &type); +if (ret) { +pr_err ("could not open initrd \"%s\": %pe\n" , + initrd,ERR_PTR (ret)); +return ERR_PTR (ret); + } }if (type == filetype_uimage) { res =bootm_load_uimage_initrd (data, load_address); -if (IS_ERR (res)) -return res; +if (data->initrd->header.ih_type ==IH_TYPE_MULTI ) + initrd_part = data->initrd_part; + + }else if (initrd) { + res =file_to_sdram (initrd, load_address,MEMTYPE_LOADER_DATA ) + ?:ERR_PTR (-ENOMEM ); + + }else if (data->os_fit) { + res =bootm_load_fit_initrd (data, load_address); + type = filetype_fit; - goto done; } - res =file_to_sdram (data->initrd_file, load_address,MEMTYPE_LOADER_DATA ); -if (!res) -return ERR_PTR (-ENOMEM ); +if (IS_ERR_OR_NULL (res)) +return res; -done: - -pr_info ("Loaded initrd %s '%s'" ,file_type_to_string (type), - data->initrd_file); -if (type == filetype_uimage && data->initrd->header.ih_type ==IH_TYPE_MULTI ) -pr_info (", multifile image %s" , data->initrd_part); -pr_info ("\n" ); -done1: -if (res) -pr_info ("initrd is at %pa-%pa\n" , &res->start, &res->end); +pr_info ("Loaded initrd from %s %s%s%s to %pa-%pa\n" , +file_type_to_string (type), initrd, + initrd_part ?"@" :"" , initrd_part ?:"" , + &res->start, &res->end); data->initrd_res = res;return data->initrd_res;
Signature · 1 line
2.47.3
PATCH 6/10 memory: move release_sdram_region into header
In reply to Ahmad FatoumTo make it clear that release_sdram_region and release_region are the same, move it into a header and give it a comment saying as much.
--- common/memory.c | 5 ----- include/memory.h | 6 +++++- 2 files changed, 5 insertions(+), 6 deletions(-)
common/memory.c +0 -5
@@ -352,11 +352,6 @@ struct resource *reserve_sdram_region(const char *name, resource_size_t start,return res; } -int release_sdram_region (struct resource *res) -{ -return release_region (res); -} -void memory_bank_find_space (struct memory_bank *bank,resource_size_t *retstart,resource_size_t *retend) {
include/memory.h +5 -1
@@ -63,7 +63,11 @@ static inline struct resource *request_sdram_region(const char *name,struct resource *reserve_sdram_region (const char *name,resource_size_t start,resource_size_t size); -int release_sdram_region (struct resource *res); +/* It's always fine to call release_region directly as well */ +static inline int release_sdram_region (struct resource *res) +{ +return release_region (res); +}void memory_bank_find_space (struct memory_bank *bank,resource_size_t *retstart,resource_size_t *retend);
Signature · 1 line
2.47.3
PATCH 7/10 resource: make NULL in release_[sdram_]region a no-op
In reply to Ahmad FatoumBy handling the NULL inside release_region, we can remove some clutter in caller error handling for release_sdram_region.
--- arch/arm/cpu/bootm-fip.c | 5 ++--- arch/arm/lib32/bootz.c | 3 +-- common/bootm.c | 18 ++++++------------ common/resource.c | 2 ++ fs/pstore/ram_core.c | 7 +++---- 5 files changed, 14 insertions(+), 21 deletions(-)
arch/arm/cpu/bootm-fip.c +2 -3
@@ -52,9 +52,8 @@ static int desc_to_sdram(struct fip_image_desc *loadable, ulong load_address)static void desc_release_sdram (struct fip_image_desc *loadable) { -struct resource *res = loadable ?desc_get_res (loadable) :NULL ; -if (res) -release_sdram_region (res); +if (loadable) +release_sdram_region (desc_get_res (loadable)); }enum {IMAGE_BL33 ,IMAGE_HW_CONFIG ,IMAGE_COUNT };
arch/arm/lib32/bootz.c +1 -2
@@ -127,8 +127,7 @@ static int do_bootz(int argc, char *argv[])return 0 ; err_out2: -if (res) -release_sdram_region (res); +release_sdram_region (res); err_out1:free (zimage); err_out:
common/bootm.c +6 -12
@@ -748,10 +748,8 @@ int bootm_boot(struct bootm_data *bootm_data)bootm_get_override (&data->oftree_file, bootm_overrides.oftree_file);if (bootm_get_override (&data->initrd_file, bootm_overrides.initrd_file)) { -if (data->initrd_res) { -release_sdram_region (data->initrd_res); - data->initrd_res =NULL ; - } +release_sdram_region (data->initrd_res); + data->initrd_res =NULL ; } ret = handler->bootm (data);
@@ -759,14 +757,10 @@ int bootm_boot(struct bootm_data *bootm_data)pr_info ("Dryrun. Aborted\n" ); err_out: -if (data->os_res) -release_sdram_region (data->os_res); -if (data->initrd_res) -release_sdram_region (data->initrd_res); -if (data->oftree_res) -release_sdram_region (data->oftree_res); -if (data->tee_res) -release_sdram_region (data->tee_res); +release_sdram_region (data->os_res); +release_sdram_region (data->initrd_res); +release_sdram_region (data->oftree_res); +release_sdram_region (data->tee_res);if (image_is_uimage (data))bootm_close_uimage (data);if (data->os_fit)
common/resource.c +2 -0
@@ -97,6 +97,8 @@ struct resource *__request_region(struct resource *parent,*/ int release_region (struct resource *res) { +if (!res) +return 0 ;if (!list_empty (&res->children))return -EBUSY ;
fs/pstore/ram_core.c +3 -4
@@ -397,10 +397,9 @@ void persistent_ram_free(struct persistent_ram_zone *prz)if (!prz)return ; -if (prz->res) { -release_sdram_region (prz->res); - prz->res =NULL ; - } +release_sdram_region (prz->res); + prz->res =NULL ; +if (prz->rs_decoder) {free_rs (prz->rs_decoder); prz->rs_decoder =NULL ;
Signature · 1 line
2.47.3
PATCH 8/10 common: elf: use release_region unconditionally
In reply to Ahmad FatoumGiven that release_region and release_sdram_region are the same, just use release_region regardless of whether SDRAM or I/O memory region was requested.
--- common/elf.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-)
common/elf.c +1 -6
@@ -18,7 +18,6 @@ struct elf_segment {struct list_head list;struct resource *r;void *phdr; -bool is_iomem_region; }; static int elf_request_region(struct elf_image *elf, resource_size_t start,
@@ -40,7 +39,6 @@ static int elf_request_region(struct elf_image *elf, resource_size_t start,pr_err ("Failed to request region: %pa %pa\n" , &start, &size);return -EINVAL ; } - r->is_iomem_region = true; } r->r = r_new;
@@ -56,10 +54,7 @@ static void elf_release_regions(struct elf_image *elf)struct elf_segment *r, *r_tmp;list_for_each_entry_safe (r, r_tmp, list, list) { -if (r->is_iomem_region) -release_region (r->r); -else -release_sdram_region (r->r); +release_region (r->r);list_del (&r->list);free (r); }
Signature · 1 line
2.47.3
PATCH 9/10 memory: always print errors on request_sdram_region failure
In reply to Ahmad FatoumA failed request_sdram_region is nearly always a problem and warrants a print out.
Introduce request_sdram_region_silent() for the few cases, where an error is tolerated and print an error message in the general case.
--- arch/arm/cpu/armv7r-mpu.c | 6 +++--- arch/arm/cpu/bootm-fip.c | 6 +++--- arch/arm/cpu/mmu_32.c | 4 ++-- common/elf.c | 4 ++-- common/memory.c | 20 +++++++++++++------- include/memory.h | 39 +++++++++++++++++++++++++++++++-------- 6 files changed, 54 insertions(+), 25 deletions(-)
arch/arm/cpu/armv7r-mpu.c +3 -3
@@ -206,9 +206,9 @@ int armv7r_mpu_init_coherent(unsigned long start, enum size reg_size)static int armv7r_request_pool (void ) {if (dma_coherent_start && dma_coherent_size) -request_sdram_region ("DMA coherent pool" , - dma_coherent_start, dma_coherent_size, -MEMTYPE_BOOT_SERVICES_DATA ,MEMATTRS_RW ); +request_sdram_region_silent ("DMA coherent pool" , + dma_coherent_start, dma_coherent_size, +MEMTYPE_BOOT_SERVICES_DATA ,MEMATTRS_RW );return 0 ; }postmem_initcall (armv7r_request_pool);
arch/arm/cpu/bootm-fip.c +3 -3
@@ -36,9 +36,9 @@ static int desc_to_sdram(struct fip_image_desc *loadable, ulong load_address)if (desc_get_res (loadable))return 0 ; - res =request_sdram_region ("fip" , load_address, - loadable->image->toc_e.size, -MEMTYPE_LOADER_CODE ,MEMATTRS_RW ); + res =request_sdram_region_silent ("fip" , load_address, + loadable->image->toc_e.size, +MEMTYPE_LOADER_CODE ,MEMATTRS_RW );if (!res)return -EBUSY ;
arch/arm/cpu/mmu_32.c +2 -2
@@ -540,8 +540,8 @@ static void create_zero_page(void)* In case the zero page is in SDRAM request it to prevent others * from using it */ -request_sdram_region ("zero page" ,0x0 ,PAGE_SIZE , -MEMTYPE_BOOT_SERVICES_DATA ,MEMATTRS_FAULT ); +request_sdram_region_silent ("zero page" ,0x0 ,PAGE_SIZE , +MEMTYPE_BOOT_SERVICES_DATA ,MEMATTRS_FAULT );zero_page_faulting ();pr_debug ("Created zero page\n" );
common/elf.c +2 -2
@@ -31,8 +31,8 @@ static int elf_request_region(struct elf_image *elf, resource_size_t start,if (!r)return -ENOMEM ; - r_new =request_sdram_region ("elf_segment" , start, size, -MEMTYPE_LOADER_CODE ,MEMATTRS_RWX ); + r_new =request_sdram_region_silent ("elf_segment" , start, size, +MEMTYPE_LOADER_CODE ,MEMATTRS_RWX );if (!r_new) { r_new =request_iomem_region ("elf_segment" , start, size);if (!r_new) {
common/memory.c +13 -7
@@ -67,7 +67,7 @@ void register_barebox_area(resource_size_t start,static int mem_register_barebox (void ) {if (barebox_start && barebox_size) - barebox_res =request_sdram_region ("barebox" , barebox_start, + barebox_res =request_sdram_region_silent ("barebox" , barebox_start, barebox_size,MEMTYPE_BOOT_SERVICES_CODE ,MEMATTRS_RWX );// FIXME
@@ -108,7 +108,7 @@ struct resource *request_barebox_region(const char *name,return iores; } -return request_sdram_region (name, start, size, memtype, memattrs); +return request_sdram_region_silent (name, start, size, memtype, memattrs); }static int mem_malloc_resource (void )
@@ -122,7 +122,7 @@ static int mem_malloc_resource(void)* regions are outside of sdram in which case * the following fails. */ -request_sdram_region ("malloc space" , +request_sdram_region_silent ("malloc space" , malloc_start, malloc_end - malloc_start +1 ,MEMTYPE_BOOT_SERVICES_DATA ,MEMATTRS_RW );
@@ -179,7 +179,7 @@ static int mem_malloc_resource(void) MEMATTRS_RW);#endif #ifdef STACK_BASE -request_sdram_region ("stack" ,STACK_BASE ,STACK_SIZE , +request_sdram_region_silent ("stack" ,STACK_BASE ,STACK_SIZE ,MEMTYPE_BOOT_SERVICES_DATA ,MEMATTRS_RW );#endif
@@ -302,19 +302,25 @@ postmem_initcall(add_mem_devices);* Request a region from the registered sdram */ struct resource *__request_sdram_region (const char *name, -resource_size_t start,resource_size_t size) +resource_size_t start,resource_size_t size, +bool verbose) {struct memory_bank *bank; +resource_size_t end = start + size -1 ;for_each_memory_bank (bank) {struct resource *res; - res =__request_region (bank->res, start, start + size -1 , + res =__request_region (bank->res, start, end, name,IORESOURCE_MEM );if (!IS_ERR (res))return res; } +if (verbose) +pr_err ("unable to request SDRAM region for %s at %pa-%pa\n" , + name, &start, &end); +return NULL ; }
@@ -339,7 +345,7 @@ struct resource *reserve_sdram_region(const char *name, resource_size_t start,* want to set the reserved flag independently of whether * CONFIG_MEMORY_ATTRIBUTES is enabled or not */ - res =__request_sdram_region (name, start, size); + res =__request_sdram_region (name, start, size, true);if (!res)return NULL ;
include/memory.h +31 -8
@@ -39,7 +39,21 @@ int barebox_add_memory_bank(const char *name, resource_size_t start,for_each_resource_region_reverse ((bank)->res, region) struct resource *__request_sdram_region(const char *name, -resource_size_t start,resource_size_t size); +resource_size_t start,resource_size_t size, +bool verbose); + +static inline struct resource *sdram_region_with_attrs (struct resource *res, +enum resource_memtype memtype, +unsigned memattrs) +{ +if (IS_ENABLED (CONFIG_MEMORY_ATTRIBUTES ) && res) { + res->type = memtype; + res->attrs = memattrs; + res->flags |=IORESOURCE_TYPE_VALID ; + } + +return res; +} static inline struct resource *request_sdram_region(const char *name, resource_size_t start,
@@ -50,14 +64,23 @@ static inline struct resource *request_sdram_region(const char *name,struct resource *res;/* IORESOURCE_MEM is implicit for all SDRAM regions */ - res =__request_sdram_region (name, start, size); -if (IS_ENABLED (CONFIG_MEMORY_ATTRIBUTES ) && res) { - res->type = memtype; - res->attrs = memattrs; - res->flags |=IORESOURCE_TYPE_VALID ; - } + res =__request_sdram_region (name, start, size, true); -return res; +return sdram_region_with_attrs (res, memtype, memattrs); +} + +static inline struct resource *request_sdram_region_silent (const char *name, +resource_size_t start, +resource_size_t size, +enum resource_memtype memtype, +unsigned memattrs) +{ +struct resource *res; + +/* IORESOURCE_MEM is implicit for all SDRAM regions */ + res =__request_sdram_region (name, start, size, false); + +return sdram_region_with_attrs (res, memtype, memattrs); } struct resource *reserve_sdram_region(const char *name, resource_size_t start,
Signature · 1 line
2.47.3
PATCH 10/10 memory: drop now duplicate request_sdram_region error messages
In reply to Ahmad FatoumNow that we have a general printout inside request_sdram_region, let's drop the now unneeded duplicate prints.
--- arch/arm/lib32/bootm.c | 13 ++----------- arch/arm/lib32/bootz.c | 4 +--- common/bootm-fit.c | 15 +++------------ common/bootm.c | 7 +------ common/uimage.c | 12 ++---------- lib/libfile.c | 5 +---- 6 files changed, 10 insertions(+), 46 deletions(-)
arch/arm/lib32/bootm.c +2 -11
@@ -162,12 +162,8 @@ static int optee_verify_header_request_region(struct image_data *data, struct op data->tee_res =request_sdram_region ("TEE" , hdr->init_load_addr_lo, hdr->init_size,MEMTYPE_RESERVED ,MEMATTRS_RW_DEVICE ); -if (!data->tee_res) { -pr_err ("Cannot request SDRAM region 0x%08x-0x%08x: %pe\n" , - hdr->init_load_addr_lo, hdr->init_load_addr_lo + hdr->init_size -1 , -ERR_PTR (-EINVAL )); +if (!data->tee_res)return -EINVAL ; - }return 0 ; }
@@ -509,8 +505,6 @@ static int do_bootz_linux(struct image_data *data) data->os_res =request_sdram_region ("zimage" , load_address, image_size,MEMTYPE_LOADER_CODE ,MEMATTRS_RWX );if (!data->os_res) { -pr_err ("bootm/zImage: failed to request memory at 0x%lx to 0x%lx (%zu).\n" , - load_address, load_address + image_size, image_size); ret = -ENOMEM ; goto err_out; }
@@ -634,15 +628,12 @@ static int do_bootm_aimage(struct image_data *data) data->os_res =request_sdram_region ("akernel" , cmp->load_addr, cmp->size,MEMTYPE_LOADER_CODE ,MEMATTRS_RWX );if (!data->os_res) { -pr_err ("Cannot request region 0x%08x - 0x%08x, using default load address\n" , - cmp->load_addr, cmp->size); +pr_err ("using default load address\n" ); data->os_address = mem_start +PAGE_ALIGN (cmp->size *4 ); data->os_res =request_sdram_region ("akernel" , data->os_address, cmp->size,MEMTYPE_LOADER_CODE ,MEMATTRS_RWX );if (!data->os_res) { -pr_err ("Cannot request region 0x%08x - 0x%08x\n" , - cmp->load_addr, cmp->size); ret = -ENOMEM ; goto err_out; }
arch/arm/lib32/bootz.c +1 -3
@@ -90,10 +90,8 @@ static int do_bootz(int argc, char *argv[]) bank->res->start +SZ_8M , end,MEMTYPE_LOADER_CODE , MEMATTRS_RWX); -if (!res) { -printf ("can't request region for kernel\n" ); +if (!res) goto err_out1; - } }memcpy (zimage, header,sizeof (*header));
common/bootm-fit.c +3 -12
@@ -26,13 +26,9 @@ int bootm_load_fit_os(struct image_data *data, unsigned long load_address) data->os_res =request_sdram_region ("kernel" , load_address, kernel_size,MEMTYPE_LOADER_CODE ,MEMATTRS_RWX ); -if (!data->os_res) { -pr_err ("unable to request SDRAM region for kernel at" -" 0x%08llx-0x%08llx\n" , - (unsigned long long )load_address, - (unsigned long long )load_address + kernel_size -1 ); +if (!data->os_res)return -ENOMEM ; - } +zero_page_memcpy ((void *)load_address, kernel, kernel_size);return 0 ; }
@@ -75,13 +71,8 @@ struct resource *bootm_load_fit_initrd(struct image_data *data, unsigned long lo res =request_sdram_region ("initrd" , load_address, initrd_size,MEMTYPE_LOADER_DATA ,MEMATTRS_RW ); -if (!res) { -pr_err ("unable to request SDRAM region for initrd at" -" 0x%08llx-0x%08llx\n" , - (unsigned long long )load_address, - (unsigned long long )load_address + initrd_size -1 ); +if (!res)return ERR_PTR (-ENOMEM ); - }memcpy ((void *)load_address, initrd, initrd_size);return res;
common/bootm.c +1 -6
@@ -450,13 +450,8 @@ int bootm_load_devicetree(struct image_data *data, void *fdt, data->oftree_res =request_sdram_region ("oftree" , load_address, fdt_size,MEMTYPE_LOADER_DATA ,MEMATTRS_RW ); -if (!data->oftree_res) { -pr_err ("unable to request SDRAM region for device tree at" -" 0x%08llx-0x%08llx\n" , - (unsigned long long )load_address, - (unsigned long long )load_address + fdt_size -1 ); +if (!data->oftree_res)return -ENOMEM ; - }memcpy ((void *)data->oftree_res->start, fdt, fdt_size);
common/uimage.c +2 -10
@@ -349,12 +349,8 @@ static long uimage_sdram_flush(void *buf, unsigned long len) uimage_resource =request_sdram_region ("uimage" , start, size,MEMTYPE_LOADER_CODE ,MEMATTRS_RWX ); -if (!uimage_resource) { -resource_size_t prsize = start + size -1 ; -printf ("unable to request SDRAM %pa - %pa\n" , - &start, &prsize); +if (!uimage_resource)return -ENOMEM ; - } }if (zero_page_contains ((unsigned long )uimage_buf + uimage_size))
@@ -388,12 +384,8 @@ struct resource *uimage_load_to_sdram(struct uimage_handle *handle, uimage_resource =request_sdram_region ("uimage" , start, size,MEMTYPE_LOADER_CODE ,MEMATTRS_RWX ); -if (!uimage_resource) { -printf ("unable to request SDRAM 0x%08llx-0x%08llx\n" , - (unsigned long long )start, - (unsigned long long )start + size -1 ); +if (!uimage_resource)return NULL ; - } ret =uimage_load (handle, image_no, uimage_sdram_flush);if (ret) {
lib/libfile.c +1 -4
@@ -789,11 +789,8 @@ struct resource *file_to_sdram(const char *filename, unsigned long adr, res =request_sdram_region ("image" , adr, size, memtype, memattrs); -if (!res) { -printf ("unable to request SDRAM 0x%08lx-0x%08lx\n" , - adr, adr + size -1 ); +if (!res) goto out; - }if (zero_page_contains (res->start + ofs)) {void *tmp =malloc (BUFSIZ );
Signature · 1 line
2.47.3
Sascha Hauer
AppliedQuoted 8 lines · Ahmad Fatoum
Linux can transparently handle concatenated individually compressed CPIOs just fine, but so far, the concantenation needed to happen before bootm is called.
This series prepares for supporting initrd concatenation by refactoring the bootm code to make it easier to extend in a follow-up series.
[...]
Applied, thanks!
[01/10] bootm: set image_data::initrd_res at a single place
https://git.pengutronix.de/cgit/barebox/commit/?id=dca8fcca2830 (link may not be stable)
[02/10] bootm: fit: split support into dedicated file
https://git.pengutronix.de/cgit/barebox/commit/?id=2b3cf02c037b (link may not be stable)
[03/10] bootm: uimage: split support into dedicated file
https://git.pengutronix.de/cgit/barebox/commit/?id=e3085717c879 (link may not be stable)
[04/10] filetype: introduce filetype_fit
https://git.pengutronix.de/cgit/barebox/commit/?id=bc0d99bc40bc (link may not be stable)
[05/10] bootm: refactor for readability and extensibility
https://git.pengutronix.de/cgit/barebox/commit/?id=b62b21eddf30 (link may not be stable)
[06/10] memory: move release_sdram_region into header
https://git.pengutronix.de/cgit/barebox/commit/?id=3900e7f40b9f (link may not be stable)
[07/10] resource: make NULL in release_[sdram_]region a no-op
https://git.pengutronix.de/cgit/barebox/commit/?id=1918ba4da8b8 (link may not be stable)
[08/10] common: elf: use release_region unconditionally
https://git.pengutronix.de/cgit/barebox/commit/?id=62761aaa41c2 (link may not be stable)
[09/10] memory: always print errors on request_sdram_region failure
https://git.pengutronix.de/cgit/barebox/commit/?id=e453a1b33322 (link may not be stable)
[10/10] memory: drop now duplicate request_sdram_region error messages
https://git.pengutronix.de/cgit/barebox/commit/?id=6a47e5b084d0 (link may not be stable)
Best regards,
Signature · 1 line
Sascha Hauer <[email protected]>