fw_env.c: Switch get_config to use '%ms' in sscanf
Subsystems (2)
PATCH v3 1/10 fw_env.c: Switch get_config to use '%ms' in sscanf
We currently limit ourself to 16 characters for the device name to read the environment from. This is insufficient for /dev/mmcblk0boot1 to work for example. Switch to '%ms' which gives us a dynamically allocated buffer instead. We're short lived enough to not bother free()ing the buffer.
---
Changes in v2:
- Rework to use '%ms' in get_config per Wolfgang
--- tools/env/fw_env.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-)
tools/env/fw_env.c +8 -5
@@ -40,7 +40,7 @@ _min1 < _min2 ? _min1 : _min2; })struct envdev_s { -char devname[16 ];/* Device name */ +const char *devname;/* Device name */ ulong devoff;/* Device offset */ ulong env_size;/* environment size */ ulong erase_size;/* device erase size */
@@ -1243,7 +1243,7 @@ static int parse_config () return -1; }#else -strcpy (DEVNAME (0 ),DEVICE1_NAME ); +DEVNAME (0 ) =DEVICE1_NAME ;DEVOFFSET (0 ) =DEVICE1_OFFSET ;ENVSIZE (0 ) =ENV1_SIZE ;/* Default values are: erase-size=env-size */
@@ -1258,7 +1258,7 @@ static int parse_config ()#endif #ifdef HAVE_REDUND -strcpy (DEVNAME (1 ),DEVICE2_NAME ); +DEVNAME (1 ) =DEVICE2_NAME ;DEVOFFSET (1 ) =DEVICE2_OFFSET ;ENVSIZE (1 ) =ENV2_SIZE ;/* Default values are: erase-size=env-size */
@@ -1297,6 +1297,7 @@ static int get_config (char *fname)int i =0 ;int rc;char dump[128 ]; +char *devname; fp =fopen (fname,"r" );if (fp ==NULL )
@@ -1307,8 +1308,8 @@ static int get_config (char *fname)if (dump[0 ] =='#' )continue ; - rc = sscanf (dump, "%s %lx %lx %lx %lx", - DEVNAME (i), + rc = sscanf (dump, "%ms %lx %lx %lx %lx", + &devname, &DEVOFFSET (i), &ENVSIZE (i), &DEVESIZE (i),
@@ -1317,6 +1318,8 @@ static int get_config (char *fname)if (rc <3 )continue ; +DEVNAME (i) = devname; +if (rc <4 )/* Assume the erase size is the same as the env-size */ DEVESIZE (i) =ENVSIZE (i);
Signature · 1 line
1.7.9.5
PATCH v3 1/10 fw_env.c: Switch get_config to use '%ms' in sscanf
Quoted 7 lines · Tom Rini
We currently limit ourself to 16 characters for the device name to read the environment from. This is insufficient for
/dev/mmcblk0boot1to work for example. Switch to '%ms' which gives us a dynamically allocated buffer instead. We're short lived enough to not bother free()ing the buffer.Signed-off-by Tom Rini <[email protected]>
Applied to u-boot-ti/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 836 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20140418/e6987504/attachment.pgp>
PATCH v3 2/10 env_mmc.c: Allow environment to be used within SPL
In reply to Tom RiniInside of SPL we only concern ourself with one MMC device, so instead of being able to use CONFIG_SYS_MMC_ENV_DEV we need to use 0 in SPL. Switch the code to use a 'dev' variable to facilitate this.
--- common/env_mmc.c | 45 +++++++++++++++++++++++++++++++++++++-------- 1 file changed, 37 insertions(+), 8 deletions(-)
common/env_mmc.c +37 -8
@@ -64,6 +64,14 @@ int env_init(void)static int init_mmc_for_env (struct mmc *mmc) { +#ifdef CONFIG_SYS_MMC_ENV_PART +int dev =CONFIG_SYS_MMC_ENV_DEV ; + +#ifdef CONFIG_SPL_BUILD + dev =0 ; +#endif +#endif +if (!mmc) {puts ("No MMC card found\n" );return -1 ;
@@ -76,8 +84,7 @@ static int init_mmc_for_env(struct mmc *mmc)#ifdef CONFIG_SYS_MMC_ENV_PART if (CONFIG_SYS_MMC_ENV_PART != mmc->part_num) { -if (mmc_switch_part (CONFIG_SYS_MMC_ENV_DEV , -CONFIG_SYS_MMC_ENV_PART )) { +if (mmc_switch_part (dev,CONFIG_SYS_MMC_ENV_PART )) {puts ("MMC partition switch failed\n" );return -1 ; }
@@ -90,9 +97,13 @@ static int init_mmc_for_env(struct mmc *mmc)static void fini_mmc_for_env (struct mmc *mmc) {#ifdef CONFIG_SYS_MMC_ENV_PART +int dev =CONFIG_SYS_MMC_ENV_DEV ; + +#ifdef CONFIG_SPL_BUILD + dev =0 ; +#endif if (CONFIG_SYS_MMC_ENV_PART != mmc->part_num) -mmc_switch_part (CONFIG_SYS_MMC_ENV_DEV , - mmc->part_num); +mmc_switch_part (dev, mmc->part_num);#endif }
@@ -174,12 +185,16 @@ static inline int read_env(struct mmc *mmc, unsigned long size, unsigned long offset, const void *buffer) { uint blk_start, blk_cnt, n; +int dev =CONFIG_SYS_MMC_ENV_DEV ; + +#ifdef CONFIG_SPL_BUILD + dev =0 ; +#endif blk_start =ALIGN (offset, mmc->read_bl_len) / mmc->read_bl_len; blk_cnt =ALIGN (size, mmc->read_bl_len) / mmc->read_bl_len; - n = mmc->block_dev.block_read (CONFIG_SYS_MMC_ENV_DEV , blk_start, - blk_cnt, (uchar *)buffer); + n = mmc->block_dev.block_read (dev, blk_start, blk_cnt, (uchar *)buffer);return (n == blk_cnt) ?0 :-1 ; }
@@ -188,16 +203,23 @@ static inline int read_env(struct mmc *mmc, unsigned long size,void env_relocate_spec (void ) {#if !defined(ENV_IS_EMBEDDED ) -struct mmc *mmc =find_mmc_device (CONFIG_SYS_MMC_ENV_DEV ); +struct mmc *mmc;u32 offset1, offset2;int read1_fail =0 , read2_fail =0 ;int crc1_ok =0 , crc2_ok =0 ;env_t *ep;int ret; +int dev =CONFIG_SYS_MMC_ENV_DEV ;ALLOC_CACHE_ALIGN_BUFFER (env_t, tmp_env1,1 );ALLOC_CACHE_ALIGN_BUFFER (env_t, tmp_env2,1 ); +#ifdef CONFIG_SPL_BUILD + dev =0 ; +#endif + + mmc =find_mmc_device (dev); +if (tmp_env1 ==NULL || tmp_env2 ==NULL ) {puts ("Can't allocate buffers for environment\n" ); ret =1 ;
@@ -274,9 +296,16 @@ void env_relocate_spec(void) {#if !defined(ENV_IS_EMBEDDED )ALLOC_CACHE_ALIGN_BUFFER (char, buf,CONFIG_ENV_SIZE ); -struct mmc *mmc =find_mmc_device (CONFIG_SYS_MMC_ENV_DEV ); +struct mmc *mmc;u32 offset;int ret; +int dev =CONFIG_SYS_MMC_ENV_DEV ; + +#ifdef CONFIG_SPL_BUILD + dev =0 ; +#endif + + mmc =find_mmc_device (dev);if (init_mmc_for_env (mmc)) { ret =1 ;
Signature · 1 line
1.7.9.5
PATCH v3 2/10 env_mmc.c: Allow environment to be used within SPL
Quoted 5 lines · Tom Rini
Inside of SPL we only concern ourself with one MMC device, so instead of being able to use
CONFIG_SYS_MMC_ENV_DEVwe need to use 0 in SPL. Switch the code to use a 'dev' variable to facilitate this.Signed-off-by Tom Rini <[email protected]>
Applied to u-boot-ti/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 836 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20140418/6ac39a26/attachment.pgp>
PATCH v3 3/10 env_mmc.c: Remove NULL check on tmp_env1/2
In reply to Tom RiniWith 452a272 we moved to allocating these variables on the stack. So they will never now be NULL so remove these checks.
--- common/env_mmc.c | 6 ------ 1 file changed, 6 deletions(-)
common/env_mmc.c +0 -6
@@ -220,12 +220,6 @@ void env_relocate_spec(void) mmc =find_mmc_device (dev); -if (tmp_env1 ==NULL || tmp_env2 ==NULL ) { -puts ("Can't allocate buffers for environment\n" ); - ret =1 ; - goto err; - } -if (init_mmc_for_env (mmc)) { ret =1 ; goto err;
Signature · 1 line
1.7.9.5
PATCH v3 3/10 env_mmc.c: Remove NULL check on tmp_env1/2
Quoted 4 lines · Tom Rini
With 452a272 we moved to allocating these variables on the stack. So they will never now be NULL so remove these checks.
Signed-off-by Tom Rini <[email protected]>
Applied to u-boot-ti/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 836 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20140418/8a60ba69/attachment.pgp>
PATCH v3 4/10 mtd: Add a CONFIG_SPL_MTD_SUPPORT for a more full NAND subsystem in SPL
In reply to Tom RiniThis mainly converts the am335x_spl_bch driver to the "normal" format which means a slight change to nand_info within the driver.
---
Changes in v2:
- Document CONFIG_SPL_MTD_SUPPORT in the README
--- README | 4 +++ drivers/mtd/nand/am335x_spl_bch.c | 54 ++++++++++++++++++------------------- include/configs/ti_armv7_common.h | 1 + spl/Makefile | 1 + 4 files changed, 33 insertions(+), 27 deletions(-)
README +4 -0
@@ -3314,6 +3314,10 @@ FIT uImage format: Support for NAND boot using simple NAND drivers that expose the cmd_ctrl() interface. + CONFIG_SPL_MTD_SUPPORT + Support for the MTD subsystem within SPL. Useful for + environment on NAND support within SPL. + CONFIG_SPL_MPC8XXX_INIT_DDR_SUPPORT Set for the SPL on PPC mpc8xxx targets, support for drivers/ddr/fsl/libddr.o in SPL binary.
drivers/mtd/nand/am335x_spl_bch.c +27 -27
146 lines not on this page · raw message
include/configs/ti_armv7_common.h +1 -0
@@ -247,6 +247,7 @@#define CONFIG_SPL_NAND_BASE #define CONFIG_SPL_NAND_DRIVERS #define CONFIG_SPL_NAND_ECC +#define CONFIG_SPL_MTD_SUPPORT #define CONFIG_SYS_NAND_U_BOOT_START CONFIG_SYS_TEXT_BASE#define CONFIG_SYS_NAND_U_BOOT_OFFS 0x80000#endif
spl/Makefile +1 -0
@@ -104,6 +104,7 @@ libs-$(CONFIG_SPL_SPI_SUPPORT) += drivers/spi/ libs-y += fs/ libs-$(CONFIG_SPL_LIBGENERIC_SUPPORT) += lib/ libs-$(CONFIG_SPL_POWER_SUPPORT) += drivers/power/ drivers/power/pmic/ +libs-$(CONFIG_SPL_MTD_SUPPORT) += drivers/mtd/ libs-$(if $(CONFIG_CMD_NAND),$(CONFIG_SPL_NAND_SUPPORT)) += drivers/mtd/nand/ libs-$(CONFIG_SPL_DRIVERS_MISC_SUPPORT) += drivers/misc/ libs-$(CONFIG_SPL_ONENAND_SUPPORT) += drivers/mtd/onenand/
Signature · 1 line
1.7.9.5
PATCH v3 4/10 mtd: Add a CONFIG_SPL_MTD_SUPPORT for a more full NAND subsystem in SPL
Quoted 5 lines · Tom Rini
This mainly converts the
am335x_spl_bchdriver to the "normal" format which means a slight change tonand_infowithin the driver.Acked-by Scott Wood <[email protected]>Signed-off-by Tom Rini <[email protected]>
Applied to u-boot-ti/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 836 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20140418/d0adb009/attachment.pgp>
PATCH v3 5/10 mtd: Build nand_util.o for CONFIG_ENV_IS_IN_NAND in SPL
In reply to Tom Rini---
Changes in v2:
- Surround adding nand_util.o with CONFIG_SPL_ENV_SUPPORT test
--- drivers/mtd/nand/Makefile | 3 +++ 1 file changed, 3 insertions(+)
drivers/mtd/nand/Makefile +3 -0
@@ -18,6 +18,9 @@ obj-$(CONFIG_SPL_NAND_LOAD) += nand_spl_load.o obj-$(CONFIG_SPL_NAND_ECC) += nand_ecc.o obj-$(CONFIG_SPL_NAND_BASE) += nand_base.o obj-$(CONFIG_SPL_NAND_INIT) += nand.o +ifeq ($(CONFIG_SPL_ENV_SUPPORT),y) +obj-$(CONFIG_ENV_IS_IN_NAND) += nand_util.o +endif else # not spl
Signature · 1 line
1.7.9.5
PATCH v3 5/10 mtd: Build nand_util.o for CONFIG_ENV_IS_IN_NAND in SPL
Quoted 2 lines · Tom Rini
Acked-by Scott Wood <[email protected]>Signed-off-by Tom Rini <[email protected]>
Applied to u-boot-ti/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 836 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20140418/e8fbbbdd/attachment.pgp>
PATCH v3 6/10 am335x_evm: Make SPL_OS also check the boot_os variable for falcon mode
In reply to Tom RiniWe use the same variable as a3m071 in the environment to determine if we should boot into Linux or U-Boot. This is useful on boards like Beaglebone Black or AM335x GP EVM where we have persistent storage for the environment.
--- board/ti/am335x/board.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-)
board/ti/am335x/board.c +12 -1
@@ -30,6 +30,7 @@#include <power/tps65910.h> #include <environment.h> #include <watchdog.h> +#include <environment.h> #include "board.h" DECLARE_GLOBAL_DATA_PTR ;
@@ -219,7 +220,17 @@ static struct emif_regs ddr3_evm_emif_reg_data = {int spl_start_uboot (void ) {/* break into full u-boot on 'c' */ -return (serial_tstc () &&serial_getc () =='c' ); +if (serial_tstc () &&serial_getc () =='c' ) +return 1 ; + +#ifdef CONFIG_SPL_ENV_SUPPORT +env_init (); +env_relocate_spec (); +if (getenv_yesno ("boot_os" ) !=1 ) +return 1 ; +#endif + +return 0 ; }#endif
Signature · 1 line
1.7.9.5
PATCH v3 6/10 am335x_evm: Make SPL_OS also check the boot_os variable for falcon mode
Quoted 6 lines · Tom Rini
We use the same variable as a3m071 in the environment to determine if we should boot into Linux or U-Boot. This is useful on boards like Beaglebone Black or AM335x GP EVM where we have persistent storage for the environment.
Signed-off-by Tom Rini <[email protected]>
Applied to u-boot-ti/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 836 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20140418/e4fefd70/attachment.pgp>
PATCH v3 7/10 README: Add CONFIG_SPL_OS_BOOT to README
In reply to Tom Rini--- README | 4 ++++ 1 file changed, 4 insertions(+)
README +4 -0
@@ -3242,6 +3242,10 @@ FIT uImage format: supports MMC, NAND and YMODEM loading of U-Boot and NAND NAND loading of the Linux Kernel. + CONFIG_SPL_OS_BOOT + Enable booting directly to an OS from SPL. + See also: doc/README.falcon + CONFIG_SPL_DISPLAY_PRINT For ARM, enable an optional function to print more information about the running system.
Signature · 1 line
1.7.9.5
PATCH v3 7/10 README: Add CONFIG_SPL_OS_BOOT to README
Quoted 1 line · Tom Rini
Signed-off-by Tom Rini <[email protected]>
Applied to u-boot-ti/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 836 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20140418/17cdcdd6/attachment.pgp>
PATCH v3 8/10 README.falcon: Document environment variables for falcon mode
In reply to Tom Rini--- doc/README.falcon | 9 +++++++++ 1 file changed, 9 insertions(+)
doc/README.falcon +9 -0
@@ -80,6 +80,15 @@ spl_start_uboot() : required Returns "0" if SPL should start the kernel, "1" if U-Boot must be started. +Environment variables +--------------------- + +A board may chose to look at the environment for decisions about falcon +mode. In this case the following variables may be supported: + +boot_os : Set to yes/Yes/true/True/1 to enable booting to OS, + any other value to fall back to U-Boot (including + unset) Using spl command -----------------
Signature · 1 line
1.7.9.5
PATCH v3 8/10 README.falcon: Document environment variables for falcon mode
Quoted 1 line · Tom Rini
Signed-off-by Tom Rini <[email protected]>
Applied to u-boot-ti/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 836 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20140418/9db8dc10/attachment.pgp>
PATCH v3 9/10 a3m071: Make spl_start_uboot test like getenv_yesno does
In reply to Tom RiniThis change makes the behaviour slightly more rebust and will match other implementations which can use getenv_yesno directly.
--- board/a3m071/a3m071.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
board/a3m071/a3m071.c +2 -1
@@ -412,7 +412,8 @@ int spl_start_uboot(void)env_init ();getenv_f ("boot_os" , s,sizeof (s)); -if ((s !=NULL ) && (strcmp (s,"yes" ) ==0 )) +if ((s !=NULL ) && (*s =='1' || *s =='y' || *s =='Y' || + *s =='t' || *s =='T' ))return 0 ;return 1 ;
Signature · 1 line
1.7.9.5
PATCH v3 9/10 a3m071: Make spl_start_uboot test like getenv_yesno does
Quoted 5 lines · Tom Rini
This change makes the behaviour slightly more rebust and will match other implementations which can use
getenv_yesnodirectly.Acked-by Stefan Roese <[email protected]>Signed-off-by Tom Rini <[email protected]>
Applied to u-boot-ti/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 836 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20140418/b12a1043/attachment.pgp>
PATCH v3 10/10 spl_mmc/CONFIG_SPL_OS_BOOT: Allow environment to determine what to boot
In reply to Tom RiniWe add two new environment variables, falcon_args_file and falcon_image_file, which when set will override the compiled in default values for falcon mode.
--- common/spl/spl_fat.c | 27 +++++++++++++++++++++++++++ doc/README.falcon | 4 ++++ 2 files changed, 31 insertions(+)
common/spl/spl_fat.c +27 -0
@@ -74,11 +74,38 @@ end:int spl_load_image_fat_os (block_dev_desc_t *block_dev,int partition) {int err; +__maybe_unused char *file; err =spl_register_fat_device (block_dev, partition);if (err)return err; +#if defined(CONFIG_SPL_ENV_SUPPORT ) && defined(CONFIG_SPL_OS_BOOT ) + file =getenv ("falcon_args_file" ); +if (file) { + err =file_fat_read (file, (void *)CONFIG_SYS_SPL_ARGS_ADDR ,0 ); +if (err <=0 ) { +printf ("spl: error reading image %s, err - %d, falling back to default\n" , + file, err); + goto defaults; + } + file =getenv ("falcon_image_file" ); +if (file) { + err =spl_load_image_fat (block_dev, partition, file); +if (err !=0 ) { +puts ("spl: falling back to default\n" ); + goto defaults; + } + +return 0 ; + }else +puts ("spl: falcon_image_file not set in environment, falling back to default\n" ); + }else +puts ("spl: falcon_args_file not set in environment, falling back to default\n" ); + +defaults: +#endif + err =file_fat_read (CONFIG_SPL_FAT_LOAD_ARGS_NAME , (void *)CONFIG_SYS_SPL_ARGS_ADDR ,0 );if (err <=0 ) {
doc/README.falcon +4 -0
@@ -89,6 +89,10 @@ mode. In this case the following variables may be supported: boot_os : Set to yes/Yes/true/True/1 to enable booting to OS, any other value to fall back to U-Boot (including unset) +falcon_args_file : Filename to load as the 'args' portion of falcon mode + rather than the hard-coded value. +falcon_image_file : Filename to load as the OS image portion of falcon + mode rather than the hard-coded value. Using spl command -----------------
Signature · 1 line
1.7.9.5
PATCH v3 10/10 spl_mmc/CONFIG_SPL_OS_BOOT: Allow environment to determine what to boot
Quoted 5 lines · Tom Rini
We add two new environment variables,
falcon_args_fileandfalcon_image_file, which when set will override the compiled in default values for falcon mode.Signed-off-by Tom Rini <[email protected]>
Applied to u-boot-ti/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 836 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20140418/a04408bb/attachment.pgp>