[U-Boot] [PATCH v1 1/1] cmd: adding malloc, math, and strcmp commands to u-boot

Vladimir Olovyannikov vladimir.olovyannikov at broadcom.com
Wed Nov 20 22:50:53 UTC 2019


Hi Tom,

> -----Original Message-----
> From: Tom Rini [mailto:trini at konsulko.com]
> Sent: Tuesday, November 19, 2019 12:38 PM
> To: Vladimir Olovyannikov <vladimir.olovyannikov at broadcom.com>
> Cc: u-boot at lists.denx.de; Suji Velupiallai
<suji.velupillai at broadcom.com>;
> Heinrich Schuchardt <xypron.glpk at gmx.de>
> Subject: Re: [U-Boot] [PATCH v1 1/1] cmd: adding malloc, math, and
strcmp
> commands to u-boot
>
> On Mon, Nov 18, 2019 at 04:26:30PM -0800, Vladimir Olovyannikov wrote:
>
> > cmd: adding malloc, math, and strcmp u-boot commands.
> > - malloc  supports allocation of heap memory and free allocated memory
> >           via u-boot command line.
>
> Can you expand on how this is used in a script?  I'm not sure I see that
> exactly.
I am upstreaming the new bcm platform. Here is an excerpt from the script
which uses
these:
#define SD_UPDATE \
	"sd_update="\
	"if malloc tmp 2000; then "\
	"else "\
		"echo [sd_update] malloc 2000 bytes ** FAILED **;"\
		"exit;"\
	"fi;"\
	"if fatload mmc ${sd_device_number} ${tmp} "\
	"${sd_update_prefix}.sd-update; then "\
	"else "\
		"echo [sd_update] fatload ${sd_update_prefix}.sd-update "\
		"** FAILED **;"\
		"exit;"\
	"fi;"\
	"if source ${tmp}; then "\
	"else "\
		"echo [sd_update] Executing script ** FAILED **;"\
		"exit;"\
	"fi;"\
	"if free tmp; then "\
	"else " \
		"echo [sd_update] free 2000 bytes ** FAILED **;"\
		"exit;"\
	"fi \0"
;
	"if math add filesize filesize 1FF; then "\
	"else "\
		"echo [mmc_flash_image_rsa] math add command ** FAILED
**;"\
		"exit;"\
	"fi;"\
	"if math div fileblocks filesize 200; then "\
	"else "\
		"echo [mmc_flash_image_rsa] math div command ** FAILED
**;"\
		"exit;"\
	"fi;"\
> Also:
> > +config CMD_MALLOC
> > +	bool "malloc"
> > +	default y
> > +	help
> > +	  Supports allocation of heap memory and free allocated memory
> commands.
> > +	  These commands are used by u-boot scripts.
> > +
> > +config CMD_MATH
> > +	bool "math"
> > +	default y
> > +	help
> > +	  Provides math commands such as add, sub, mul, div, shift,
> > +	  convert decimal to hex functionalities to be available in the
script.
>
> First, why do we need this, rather than using setexpr ?
I agree, the platform needs to use setexpr as it contains all math
operations.
>
> > +
> >  config CMD_SOURCE
> >  	bool "source"
> >  	default y
> > @@ -1301,6 +1315,13 @@ config CMD_SETEXPR
> >  	  Also supports loading the value at a memory location into a
variable.
> >  	  If CONFIG_REGEX is enabled, setexpr also supports a gsub
function.
> >
> > +config CMD_STRCMP
> > +	bool "strcmp"
> > +	default y
> > +	help
> > +	  Provides string compare command feature to u-boot scripts.
>
> Second, new commands must not default to y, but they should be enabled
> on sandbox and new test.py tests added for them.  Thanks!
OK, thank you.
Is there an example/doc on how to enable these on sandbox and to provide
tests?

Vladimir
>
> --
> Tom


More information about the U-Boot mailing list