bootcount_ext: Add flag to enable/disable bootcount
PATCH 1/1 bootcount_ext: Add flag to enable/disable bootcount
After a successful upgrade, multiple problem during boot sequence may trigger the altbootcmd process.
This patch adds a 3rd byte to the bootcount file to enable/disable the bootcount check.
When reading old bootcount file, 2 bytes long, it will consider that bootcount is enabled, and update the file accordingly.
The bootcount file is only saved when upgrade_available is true, this allows to save writes to the filesystem.
--- drivers/bootcount/bootcount_ext.c | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-)
drivers/bootcount/bootcount_ext.c +18 -6
@@ -9,6 +9,8 @@#define BC_MAGIC 0xbc +static u8 upgrade_available =1 ; +void bootcount_store (ulong a) {u8 *buf;
@@ -21,13 +23,18 @@ void bootcount_store(ulong a)return ; } - buf =map_sysmem (CONFIG_SYS_BOOTCOUNT_ADDR ,2 ); +/* Only update bootcount during upgrade process */ +if (!upgrade_available) +return ; + + buf =map_sysmem (CONFIG_SYS_BOOTCOUNT_ADDR ,3 ); buf[0 ] =BC_MAGIC ; buf[1 ] = (a &0xff ); + buf[2 ] = upgrade_available;unmap_sysmem (buf); ret =fs_write (CONFIG_SYS_BOOTCOUNT_EXT_NAME , -CONFIG_SYS_BOOTCOUNT_ADDR ,0 ,2 , &len); +CONFIG_SYS_BOOTCOUNT_ADDR ,0 ,3 , &len);if (ret !=0 )puts ("Error storing bootcount\n" ); }
@@ -45,15 +52,20 @@ ulong bootcount_load(void) } ret =fs_read (CONFIG_SYS_BOOTCOUNT_EXT_NAME ,CONFIG_SYS_BOOTCOUNT_ADDR , -0 ,2 , &len_read); -if (ret !=0 || len_read !=2 ) { +0 ,3 , &len_read); +if (ret !=0 || len_read <2 || len_read >3 ) {puts ("Error loading bootcount\n" );return 0 ; } buf =map_sysmem (CONFIG_SYS_BOOTCOUNT_ADDR ,2 ); -if (buf[0 ] ==BC_MAGIC ) - ret = buf[1 ]; +/* Use the 3rd byte to enable/disable bootcount */ +if (buf[0 ] ==BC_MAGIC ) { +if (len_read ==3 ) + upgrade_available = buf[2 ]; +if (upgrade_available) + ret = buf[1 ]; + }unmap_sysmem (buf);
Signature · 1 line
2.18.0
PATCH 1/1 bootcount_ext: Add flag to enable/disable bootcount
Hi Fr?d?ric,
Quoted 8 lines · Fr?d?ric Danis
After a successful upgrade, multiple problem during boot sequence may trigger the altbootcmd process.
This patch adds a 3rd byte to the bootcount file to enable/disable the bootcount check.
When reading old bootcount file, 2 bytes long, it will consider that bootcount is enabled, and update the file accordingly.
Is this format documented somewhere? Should it perhaps have a version number so you can copy with future changes?
Review
Quoted 9 lines
The bootcount file is only saved when
upgrade_availableis true, this allows to save writes to the filesystem.Signed-off-by Fr?d?ric Danis <[email protected]>--- drivers/bootcount/bootcount_ext.c | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-)(quoted diff) +0
-0
b/drivers/bootcount/bootcount_ext.c
Quoted 20 lines
index
075e590896..740bce0296100644drivers/bootcount/bootcount_ext.c +5
-1@@ -9,6 +9,8 @@#define BC_MAGIC 0xbc +static u8 upgrade_available =1 ; +void bootcount_store (ulong a) {u8 *buf;@@ -21,13 +23,18 @@ void bootcount_store(ulong a)return ; } - buf =map_sysmem (CONFIG_SYS_BOOTCOUNT_ADDR ,2 ); +/* Only update bootcount during upgrade process */ +if (!upgrade_available) +return ;
drivers/bootcount/bootcount_ext.c void bootcount_store(ulong a) · line 37
Quoted 10 lines
drivers/bootcount/bootcount_ext.c +4
-1+ + buf =map_sysmem (CONFIG_SYS_BOOTCOUNT_ADDR ,3 ); buf[0 ] =BC_MAGIC ; buf[1 ] = (a &0xff ); + buf[2 ] = upgrade_available;unmap_sysmem (buf); ret =fs_write (CONFIG_SYS_BOOTCOUNT_EXT_NAME , -CONFIG_SYS_BOOTCOUNT_ADDR ,0 ,2 , &len); +CONFIG_SYS_BOOTCOUNT_ADDR ,0 ,3 , &len);
Separate from this patch...to me it seems ugly to put this info in CONFIG. Could it not be structured as a driver, with device tree used to hold the information?
See for example fs_loader.txt
drivers/bootcount/bootcount_ext.c ulong bootcount_load(void) · line 54
Quoted 7 lines
drivers/bootcount/bootcount_ext.c +0
-0if (ret !=0 )puts ("Error storing bootcount\n" ); }@@ -45,15 +52,20 @@ ulong bootcount_load(void) } ret = fs_read(CONFIG_SYS_BOOTCOUNT_EXT_NAME,
CONFIG_SYS_BOOTCOUNT_ADDR,
Quoted 22 lines
drivers/bootcount/bootcount_ext.c +9
-5- 0, 2, &len_read); -if (ret !=0 || len_read !=2 ) { + 0, 3, &len_read); +if (ret !=0 || len_read <2 || len_read >3 ) {puts ("Error loading bootcount\n" );return 0 ; } buf =map_sysmem (CONFIG_SYS_BOOTCOUNT_ADDR ,2 ); -if (buf[0 ] ==BC_MAGIC ) - ret = buf[1 ]; +/* Use the 3rd byte to enable/disable bootcount */ +if (buf[0 ] ==BC_MAGIC ) { +if (len_read ==3 ) + upgrade_available = buf[2 ]; +if (upgrade_available) + ret = buf[1 ]; + }unmap_sysmem (buf); --
Quoted 2 lines
2.18.0
Regards,
Simon
PATCH 1/1 bootcount_ext: Add flag to enable/disable bootcount
Hi Simon,
Quoted 14 lines · Simon Glass
Hi Fr?d?ric,
Quoted 8 lines · On Wed, 11 Mar 2020 at 05:00, Fr?d?ric Danis <frederic.danis at collabora.com…
After a successful upgrade, multiple problem during boot sequence may trigger the altbootcmd process.
This patch adds a 3rd byte to the bootcount file to enable/disable the bootcount check.
When reading old bootcount file, 2 bytes long, it will consider that bootcount is enabled, and update the file accordingly.
Quoted 2 lines
Is this format documented somewhere? Should it perhaps have a version number so you can copy with future changes?
I will change the Magic byte and add a version number.
Can you give me advice where I should add this format documentation?
Quoted 47 lines
Quoted 5 lines
The bootcount file is only saved when
upgrade_availableis true, this allows to save writes to the filesystem.Signed-off-by Fr?d?ric Danis <[email protected]<mailto:[email protected]>>
Review
Quoted 5 lines
---
?drivers/bootcount/bootcount_ext.c| 24 ++++++++++++++++++------ ? 1 file changed, 18 insertions(+), 6 deletions(-)(quoted diff) +0
-0
b/drivers/bootcount/bootcount_ext.cQuoted 20 lines
index
075e590896..740bce0296100644drivers/bootcount/bootcount_ext.c +0
-0@@ -9,6 +9,8 @@? #define
BC_MAGIC? ? ? ?0xbcdrivers/bootcount/bootcount_ext.c +2
-0+static u8 upgrade_available =1 ; +? void
bootcount_store(ulong a)
? {
? ? ? ? ?u8 *buf;drivers/bootcount/bootcount_ext.c +3
-1@@ -21,13 +23,18 @@ void bootcount_store(ulong a) ? ? ? ? ? ? ? ? ?return; ? ? ? ? ?} -? ? ? ?buf = map_sysmem(CONFIG_SYS_BOOTCOUNT_ADDR, 2); +? ? ? ?/* Only update bootcount during upgrade process */ +? ? ? ?if (!upgrade_available) +? ? ? ? ? ? ? ?return;drivers/bootcount/bootcount_ext.c void bootcount_store(ulong a) · line 37
Quoted 10 lines
drivers/bootcount/bootcount_ext.c +4
-1+ +? ? ? ?buf = map_sysmem(CONFIG_SYS_BOOTCOUNT_ADDR, 3); ? ? ? ? ?buf[0] = BC_MAGIC; ? ? ? ? ?buf[1] = (a & 0xff); +? ? ? ?buf[2] = upgrade_available; ? ? ? ? ?unmap_sysmem(buf); ? ? ? ? ?ret = fs_write(CONFIG_SYS_BOOTCOUNT_EXT_NAME, -? ? ? ? ? ? ? ? ? ? ? CONFIG_SYS_BOOTCOUNT_ADDR, 0, 2, &len); +? ? ? ? ? ? ? ? ? ? ? CONFIG_SYS_BOOTCOUNT_ADDR, 0, 3, &len);Separate from this patch...to me it seems ugly to put this info in CONFIG. Could it not be structured as a driver, with device tree used to hold the information?
Quoted 1 line
See for example fs_loader.txt
OK, I will try to send another patch for this ? but I don't know when
Quoted 28 lines
drivers/bootcount/bootcount_ext.c ulong bootcount_load(void) · line 54
Quoted 8 lines
drivers/bootcount/bootcount_ext.c +0
-0? ? ? ? ?if (ret != 0) ? ? ? ? ? ? ? ? ?puts("Error storing bootcount\n"); ? }@@ -45,15 +52,20 @@ ulong bootcount_load(void) ? ? ? ? ?} ? ? ? ? ?ret = fs_read(CONFIG_SYS_BOOTCOUNT_EXT_NAME,
CONFIG_SYS_BOOTCOUNT_ADDR,Quoted 19 lines
drivers/bootcount/bootcount_ext.c +9
-4-? ? ? ? ? ? ? ? ? ? ?0, 2, &len_read); -? ? ? ?if (ret != 0 || len_read != 2) { +? ? ? ? ? ? ? ? ? ? ?0, 3, &len_read); +? ? ? ?if (ret != 0 || len_read < 2 || len_read > 3) { ? ? ? ? ? ? ? ? ?puts("Error loading bootcount\n"); ? ? ? ? ? ? ? ? ?return 0; ? ? ? ? ?} ? ? ? ? ?buf = map_sysmem(CONFIG_SYS_BOOTCOUNT_ADDR, 2); -? ? ? ?if (buf[0] == BC_MAGIC) -? ? ? ? ? ? ? ?ret = buf[1]; +? ? ? ?/* Use the 3rd byte to enable/disable bootcount */ +? ? ? ?if (buf[0] == BC_MAGIC) { +? ? ? ? ? ? ? ?if (len_read == 3) +? ? ? ? ? ? ? ? ? ? ? ?upgrade_available = buf[2]; +? ? ? ? ? ? ? ?if (upgrade_available) +? ? ? ? ? ? ? ? ? ? ? ?ret = buf[1]; +? ? ? ?}
Quoted 8 lines
Quoted 5 lines
drivers/bootcount/bootcount_ext.c +0
-1? ? ? ? ?unmap_sysmem(buf); --2.18.0
Regards,
Simon
Regards,
Fred
PATCH 1/1 bootcount_ext: Add flag to enable/disable bootcount
Hi Fr?d?ric,
Quoted 17 lines · Fr?d?ric Danis
Hi Simon,
On 12/03/2020 04:22, Simon Glass wrote:
Hi Fr?d?ric,
Quoted 8 lines · Fr?d?ric Danis
After a successful upgrade, multiple problem during boot sequence may trigger the altbootcmd process.
This patch adds a 3rd byte to the bootcount file to enable/disable the bootcount check.
When reading old bootcount file, 2 bytes long, it will consider that bootcount is enabled, and update the file accordingly.
Quoted 6 lines
Is this format documented somewhere? Should it perhaps have a version number so you can copy with future changes?
I will change the Magic byte and add a version number.
Can you give me advice where I should add this format documentation?
I suggest doc/README.bootcount
Quoted 44 lines
Quoted 31 lines
The bootcount file is only saved when
upgrade_availableis true, this allows to save writes to the filesystem.Signed-off-by Fr?d?ric Danis <[email protected]>--- drivers/bootcount/bootcount_ext.c | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-)drivers/bootcount/bootcount_ext.c +5
-1@@ -9,6 +9,8 @@#define BC_MAGIC 0xbc +static u8 upgrade_available =1 ; +void bootcount_store (ulong a) {u8 *buf;@@ -21,13 +23,18 @@ void bootcount_store(ulong a)return ; } - buf =map_sysmem (CONFIG_SYS_BOOTCOUNT_ADDR ,2 ); +/* Only update bootcount during upgrade process */ +if (!upgrade_available) +return ;drivers/bootcount/bootcount_ext.c void bootcount_store(ulong a) · line 37
Quoted 10 lines
drivers/bootcount/bootcount_ext.c +4
-1+ + buf =map_sysmem (CONFIG_SYS_BOOTCOUNT_ADDR ,3 ); buf[0 ] =BC_MAGIC ; buf[1 ] = (a &0xff ); + buf[2 ] = upgrade_available;unmap_sysmem (buf); ret =fs_write (CONFIG_SYS_BOOTCOUNT_EXT_NAME , -CONFIG_SYS_BOOTCOUNT_ADDR ,0 ,2 , &len); +CONFIG_SYS_BOOTCOUNT_ADDR ,0 ,3 , &len);Separate from this patch...to me it seems ugly to put this info in CONFIG. Could it not be structured as a driver, with device tree used to hold the information?
Quoted 5 lines
See for example fs_loader.txt
OK, I will try to send another patch for this ? but I don't know when
It looks like we already have chosen.txt which describes the device-tree binding. Perhaps it can fit into that?
Regards,
Simon