Various minor fixes
Subsystems (3)
v4 cover Various minor fixes
This series collects a few minor fixes and improvements that have been hanging around in a branch for a while.
Changes in v4:
- Indicate that hd does not show the offset correctly
- Add an xxd + sed example too
- Fix 'existing' typo
Changes in v3:
- Show phase only for IH_OS_U_BOOT, drop the last debug()
- Add new patch to describe the md command
- Add this to the docs for the md command
- Add comments as to why we have os_malloc() and os_realloc()
Changes in v2:
- Drop the file instead of fixing it up
- Add new patch to add os_realloc()
- Drop unnecessary check before calling os_free()
- Update the comment for os_free()
- Also free the RAM buffer
- Convert the rest of the allocations in os.c, etc.
Simon Glass (9):
spl: Drop duplicate 'Jumping to U-Boot' message
binman: Indicate how to make binman verbose
doc: describe the md command
doc: Add a note about producing 'md.b' output using hexdump
s5p4418_nanopi2: Drop dead code
sandbox: Add os_realloc()
sandbox: Avoid using malloc() for system state
sandbox: Write out bloblist when exiting
bootm: Fix duplicate debugging in bootm_process_cmdline()
Makefile | 1 + arch/arm/mach-nexell/Makefile | 1 - arch/arm/mach-nexell/cmd_boot_linux.c | 144 -------------------------- arch/sandbox/cpu/os.c | 72 ++++++++++--- arch/sandbox/cpu/spl.c | 10 +- arch/sandbox/cpu/start.c | 12 ++- arch/sandbox/cpu/state.c | 23 ++-- common/bootm.c | 2 +- common/spl/spl.c | 3 +- doc/Makefile | 1 - doc/usage/index.rst | 1 + doc/usage/md.rst | 106 +++++++++++++++++++ include/os.h | 15 ++- tools/binman/README | 4 +- 14 files changed, 214 insertions(+), 181 deletions(-) delete mode 100644 arch/arm/mach-nexell/cmd_boot_linux.c create mode 100644 doc/usage/md.rst
Signature · 1 line
2.30.0.478.g8a0d178c01-goog
PATCH v4 1/9 spl: Drop duplicate 'Jumping to U-Boot' message
This is printed twice but we only need one message, since there is very little processing in between them. Drop the second one, since all branches of the switch() already have output. Update the U-Boot message to include the phase being jumped to.
---
(no changes since v3)
Changes in v3:
- Show phase only for IH_OS_U_BOOT, drop the last debug()
common/spl/spl.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
common/spl/spl.c +1 -2
@@ -693,7 +693,7 @@ void board_init_r(gd_t *dummy1, ulong dummy2)#endif switch (spl_image.os) {case IH_OS_U_BOOT : -debug ("Jumping to U-Boot\n" ); +debug ("Jumping to %s...\n" ,spl_phase_name (spl_next_phase ()));break ;#if CONFIG_IS_ENABLED (ATF )case IH_OS_ARM_TRUSTED_FIRMWARE :
@@ -740,7 +740,6 @@ void board_init_r(gd_t *dummy1, ulong dummy2)debug ("Failed to stash bootstage: err=%d\n" , ret);#endif -debug ("loaded - jumping to %s...\n" ,spl_phase_name (spl_next_phase ()));spl_board_prepare_for_boot ();jump_to_image_no_args (&spl_image); }
Signature · 1 line
2.30.0.478.g8a0d178c01-goog
PATCH v4 1/9 spl: Drop duplicate 'Jumping to U-Boot' message
Quoted 6 lines · Simon Glass
This is printed twice but we only need one message, since there is very little processing in between them. Drop the second one, since all branches of the
switch()already have output. Update the U-Boot message to include the phase being jumped to.Signed-off-by Simon Glass <[email protected]>
Applied to u-boot/next, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 659 bytes Desc: not available URL: <https://lists.denx.de/pipermail/u-boot/attachments/20210303/4c15ed0f/attachment.sig>
PATCH v4 2/9 binman: Indicate how to make binman verbose
In reply to Simon GlassAdd notes about how to make binman produce verbose logging when building.
Add a comment on how to do this.
---
(no changes since v1)
Makefile | 1 + tools/binman/README | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-)
Makefile +1 -0
@@ -1330,6 +1330,7 @@ u-boot.ldr: u-boot # binman # --------------------------------------------------------------------------- # Use 'make BINMAN_DEBUG=1' to enable debugging +# Use 'make BINMAN_VERBOSE=3' to set vebosity level default_dt := $(if $(DEVICE_TREE),$(DEVICE_TREE),$(CONFIG_DEFAULT_DEVICE_TREE)) quiet_cmd_binman = BINMAN $@ cmd_binman = $(srctree)/tools/binman/binman $(if $(BINMAN_DEBUG),-D) \
tools/binman/README +3 -1
@@ -637,7 +637,8 @@ Logging Binman normally operates silently unless there is an error, in which case it just displays the error. The -D/--debug option can be used to create a full -backtrace when errors occur. +backtrace when errors occur. You can use BINMAN_DEBUG=1 when building to select +this. Internally binman logs some output while it is running. This can be displayed by increasing the -v/--verbosity from the default of 1:
@@ -649,6 +650,7 @@ by increasing the -v/--verbosity from the default of 1: 4: detailed information about each operation 5: debug (all output) +You can use BINMAN_VERBOSE=5 (for example) when building to select this. Hashing Entries ---------------
Signature · 1 line
2.30.0.478.g8a0d178c01-goog
PATCH v4 2/9 binman: Indicate how to make binman verbose
Quoted 5 lines · Simon Glass
Add notes about how to make binman produce verbose logging when building.
Add a comment on how to do this.
Signed-off-by Simon Glass <[email protected]>
Applied to u-boot/next, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 659 bytes Desc: not available URL: <https://lists.denx.de/pipermail/u-boot/attachments/20210303/5dd71101/attachment.sig>
PATCH v4 3/9 doc: describe the md command
In reply to Simon GlassProvide a man-page for the md command.
---
(no changes since v3)
Changes in v3:
- Add new patch to describe the md command
doc/Makefile | 1 - doc/usage/index.rst | 1 + doc/usage/md.rst | 96 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 97 insertions(+), 1 deletion(-) create mode 100644 doc/usage/md.rst
doc/Makefile +0 -1
@@ -56,7 +56,6 @@ quiet_cmd_sphinx = SPHINX $@ --> file://$(abspath $(BUILDDIR)/$3/$4) PYTHONDONTWRITEBYTECODE=1 \ BUILDDIR=$(abspath $(BUILDDIR)) SPHINX_CONF=$(abspath $(srctree)/$(src)/$5/$(SPHINX_CONF)) \ $(SPHINXBUILD) \ - -W \ -b $2 \ -c $(abspath $(srctree)/$(src)) \ -d $(abspath $(BUILDDIR)/.doctrees/$3) \
doc/usage/index.rst +1 -0
@@ -26,6 +26,7 @@ Shell commands load loady mbr + md pstore sbi true
doc/usage/md.rst new file +96 -0
96 lines not on this page · raw message
Signature · 1 line
2.30.0.478.g8a0d178c01-goog
PATCH v4 3/9 doc: describe the md command
Quoted 3 lines · Simon Glass
Provide a man-page for the md command.
Signed-off-by Simon Glass <[email protected]>
Applied to u-boot/next, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 659 bytes Desc: not available URL: <https://lists.denx.de/pipermail/u-boot/attachments/20210303/49f016d1/attachment.sig>
PATCH v4 4/9 doc: Add a note about producing 'md.b' output using hexdump
In reply to Simon GlassComparing a hex dump on the U-Boot command line with the contents of a file on the host system is fairly easy and convenient to do manually if it is small. But the format used hexdump by default differs from that shown by U-Boot. Add a note about how to make them the same.
(For large dumps, writing the data to the network with tftpput, or to a USB stick with ext4save is easiest.)
---
Changes in v4:
- Indicate that hd does not show the offset correctly
- Add an xxd + sed example too
Changes in v3:
- Add this to the docs for the md command
doc/usage/md.rst | 10 ++++++++++ 1 file changed, 10 insertions(+)
doc/usage/md.rst +10 -0
@@ -39,6 +39,16 @@ length number of values to dump. Defaults to 40 (0d64). Note that this is not the same as the number of bytes, unless .b is used. +Note that the format of 'md.b' can be emulated from linux with:: + + # This works but requires using sed to get the extra spaces + # <addr> is the address, <f> is the filename + xxd -o <addr> -g1 <f> |sed 's/ / /' >bad + + # This uses a single tool but the offset always starts at 0 + # <f> is the filename + hexdump -v -e '"%08.8_ax: " 16/1 "%02x " " "' -e '16/1 "%_p" "\n" ' <f> + Example -------
Signature · 1 line
2.30.0.478.g8a0d178c01-goog
PATCH v4 4/9 doc: Add a note about producing 'md.b' output using hexdump
Quoted 9 lines · Simon Glass
Comparing a hex dump on the U-Boot command line with the contents of a file on the host system is fairly easy and convenient to do manually if it is small. But the format used hexdump by default differs from that shown by U-Boot. Add a note about how to make them the same.
(For large dumps, writing the data to the network with tftpput, or to a USB stick with ext4save is easiest.)
Signed-off-by Simon Glass <[email protected]>
Applied to u-boot/next, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 659 bytes Desc: not available URL: <https://lists.denx.de/pipermail/u-boot/attachments/20210303/07e89a2b/attachment.sig>
PATCH v4 5/9 s5p4418_nanopi2: Drop dead code
In reply to Simon GlassThis code is still using the old command typedef. It was not noticed since this file is not currently built. It is using a non-existent option in the Makefile.
Drop this file since it is not needed for correct operation.
---
(no changes since v2)
Changes in v2:
- Drop the file instead of fixing it up
arch/arm/mach-nexell/Makefile | 1 - arch/arm/mach-nexell/cmd_boot_linux.c | 144 -------------------------- 2 files changed, 145 deletions(-) delete mode 100644 arch/arm/mach-nexell/cmd_boot_linux.c
arch/arm/mach-nexell/Makefile +0 -1
@@ -10,4 +10,3 @@ obj-y += nx_gpio.o obj-y += tieoff.o obj-$(CONFIG_ARCH_S5P4418) += reg-call.o obj-$(CONFIG_ARCH_S5P4418) += nx_sec_reg.o -obj-$(CONFIG_CMD_BOOTL) += cmd_boot_linux.o
arch/arm/mach-nexell/cmd_boot_linux.c deleted +0 -144
144 lines not on this page · raw message
Signature · 1 line
2.30.0.478.g8a0d178c01-goog
PATCH v4 5/9 s5p4418_nanopi2: Drop dead code
Quoted 7 lines · Simon Glass
This code is still using the old command typedef. It was not noticed since this file is not currently built. It is using a non-existent option in the
Makefile.Drop this file since it is not needed for correct operation.
Signed-off-by Simon Glass <[email protected]>
Applied to u-boot/next, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 659 bytes Desc: not available URL: <https://lists.denx.de/pipermail/u-boot/attachments/20210303/4b6127af/attachment.sig>
PATCH v4 6/9 sandbox: Add os_realloc()
In reply to Simon GlassWe provide os_malloc() and os_free() but not os_realloc(). Add this, following the usual semantics. Also update os_malloc() to behave correctly when passed a zero size.
---
(no changes since v3)
Changes in v3:
- Add comments as to why we have os_malloc() and os_realloc()
Changes in v2:
- Add new patch to add os_realloc()
arch/sandbox/cpu/os.c | 48 +++++++++++++++++++++++++++++++++++++++++++ include/os.h | 12 ++++++++++- 2 files changed, 59 insertions(+), 1 deletion(-)
arch/sandbox/cpu/os.c +48 -0
@@ -267,11 +267,18 @@ void os_tty_raw(int fd, bool allow_sigs)signal (SIGINT , os_sigint_handler); } +/* +* Provide our own malloc so we don't use space in the sandbox ram_buf for +* allocations that are internal to sandbox, or need to be done before U-Boot's +* malloc() is ready. +*/ void *os_malloc (size_t length) {int page_size =getpagesize ();struct os_mem_hdr *hdr; +if (!length) +return NULL ;/* * Use an address that is hopefully available to us so that pointers * to this memory are fairly obvious. If we end up with a different
@@ -298,6 +305,47 @@ void os_free(void *ptr) } } +/* These macros are from kernel.h but not accessible in this file */ +#define ALIGN (x, a) __ALIGN_MASK((x), (typeof(x))(a) - 1) +#define __ALIGN_MASK (x, mask) (((x) + (mask)) & ~(mask)) + +/* +* Provide our own malloc so we don't use space in the sandbox ram_buf for +* allocations that are internal to sandbox, or need to be done before U-Boot's +* malloc() is ready. +*/ +void *os_realloc (void *ptr,size_t length) +{ +int page_size =getpagesize (); +struct os_mem_hdr *hdr; +void *new_ptr; + +/* Reallocating a NULL pointer is just an alloc */ +if (!ptr) +return os_malloc (length); + +/* Changing a length to 0 is just a free */ +if (length) { +os_free (ptr); +return NULL ; + } + +/* +* If the new size is the same number of pages as the old, nothing to +* do. There isn't much point in shrinking things +*/ + hdr = ptr - page_size; +if (ALIGN (length, page_size) <=ALIGN (hdr->length, page_size)) +return ptr; + +/* We have to grow it, so allocate something new */ + new_ptr =os_malloc (length); +memcpy (new_ptr, ptr, hdr->length); +os_free (ptr); + +return new_ptr; +} +void os_usleep (unsigned long usec) {usleep (usec);
include/os.h +11 -1
@@ -114,7 +114,7 @@ void os_fd_restore(void);* os_malloc() - aquires some memory from the underlying os. * * @length: Number of bytes to be allocated -* Return: Pointer to length bytes or NULL on error +* Return: Pointer to length bytes or NULL if @length is 0 or on error */ void *os_malloc (size_t length);
@@ -127,6 +127,16 @@ void *os_malloc(size_t length);*/ void os_free (void *ptr); +/** +* os_realloc() - reallocate memory +* +* This follows the semantics of realloc(), so can perform an os_malloc() or +* os_free() depending on @ptr and @length. +* +* Return: Pointer to reallocated memory or NULL if @length is 0 +*/ +void *os_realloc (void *ptr,size_t length); +/** * os_usleep() - access to the usleep function of the os *
Signature · 1 line
2.30.0.478.g8a0d178c01-goog
PATCH v4 6/9 sandbox: Add os_realloc()
Quoted 6 lines · Simon Glass
We provide
os_malloc()andos_free()but notos_realloc(). Add this, following the usual semantics. Also updateos_malloc()to behave correctly when passed a zero size.Signed-off-by Simon Glass <[email protected]>Reviewed-by Heinrich Schuchardt <[email protected]>
Applied to u-boot/next, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 659 bytes Desc: not available URL: <https://lists.denx.de/pipermail/u-boot/attachments/20210303/610aa636/attachment.sig>
PATCH v4 7/9 sandbox: Avoid using malloc() for system state
In reply to Simon GlassThis state is not accessible to the running U-Boot but at present it is allocated in the emulated SDRAM. This doesn't seem very useful. Adjust it to allocate from the OS instead.
The RAM buffer is currently not freed, but should be, so add that into state_uninit(). Update the comment for os_free() to indicate that NULL is a valid parameter value.
Note that the strdup() in spl_board_load_image() is changed as well, since strdup() allocates memory in the RAM buffer.
---
(no changes since v2)
Changes in v2:
- Drop unnecessary check before calling os_free()
- Update the comment for os_free()
- Also free the RAM buffer
- Convert the rest of the allocations in os.c, etc.
arch/sandbox/cpu/os.c | 24 ++++++++++++------------ arch/sandbox/cpu/spl.c | 10 +++++++--- arch/sandbox/cpu/start.c | 12 +++++++----- arch/sandbox/cpu/state.c | 18 +++++++++--------- include/os.h | 3 ++- 5 files changed, 37 insertions(+), 30 deletions(-)
arch/sandbox/cpu/os.c +12 -12
@@ -153,7 +153,7 @@ int os_read_file(const char *fname, void **bufp, int *sizep)printf ("Cannot seek to start of file '%s'\n" , fname); goto err; } - *bufp =malloc (size); + *bufp =os_malloc (size);if (!*bufp) {printf ("Not enough memory to read file '%s'\n" , fname); ret = -ENOMEM ;
@@ -391,8 +391,8 @@ int os_parse_args(struct sandbox_state *state, int argc, char *argv[]) state->argv = argv;/* dynamically construct the arguments to the system getopt_long */ - short_opts =malloc (sizeof (*short_opts) * num_options *2 +1 ); - long_opts =malloc (sizeof (*long_opts) * (num_options +1 )); + short_opts =os_malloc (sizeof (*short_opts) * num_options *2 +1 ); + long_opts =os_malloc (sizeof (*long_opts) * (num_options +1 ));if (!short_opts || !long_opts)return 1 ;
@@ -471,7 +471,7 @@ void os_dirent_free(struct os_dirent_node *node)while (node) { next = node->next; -free (node); +os_free (node); node = next; } }
@@ -496,7 +496,7 @@ int os_dirent_ls(const char *dirname, struct os_dirent_node **headp)/* Create a buffer upfront, with typically sufficient size */ dirlen =strlen (dirname) +2 ; len = dirlen +256 ; - fname =malloc (len); + fname =os_malloc (len);if (!fname) { ret = -ENOMEM ; goto done;
@@ -509,7 +509,7 @@ int os_dirent_ls(const char *dirname, struct os_dirent_node **headp) ret = errno;break ; } - next =malloc (sizeof (*node) +strlen (entry->d_name) +1 ); + next =os_malloc (sizeof (*node) +strlen (entry->d_name) +1 );if (!next) {os_dirent_free (head); ret = -ENOMEM ;
@@ -518,10 +518,10 @@ int os_dirent_ls(const char *dirname, struct os_dirent_node **headp)if (dirlen +strlen (entry->d_name) > len) { len = dirlen +strlen (entry->d_name); old_fname = fname; - fname =realloc (fname, len); + fname =os_realloc (fname, len);if (!fname) { -free (old_fname); -free (next); +os_free (old_fname); +os_free (next);os_dirent_free (head); ret = -ENOMEM ; goto done;
@@ -555,7 +555,7 @@ int os_dirent_ls(const char *dirname, struct os_dirent_node **headp) done:closedir (dir); -free (fname); +os_free (fname);return ret; }
@@ -672,7 +672,7 @@ static int add_args(char ***argvp, char *add_args[], int count)for (argc =0 ; (*argvp)[argc]; argc++) ; - argv =malloc ((argc + count +1 ) *sizeof (char *)); + argv =os_malloc ((argc + count +1 ) *sizeof (char *));if (!argv) {printf ("Out of memory for %d argv\n" , count);return -ENOMEM ;
@@ -755,7 +755,7 @@ static int os_jump_to_file(const char *fname)os_exit (2 ); err =execv (fname, argv); -free (argv); +os_free (argv);if (err) {perror ("Unable to run image" );printf ("Image filename '%s'\n" , fname);
arch/sandbox/cpu/spl.c +7 -3
@@ -42,10 +42,14 @@ static int spl_board_load_image(struct spl_image_info *spl_image,return ret; } -/* Set up spl_image to boot from jump_to_image_no_args() */ - spl_image->arg =strdup (fname); +/* +* Set up spl_image to boot from jump_to_image_no_args(). Allocate this +* outsdide the RAM buffer (i.e. don't use strdup()). +*/ + spl_image->arg =os_malloc (strlen (fname) +1 );if (!spl_image->arg) -return log_msg_ret ("Setup exec filename" , -ENOMEM ); +return log_msg_ret ("exec" , -ENOMEM ); +strcpy (spl_image->arg, fname);return 0 ; }
arch/sandbox/cpu/start.c +7 -5
@@ -87,7 +87,7 @@ int sandbox_early_getopt_check(void)/* Sort the options */ size =sizeof (*sorted_opt) * num_options; - sorted_opt =malloc (size); + sorted_opt =os_malloc (size);if (!sorted_opt) {printf ("No memory to sort options\n" );os_exit (1 );
@@ -187,7 +187,7 @@ static int sandbox_cmdline_cb_default_fdt(struct sandbox_state *state,int len; len =strlen (state->argv[0 ]) +strlen (fmt) +1 ; - fname =malloc (len); + fname =os_malloc (len);if (!fname)return -ENOMEM ;snprintf (fname, len, fmt, state->argv[0 ]);
@@ -207,7 +207,7 @@ static int sandbox_cmdline_cb_test_fdt(struct sandbox_state *state,int len; len =strlen (state->argv[0 ]) +strlen (fmt) +1 ; - fname =malloc (len); + fname =os_malloc (len);if (!fname)return -ENOMEM ;strcpy (fname, state->argv[0 ]);
@@ -435,16 +435,18 @@ int main(int argc, char *argv[]) {struct sandbox_state *state;gd_t data; +int size;int ret;/* * Copy argv[] so that we can pass the arguments in the original * sequence when resetting the sandbox. */ - os_argv =calloc (argc +1 ,sizeof (char *)); + size =sizeof (char *) * (argc +1 ); + os_argv =os_malloc (size);if (!os_argv)os_exit (1 ); -memcpy (os_argv, argv,sizeof (char *) * (argc +1 )); +memcpy (os_argv, argv, size);memset (&data,'\0' ,sizeof (data)); gd = &data;
arch/sandbox/cpu/state.c +9 -9
@@ -29,17 +29,17 @@ static int state_ensure_space(int extra_size)return 0 ; size = used + extra_size; - buf =malloc (size); + buf =os_malloc (size);if (!buf)return -ENOMEM ; ret =fdt_open_into (blob, buf, size);if (ret) { -free (buf); +os_free (buf);return -EIO ; } -free (blob); +os_free (blob); state->state_fdt = buf;return 0 ; }
@@ -55,7 +55,7 @@ static int state_read_file(struct sandbox_state *state, const char *fname)printf ("Cannot find sandbox state file '%s'\n" , fname);return -ENOENT ; } - state->state_fdt =malloc (size); + state->state_fdt =os_malloc (size);if (!state->state_fdt) {puts ("No memory to read sandbox state\n" );return -ENOMEM ;
@@ -77,7 +77,7 @@ static int state_read_file(struct sandbox_state *state, const char *fname) err_read:os_close (fd); err_open: -free (state->state_fdt); +os_free (state->state_fdt); state->state_fdt =NULL ;return ret;
@@ -244,7 +244,7 @@ int sandbox_write_state(struct sandbox_state *state, const char *fname)/* Create a state FDT if we don't have one */ if (!state->state_fdt) { size =0x4000 ; - state->state_fdt =malloc (size); + state->state_fdt =os_malloc (size);if (!state->state_fdt) {puts ("No memory to create FDT\n" );return -ENOMEM ;
@@ -302,7 +302,7 @@ int sandbox_write_state(struct sandbox_state *state, const char *fname) err_write:os_close (fd); err_create: -free (state->state_fdt); +os_free (state->state_fdt);return ret; }
@@ -419,8 +419,8 @@ int state_uninit(void)if (state->jumped_fname)os_unlink (state->jumped_fname); -if (state->state_fdt) -free (state->state_fdt); +os_free (state->state_fdt); +os_free (state->ram_buf);memset (state,'\0' ,sizeof (*state));return 0 ;
include/os.h +2 -1
@@ -123,7 +123,8 @@ void *os_malloc(size_t length);* * This returns the memory to the OS. * -* @ptr: Pointer to memory block to free +* @ptr: Pointer to memory block to free. If this is NULL then this +* function does nothing */ void os_free (void *ptr);
Signature · 1 line
2.30.0.478.g8a0d178c01-goog
PATCH v4 7/9 sandbox: Avoid using malloc() for system state
Quoted 4 lines · Simon Glass
This state is not accessible to the running U-Boot but at present it is allocated in the emulated SDRAM. This doesn't seem very useful. Adjust it to allocate from the OS instead.
Quoted 8 lines
The RAM buffer is currently not freed, but should be, so add that into
state_uninit(). Update the comment foros_free()to indicate that NULL is a valid parameter value.Note that the
strdup()inspl_board_load_image()is changed as well, sincestrdup()allocates memory in the RAM buffer.Signed-off-by Simon Glass <[email protected]>
Applied to u-boot/next, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 659 bytes Desc: not available URL: <https://lists.denx.de/pipermail/u-boot/attachments/20210303/d41210e0/attachment.sig>
PATCH v4 7/9 sandbox: Avoid using malloc() for system state
In reply to Simon GlassQuoted 4 lines · Simon Glass
This state is not accessible to the running U-Boot but at present it is allocated in the emulated SDRAM. This doesn't seem very useful. Adjust it to allocate from the OS instead.
Quoted 8 lines
The RAM buffer is currently not freed, but should be, so add that into
state_uninit(). Update the comment foros_free()to indicate that NULL is a valid parameter value.Note that the
strdup()inspl_board_load_image()is changed as well, sincestrdup()allocates memory in the RAM buffer.Signed-off-by Simon Glass <[email protected]>
This patch was merged as commit b308d9fd18fa4b9b.
It breaks the exception handling:
Before the patch if an exception occured pc_reloc would point to the address in u-boot.map:
=> exception undef
Illegal instruction
pc = 0x55e4ef74c434, pc_reloc = 0x55434
With your patch pc_reloc is incorrect:
=> exception undef
Illegal instruction
pc = 0x56003896cd13, pc_reloc = 0x56002896cd13
Why is gd->reloc_off not filled correctly anymore?
os_find_text_base() has this comment:
"This code assumes that the first line of /proc/self/maps holds information about the text."
$ cat /proc/389589/maps 10000000-10002000 rwxp 00000000 00:00 0 560038916000-560038947000 r--p 00000000 fd:01 13376716 560038947000-560038aa4000 r-xp 00031000 fd:01 13376716 560038aa4000-560038ba8000 r--p 0018e000 fd:01 13376716 560038ba8000-560038bb1000 r--p 00291000 fd:01 13376716 560038bb1000-560038bd4000 rw-p 0029a000 fd:01 13376716
=> bdinfo
relocaddr = 0x0000000007858000
reloc off = 0x0000000010000000
The problem is that you first call mmap() to allocate space for the state at address 0x10000000 and then call os_find_text_base(). Calling os_find_text_base() must be the first thing you do!
Best regards
Heinrich
Quoted 270 lines
---
(no changes since v2)
Changes in v2:
- Drop unnecessary check before callingos_free()
- Update the comment foros_free()
- Also free the RAM buffer
- Convert the rest of the allocations inos.c, etc.arch/sandbox/cpu/os.c | 24 ++++++++++++------------ arch/sandbox/cpu/spl.c | 10 +++++++--- arch/sandbox/cpu/start.c | 12 +++++++----- arch/sandbox/cpu/state.c | 18 +++++++++--------- include/os.h | 3 ++- 5 files changed, 37 insertions(+), 30 deletions(-)arch/sandbox/cpu/os.c +12
-12@@ -153,7 +153,7 @@ int os_read_file(const char *fname, void **bufp, int *sizep)printf ("Cannot seek to start of file '%s'\n" , fname); goto err; } - *bufp =malloc (size); + *bufp =os_malloc (size);if (!*bufp) {printf ("Not enough memory to read file '%s'\n" , fname); ret = -ENOMEM ;@@ -391,8 +391,8 @@ int os_parse_args(struct sandbox_state *state, int argc, char *argv[]) state->argv = argv;/* dynamically construct the arguments to the system getopt_long */ - short_opts =malloc (sizeof (*short_opts) * num_options *2 +1 ); - long_opts =malloc (sizeof (*long_opts) * (num_options +1 )); + short_opts =os_malloc (sizeof (*short_opts) * num_options *2 +1 ); + long_opts =os_malloc (sizeof (*long_opts) * (num_options +1 ));if (!short_opts || !long_opts)return 1 ;@@ -471,7 +471,7 @@ void os_dirent_free(struct os_dirent_node *node)while (node) { next = node->next; -free (node); +os_free (node); node = next; } }@@ -496,7 +496,7 @@ int os_dirent_ls(const char *dirname, struct os_dirent_node **headp)/* Create a buffer upfront, with typically sufficient size */ dirlen =strlen (dirname) +2 ; len = dirlen +256 ; - fname =malloc (len); + fname =os_malloc (len);if (!fname) { ret = -ENOMEM ; goto done;@@ -509,7 +509,7 @@ int os_dirent_ls(const char *dirname, struct os_dirent_node **headp) ret = errno;break ; } - next =malloc (sizeof (*node) +strlen (entry->d_name) +1 ); + next =os_malloc (sizeof (*node) +strlen (entry->d_name) +1 );if (!next) {os_dirent_free (head); ret = -ENOMEM ;@@ -518,10 +518,10 @@ int os_dirent_ls(const char *dirname, struct os_dirent_node **headp)if (dirlen +strlen (entry->d_name) > len) { len = dirlen +strlen (entry->d_name); old_fname = fname; - fname =realloc (fname, len); + fname =os_realloc (fname, len);if (!fname) { -free (old_fname); -free (next); +os_free (old_fname); +os_free (next);os_dirent_free (head); ret = -ENOMEM ; goto done;@@ -555,7 +555,7 @@ int os_dirent_ls(const char *dirname, struct os_dirent_node **headp) done:closedir (dir); -free (fname); +os_free (fname);return ret; }@@ -672,7 +672,7 @@ static int add_args(char ***argvp, char *add_args[], int count)for (argc =0 ; (*argvp)[argc]; argc++) ; - argv =malloc ((argc + count +1 ) *sizeof (char *)); + argv =os_malloc ((argc + count +1 ) *sizeof (char *));if (!argv) {printf ("Out of memory for %d argv\n" , count);return -ENOMEM ;@@ -755,7 +755,7 @@ static int os_jump_to_file(const char *fname)os_exit (2 ); err =execv (fname, argv); -free (argv); +os_free (argv);if (err) {perror ("Unable to run image" );printf ("Image filename '%s'\n" , fname);arch/sandbox/cpu/spl.c +7
-3@@ -42,10 +42,14 @@ static int spl_board_load_image(struct spl_image_info *spl_image,return ret; } -/* Set up spl_image to boot from jump_to_image_no_args() */ - spl_image->arg =strdup (fname); +/* +* Set up spl_image to boot from jump_to_image_no_args(). Allocate this +* outsdide the RAM buffer (i.e. don't use strdup()). +*/ + spl_image->arg =os_malloc (strlen (fname) +1 );if (!spl_image->arg) -return log_msg_ret ("Setup exec filename" , -ENOMEM ); +return log_msg_ret ("exec" , -ENOMEM ); +strcpy (spl_image->arg, fname);return 0 ; }arch/sandbox/cpu/start.c +7
-5@@ -87,7 +87,7 @@ int sandbox_early_getopt_check(void)/* Sort the options */ size =sizeof (*sorted_opt) * num_options; - sorted_opt =malloc (size); + sorted_opt =os_malloc (size);if (!sorted_opt) {printf ("No memory to sort options\n" );os_exit (1 );@@ -187,7 +187,7 @@ static int sandbox_cmdline_cb_default_fdt(struct sandbox_state *state,int len; len =strlen (state->argv[0 ]) +strlen (fmt) +1 ; - fname =malloc (len); + fname =os_malloc (len);if (!fname)return -ENOMEM ;snprintf (fname, len, fmt, state->argv[0 ]);@@ -207,7 +207,7 @@ static int sandbox_cmdline_cb_test_fdt(struct sandbox_state *state,int len; len =strlen (state->argv[0 ]) +strlen (fmt) +1 ; - fname =malloc (len); + fname =os_malloc (len);if (!fname)return -ENOMEM ;strcpy (fname, state->argv[0 ]);@@ -435,16 +435,18 @@ int main(int argc, char *argv[]) {struct sandbox_state *state;gd_t data; +int size;int ret;/* * Copy argv[] so that we can pass the arguments in the original * sequence when resetting the sandbox. */ - os_argv =calloc (argc +1 ,sizeof (char *)); + size =sizeof (char *) * (argc +1 ); + os_argv =os_malloc (size);if (!os_argv)os_exit (1 ); -memcpy (os_argv, argv,sizeof (char *) * (argc +1 )); +memcpy (os_argv, argv, size);memset (&data,'\0' ,sizeof (data)); gd = &data;arch/sandbox/cpu/state.c +9
-9@@ -29,17 +29,17 @@ static int state_ensure_space(int extra_size)return 0 ; size = used + extra_size; - buf =malloc (size); + buf =os_malloc (size);if (!buf)return -ENOMEM ; ret =fdt_open_into (blob, buf, size);if (ret) { -free (buf); +os_free (buf);return -EIO ; } -free (blob); +os_free (blob); state->state_fdt = buf;return 0 ; }@@ -55,7 +55,7 @@ static int state_read_file(struct sandbox_state *state, const char *fname)printf ("Cannot find sandbox state file '%s'\n" , fname);return -ENOENT ; } - state->state_fdt =malloc (size); + state->state_fdt =os_malloc (size);if (!state->state_fdt) {puts ("No memory to read sandbox state\n" );return -ENOMEM ;@@ -77,7 +77,7 @@ static int state_read_file(struct sandbox_state *state, const char *fname) err_read:os_close (fd); err_open: -free (state->state_fdt); +os_free (state->state_fdt); state->state_fdt =NULL ;return ret;@@ -244,7 +244,7 @@ int sandbox_write_state(struct sandbox_state *state, const char *fname)/* Create a state FDT if we don't have one */ if (!state->state_fdt) { size =0x4000 ; - state->state_fdt =malloc (size); + state->state_fdt =os_malloc (size);if (!state->state_fdt) {puts ("No memory to create FDT\n" );return -ENOMEM ;@@ -302,7 +302,7 @@ int sandbox_write_state(struct sandbox_state *state, const char *fname) err_write:os_close (fd); err_create: -free (state->state_fdt); +os_free (state->state_fdt);return ret; }@@ -419,8 +419,8 @@ int state_uninit(void)if (state->jumped_fname)os_unlink (state->jumped_fname); -if (state->state_fdt) -free (state->state_fdt); +os_free (state->state_fdt); +os_free (state->ram_buf);memset (state,'\0' ,sizeof (*state));return 0 ;include/os.h +2
-1@@ -123,7 +123,8 @@ void *os_malloc(size_t length);* * This returns the memory to the OS. * -* @ptr: Pointer to memory block to free +* @ptr: Pointer to memory block to free. If this is NULL then this +* function does nothing */ void os_free (void *ptr);
PATCH v4 8/9 sandbox: Write out bloblist when exiting
In reply to Simon GlassSandbox provides a way to write out its emulated memory on exit. This makes it possible to pass a bloblist from one phase (e.g. SPL) to the next.
However the bloblist is not closed off, so the checksum is generally invalid. Fix this by finishing up the bloblist before writing the memory file.
---
Changes in v4:
- Fix 'existing' typo
arch/sandbox/cpu/state.c | 5 +++++ 1 file changed, 5 insertions(+)
arch/sandbox/cpu/state.c +5 -0
@@ -4,6 +4,7 @@*/ #include <common.h> +#include <bloblist.h> #include <errno.h> #include <fdtdec.h> #include <log.h>
@@ -398,8 +399,12 @@ int state_uninit(void) {int err; +log_info ("Writing sandbox state\n" ); state = &main_state; +/* Finish the bloblist, so that it is correct before writing memory */ +bloblist_finish (); +if (state->write_ram_buf) { err =os_write_ram_buf (state->ram_buf_fname);if (err) {
Signature · 1 line
2.30.0.478.g8a0d178c01-goog
PATCH v4 8/9 sandbox: Write out bloblist when exiting
Quoted 9 lines · Simon Glass
Sandbox provides a way to write out its emulated memory on exit. This makes it possible to pass a bloblist from one phase (e.g. SPL) to the next.
However the bloblist is not closed off, so the checksum is generally invalid. Fix this by finishing up the bloblist before writing the memory file.
Signed-off-by Simon Glass <[email protected]>
Applied to u-boot/next, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 659 bytes Desc: not available URL: <https://lists.denx.de/pipermail/u-boot/attachments/20210303/8766c9ef/attachment.sig>
PATCH v4 9/9 bootm: Fix duplicate debugging in bootm_process_cmdline()
In reply to Simon GlassThese two returns use the same string so are not distinguishable with LOG_ERROR_RETURN. Fix it.
---
(no changes since v1)
common/bootm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
common/bootm.c +1 -1
@@ -585,7 +585,7 @@ int bootm_process_cmdline(char *buf, int maxlen, int flags)if (IS_ENABLED (CONFIG_BOOTARGS_SUBST ) && (flags &BOOTM_CL_SUBST )) { ret =process_subst (buf, maxlen);if (ret) -return log_msg_ret ("silent" , ret); +return log_msg_ret ("subst" , ret); }return 0 ;
Signature · 1 line
2.30.0.478.g8a0d178c01-goog
PATCH v4 9/9 bootm: Fix duplicate debugging in bootm_process_cmdline()
Quoted 4 lines · Simon Glass
These two returns use the same string so are not distinguishable with
LOG_ERROR_RETURN. Fix it.Signed-off-by Simon Glass <[email protected]>
Applied to u-boot/next, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 659 bytes Desc: not available URL: <https://lists.denx.de/pipermail/u-boot/attachments/20210303/753a9b00/attachment.sig>