add CONFIG_ENV_SECT_SIZE_AUTO
cover add CONFIG_ENV_SECT_SIZE_AUTO
This is roughly the U-Boot side equivalent to commit e282c422e0 (tools: fw_env: use erasesize from MEMGETINFO ioctl), at least for SPI_FLASH backend.
When CONFIG_ENV_SECT_SIZE_AUTO is not selected (and it is of course default n), there's no functional change, and the compiler even seems to generate identical binary code.
The motivation is to cut about half a second off boottime on our newer revisions, while still having the same U-Boot binary work on both.
Rasmus Villemoes (2):
env/sf.c: use a variable to hold the sector size
env: add CONFIG_ENV_SECT_SIZE_AUTO
env/Kconfig | 14 ++++++++++++++ env/sf.c | 32 ++++++++++++++++++++------------ 2 files changed, 34 insertions(+), 12 deletions(-)
Signature · 1 line
2.23.0
PATCH 1/2 env/sf.c: use a variable to hold the sector size
As preparation for the next patch, use a local variable to represent the sector size. No functional change.
--- env/sf.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-)
env/sf.c +12 -10
@@ -70,6 +70,7 @@ static int env_sf_save(void)env_t env_new;char *saved_buffer =NULL , flag =ENV_REDUND_OBSOLETE ;u32 saved_size, saved_offset, sector; +u32 sect_size =CONFIG_ENV_SECT_SIZE ;int ret; ret =setup_flash_device ();
@@ -90,8 +91,8 @@ static int env_sf_save(void) }/* Is the sector larger than the env (i.e. embedded) */ -if (CONFIG_ENV_SECT_SIZE >CONFIG_ENV_SIZE ) { - saved_size =CONFIG_ENV_SECT_SIZE -CONFIG_ENV_SIZE ; +if (sect_size >CONFIG_ENV_SIZE ) { + saved_size = sect_size -CONFIG_ENV_SIZE ; saved_offset = env_new_offset +CONFIG_ENV_SIZE ; saved_buffer =memalign (ARCH_DMA_MINALIGN , saved_size);if (!saved_buffer) {
@@ -104,11 +105,11 @@ static int env_sf_save(void) goto done; } - sector =DIV_ROUND_UP (CONFIG_ENV_SIZE ,CONFIG_ENV_SECT_SIZE ); + sector =DIV_ROUND_UP (CONFIG_ENV_SIZE , sect_size);puts ("Erasing SPI flash..." ); ret =spi_flash_erase (env_flash, env_new_offset, - sector *CONFIG_ENV_SECT_SIZE ); + sector * sect_size);if (ret) goto done;
@@ -119,7 +120,7 @@ static int env_sf_save(void)if (ret) goto done; -if (CONFIG_ENV_SECT_SIZE >CONFIG_ENV_SIZE ) { +if (sect_size >CONFIG_ENV_SIZE ) { ret =spi_flash_write (env_flash, saved_offset, saved_size, saved_buffer);if (ret)
@@ -184,6 +185,7 @@ out:static int env_sf_save (void ) {u32 saved_size, saved_offset, sector; +u32 sect_size =CONFIG_ENV_SECT_SIZE ;char *saved_buffer =NULL ;int ret =1 ;env_t env_new;
@@ -193,8 +195,8 @@ static int env_sf_save(void)return ret;/* Is the sector larger than the env (i.e. embedded) */ -if (CONFIG_ENV_SECT_SIZE >CONFIG_ENV_SIZE ) { - saved_size =CONFIG_ENV_SECT_SIZE -CONFIG_ENV_SIZE ; +if (sect_size >CONFIG_ENV_SIZE ) { + saved_size = sect_size -CONFIG_ENV_SIZE ; saved_offset =CONFIG_ENV_OFFSET +CONFIG_ENV_SIZE ; saved_buffer =malloc (saved_size);if (!saved_buffer)
@@ -210,11 +212,11 @@ static int env_sf_save(void)if (ret) goto done; - sector =DIV_ROUND_UP (CONFIG_ENV_SIZE ,CONFIG_ENV_SECT_SIZE ); + sector =DIV_ROUND_UP (CONFIG_ENV_SIZE , sect_size);puts ("Erasing SPI flash..." ); ret =spi_flash_erase (env_flash,CONFIG_ENV_OFFSET , - sector *CONFIG_ENV_SECT_SIZE ); + sector * sect_size);if (ret) goto done;
@@ -224,7 +226,7 @@ static int env_sf_save(void)if (ret) goto done; -if (CONFIG_ENV_SECT_SIZE >CONFIG_ENV_SIZE ) { +if (sect_size >CONFIG_ENV_SIZE ) { ret =spi_flash_write (env_flash, saved_offset, saved_size, saved_buffer);if (ret)
Signature · 1 line
2.23.0
PATCH 1/2 env/sf.c: use a variable to hold the sector size
Quoted 3 lines · Rasmus Villemoes
As preparation for the next patch, use a local variable to represent the sector size. No functional change.
ping
Quoted 94 lines
Signed-off-by Rasmus Villemoes <[email protected]>--- env/sf.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-)env/sf.c +12
-10@@ -70,6 +70,7 @@ static int env_sf_save(void)env_t env_new;char *saved_buffer =NULL , flag =ENV_REDUND_OBSOLETE ;u32 saved_size, saved_offset, sector; +u32 sect_size =CONFIG_ENV_SECT_SIZE ;int ret; ret =setup_flash_device ();@@ -90,8 +91,8 @@ static int env_sf_save(void) }/* Is the sector larger than the env (i.e. embedded) */ -if (CONFIG_ENV_SECT_SIZE >CONFIG_ENV_SIZE ) { - saved_size =CONFIG_ENV_SECT_SIZE -CONFIG_ENV_SIZE ; +if (sect_size >CONFIG_ENV_SIZE ) { + saved_size = sect_size -CONFIG_ENV_SIZE ; saved_offset = env_new_offset +CONFIG_ENV_SIZE ; saved_buffer =memalign (ARCH_DMA_MINALIGN , saved_size);if (!saved_buffer) {@@ -104,11 +105,11 @@ static int env_sf_save(void) goto done; } - sector =DIV_ROUND_UP (CONFIG_ENV_SIZE ,CONFIG_ENV_SECT_SIZE ); + sector =DIV_ROUND_UP (CONFIG_ENV_SIZE , sect_size);puts ("Erasing SPI flash..." ); ret =spi_flash_erase (env_flash, env_new_offset, - sector *CONFIG_ENV_SECT_SIZE ); + sector * sect_size);if (ret) goto done;@@ -119,7 +120,7 @@ static int env_sf_save(void)if (ret) goto done; -if (CONFIG_ENV_SECT_SIZE >CONFIG_ENV_SIZE ) { +if (sect_size >CONFIG_ENV_SIZE ) { ret =spi_flash_write (env_flash, saved_offset, saved_size, saved_buffer);if (ret)@@ -184,6 +185,7 @@ out:static int env_sf_save (void ) {u32 saved_size, saved_offset, sector; +u32 sect_size =CONFIG_ENV_SECT_SIZE ;char *saved_buffer =NULL ;int ret =1 ;env_t env_new;@@ -193,8 +195,8 @@ static int env_sf_save(void)return ret;/* Is the sector larger than the env (i.e. embedded) */ -if (CONFIG_ENV_SECT_SIZE >CONFIG_ENV_SIZE ) { - saved_size =CONFIG_ENV_SECT_SIZE -CONFIG_ENV_SIZE ; +if (sect_size >CONFIG_ENV_SIZE ) { + saved_size = sect_size -CONFIG_ENV_SIZE ; saved_offset =CONFIG_ENV_OFFSET +CONFIG_ENV_SIZE ; saved_buffer =malloc (saved_size);if (!saved_buffer)@@ -210,11 +212,11 @@ static int env_sf_save(void)if (ret) goto done; - sector =DIV_ROUND_UP (CONFIG_ENV_SIZE ,CONFIG_ENV_SECT_SIZE ); + sector =DIV_ROUND_UP (CONFIG_ENV_SIZE , sect_size);puts ("Erasing SPI flash..." ); ret =spi_flash_erase (env_flash,CONFIG_ENV_OFFSET , - sector *CONFIG_ENV_SECT_SIZE ); + sector * sect_size);if (ret) goto done;@@ -224,7 +226,7 @@ static int env_sf_save(void)if (ret) goto done; -if (CONFIG_ENV_SECT_SIZE >CONFIG_ENV_SIZE ) { +if (sect_size >CONFIG_ENV_SIZE ) { ret =spi_flash_write (env_flash, saved_offset, saved_size, saved_buffer);if (ret)
Signature · 8 lines
Rasmus Villemoes Software Developer Prevas A/S Hedeager 3 DK-8200 Aarhus N +45 51210274 rasmus.villemoes at prevas.dk www.prevas.dk
PATCH 1/2 env/sf.c: use a variable to hold the sector size
Quoted 6 lines · Rasmus Villemoes
Quoted 3 lines · Rasmus Villemoes
As preparation for the next patch, use a local variable to represent the sector size. No functional change.
ping
I should probably put this series, and other env things in to -next soon after reading them over one more time. 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/20200918/674559a5/attachment.sig>
PATCH 2/2 env: add CONFIG_ENV_SECT_SIZE_AUTO
In reply to Rasmus VillemoesThis is roughly the U-Boot side equivalent to commit e282c422e0 (tools: fw_env: use erasesize from MEMGETINFO ioctl). The motivation is the case where one has a board with several revisions, where the SPI flashes have different erase sizes.
In our case, we have an 8K environment, and the flashes have erase sizes of 4K (newer boards) and 64K (older boards). Currently, we must set CONFIG_ENV_SECT_SIZE to 64K to make the code work on the older boards, but for the newer ones, that ends up wasting quite a bit of time reading/erasing/restoring the last 56K.
At first, I wanted to allow setting CONFIG_ENV_SECT_SIZE to 0 to mean "use the erase size the chip reports", but that config option is used in a number of preprocessor conditionals, and shared between ENV_IS_IN_FLASH and ENV_IS_IN_SPI_FLASH.
So instead, introduce a new boolean config option, which for now can only be used with ENV_IS_IN_SPI_FLASH. If left off, there's no change in behaviour.
The only slightly annoying detail is that, when selected, the compiler is apparently not smart enough to see that the the saved_size and saved_offset variables are only used under the same "if (sect_size > CONFIG_ENV_SIZE)" condition as where they are computed, so we need to initialize them to 0 to avoid "may be used uninitialized" warnings.
On our newer boards with the 4K erase size, saving the environment now takes 0.080 seconds instead of 0.53 seconds, which directly translates to that much faster boot time since our logic always causes the environment to be written during boot.
--- env/Kconfig | 14 ++++++++++++++ env/sf.c | 10 ++++++++-- 2 files changed, 22 insertions(+), 2 deletions(-)
env/Kconfig +14 -0
@@ -317,6 +317,20 @@ config ENV_IS_IN_SPI_FLASH during a "saveenv" operation. CONFIG_ENV_OFFSET_REDUND must be aligned to an erase sector boundary. +config ENV_SECT_SIZE_AUTO + bool "Use automatically detected sector size" + depends on ENV_IS_IN_SPI_FLASH + help + Some boards exist in multiple variants, with different + flashes having different sector sizes. In such cases, you + can select this option to make U-Boot use the actual sector + size when figuring out how much to erase, which can thus be + more efficient on the flashes with smaller erase size. Since + the environment must always be aligned on a sector boundary, + CONFIG_ENV_OFFSET must be aligned to the largest of the + different sector sizes, and CONFIG_ENV_SECT_SIZE should be + set to that value. + config USE_ENV_SPI_BUS bool "SPI flash bus for environment" depends on ENV_IS_IN_SPI_FLASH
env/sf.c +8 -2
@@ -69,7 +69,7 @@ static int env_sf_save(void) {env_t env_new;char *saved_buffer =NULL , flag =ENV_REDUND_OBSOLETE ; -u32 saved_size, saved_offset, sector; +u32 saved_size =0 , saved_offset =0 , sector;u32 sect_size =CONFIG_ENV_SECT_SIZE ;int ret;
@@ -77,6 +77,9 @@ static int env_sf_save(void)if (ret)return ret; +if (IS_ENABLED (CONFIG_ENV_SECT_SIZE_AUTO )) + sect_size = env_flash->mtd.erasesize; + ret =env_export (&env_new);if (ret)return -EIO ;
@@ -184,7 +187,7 @@ out:#else static int env_sf_save (void ) { -u32 saved_size, saved_offset, sector; +u32 saved_size =0 , saved_offset =0 , sector;u32 sect_size =CONFIG_ENV_SECT_SIZE ;char *saved_buffer =NULL ;int ret =1 ;
@@ -194,6 +197,9 @@ static int env_sf_save(void)if (ret)return ret; +if (IS_ENABLED (CONFIG_ENV_SECT_SIZE_AUTO )) + sect_size = env_flash->mtd.erasesize; +/* Is the sector larger than the env (i.e. embedded) */ if (sect_size >CONFIG_ENV_SIZE ) { saved_size = sect_size -CONFIG_ENV_SIZE ;
Signature · 1 line
2.23.0
PATCH 2/2 env: add CONFIG_ENV_SECT_SIZE_AUTO
Quoted 14 lines · Rasmus Villemoes
CAUTION: This email originated from outside of the organization. Do not click links or open attachments unless you recognize the sender and know the content is safe.
This is roughly the U-Boot side equivalent to commit
e282c422e0(tools:fw_env: use erasesize from MEMGETINFO ioctl). The motivation is the case where one has a board with several revisions, where the SPI flashes have different erase sizes.In our case, we have an 8K environment, and the flashes have erase sizes of 4K (newer boards) and 64K (older boards). Currently, we must set
CONFIG_ENV_SECT_SIZEto 64K to make the code work on the older boards, but for the newer ones, that ends up wasting quite a bit of time reading/erasing/restoring the last 56K.
Quoted 4 lines
At first, I wanted to allow setting
CONFIG_ENV_SECT_SIZEto 0 to mean "use the erase size the chip reports", but that config option is used in a number of preprocessor conditionals, and shared betweenENV_IS_IN_FLASHandENV_IS_IN_SPI_FLASH.
I see, It had been good if one could have used 0
Quoted 4 lines
So instead, introduce a new boolean config option, which for now can only be used with
ENV_IS_IN_SPI_FLASH. If left off, there's no change in behaviour.
Please don't stop at just SPI Flash, we could use this for common NOR flashes too.
Quoted 88 lines
The only slightly annoying detail is that, when selected, the compiler is apparently not smart enough to see that the the
saved_sizeandsaved_offsetvariables are only used under the same "if (sect_size>CONFIG_ENV_SIZE)" condition as where they are computed, so we need to initialize them to 0 to avoid "may be used uninitialized" warnings.On our newer boards with the 4K erase size, saving the environment now takes 0.080 seconds instead of 0.53 seconds, which directly translates to that much faster boot time since our logic always causes the environment to be written during boot.
Signed-off-by Rasmus Villemoes <[email protected]>--- env/Kconfig | 14 ++++++++++++++ env/sf.c | 10 ++++++++-- 2 files changed, 22 insertions(+), 2 deletions(-)env/Kconfig +14
-0@@ -317,6 +317,20 @@ config ENV_IS_IN_SPI_FLASH during a "saveenv" operation. CONFIG_ENV_OFFSET_REDUND must be aligned to an erase sector boundary. +config ENV_SECT_SIZE_AUTO + bool "Use automatically detected sector size" + depends on ENV_IS_IN_SPI_FLASH + help + Some boards exist in multiple variants, with different + flashes having different sector sizes. In such cases, you + can select this option to make U-Boot use the actual sector + size when figuring out how much to erase, which can thus be + more efficient on the flashes with smaller erase size. Since + the environment must always be aligned on a sector boundary, + CONFIG_ENV_OFFSET must be aligned to the largest of the + different sector sizes, and CONFIG_ENV_SECT_SIZE should be + set to that value. + config USE_ENV_SPI_BUS bool "SPI flash bus for environment" depends on ENV_IS_IN_SPI_FLASHenv/sf.c +8
-3@@ -69,7 +69,7 @@ static int env_sf_save(void) {env_t env_new;char *saved_buffer =NULL , flag =ENV_REDUND_OBSOLETE ; -u32 saved_size, saved_offset, sector; +u32 saved_size =0 , saved_offset =0 , sector;u32 sect_size =CONFIG_ENV_SECT_SIZE ;int ret;@@ -77,6 +77,9 @@ static int env_sf_save(void)if (ret)return ret; +if (IS_ENABLED (CONFIG_ENV_SECT_SIZE_AUTO )) + sect_size = env_flash->mtd.erasesize; + ret =env_export (&env_new);if (ret)return -EIO ;@@ -184,7 +187,7 @@ out:#else static int env_sf_save (void ) { -u32 saved_size, saved_offset, sector; +u32 saved_size =0 , saved_offset =0 , sector;u32 sect_size =CONFIG_ENV_SECT_SIZE ;char *saved_buffer =NULL ;int ret =1 ;@@ -194,6 +197,9 @@ static int env_sf_save(void)if (ret)return ret; +if (IS_ENABLED (CONFIG_ENV_SECT_SIZE_AUTO )) + sect_size = env_flash->mtd.erasesize; +/* Is the sector larger than the env (i.e. embedded) */ if (sect_size >CONFIG_ENV_SIZE ) { saved_size = sect_size -CONFIG_ENV_SIZE ; --2.23.0
PATCH 2/2 env: add CONFIG_ENV_SECT_SIZE_AUTO
Quoted 7 lines · Joakim Tjernlund
Quoted 4 lines · Rasmus Villemoes
At first, I wanted to allow setting
CONFIG_ENV_SECT_SIZEto 0 to mean "use the erase size the chip reports", but that config option is used in a number of preprocessor conditionals, and shared betweenENV_IS_IN_FLASHandENV_IS_IN_SPI_FLASH.
Quoted 8 lines
I see, It had been good if one could have used 0
Quoted 4 lines
So instead, introduce a new boolean config option, which for now can only be used with
ENV_IS_IN_SPI_FLASH. If left off, there's no change in behaviour.Please don't stop at just SPI Flash, we could use this for common NOR flashes too.
Certainly, but I don't have any such hardware, and the code also seems to require a bit more work than the sf.c case due to the preprocessor uses. It's quite possible that the
#if CONFIG_ENV_SECT_SIZE > CONFIG_ENV_SIZE
foo; bar;
#endif
can be replaced by
u32 sect_size = CONFIG_ENV_SECT_SIZE;
if (IS_ENABLED(CONFIG_ENV_SECT_SIZE_AUTO))
sect_size = [...however we want to get that info....]
if (sect_size > CONFIG_ENV_SIZE {
foo; bar;
}
but then there's the uses of CONFIG_ENV_SECT_SIZE to initialize end_addr and end_addr_new. So I think doing the flash.c part requires someone with hardware access.
Rasmus
PATCH 2/2 env: add CONFIG_ENV_SECT_SIZE_AUTO
Quoted 30 lines · Rasmus Villemoes
Quoted 6 lines · Joakim Tjernlund
Quoted 4 lines · Rasmus Villemoes
At first, I wanted to allow setting
CONFIG_ENV_SECT_SIZEto 0 to mean "use the erase size the chip reports", but that config option is used in a number of preprocessor conditionals, and shared betweenENV_IS_IN_FLASHandENV_IS_IN_SPI_FLASH.Quoted 7 lines
I see, It had been good if one could have used 0
Quoted 3 lines
So instead, introduce a new boolean config option, which for now can only be used with
ENV_IS_IN_SPI_FLASH. If left off, there's no change in behaviour.Please don't stop at just SPI Flash, we could use this for common NOR flashes too.
Certainly, but I don't have any such hardware, and the code also seems to require a bit more work than the
sf.ccase due to the preprocessor uses. It's quite possible that the#if
CONFIG_ENV_SECT_SIZE>CONFIG_ENV_SIZE
foo; bar;
#endifcan be replaced by
u32
sect_size=CONFIG_ENV_SECT_SIZE;
if (IS_ENABLED(CONFIG_ENV_SECT_SIZE_AUTO))
sect_size= [...however we want to get that info....]
Quoted 7 lines
if (
sect_size>CONFIG_ENV_SIZE{
foo; bar;
}but then there's the uses of
CONFIG_ENV_SECT_SIZEto initializeend_addrandend_addr_new. So I think doing theflash.cpart requires someone with hardware access.
I can test NOR Flash ,I am on an older u-boot ATM but fw_setenv stuff should be simple to backport How would fw_env.config be dealt with? Just ignored when auto size?
Jocke
PATCH 2/2 env: add CONFIG_ENV_SECT_SIZE_AUTO
Quoted 2 lines · Joakim Tjernlund
I can test NOR Flash ,I am on an older u-boot ATM but
fw_setenvstuff should be simple to backport How would fw_env.config be dealt with? Just ignored when auto size?
AFAIK, the U-Boot configuration doesn't affect the userspace fw_env tools, so auto size has to be opt-in separately in fw_env.config, which is where I did use 0 to mean auto (see the referenced commit e282c422e0). You should be able to test that part already with just fw_setenv built from master and an appropriate fw_env.config [or perhaps you need to add another "mtdinfo.type == ..." condition first].
Rasmus
PATCH 2/2 env: add CONFIG_ENV_SECT_SIZE_AUTO
Quoted 8 lines · Rasmus Villemoes
CAUTION: This email originated from outside of the organization. Do not click links or open attachments unless you recognize the sender and know the content is safe.
Quoted 2 lines · Joakim Tjernlund
I can test NOR Flash ,I am on an older u-boot ATM but
fw_setenvstuff should be simple to backport How would fw_env.config be dealt with? Just ignored when auto size?
Quoted 6 lines
AFAIK, the U-Boot configuration doesn't affect the userspace
fw_envtools, so auto size has to be opt-in separately in fw_env.config, which is where I did use 0 to mean auto (see the referenced commite282c422e0). You should be able to test that part already with justfw_setenvbuilt from master and an appropriate fw_env.config [or perhaps you need to add another "mtdinfo.type == ..." condition first].
Oh, I misunderstood then. I was mostly interested in fw_setenv ATM Looking at your fw_setenv commit I have one question:
Will this auto mode also work when erase size < env size ? We have the case:
# MTD device name Device offset Env. size Flash sector size
/dev/mtd1 0x0000 0x2000 0x00001000
Above does not work because EB < Env. size, one have to set the sector size to >= Env. size(0x2000)
Jocke
PATCH 2/2 env: add CONFIG_ENV_SECT_SIZE_AUTO
Quoted 19 lines · Joakim Tjernlund
Quoted 6 lines · Rasmus Villemoes
Quoted 2 lines · Joakim Tjernlund
I can test NOR Flash ,I am on an older u-boot ATM but
fw_setenvstuff should be simple to backport How would fw_env.config be dealt with? Just ignored when auto size?Quoted 6 lines
AFAIK, the U-Boot configuration doesn't affect the userspace
fw_envtools, so auto size has to be opt-in separately in fw_env.config, which is where I did use 0 to mean auto (see the referenced commite282c422e0). You should be able to test that part already with justfw_setenvbuilt from master and an appropriate fw_env.config [or perhaps you need to add another "mtdinfo.type == ..." condition first].Oh, I misunderstood then. I was mostly interested in
fw_setenvATM Looking at yourfw_setenvcommit I have one question:
Will this auto mode also work when erase size < env size ? We have the case:
Quoted 5 lines
# MTD device name Device offset Env. size Flash sector size
/dev/mtd10x00000x20000x00001000Above does not work because EB < Env. size, one have to set the sector size to >= Env. size(0x2000)
Yes, it should work just fine. My own board has env size 0x2000, so it spans two 4K sectors (on the boards with the newer flash). As long as one leaves the fifth column (number of sectors) empty or 0, the logic a bit further down will automatically compute how many sectors the environment occupies.
Are you saying that the above config is not accepted by fw_setenv or that it causes a run-time error when actually trying to save the env? If so, I'd like to see a strace output.
Rasmus
PATCH 2/2 env: add CONFIG_ENV_SECT_SIZE_AUTO
Quoted 25 lines · Rasmus Villemoes
CAUTION: This email originated from outside of the organization. Do not click links or open attachments unless you recognize the sender and know the content is safe.
Quoted 21 lines · Joakim Tjernlund
Quoted 11 lines · Rasmus Villemoes
Quoted 2 lines · Joakim Tjernlund
I can test NOR Flash ,I am on an older u-boot ATM but
fw_setenvstuff should be simple to backport How would fw_env.config be dealt with? Just ignored when auto size?AFAIK, the U-Boot configuration doesn't affect the userspace
fw_envtools, so auto size has to be opt-in separately in fw_env.config, which is where I did use 0 to mean auto (see the referenced commite282c422e0). You should be able to test that part already with justfw_setenvbuilt from master and an appropriate fw_env.config [or perhaps you need to add another "mtdinfo.type == ..." condition first].Oh, I misunderstood then. I was mostly interested in
fw_setenvATM Looking at yourfw_setenvcommit I have one question:
Will this auto mode also work when erase size < env size ? We have the case:# MTD device name Device offset Env. size Flash sector size /dev/mtd1 0x0000 0x2000 0x00001000
Quoted 8 lines
Quoted 2 lines
Above does not work because EB < Env. size, one have to set the sector size to >= Env. size(0x2000)
Yes, it should work just fine. My own board has env size
0x2000, so it spans two 4K sectors (on the boards with the newer flash). As long as one leaves the fifth column (number of sectors) empty or 0, the logic a bit further down will automatically compute how many sectors the environment occupies.
Nice, got to try your latest fw_setenv patch then :)
Quoted 4 lines
Are you saying that the above config is not accepted by
fw_setenvor that it causes a run-time error when actually trying to save the env? If so, I'd like to see a strace output.
No, I have yet to try your patch. I am saying that
/dev/mtd1 0x0000 0x2000 0x00001000
in my somewhat older fw_setenv, I think it would silently ignore writing the env. in that case(if I recall correctly)
PATCH 2/2 env: add CONFIG_ENV_SECT_SIZE_AUTO
In reply to Joakim TjernlundQuoted 16 lines · Joakim Tjernlund
Quoted 8 lines · Rasmus Villemoes
CAUTION: This email originated from outside of the organization. Do not click links or open attachments unless you recognize the sender and know the content is safe.
Quoted 2 lines · Joakim Tjernlund
I can test NOR Flash ,I am on an older u-boot ATM but
fw_setenvstuff should be simple to backport How would fw_env.config be dealt with? Just ignored when auto size?Quoted 6 lines
AFAIK, the U-Boot configuration doesn't affect the userspace
fw_envtools, so auto size has to be opt-in separately in fw_env.config, which is where I did use 0 to mean auto (see the referenced commite282c422e0). You should be able to test that part already with justfw_setenvbuilt from master and an appropriate fw_env.config [or perhaps you need to add another "mtdinfo.type == ..." condition first].
Quoted 6 lines
Oh, I misunderstood then. I was mostly interested in
fw_setenvATM Looking at yourfw_setenvcommit I have one question:
Will this auto mode also work when erase size < env size ? We have the case:# MTD device name Device offset Env. size Flash sector size
From my POV, this "Flash sector size" name is misleading. "Size to erase" would be better. It must be >= Env. size and a multiple of EB size.
auto would mean to select a size >= Env. size, round up to closest multiple of EB size.
Quoted 6 lines
/dev/mtd10x00000x20000x00001000Above does not work because EB < Env. size, one have to set the sector size to >= Env. size(0x2000)
Jocke
PATCH 2/2 env: add CONFIG_ENV_SECT_SIZE_AUTO
Quoted 22 lines · Joakim Tjernlund
Quoted 21 lines · Joakim Tjernlund
Quoted 8 lines · Rasmus Villemoes
CAUTION: This email originated from outside of the organization. Do not click links or open attachments unless you recognize the sender and know the content is safe.
Quoted 2 lines · Joakim Tjernlund
I can test NOR Flash ,I am on an older u-boot ATM but
fw_setenvstuff should be simple to backport How would fw_env.config be dealt with? Just ignored when auto size?Quoted 6 lines
AFAIK, the U-Boot configuration doesn't affect the userspace
fw_envtools, so auto size has to be opt-in separately in fw_env.config, which is where I did use 0 to mean auto (see the referenced commite282c422e0). You should be able to test that part already with justfw_setenvbuilt from master and an appropriate fw_env.config [or perhaps you need to add another "mtdinfo.type == ..." condition first].Oh, I misunderstood then. I was mostly interested in
fw_setenvATM Looking at yourfw_setenvcommit I have one question:
Will this auto mode also work when erase size < env size ? We have the case:
Quoted 5 lines
Quoted 1 line
# MTD device name Device offset Env. size Flash sector size
From my POV, this "Flash sector size" name is misleading. "Size to erase" would be better. It must be >= Env. size and a multiple of EB size.
auto would mean to select a size >= Env. size, round up to closest multiple of EB size.
No, it is indeed supposed to be the flash sector size, and _not_ the size to erase; that's why the code has logic to compute how many sectors to erase (which you can also optionally specify in a fifth column, but as I said, that's done automatically if not specified), and the erase size is then, later yet, of course computed as (erase size)*#sectors.
All that has nothing at all to do with my patch, that's how it all used to work.
Quoted 4 lines
Quoted 4 lines
/dev/mtd10x00000x20000x00001000Above does not work because EB < Env. size, one have to set the sector size to >= Env. size(0x2000)
Are you sure? As I said, it works just fine on my end. The only thing my auto-patch does is to make
/dev/mtd1 0x0000 0x2000 0x00001000
equivalent to
/dev/mtd1 0x0000 0x2000 0
if the flash does have 4k erase size, so my patch wouldn't make the latter work if the former didn't already. [But again, the reason I can't use the former is to be compatible with the boards that have 64K erase size].
Rasmus
PATCH 2/2 env: add CONFIG_ENV_SECT_SIZE_AUTO
Quoted 38 lines · Rasmus Villemoes
Quoted 22 lines · Joakim Tjernlund
Quoted 21 lines · Joakim Tjernlund
Quoted 8 lines · Rasmus Villemoes
CAUTION: This email originated from outside of the organization. Do not click links or open attachments unless you recognize the sender and know the content is safe.
Quoted 2 lines · Joakim Tjernlund
I can test NOR Flash ,I am on an older u-boot ATM but
fw_setenvstuff should be simple to backport How would fw_env.config be dealt with? Just ignored when auto size?Quoted 6 lines
AFAIK, the U-Boot configuration doesn't affect the userspace
fw_envtools, so auto size has to be opt-in separately in fw_env.config, which is where I did use 0 to mean auto (see the referenced commite282c422e0). You should be able to test that part already with justfw_setenvbuilt from master and an appropriate fw_env.config [or perhaps you need to add another "mtdinfo.type == ..." condition first].Oh, I misunderstood then. I was mostly interested in
fw_setenvATM Looking at yourfw_setenvcommit I have one question:
Will this auto mode also work when erase size < env size ? We have the case:Quoted 5 lines
Quoted 1 line
# MTD device name Device offset Env. size Flash sector size
From my POV, this "Flash sector size" name is misleading. "Size to erase" would be better. It must be >= Env. size and a multiple of EB size.
auto would mean to select a size >= Env. size, round up to closest multiple of EB size.No, it is indeed supposed to be the flash sector size, and _not_ the size to erase; that's why the code has logic to compute how many sectors to erase (which you can also optionally specify in a fifth column, but as I said, that's done automatically if not specified), and the erase size is then, later yet, of course computed as (erase size)*#sectors.
All that has nothing at all to do with my patch, that's how it all used to work.
Quoted 7 lines
Quoted 4 lines
Quoted 4 lines
/dev/mtd10x00000x20000x00001000Above does not work because EB < Env. size, one have to set the sector size to >= Env. size(0x2000)
Are you sure? As I said, it works just fine on my end. The only thing my auto-patch does is to make
Yes, but then my fw_setenv is from 2015.04, not much has happened to fw_setenv since then though I will test you auto fw_setenv soon
Jocke
Quoted 13 lines
/dev/mtd10x00000x20000x00001000equivalent to
/dev/mtd10x00000x20000if the flash does have 4k erase size, so my patch wouldn't make the latter work if the former didn't already. [But again, the reason I can't use the former is to be compatible with the boards that have 64K erase size].
Rasmus
PATCH 2/2 env: add CONFIG_ENV_SECT_SIZE_AUTO
Quoted 41 lines · Joakim Tjernlund
Quoted 40 lines · Rasmus Villemoes
Quoted 22 lines · Joakim Tjernlund
Quoted 21 lines · Joakim Tjernlund
Quoted 8 lines · Rasmus Villemoes
CAUTION: This email originated from outside of the organization. Do not click links or open attachments unless you recognize the sender and know the content is safe.
Quoted 2 lines · Joakim Tjernlund
I can test NOR Flash ,I am on an older u-boot ATM but
fw_setenvstuff should be simple to backport How would fw_env.config be dealt with? Just ignored when auto size?Quoted 6 lines
AFAIK, the U-Boot configuration doesn't affect the userspace
fw_envtools, so auto size has to be opt-in separately in fw_env.config, which is where I did use 0 to mean auto (see the referenced commite282c422e0). You should be able to test that part already with justfw_setenvbuilt from master and an appropriate fw_env.config [or perhaps you need to add another "mtdinfo.type == ..." condition first].Oh, I misunderstood then. I was mostly interested in
fw_setenvATM Looking at yourfw_setenvcommit I have one question:
Will this auto mode also work when erase size < env size ? We have the case:Quoted 5 lines
Quoted 1 line
# MTD device name Device offset Env. size Flash sector size
From my POV, this "Flash sector size" name is misleading. "Size to erase" would be better. It must be >= Env. size and a multiple of EB size.
auto would mean to select a size >= Env. size, round up to closest multiple of EB size.No, it is indeed supposed to be the flash sector size, and _not_ the size to erase; that's why the code has logic to compute how many sectors to erase (which you can also optionally specify in a fifth column, but as I said, that's done automatically if not specified), and the erase size is then, later yet, of course computed as (erase size)*#sectors.
All that has nothing at all to do with my patch, that's how it all used to work.
Quoted 2 lines
Quoted 2 lines
/dev/mtd10x00000x20000x00001000
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
Quoted 2 lines
Above does not work because EB < Env. size, one have to set the sector size to >= Env. size(0x2000)
Are you sure? As I said, it works just fine on my end. The only thing my auto-patch does is to make
Yes, but then my
fw_setenvis from 2015.04, not much has happened tofw_setenvsince then though I will test you autofw_setenvsoon
Some docs about this new auto mode in fw_env.config would probably be a good idea too.
PATCH 2/2 env: add CONFIG_ENV_SECT_SIZE_AUTO
In reply to Rasmus VillemoesQuoted 25 lines · Rasmus Villemoes
This is roughly the U-Boot side equivalent to commit
e282c422e0(tools:fw_env: use erasesize from MEMGETINFO ioctl). The motivation is the case where one has a board with several revisions, where the SPI flashes have different erase sizes.>
In our case, we have an 8K environment, and the flashes have erase sizes of 4K (newer boards) and 64K (older boards). Currently, we must setCONFIG_ENV_SECT_SIZEto 64K to make the code work on the older boards, but for the newer ones, that ends up wasting quite a bit of time reading/erasing/restoring the last 56K.At first, I wanted to allow setting
CONFIG_ENV_SECT_SIZEto 0 to mean "use the erase size the chip reports", but that config option is used in a number of preprocessor conditionals, and shared betweenENV_IS_IN_FLASHandENV_IS_IN_SPI_FLASH.So instead, introduce a new boolean config option, which for now can only be used with
ENV_IS_IN_SPI_FLASH. If left off, there's no change in behaviour.The only slightly annoying detail is that, when selected, the compiler is apparently not smart enough to see that the the
saved_sizeandsaved_offsetvariables are only used under the same "if (sect_size>CONFIG_ENV_SIZE)" condition as where they are computed, so we need to initialize them to 0 to avoid "may be used uninitialized" warnings.
Quoted 4 lines
On our newer boards with the 4K erase size, saving the environment now takes 0.080 seconds instead of 0.53 seconds, which directly translates to that much faster boot time since our logic always causes the environment to be written during boot.
ping
Quoted 74 lines
Signed-off-by Rasmus Villemoes <[email protected]>--- env/Kconfig | 14 ++++++++++++++ env/sf.c | 10 ++++++++-- 2 files changed, 22 insertions(+), 2 deletions(-)env/Kconfig +14
-0@@ -317,6 +317,20 @@ config ENV_IS_IN_SPI_FLASH during a "saveenv" operation. CONFIG_ENV_OFFSET_REDUND must be aligned to an erase sector boundary. +config ENV_SECT_SIZE_AUTO + bool "Use automatically detected sector size" + depends on ENV_IS_IN_SPI_FLASH + help + Some boards exist in multiple variants, with different + flashes having different sector sizes. In such cases, you + can select this option to make U-Boot use the actual sector + size when figuring out how much to erase, which can thus be + more efficient on the flashes with smaller erase size. Since + the environment must always be aligned on a sector boundary, + CONFIG_ENV_OFFSET must be aligned to the largest of the + different sector sizes, and CONFIG_ENV_SECT_SIZE should be + set to that value. + config USE_ENV_SPI_BUS bool "SPI flash bus for environment" depends on ENV_IS_IN_SPI_FLASHenv/sf.c +8
-2@@ -69,7 +69,7 @@ static int env_sf_save(void) {env_t env_new;char *saved_buffer =NULL , flag =ENV_REDUND_OBSOLETE ; -u32 saved_size, saved_offset, sector; +u32 saved_size =0 , saved_offset =0 , sector;u32 sect_size =CONFIG_ENV_SECT_SIZE ;int ret;@@ -77,6 +77,9 @@ static int env_sf_save(void)if (ret)return ret; +if (IS_ENABLED (CONFIG_ENV_SECT_SIZE_AUTO )) + sect_size = env_flash->mtd.erasesize; + ret =env_export (&env_new);if (ret)return -EIO ;@@ -184,7 +187,7 @@ out:#else static int env_sf_save (void ) { -u32 saved_size, saved_offset, sector; +u32 saved_size =0 , saved_offset =0 , sector;u32 sect_size =CONFIG_ENV_SECT_SIZE ;char *saved_buffer =NULL ;int ret =1 ;@@ -194,6 +197,9 @@ static int env_sf_save(void)if (ret)return ret; +if (IS_ENABLED (CONFIG_ENV_SECT_SIZE_AUTO )) + sect_size = env_flash->mtd.erasesize; +/* Is the sector larger than the env (i.e. embedded) */ if (sect_size >CONFIG_ENV_SIZE ) { saved_size = sect_size -CONFIG_ENV_SIZE ;
Signature · 8 lines
Rasmus Villemoes Software Developer Prevas A/S Hedeager 3 DK-8200 Aarhus N +45 51210274 rasmus.villemoes at prevas.dk www.prevas.dk
PATCH 2/2 env: add CONFIG_ENV_SECT_SIZE_AUTO
Dear Rasmus,
Quoted 5 lines · In message <[email protected]> you wrote:
Quoted 5 lines
On our newer boards with the 4K erase size, saving the environment now takes 0.080 seconds instead of 0.53 seconds, which directly translates to that much faster boot time since our logic always causes the environment to be written during boot.
Is this your way of implementing scheduled obsolescence?
Automatically writing the environment on every boot is always a really bad idea. Never ever do that.
Best regards,
Wolfgang Denk
Signature · 5 lines
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de When the bosses talk about improving productivity, they are never talking about themselves.
PATCH 2/2 env: add CONFIG_ENV_SECT_SIZE_AUTO
Quoted 10 lines · Wolfgang Denk
Dear Rasmus,
Quoted 5 lines · In message <[email protected]> you wrote:
Quoted 5 lines
On our newer boards with the 4K erase size, saving the environment now takes 0.080 seconds instead of 0.53 seconds, which directly translates to that much faster boot time since our logic always causes the environment to be written during boot.
Is this your way of implementing scheduled obsolescence?
I'll ignore that.
Quoted 2 lines
Automatically writing the environment on every boot is always a really bad idea. Never ever do that.
Well, there's really no other place on this piece of hardware to implement a boot counter/slot selection. Sure, we could use another part of the spi flash and define our own storage format etc., but then we might as well use the u-boot environment, which allows us to use existing tools/APIs both on the U-Boot and linux side.
And yes, the number of erase cycles compared to how often this device is booted was taken into account when this was decided.
Rasmus
PATCH 2/2 env: add CONFIG_ENV_SECT_SIZE_AUTO
Met vriendelijke groet / kind regards,
Mike Looijmans
System Expert
TOPIC Embedded Products B.V.
Materiaalweg 4, 5681 RJ Best
The Netherlands
T: +31 (0) 499 33 69 69
E: mike.looijmans at topicproducts.com
W: www.topicproducts.com
Please consider the environment before printing this e-mail
Quoted 17 lines · Rasmus Villemoes
Quoted 10 lines · Wolfgang Denk
Dear Rasmus,
Quoted 5 lines · In message <[email protected]> you wrote:
Quoted 5 lines
On our newer boards with the 4K erase size, saving the environment now takes 0.080 seconds instead of 0.53 seconds, which directly translates to that much faster boot time since our logic always causes the environment to be written during boot.
Is this your way of implementing scheduled obsolescence?
I'll ignore that.
Quoted 2 lines
Automatically writing the environment on every boot is always a really bad idea. Never ever do that.
Quoted 8 lines
Well, there's really no other place on this piece of hardware to implement a boot counter/slot selection. Sure, we could use another part of the spi flash and define our own storage format etc., but then we might as well use the u-boot environment, which allows us to use existing
tools/APIsboth on the U-Boot and linux side.And yes, the number of erase cycles compared to how often this device is booted was taken into account when this was decided.
If it's SPI NOR flash, you can make use of the fact that you can change any 1 into a 0 without erasing the flash sector.
So if you use a unary counter (the number of consecutive zero bits), incrementing the counter doesn't require a sector flash.
I once used this for a medical device. After an upgade, the flash would boot-count and after 3 failed boots fall back to the previous image. The software would mark the image as "good" once booted okay by clearing the special "image is okay" bit.
This way there's only one erase cycle for every software upgrade, even with the use of a bootcounter.
PATCH 2/2 env: add CONFIG_ENV_SECT_SIZE_AUTO
Quoted 18 lines · Mike Looijmans
Quoted 11 lines
Quoted 2 lines
Automatically writing the environment on every boot is always a really bad idea. Never ever do that.
Well, there's really no other place on this piece of hardware to implement a boot counter/slot selection. Sure, we could use another part of the spi flash and define our own storage format etc., but then we might as well use the u-boot environment, which allows us to use existing
tools/APIsboth on the U-Boot and linux side.And yes, the number of erase cycles compared to how often this device is booted was taken into account when this was decided.
If it's SPI NOR flash, you can make use of the fact that you can change any 1 into a 0 without erasing the flash sector.
So if you use a unary counter (the number of consecutive zero bits), incrementing the counter doesn't require a sector flash.
Quoted 7 lines
I once used this for a medical device. After an upgade, the flash would boot-count and after 3 failed boots fall back to the previous image. The software would mark the image as "good" once booted okay by clearing the special "image is okay" bit.
This way there's only one erase cycle for every software upgrade, even with the use of a bootcounter.
Yes, I/we considered some scheme like that (though we store a bit more information, so not exactly what you described), essentially just using a sector as append-only storage for an array if fixed-size small blobs (I think we could fit everything into 16 bytes or so, but if its 4 or 16 or ... doesn't really matter). On reading, we'd read the whole sector and use the last not-all-ones blob, probably with some sanity checking. On writing, we'd only have to do an erase once every 256 or 1024 or whatever. But regardless, the complexity of having to write a small linux tool for that and patching the u-boot side similarly, and maintaining that code forever (because we really _do_ plan to keep updating the software on these devices, including u-boot), and that the spi flash has 100000 expected erase cycles, meant that we went for the much simpler, and easily extendible, solution.
In the field, these devices are usually turned on and then run for _months_. But when they are booted, getting up and running quickly is somewhat important. In our test rack, they are exposed to 1000s of power-cut tests among others (so one of those might eventually wear out the spi flash - but actually getting data on when that can be expected is just a bonus), so there saving half a second of boot time means we can do more tests in a given time span.
Rasmus