From f4070e6f6c680034d67f13b878f0da55b3b51f92 Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Tue, 28 Apr 2020 21:56:10 +0200 Subject: hush: avoid NULL check before free() free() checks if its argument is NULL. Don't duplicate this in the calling code. Signed-off-by: Heinrich Schuchardt Reviewed-by: Simon Glass --- common/cli_hush.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'common') diff --git a/common/cli_hush.c b/common/cli_hush.c index cf1e273..a62af07 100644 --- a/common/cli_hush.c +++ b/common/cli_hush.c @@ -1849,8 +1849,7 @@ static int run_list_real(struct pipe *pi) continue; } else { /* insert new value from list for variable */ - if (pi->progs->argv[0]) - free(pi->progs->argv[0]); + free(pi->progs->argv[0]); pi->progs->argv[0] = *list++; #ifndef __U_BOOT__ pi->progs->glob_result.gl_pathv[0] = -- cgit v1.1 From c522949a29d44d728517cc2579ed719747da3e5d Mon Sep 17 00:00:00 2001 From: Philippe Reynes Date: Wed, 29 Apr 2020 15:26:17 +0200 Subject: rsa: sig: fix config signature check for fit with padding The signature check on config node is broken on fit with padding. To compute the signature for config node, U-Boot compute the signature on all properties of requested node for this config, except for the property "data". But, when padding is used for binary in a fit, there isn't a property "data" but two properties: "data-offset" and "data-size". So to fix the check of signature, we also don't use the properties "data-offset" and "data-size" when checking the signature on config node. Reviewed-by: Simon Glass Signed-off-by: Philippe Reynes --- common/image-fit-sig.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'common') diff --git a/common/image-fit-sig.c b/common/image-fit-sig.c index 3e73578..a3a0c61 100644 --- a/common/image-fit-sig.c +++ b/common/image-fit-sig.c @@ -249,7 +249,7 @@ static int fit_config_check_sig(const void *fit, int noffset, int required_keynode, int conf_noffset, char **err_msgp) { - char * const exc_prop[] = {"data"}; + char * const exc_prop[] = {"data", "data-size", "data-position"}; const char *prop, *end, *name; struct image_sign_info info; const uint32_t *strings; -- cgit v1.1 From 9297e366d6a847f7ac64f4ec7102b236d8ebe1f4 Mon Sep 17 00:00:00 2001 From: Marek Bykowski Date: Wed, 29 Apr 2020 18:23:07 +0200 Subject: malloc: dlmalloc: add an ability for the malloc to be re-init/init multiple times Malloc gets initialized with a call to mem_malloc_init() with the address the allocation starts to and its size. Currently it is not possible to move the malloc from one memory area to another as the malloc would eventually fail. This patch adds in the ability to re-init the malloc with the updated start address and the size. One of the use cases of this feature is SPL U-Boot running from within the static memory and calling to malloc init from within board_init_f(): arch/arm/cpu/armv8/start.S:reset vector arch/arm/cpu/armv8/start.S:main() arch/arm/lib/crt0_64.S:board_init_f() board//common/spl.c:board_init_f() board//common/spl.c:mem_malloc_init((ulong)CONFIG_SYS_SPL_MALLOC_START, CONFIG_SYS_SPL_MALLOC_SIZE); Shortly after the DDR (main) memory is init and ready we call to malloc init again but this time with the start address in the DDR memory and a much greater size for moving the allocation off the static to the DDR memory: board//common/spl.c:mem_malloc_init((ulong)CONFIG_SPL_MALLOC_OFFSET, CONFIG_SPL_MALLOC_SIZE); Where CONFIG_SYS_SPL_MALLOC_START and CONFIG_SPL_MALLOC_OFFSET are the start addresses of the malloc in the static and DDR memories respectively and CONFIG_SYS_SPL_MALLOC_SIZE=SZ_16K and CONFIG_SPL_MALLOC_SIZE=SZ_2M are the sizes of the mallocs in these memories. Note, now we have a much greater memory, enlarging from 16K to 2M, available for allocation. There is an alternative approach already existing in U-Boot with the use of an early (simplified) malloc and the proper (dlamalloc) malloc however necessitating managing the two mallocs whereas this approach proposes using a single dlmalloc. Signed-off-by: Marek Bykowski --- common/dlmalloc.c | 41 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 38 insertions(+), 3 deletions(-) (limited to 'common') diff --git a/common/dlmalloc.c b/common/dlmalloc.c index db5ab55..e8f07f1 100644 --- a/common/dlmalloc.c +++ b/common/dlmalloc.c @@ -280,6 +280,7 @@ nextchunk-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Unused space (may be 0 bytes long) . . . . | + nextchunk-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ `foot:' | Size of chunk, in bytes | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ @@ -574,6 +575,10 @@ static void malloc_bin_reloc(void) static inline void malloc_bin_reloc(void) {} #endif +#ifdef CONFIG_SYS_MALLOC_DEFAULT_TO_INIT +static void malloc_init(void); +#endif + ulong mem_malloc_start = 0; ulong mem_malloc_end = 0; ulong mem_malloc_brk = 0; @@ -604,6 +609,10 @@ void mem_malloc_init(ulong start, ulong size) mem_malloc_end = start + size; mem_malloc_brk = start; +#ifdef CONFIG_SYS_MALLOC_DEFAULT_TO_INIT + malloc_init(); +#endif + debug("using memory %#lx-%#lx for malloc()\n", mem_malloc_start, mem_malloc_end); #ifdef CONFIG_SYS_MALLOC_CLEAR_ON_INIT @@ -708,7 +717,36 @@ static unsigned int max_n_mmaps = 0; static unsigned long max_mmapped_mem = 0; #endif +#ifdef CONFIG_SYS_MALLOC_DEFAULT_TO_INIT +static void malloc_init(void) +{ + int i, j; + + debug("bins (av_ array) are at %p\n", (void *)av_); + + av_[0] = NULL; av_[1] = NULL; + for (i = 2, j = 2; i < NAV * 2 + 2; i += 2, j++) { + av_[i] = bin_at(j - 2); + av_[i + 1] = bin_at(j - 2); + + /* Just print the first few bins so that + * we can see there are alright. + */ + if (i < 10) + debug("av_[%d]=%lx av_[%d]=%lx\n", + i, (ulong)av_[i], + i + 1, (ulong)av_[i + 1]); + } + /* Init the static bookkeeping as well */ + sbrk_base = (char *)(-1); + max_sbrked_mem = 0; + max_total_mem = 0; +#ifdef DEBUG + memset((void *)¤t_mallinfo, 0, sizeof(struct mallinfo)); +#endif +} +#endif /* Debugging support @@ -1051,9 +1089,6 @@ static mchunkptr mremap_chunk(p, new_size) mchunkptr p; size_t new_size; #endif /* HAVE_MMAP */ - - - /* Extend the top-most chunk by obtaining memory from system. Main interface to sbrk (but see also malloc_trim). -- cgit v1.1 From 5cf9e3b237f24e66ff1a657e954ffe3dc92e09eb Mon Sep 17 00:00:00 2001 From: Ovidiu Panait Date: Mon, 20 Apr 2020 10:31:44 +0300 Subject: common/board_r: arm: Merge initr_enable_interrupts into interrupts_init initr_enable_interrupts() is an ARM-specific wrapper over enable_interrupts(), which is run during the common init sequence. It can be eliminated by moving the enable_interrupts() call to the end of interrupt_init() function, in arch/arm/lib/interrupts*.c. Signed-off-by: Ovidiu Panait Reviewed-by: Simon Glass --- common/board_r.c | 12 ------------ 1 file changed, 12 deletions(-) (limited to 'common') diff --git a/common/board_r.c b/common/board_r.c index 0bbeaa7..bdb0389 100644 --- a/common/board_r.c +++ b/common/board_r.c @@ -518,15 +518,6 @@ static int initr_api(void) } #endif -/* enable exceptions */ -#ifdef CONFIG_ARM -static int initr_enable_interrupts(void) -{ - enable_interrupts(); - return 0; -} -#endif - #ifdef CONFIG_CMD_NET static int initr_ethaddr(void) { @@ -813,9 +804,6 @@ static init_fnc_t init_sequence_r[] = { initr_kgdb, #endif interrupt_init, -#ifdef CONFIG_ARM - initr_enable_interrupts, -#endif #if defined(CONFIG_MICROBLAZE) || defined(CONFIG_M68K) timer_init, /* initialize timer */ #endif -- cgit v1.1 From 1a4c077b751475cc3a6e77d2216990feccc068dd Mon Sep 17 00:00:00 2001 From: Ovidiu Panait Date: Mon, 20 Apr 2020 10:31:46 +0300 Subject: common/board_r: Drop initr_bedbug wrapper Drop initr_bedbug wrapper and call bedbug_init directly during the init sequence. Signed-off-by: Ovidiu Panait Reviewed-by: Simon Glass --- common/board_r.c | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) (limited to 'common') diff --git a/common/board_r.c b/common/board_r.c index bdb0389..d9015cd 100644 --- a/common/board_r.c +++ b/common/board_r.c @@ -637,15 +637,6 @@ int initr_mem(void) } #endif -#ifdef CONFIG_CMD_BEDBUG -static int initr_bedbug(void) -{ - bedbug_init(); - - return 0; -} -#endif - static int run_main_loop(void) { #ifdef CONFIG_SANDBOX @@ -848,7 +839,7 @@ static init_fnc_t init_sequence_r[] = { #endif #ifdef CONFIG_CMD_BEDBUG INIT_FUNC_WATCHDOG_RESET - initr_bedbug, + bedbug_init, #endif #if defined(CONFIG_PRAM) initr_mem, -- cgit v1.1 From 5168d7a6264be30f82c1c074e43c24fcacbb4283 Mon Sep 17 00:00:00 2001 From: Thirupathaiah Annapureddy Date: Wed, 18 Mar 2020 11:38:42 -0700 Subject: menu: add support for client defined statusline function Currently displaying status line is done in a weak function menu_display_statusline(). bootmenu.c overrides the weak default function. It calls menu_default_choice() and interprets the data as struct bootmenu_entry. pxe boot also uses common menu code for pxe menus. If there is a system that enables both bootmenu and pxe, menu_display_statusline() defined in bootmenu.c will be called and it will interpret struct pxe_label as struct bootmenu_entry. This leads to data aborts and pxe menu corruptions. This patch adds support for client defined statusline function to resolve the above bug. Signed-off-by: Thirupathaiah Annapureddy --- common/menu.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'common') diff --git a/common/menu.c b/common/menu.c index 7b66d19..5fb2ffb 100644 --- a/common/menu.c +++ b/common/menu.c @@ -36,6 +36,7 @@ struct menu { int timeout; char *title; int prompt; + void (*display_statusline)(struct menu *); void (*item_data_print)(void *); char *(*item_choice)(void *); void *item_choice_data; @@ -106,10 +107,6 @@ static inline void *menu_item_destroy(struct menu *m, return NULL; } -__weak void menu_display_statusline(struct menu *m) -{ -} - /* * Display a menu so the user can make a choice of an item. First display its * title, if any, and then each item in the menu. @@ -120,7 +117,8 @@ static inline void menu_display(struct menu *m) puts(m->title); putc('\n'); } - menu_display_statusline(m); + if (m->display_statusline) + m->display_statusline(m); menu_items_iter(m, menu_item_print, NULL); } @@ -344,6 +342,9 @@ int menu_item_add(struct menu *m, char *item_key, void *item_data) * timeout. If 1, the user will be prompted for input regardless of the value * of timeout. * + * display_statusline - If not NULL, will be called to show a statusline when + * the menu is displayed. + * * item_data_print - If not NULL, will be called for each item when the menu * is displayed, with the pointer to the item's data passed as the argument. * If NULL, each item's key will be printed instead. Since an item's key is @@ -360,6 +361,7 @@ int menu_item_add(struct menu *m, char *item_key, void *item_data) * insufficient memory available to create the menu. */ struct menu *menu_create(char *title, int timeout, int prompt, + void (*display_statusline)(struct menu *), void (*item_data_print)(void *), char *(*item_choice)(void *), void *item_choice_data) @@ -374,6 +376,7 @@ struct menu *menu_create(char *title, int timeout, int prompt, m->default_item = NULL; m->prompt = prompt; m->timeout = timeout; + m->display_statusline = display_statusline; m->item_data_print = item_data_print; m->item_choice = item_choice; m->item_choice_data = item_choice_data; -- cgit v1.1