Skip to contentSkip to conversation

: drivers: bootcount: Add support for FAT filesystem

PATCH Superseded Vasileios Amoiridis 4 participants 14 messages Jun 10, 2024 – Jun 11, 2024

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v2 cover : drivers: bootcount: Add support for FAT filesystem

Changes in v2:
- Use generic code by utilizing FS_TYPE_ANY
- Change filename from bootcount_ext.c to bootcount_fs.c

v1: https://lore.kernel.org/u-boot/[email protected]/

This patch adds support to save the bootcount variable in a file located in FAT filesystem. Up to now, there was support only for EXT filesystem.

The reason I put this as RFC is because the file "bootcount_ext.c" will no longer represent the implementation for the EXT filesystem, but also for the FAT filesystem. Should it be renamed? If not, wouldn't it be inconsistent?

Cheers,
Vasilis

P.S: Documentation has not been modified yet, I will submit in the v2 (if any).

Vasileios Amoiridis (1):
drivers: bootcount: Add support for FAT filesystem

 doc/README.bootcount                          | 12 ++---
 drivers/bootcount/Kconfig                     | 53 +++++++++++++------
 drivers/bootcount/Makefile                    |  2 +-
 .../{bootcount_ext.c => bootcount_fs.c}       | 12 ++---
 4 files changed, 50 insertions(+), 29 deletions(-)
 rename drivers/bootcount/{bootcount_ext.c => bootcount_fs.c} (81%)
Signature · 1 line
2.25.1
#1 lore raw

PATCH v2 1/1 drivers: bootcount: Add support for FAT filesystem

Add support to save boot count variable in a file in a FAT filesystem.

---
 doc/README.bootcount                          | 12 ++---
 drivers/bootcount/Kconfig                     | 53 +++++++++++++------
 drivers/bootcount/Makefile                    |  2 +-
 .../{bootcount_ext.c => bootcount_fs.c}       | 12 ++---
 4 files changed, 50 insertions(+), 29 deletions(-)
 rename drivers/bootcount/{bootcount_ext.c => bootcount_fs.c} (81%)
doc/README.bootcount +6 -6
index f6c5f82f..0f4ffb68 100644
@@ -23,15 +23,15 @@ It is the responsibility of some application code (typically a Linux
 application) to reset the variable "bootcount" to 0 when the system booted
 successfully, thus allowing for more boot cycles.
 
-CONFIG_BOOTCOUNT_EXT
+CONFIG_BOOTCOUNT_FS
 --------------------
 
-This adds support for maintaining boot count in a file on an EXT filesystem.
-The file to use is defined by:
+This adds support for maintaining boot count in a file on a filesystem.
+Supported filesystems are FAT and EXT. The file to use is defined by:
 
-CONFIG_SYS_BOOTCOUNT_EXT_INTERFACE
-CONFIG_SYS_BOOTCOUNT_EXT_DEVPART
-CONFIG_SYS_BOOTCOUNT_EXT_NAME
+CONFIG_SYS_BOOTCOUNT_FS_INTERFACE
+CONFIG_SYS_BOOTCOUNT_FS_DEVPART
+CONFIG_SYS_BOOTCOUNT_FS_NAME
 
 The format of the file is:
 
drivers/bootcount/Kconfig +37 -16

91 lines not on this page · raw message

drivers/bootcount/Makefile +1 -1
index e7771f5b..245f8796 100644
@@ -6,7 +6,7 @@ obj-$(CONFIG_BOOTCOUNT_AT91)	+= bootcount_at91.o
 obj-$(CONFIG_BOOTCOUNT_AM33XX)	+= bootcount_davinci.o
 obj-$(CONFIG_BOOTCOUNT_RAM)	+= bootcount_ram.o
 obj-$(CONFIG_BOOTCOUNT_ENV)	+= bootcount_env.o
-obj-$(CONFIG_BOOTCOUNT_EXT)	+= bootcount_ext.o
+obj-$(CONFIG_BOOTCOUNT_FS)	+= bootcount_fs.o
 obj-$(CONFIG_BOOTCOUNT_AM33XX_NVMEM)	+= bootcount_nvmem.o
 
 obj-$(CONFIG_DM_BOOTCOUNT)      += bootcount-uclass.o
drivers/bootcount/bootcount_fs.c renamed from drivers/bootcount/bootcount_ext.c +6 -6
similarity index 81%
rename from drivers/bootcount/bootcount_ext.c
rename to drivers/bootcount/bootcount_fs.c
index 9639e638..569592d8 100644
@@ -25,8 +25,8 @@ void bootcount_store(ulong a)
 	loff_t len;
 	int ret;
 
-	if (fs_set_blk_dev(CONFIG_SYS_BOOTCOUNT_EXT_INTERFACE,
-			   CONFIG_SYS_BOOTCOUNT_EXT_DEVPART, FS_TYPE_EXT)) {
+	if (fs_set_blk_dev(CONFIG_SYS_BOOTCOUNT_FS_INTERFACE,
+			   CONFIG_SYS_BOOTCOUNT_FS_DEVPART, FS_TYPE_ANY)) {
 		puts("Error selecting device\n");
 		return;
 	}
@@ -42,7 +42,7 @@ void bootcount_store(ulong a)
 	buf->upgrade_available = upgrade_available;
 	unmap_sysmem(buf);
 
-	ret = fs_write(CONFIG_SYS_BOOTCOUNT_EXT_NAME,
+	ret = fs_write(CONFIG_SYS_BOOTCOUNT_FS_NAME,
 		       CONFIG_SYS_BOOTCOUNT_ADDR, 0, sizeof(bootcount_ext_t),
 		       &len);
 	if (ret != 0)
@@ -55,13 +55,13 @@ ulong bootcount_load(void)
 	loff_t len_read;
 	int ret;
 
-	if (fs_set_blk_dev(CONFIG_SYS_BOOTCOUNT_EXT_INTERFACE,
-			   CONFIG_SYS_BOOTCOUNT_EXT_DEVPART, FS_TYPE_EXT)) {
+	if (fs_set_blk_dev(CONFIG_SYS_BOOTCOUNT_FS_INTERFACE,
+			   CONFIG_SYS_BOOTCOUNT_FS_DEVPART, FS_TYPE_ANY)) {
 		puts("Error selecting device\n");
 		return 0;
 	}
 
-	ret = fs_read(CONFIG_SYS_BOOTCOUNT_EXT_NAME, CONFIG_SYS_BOOTCOUNT_ADDR,
+	ret = fs_read(CONFIG_SYS_BOOTCOUNT_FS_NAME, CONFIG_SYS_BOOTCOUNT_ADDR,
 		      0, sizeof(bootcount_ext_t), &len_read);
 	if (ret != 0 || len_read != sizeof(bootcount_ext_t)) {
 		puts("Error loading bootcount\n");
Signature · 1 line
2.25.1
Reviewed-by on v2 1/1
#2 lore raw

Re: [PATCH v2 1/1] drivers: bootcount: Add support for FAT filesystem

Quoted 3 lines · Vasileios Amoiridis

Add support to save boot count variable in a file in a FAT filesystem.

Thanks for doing this.

Would you be able to do a follow-up that converts doc/README.bootcount to rST as say doc/api/bootcount.rst ?

Signature · 1 line
Tom
#3 lore raw

Re: [PATCH v2 1/1] drivers: bootcount: Add support for FAT filesystem

Quoted 4 lines · Tom Rini
Quoted 2 lines · Vasileios Amoiridis

Add support to save boot count variable in a file in a FAT filesystem.

Quoted 11 lines
Quoted 1 line

Thanks for doing this.

Would you be able to do a follow-up that converts doc/README.bootcount to rST as say doc/api/bootcount.rst ?

Signature · 1 line
Tom

Hi Tom,

Yes I could do that. I will send a follow-up with the change that you propose.

Cheers,
Vasilis

#4 lore raw

Re: [PATCH v2 1/1] drivers: bootcount: Add support for FAT filesystem

Quoted 14 lines · Vasileios Amoiridis
Quoted 13 lines · Tom Rini
Quoted 3 lines · Vasileios Amoiridis

Add support to save boot count variable in a file in a FAT filesystem.

Thanks for doing this.

Would you be able to do a follow-up that converts doc/README.bootcount to rST as say doc/api/bootcount.rst ?

Quoted 6 lines
Quoted 2 lines
Signature · 1 line
Tom

Hi Tom,

Yes I could do that. I will send a follow-up with the change that you propose.

Great, thanks!

Signature · 1 line
Tom
Reviewed-by on v2 1/1
#5 lore raw

Re: [PATCH v2 1/1] drivers: bootcount: Add support for FAT filesystem

In reply to Vasileios Amoiridis

Hello Amoiridis,

Quoted 10 lines · Vasileios Amoiridis

Add support to save boot count variable in a file in a FAT filesystem.

---
  doc/README.bootcount                          | 12 ++---
  drivers/bootcount/Kconfig                     | 53 +++++++++++++------
  drivers/bootcount/Makefile                    |  2 +-
  .../{bootcount_ext.c => bootcount_fs.c}       | 12 ++---
  4 files changed, 50 insertions(+), 29 deletions(-)

rename drivers/bootcount/{bootcount_ext.c => bootcount_fs.c} (81%)

Thanks!

bye,
Heiko

Signature · 3 lines
DENX Software Engineering GmbH,      Managing Director: Erika Unter
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-52   Fax: +49-8142-66989-80   Email: [email protected]
#6 lore raw

Re: [PATCH v2 1/1] drivers: bootcount: Add support for FAT filesystem

In reply to Vasileios Amoiridis

Hi Vasileios,

Quoted 42 lines · Vasileios Amoiridis

Add support to save boot count variable in a file in a FAT filesystem.

---
  doc/README.bootcount                          | 12 ++---
  drivers/bootcount/Kconfig                     | 53 +++++++++++++------
  drivers/bootcount/Makefile                    |  2 +-
  .../{bootcount_ext.c => bootcount_fs.c}       | 12 ++---
  4 files changed, 50 insertions(+), 29 deletions(-)

rename drivers/bootcount/{bootcount_ext.c => bootcount_fs.c} (81%)

doc/README.bootcount +6 -6
index f6c5f82f..0f4ffb68 100644
@@ -23,15 +23,15 @@ It is the responsibility of some application code (typically a Linux
  application) to reset the variable "bootcount" to 0 when the system booted
  successfully, thus allowing for more boot cycles.
 
-CONFIG_BOOTCOUNT_EXT
+CONFIG_BOOTCOUNT_FS
  --------------------
 
-This adds support for maintaining boot count in a file on an EXT filesystem.
-The file to use is defined by:
+This adds support for maintaining boot count in a file on a filesystem.
+Supported filesystems are FAT and EXT. The file to use is defined by:
 
-CONFIG_SYS_BOOTCOUNT_EXT_INTERFACE
-CONFIG_SYS_BOOTCOUNT_EXT_DEVPART
-CONFIG_SYS_BOOTCOUNT_EXT_NAME
+CONFIG_SYS_BOOTCOUNT_FS_INTERFACE
+CONFIG_SYS_BOOTCOUNT_FS_DEVPART
+CONFIG_SYS_BOOTCOUNT_FS_NAME
 
  The format of the file is:
 
drivers/bootcount/Kconfig +0 -0
index 3c56253b..d3679eb5 100644

drivers/bootcount/Kconfig config BOOTCOUNT_GENERIC · line 30

Quoted 10 lines
drivers/bootcount/Kconfig +3 -4
@@ -25,10 +25,9 @@ config BOOTCOUNT_GENERIC
  	    Set to the address where the bootcount and bootcount magic
  	    will be stored.
 
-config BOOTCOUNT_EXT
-	bool "Boot counter on EXT filesystem"
-	depends on FS_EXT4
-	select EXT4_WRITE
+config BOOTCOUNT_FS
+	bool "Boot counter on a filesystem"
+	depends on FS_EXT4 || FS_FAT

Do we really need this 'depends on' here? Especially if we have a choice below...

drivers/bootcount/Kconfig config BOOTCOUNT_GENERIC · line 32

Quoted 2 lines
drivers/bootcount/Kconfig +0 -0
  	help
  	  Add support for maintaining boot count in a file on an EXT

The help text is still mentioning EXT here.

I would recommend removing it, or listing the supported filesystems at the moment. While I assume you tested with FAT, I assume that with FS_ANY, any FS should be supported?

Quoted 19 lines
drivers/bootcount/Kconfig +12 -2
  	  filesystem.
@@ -184,26 +183,48 @@ config SYS_BOOTCOUNT_SINGLEWORD
  	  This option enables packing boot count magic value and boot count
  	  into single word (32 bits).
 
-config SYS_BOOTCOUNT_EXT_INTERFACE
-	string "Interface on which to find boot counter EXT filesystem"
+if BOOTCOUNT_FS
+choice
+	prompt "Filesystem type"
+	default BOOTCOUNT_EXT
+
+config BOOTCOUNT_EXT
+	bool "Boot counter on EXT filesystem"
+	depends on FS_EXT4
+	select EXT4_WRITE
+	help
+	  Add support for maintaing boot counter in a file on EXT filesystem"
+

drivers/bootcount/Kconfig config SYS_BOOTCOUNT_SINGLEWORD · line 207

Quoted 10 lines
drivers/bootcount/Kconfig +10 -0
+config BOOTCOUNT_FAT
+	bool "Boot counter on FAT filesystem"
+	depends on FS_FAT
+	select FAT_WRITE
+	help
+	  Add support for maintaing boot counter in a file on FAT filesystem"
+
+endchoice
+endif
+

Since we now support FS_ANY, do we really need this choice at all?

Alternatively, should it **really** be a choice and not just a bunch of configs that depends on BOOTCOUNT_FS + whatever's needed to write on that FS instead? I think we could have both BOOTCOUNT_EXT and BOOTCOUNT_FAT set without issue?

Cheers,
Quentin

#7 lore raw

Re: [PATCH v2 1/1] drivers: bootcount: Add support for FAT filesystem

Quoted 51 lines · Quentin Schulz

Hi Vasileios,

doc/README.bootcount It is the responsibility of some application code

Quoted 16 lines · Vasileios Amoiridis

Add support to save boot count variable in a file in a FAT filesystem.

---
  doc/README.bootcount                          | 12 ++---
  drivers/bootcount/Kconfig                     | 53 +++++++++++++------
  drivers/bootcount/Makefile                    |  2 +-
  .../{bootcount_ext.c => bootcount_fs.c}       | 12 ++---
  4 files changed, 50 insertions(+), 29 deletions(-)

rename drivers/bootcount/{bootcount_ext.c => bootcount_fs.c} (81%)

doc/README.bootcount +0 -0
index f6c5f82f..0f4ffb68 100644
@@ -23,15 +23,15 @@ It is the responsibility of some application code

(typically a Linux

doc/README.bootcount It is the responsibility of some application code · line 23

Quoted 1 line
doc/README.bootcount +0 -0
  application) to reset the variable "bootcount" to 0 when the system

booted

doc/README.bootcount It is the responsibility of some application code (typically a Linux

Quoted 7 lines
doc/README.bootcount +1 -2
  successfully, thus allowing for more boot cycles.
 
-CONFIG_BOOTCOUNT_EXT
+CONFIG_BOOTCOUNT_FS
  --------------------
 
-This adds support for maintaining boot count in a file on an EXT

filesystem.

Quoted 21 lines
doc/README.bootcount +5 -4
-The file to use is defined by:
+This adds support for maintaining boot count in a file on a filesystem.
+Supported filesystems are FAT and EXT. The file to use is defined by:
 
-CONFIG_SYS_BOOTCOUNT_EXT_INTERFACE
-CONFIG_SYS_BOOTCOUNT_EXT_DEVPART
-CONFIG_SYS_BOOTCOUNT_EXT_NAME
+CONFIG_SYS_BOOTCOUNT_FS_INTERFACE
+CONFIG_SYS_BOOTCOUNT_FS_DEVPART
+CONFIG_SYS_BOOTCOUNT_FS_NAME
 
  The format of the file is:
 
drivers/bootcount/Kconfig +0 -0
index 3c56253b..d3679eb5 100644
@@ -25,10 +25,9 @@ config BOOTCOUNT_GENERIC
  	    Set to the address where the bootcount and bootcount magic
  	    will be stored.
 
Quoted 10 lines

drivers/bootcount/Kconfig config BOOTCOUNT_GENERIC · line 30

Quoted 7 lines
drivers/bootcount/Kconfig +3 -4
-config BOOTCOUNT_EXT
-	bool "Boot counter on EXT filesystem"
-	depends on FS_EXT4
-	select EXT4_WRITE
+config BOOTCOUNT_FS
+	bool "Boot counter on a filesystem"
+	depends on FS_EXT4 || FS_FAT

Do we really need this 'depends on' here? Especially if we have a choice below...

Well, probably this is redundant indeed.

Quoted 4 lines

drivers/bootcount/Kconfig config BOOTCOUNT_GENERIC · line 32

Quoted 2 lines
drivers/bootcount/Kconfig +0 -0
  	help
  	  Add support for maintaining boot count in a file on an EXT

The help text is still mentioning EXT here.

Ahh, I missed that.

Quoted 4 lines

I would recommend removing it, or listing the supported filesystems at the moment. While I assume you tested with FAT, I assume that with FS_ANY, any FS should be supported?

Well, I tested it with both FAT and EXT4 and it works. AFAIU, due to the implementation of the filesystem handling code in U-Boot, if the fs supports a write a function, then it should work. But I cannot test for other filesystems apart from FAT and EXT4 so I think it's better to limit the option to these two.

Quoted 31 lines
Quoted 19 lines
drivers/bootcount/Kconfig +12 -2
  	  filesystem.
@@ -184,26 +183,48 @@ config SYS_BOOTCOUNT_SINGLEWORD
  	  This option enables packing boot count magic value and boot count
  	  into single word (32 bits).
 
-config SYS_BOOTCOUNT_EXT_INTERFACE
-	string "Interface on which to find boot counter EXT filesystem"
+if BOOTCOUNT_FS
+choice
+	prompt "Filesystem type"
+	default BOOTCOUNT_EXT
+
+config BOOTCOUNT_EXT
+	bool "Boot counter on EXT filesystem"
+	depends on FS_EXT4
+	select EXT4_WRITE
+	help
+	  Add support for maintaing boot counter in a file on EXT filesystem"
+

drivers/bootcount/Kconfig config SYS_BOOTCOUNT_SINGLEWORD · line 207

Quoted 10 lines
drivers/bootcount/Kconfig +10 -0
+config BOOTCOUNT_FAT
+	bool "Boot counter on FAT filesystem"
+	depends on FS_FAT
+	select FAT_WRITE
+	help
+	  Add support for maintaing boot counter in a file on FAT filesystem"
+
+endchoice
+endif
+

Since we now support FS_ANY, do we really need this choice at all?

Quoted 7 lines

Alternatively, should it **really** be a choice and not just a bunch of configs that depends on BOOTCOUNT_FS + whatever's needed to write on that FS instead? I think we could have both BOOTCOUNT_EXT and BOOTCOUNT_FAT set without issue?

Cheers,
Quentin

Well, I think I kind of get the point but I am still a bit confused. Do you mean that basically the configuration should be done the other way around? Instead of choosing BOOTCOUNT_FS and then specifically to choose EXT or FAT, to choose one of EXT/FAT and then to select BOOTCOUNT_FS? If yes, what is the advantage of this approach?

Cheers,
Vasilis

#8 lore raw

Re: [PATCH v2 1/1] drivers: bootcount: Add support for FAT filesystem

Hi Vasileios,

Quoted 76 lines · Vasileios Amoiridis
Quoted 51 lines · Quentin Schulz

Hi Vasileios,

doc/README.bootcount It is the responsibility of some application code

Quoted 16 lines · Vasileios Amoiridis

Add support to save boot count variable in a file in a FAT filesystem.

---
   doc/README.bootcount                          | 12 ++---
   drivers/bootcount/Kconfig                     | 53 +++++++++++++------
   drivers/bootcount/Makefile                    |  2 +-
   .../{bootcount_ext.c => bootcount_fs.c}       | 12 ++---
   4 files changed, 50 insertions(+), 29 deletions(-)

rename drivers/bootcount/{bootcount_ext.c => bootcount_fs.c} (81%)

doc/README.bootcount +0 -0
index f6c5f82f..0f4ffb68 100644
@@ -23,15 +23,15 @@ It is the responsibility of some application code

(typically a Linux

doc/README.bootcount It is the responsibility of some application code · line 23

Quoted 1 line
doc/README.bootcount +0 -0
   application) to reset the variable "bootcount" to 0 when the system

booted

doc/README.bootcount It is the responsibility of some application code (typically a Linux

Quoted 7 lines
doc/README.bootcount +1 -2
   successfully, thus allowing for more boot cycles.
 
-CONFIG_BOOTCOUNT_EXT
+CONFIG_BOOTCOUNT_FS
   --------------------
 
-This adds support for maintaining boot count in a file on an EXT

filesystem.

Quoted 21 lines
doc/README.bootcount +5 -4
-The file to use is defined by:
+This adds support for maintaining boot count in a file on a filesystem.
+Supported filesystems are FAT and EXT. The file to use is defined by:
 
-CONFIG_SYS_BOOTCOUNT_EXT_INTERFACE
-CONFIG_SYS_BOOTCOUNT_EXT_DEVPART
-CONFIG_SYS_BOOTCOUNT_EXT_NAME
+CONFIG_SYS_BOOTCOUNT_FS_INTERFACE
+CONFIG_SYS_BOOTCOUNT_FS_DEVPART
+CONFIG_SYS_BOOTCOUNT_FS_NAME
 
   The format of the file is:
 
drivers/bootcount/Kconfig +0 -0
index 3c56253b..d3679eb5 100644
@@ -25,10 +25,9 @@ config BOOTCOUNT_GENERIC
   	    Set to the address where the bootcount and bootcount magic
   	    will be stored.
 
Quoted 10 lines

drivers/bootcount/Kconfig config BOOTCOUNT_GENERIC · line 30

Quoted 7 lines
drivers/bootcount/Kconfig +3 -4
-config BOOTCOUNT_EXT
-	bool "Boot counter on EXT filesystem"
-	depends on FS_EXT4
-	select EXT4_WRITE
+config BOOTCOUNT_FS
+	bool "Boot counter on a filesystem"
+	depends on FS_EXT4 || FS_FAT

Do we really need this 'depends on' here? Especially if we have a choice below...

Well, probably this is redundant indeed.

Quoted 4 lines

drivers/bootcount/Kconfig config BOOTCOUNT_GENERIC · line 32

Quoted 2 lines
drivers/bootcount/Kconfig +0 -0
   	help
   	  Add support for maintaining boot count in a file on an EXT

The help text is still mentioning EXT here.

Ahh, I missed that.

Quoted 4 lines

I would recommend removing it, or listing the supported filesystems at the moment. While I assume you tested with FAT, I assume that with FS_ANY, any FS should be supported?

Quoted 6 lines

Well, I tested it with both FAT and EXT4 and it works. AFAIU, due to the implementation of the filesystem handling code in U-Boot, if the fs supports a write a function, then it should work. But I cannot test for other filesystems apart from FAT and EXT4 so I think it's better to limit the option to these two.

I guess we can let people figure things out themselves and add new options for when they have tested them, no strong opinion here.

Quoted 18 lines
Quoted 18 lines
Quoted 18 lines
drivers/bootcount/Kconfig +11 -2
   	  filesystem.
@@ -184,26 +183,48 @@ config SYS_BOOTCOUNT_SINGLEWORD
   	  This option enables packing boot count magic value and boot count
   	  into single word (32 bits).
 
-config SYS_BOOTCOUNT_EXT_INTERFACE
-	string "Interface on which to find boot counter EXT filesystem"
+if BOOTCOUNT_FS
+choice
+	prompt "Filesystem type"
+	default BOOTCOUNT_EXT
+
+config BOOTCOUNT_EXT
+	bool "Boot counter on EXT filesystem"
+	depends on FS_EXT4
+	select EXT4_WRITE
+	help
+	  Add support for maintaing boot counter in a file on EXT filesystem"
Quoted 8 lines
Quoted 8 lines

drivers/bootcount/Kconfig config SYS_BOOTCOUNT_SINGLEWORD · line 204

Quoted 8 lines
drivers/bootcount/Kconfig +8 -0
+
+config BOOTCOUNT_FAT
+	bool "Boot counter on FAT filesystem"
+	depends on FS_FAT
+	select FAT_WRITE
+	help
+	  Add support for maintaing boot counter in a file on FAT filesystem"
+

Seems like I missed a typo here as well:

s/maintaing/maintaining/ ? At least that's what we have in doc/README.bootcount

Quoted 10 lines
Quoted 10 lines

drivers/bootcount/Kconfig config SYS_BOOTCOUNT_SINGLEWORD · line 207

Quoted 3 lines
drivers/bootcount/Kconfig +3 -0
+endchoice
+endif
+

Since we now support FS_ANY, do we really need this choice at all?

Alternatively, should it **really** be a choice and not just a bunch of configs that depends on BOOTCOUNT_FS + whatever's needed to write on that FS instead? I think we could have both BOOTCOUNT_EXT and BOOTCOUNT_FAT set without issue?

Quoted 9 lines
Quoted 2 lines

Cheers,
Quentin

Well, I think I kind of get the point but I am still a bit confused. Do you mean that basically the configuration should be done the other way around? Instead of choosing BOOTCOUNT_FS and then specifically to choose EXT or FAT, to choose one of EXT/FAT and then to select BOOTCOUNT_FS? If yes, what is the advantage of this approach?

I'm suggesting:

"""
config BOOTCOUNT_FS
bool "Boot counter on a filesystem"
help

config BOOTCOUNT_EXT
bool "Boot counter on EXT filesystem"
default y
depends on BOOTCOUNT_FS
depends on FS_EXT4
select EXT4_WRITE
help
Add support for maintaing boot counter in a file on EXT filesystem"

config BOOTCOUNT_FAT
bool "Boot counter on FAT filesystem"
depends on BOOTCOUNT_FS
depends on FS_FAT
select FAT_WRITE
help
Add support for maintaing boot counter in a file on FAT filesystem"
"""

This way we can have defconfigs where BOOTCOUNT_FAT and BOOTCOUNT_EXT are both selected, the user would then be free to decide if the same partition on two different devices but for the same purpose can be either ext2/3/4 or FAT, without recompiling U-Boot just for that.

However, it would now be possible to have BOOTCOUNT_FS=y but neither BOOTCOUNT_EXT nor BOOTCOUNT_FAT set to y (e.g. if FS_EXT4 or FS_FAT isn't defined).

Finally, the other option was just to NOT have BOOTCOUNT_FAT or BOOTCOUNT_EXT and let people select FS_EXT4/FS_FAT and EXT4_WRITE/FAT_WRITE themselves since the BOOTCOUNT_FAT/EXT aren't actually used in C code. This is less user-friendly though.

Cheers,
Quentin

#9 lore raw

Re: [PATCH v2 1/1] drivers: bootcount: Add support for FAT filesystem

Quoted 171 lines · Quentin Schulz

Hi Vasileios,

Quoted 76 lines · Vasileios Amoiridis
Quoted 51 lines · Quentin Schulz

Hi Vasileios,

doc/README.bootcount It is the responsibility of some application code

Quoted 16 lines · Vasileios Amoiridis

Add support to save boot count variable in a file in a FAT filesystem.

---
   doc/README.bootcount                          | 12 ++---
   drivers/bootcount/Kconfig                     | 53 +++++++++++++------
   drivers/bootcount/Makefile                    |  2 +-
   .../{bootcount_ext.c => bootcount_fs.c}       | 12 ++---
   4 files changed, 50 insertions(+), 29 deletions(-)

rename drivers/bootcount/{bootcount_ext.c => bootcount_fs.c} (81%)

doc/README.bootcount +0 -0
index f6c5f82f..0f4ffb68 100644
@@ -23,15 +23,15 @@ It is the responsibility of some application code

(typically a Linux

doc/README.bootcount It is the responsibility of some application code · line 23

Quoted 1 line
doc/README.bootcount +0 -0
   application) to reset the variable "bootcount" to 0 when the system

booted

doc/README.bootcount It is the responsibility of some application code (typically a Linux

Quoted 7 lines
doc/README.bootcount +1 -2
   successfully, thus allowing for more boot cycles.
 
-CONFIG_BOOTCOUNT_EXT
+CONFIG_BOOTCOUNT_FS
   --------------------
 
-This adds support for maintaining boot count in a file on an EXT

filesystem.

Quoted 21 lines
doc/README.bootcount +5 -4
-The file to use is defined by:
+This adds support for maintaining boot count in a file on a filesystem.
+Supported filesystems are FAT and EXT. The file to use is defined by:
 
-CONFIG_SYS_BOOTCOUNT_EXT_INTERFACE
-CONFIG_SYS_BOOTCOUNT_EXT_DEVPART
-CONFIG_SYS_BOOTCOUNT_EXT_NAME
+CONFIG_SYS_BOOTCOUNT_FS_INTERFACE
+CONFIG_SYS_BOOTCOUNT_FS_DEVPART
+CONFIG_SYS_BOOTCOUNT_FS_NAME
 
   The format of the file is:
 
drivers/bootcount/Kconfig +0 -0
index 3c56253b..d3679eb5 100644
@@ -25,10 +25,9 @@ config BOOTCOUNT_GENERIC
   	    Set to the address where the bootcount and bootcount magic
   	    will be stored.
 
Quoted 10 lines

drivers/bootcount/Kconfig config BOOTCOUNT_GENERIC · line 30

Quoted 7 lines
drivers/bootcount/Kconfig +3 -4
-config BOOTCOUNT_EXT
-	bool "Boot counter on EXT filesystem"
-	depends on FS_EXT4
-	select EXT4_WRITE
+config BOOTCOUNT_FS
+	bool "Boot counter on a filesystem"
+	depends on FS_EXT4 || FS_FAT

Do we really need this 'depends on' here? Especially if we have a choice below...

Well, probably this is redundant indeed.

Quoted 4 lines

drivers/bootcount/Kconfig config BOOTCOUNT_GENERIC · line 32

Quoted 2 lines
drivers/bootcount/Kconfig +0 -0
   	help
   	  Add support for maintaining boot count in a file on an EXT

The help text is still mentioning EXT here.

Ahh, I missed that.

Quoted 4 lines

I would recommend removing it, or listing the supported filesystems at the moment. While I assume you tested with FAT, I assume that with FS_ANY, any FS should be supported?

Quoted 6 lines

Well, I tested it with both FAT and EXT4 and it works. AFAIU, due to the implementation of the filesystem handling code in U-Boot, if the fs supports a write a function, then it should work. But I cannot test for other filesystems apart from FAT and EXT4 so I think it's better to limit the option to these two.

I guess we can let people figure things out themselves and add new options for when they have tested them, no strong opinion here.

Quoted 18 lines
Quoted 18 lines
Quoted 18 lines
drivers/bootcount/Kconfig +11 -2
   	  filesystem.
@@ -184,26 +183,48 @@ config SYS_BOOTCOUNT_SINGLEWORD
   	  This option enables packing boot count magic value and boot count
   	  into single word (32 bits).
 
-config SYS_BOOTCOUNT_EXT_INTERFACE
-	string "Interface on which to find boot counter EXT filesystem"
+if BOOTCOUNT_FS
+choice
+	prompt "Filesystem type"
+	default BOOTCOUNT_EXT
+
+config BOOTCOUNT_EXT
+	bool "Boot counter on EXT filesystem"
+	depends on FS_EXT4
+	select EXT4_WRITE
+	help
+	  Add support for maintaing boot counter in a file on EXT filesystem"
Quoted 8 lines
Quoted 8 lines

drivers/bootcount/Kconfig config SYS_BOOTCOUNT_SINGLEWORD · line 204

Quoted 8 lines
drivers/bootcount/Kconfig +8 -0
+
+config BOOTCOUNT_FAT
+	bool "Boot counter on FAT filesystem"
+	depends on FS_FAT
+	select FAT_WRITE
+	help
+	  Add support for maintaing boot counter in a file on FAT filesystem"
+

Seems like I missed a typo here as well:

s/maintaing/maintaining/ ? At least that's what we have in doc/README.bootcount

Quoted 10 lines
Quoted 10 lines

drivers/bootcount/Kconfig config SYS_BOOTCOUNT_SINGLEWORD · line 207

Quoted 3 lines
drivers/bootcount/Kconfig +3 -0
+endchoice
+endif
+

Since we now support FS_ANY, do we really need this choice at all?

Alternatively, should it **really** be a choice and not just a bunch of configs that depends on BOOTCOUNT_FS + whatever's needed to write on that FS instead? I think we could have both BOOTCOUNT_EXT and BOOTCOUNT_FAT set without issue?

Quoted 9 lines
Quoted 2 lines

Cheers,
Quentin

Well, I think I kind of get the point but I am still a bit confused. Do you mean that basically the configuration should be done the other way around? Instead of choosing BOOTCOUNT_FS and then specifically to choose EXT or FAT, to choose one of EXT/FAT and then to select BOOTCOUNT_FS? If yes, what is the advantage of this approach?

I'm suggesting:

"""
config BOOTCOUNT_FS
bool "Boot counter on a filesystem"
help

config BOOTCOUNT_EXT
bool "Boot counter on EXT filesystem"
default y
depends on BOOTCOUNT_FS
depends on FS_EXT4
select EXT4_WRITE
help
Add support for maintaing boot counter in a file on EXT filesystem"

config BOOTCOUNT_FAT
bool "Boot counter on FAT filesystem"
depends on BOOTCOUNT_FS
depends on FS_FAT
select FAT_WRITE
help
Add support for maintaing boot counter in a file on FAT filesystem"
"""

This way we can have defconfigs where BOOTCOUNT_FAT and BOOTCOUNT_EXT are both selected, the user would then be free to decide if the same partition on two different devices but for the same purpose can be either ext2/3/4 or FAT, without recompiling U-Boot just for that.

Quoted 8 lines

However, it would now be possible to have BOOTCOUNT_FS=y but neither BOOTCOUNT_EXT nor BOOTCOUNT_FAT set to y (e.g. if FS_EXT4 or FS_FAT isn't defined).

Finally, the other option was just to NOT have BOOTCOUNT_FAT or BOOTCOUNT_EXT and let people select FS_EXT4/FS_FAT and EXT4_WRITE/FAT_WRITE themselves since the BOOTCOUNT_FAT/EXT aren't actually used in C code. This is less user-friendly though.

I was thinking that with FS_ANY, we don't need a symbol per filesystem type but can just handle it in the help text with something like "Please ensure that you have enabled write support for the filesystem that you will be used by the partition that you configure this feature for."

Signature · 1 line
Tom
#10 lore raw

Re: [PATCH v2 1/1] drivers: bootcount: Add support for FAT filesystem

Quoted 181 lines · Tom Rini
Quoted 171 lines · Quentin Schulz

Hi Vasileios,

Quoted 76 lines · Vasileios Amoiridis
Quoted 51 lines · Quentin Schulz

Hi Vasileios,

doc/README.bootcount It is the responsibility of some application code

Quoted 16 lines · Vasileios Amoiridis

Add support to save boot count variable in a file in a FAT filesystem.

---
   doc/README.bootcount                          | 12 ++---
   drivers/bootcount/Kconfig                     | 53 +++++++++++++------
   drivers/bootcount/Makefile                    |  2 +-
   .../{bootcount_ext.c => bootcount_fs.c}       | 12 ++---
   4 files changed, 50 insertions(+), 29 deletions(-)

rename drivers/bootcount/{bootcount_ext.c => bootcount_fs.c} (81%)

doc/README.bootcount +0 -0
index f6c5f82f..0f4ffb68 100644
@@ -23,15 +23,15 @@ It is the responsibility of some application code

(typically a Linux

doc/README.bootcount It is the responsibility of some application code · line 23

Quoted 1 line
doc/README.bootcount +0 -0
   application) to reset the variable "bootcount" to 0 when the system

booted

doc/README.bootcount It is the responsibility of some application code (typically a Linux

Quoted 7 lines
doc/README.bootcount +1 -2
   successfully, thus allowing for more boot cycles.
 
-CONFIG_BOOTCOUNT_EXT
+CONFIG_BOOTCOUNT_FS
   --------------------
 
-This adds support for maintaining boot count in a file on an EXT

filesystem.

Quoted 21 lines
doc/README.bootcount +5 -4
-The file to use is defined by:
+This adds support for maintaining boot count in a file on a filesystem.
+Supported filesystems are FAT and EXT. The file to use is defined by:
 
-CONFIG_SYS_BOOTCOUNT_EXT_INTERFACE
-CONFIG_SYS_BOOTCOUNT_EXT_DEVPART
-CONFIG_SYS_BOOTCOUNT_EXT_NAME
+CONFIG_SYS_BOOTCOUNT_FS_INTERFACE
+CONFIG_SYS_BOOTCOUNT_FS_DEVPART
+CONFIG_SYS_BOOTCOUNT_FS_NAME
 
   The format of the file is:
 
drivers/bootcount/Kconfig +0 -0
index 3c56253b..d3679eb5 100644
@@ -25,10 +25,9 @@ config BOOTCOUNT_GENERIC
   	    Set to the address where the bootcount and bootcount magic
   	    will be stored.
 
Quoted 10 lines

drivers/bootcount/Kconfig config BOOTCOUNT_GENERIC · line 30

Quoted 7 lines
drivers/bootcount/Kconfig +3 -4
-config BOOTCOUNT_EXT
-	bool "Boot counter on EXT filesystem"
-	depends on FS_EXT4
-	select EXT4_WRITE
+config BOOTCOUNT_FS
+	bool "Boot counter on a filesystem"
+	depends on FS_EXT4 || FS_FAT

Do we really need this 'depends on' here? Especially if we have a choice below...

Well, probably this is redundant indeed.

Quoted 4 lines

drivers/bootcount/Kconfig config BOOTCOUNT_GENERIC · line 32

Quoted 2 lines
drivers/bootcount/Kconfig +0 -0
   	help
   	  Add support for maintaining boot count in a file on an EXT

The help text is still mentioning EXT here.

Ahh, I missed that.

Quoted 4 lines

I would recommend removing it, or listing the supported filesystems at the moment. While I assume you tested with FAT, I assume that with FS_ANY, any FS should be supported?

Quoted 6 lines

Well, I tested it with both FAT and EXT4 and it works. AFAIU, due to the implementation of the filesystem handling code in U-Boot, if the fs supports a write a function, then it should work. But I cannot test for other filesystems apart from FAT and EXT4 so I think it's better to limit the option to these two.

I guess we can let people figure things out themselves and add new options for when they have tested them, no strong opinion here.

Quoted 18 lines
Quoted 18 lines
Quoted 18 lines
drivers/bootcount/Kconfig +11 -2
   	  filesystem.
@@ -184,26 +183,48 @@ config SYS_BOOTCOUNT_SINGLEWORD
   	  This option enables packing boot count magic value and boot count
   	  into single word (32 bits).
 
-config SYS_BOOTCOUNT_EXT_INTERFACE
-	string "Interface on which to find boot counter EXT filesystem"
+if BOOTCOUNT_FS
+choice
+	prompt "Filesystem type"
+	default BOOTCOUNT_EXT
+
+config BOOTCOUNT_EXT
+	bool "Boot counter on EXT filesystem"
+	depends on FS_EXT4
+	select EXT4_WRITE
+	help
+	  Add support for maintaing boot counter in a file on EXT filesystem"
Quoted 8 lines
Quoted 8 lines

drivers/bootcount/Kconfig config SYS_BOOTCOUNT_SINGLEWORD · line 204

Quoted 8 lines
drivers/bootcount/Kconfig +8 -0
+
+config BOOTCOUNT_FAT
+	bool "Boot counter on FAT filesystem"
+	depends on FS_FAT
+	select FAT_WRITE
+	help
+	  Add support for maintaing boot counter in a file on FAT filesystem"
+

Seems like I missed a typo here as well:

s/maintaing/maintaining/ ? At least that's what we have in doc/README.bootcount

Quoted 10 lines
Quoted 10 lines

drivers/bootcount/Kconfig config SYS_BOOTCOUNT_SINGLEWORD · line 207

Quoted 3 lines
drivers/bootcount/Kconfig +3 -0
+endchoice
+endif
+

Since we now support FS_ANY, do we really need this choice at all?

Alternatively, should it **really** be a choice and not just a bunch of configs that depends on BOOTCOUNT_FS + whatever's needed to write on that FS instead? I think we could have both BOOTCOUNT_EXT and BOOTCOUNT_FAT set without issue?

Quoted 9 lines
Quoted 2 lines

Cheers,
Quentin

Well, I think I kind of get the point but I am still a bit confused. Do you mean that basically the configuration should be done the other way around? Instead of choosing BOOTCOUNT_FS and then specifically to choose EXT or FAT, to choose one of EXT/FAT and then to select BOOTCOUNT_FS? If yes, what is the advantage of this approach?

I'm suggesting:

"""
config BOOTCOUNT_FS
bool "Boot counter on a filesystem"
help

config BOOTCOUNT_EXT
bool "Boot counter on EXT filesystem"
default y
depends on BOOTCOUNT_FS
depends on FS_EXT4
select EXT4_WRITE
help
Add support for maintaing boot counter in a file on EXT filesystem"

config BOOTCOUNT_FAT
bool "Boot counter on FAT filesystem"
depends on BOOTCOUNT_FS
depends on FS_FAT
select FAT_WRITE
help
Add support for maintaing boot counter in a file on FAT filesystem"
"""

This way we can have defconfigs where BOOTCOUNT_FAT and BOOTCOUNT_EXT are both selected, the user would then be free to decide if the same partition on two different devices but for the same purpose can be either ext2/3/4 or FAT, without recompiling U-Boot just for that.

Quoted 8 lines

However, it would now be possible to have BOOTCOUNT_FS=y but neither BOOTCOUNT_EXT nor BOOTCOUNT_FAT set to y (e.g. if FS_EXT4 or FS_FAT isn't defined).

Finally, the other option was just to NOT have BOOTCOUNT_FAT or BOOTCOUNT_EXT and let people select FS_EXT4/FS_FAT and EXT4_WRITE/FAT_WRITE themselves since the BOOTCOUNT_FAT/EXT aren't actually used in C code. This is less user-friendly though.

Quoted 5 lines

I was thinking that with FS_ANY, we don't need a symbol per filesystem type but can just handle it in the help text with something like "Please ensure that you have enabled write support for the filesystem that you will be used by the partition that you configure this feature for."

Hi Tom,

I see that both you and Quentin are leaning towards this solution which is totally fine by me. As I said before, the user already needs to specify the device interface and the partition to be used so they can also be responsible to enable the appropriate filesystem write functionality. Indeed if more filesystems are added, it would be quite ugly to have multiple symbols just to choose a config.

Also, if the user forgets to enable the appropriate *_WRITE config, it will trigger an error message in U-Boot that this operation is not supported which will be pretty obvious what needs to be done.

So I can go with a v3, following your proposals.

Cheers,
Vasilis

Quoted 2 lines
Signature · 1 line
Tom
#11 lore raw

Re: [PATCH v2 1/1] drivers: bootcount: Add support for FAT filesystem

Hi Vasileios,

Quoted 188 lines · Vasileios Amoiridis
Quoted 181 lines · Tom Rini
Quoted 171 lines · Quentin Schulz

Hi Vasileios,

Quoted 76 lines · Vasileios Amoiridis
Quoted 51 lines · Quentin Schulz

Hi Vasileios,

doc/README.bootcount It is the responsibility of some application code

Quoted 16 lines · Vasileios Amoiridis

Add support to save boot count variable in a file in a FAT filesystem.

---
    doc/README.bootcount                          | 12 ++---
    drivers/bootcount/Kconfig                     | 53 +++++++++++++------
    drivers/bootcount/Makefile                    |  2 +-
    .../{bootcount_ext.c => bootcount_fs.c}       | 12 ++---
    4 files changed, 50 insertions(+), 29 deletions(-)

rename drivers/bootcount/{bootcount_ext.c => bootcount_fs.c} (81%)

doc/README.bootcount +0 -0
index f6c5f82f..0f4ffb68 100644
@@ -23,15 +23,15 @@ It is the responsibility of some application code

(typically a Linux

doc/README.bootcount It is the responsibility of some application code · line 23

Quoted 1 line
doc/README.bootcount +0 -0
    application) to reset the variable "bootcount" to 0 when the system

booted

doc/README.bootcount It is the responsibility of some application code (typically a Linux

Quoted 7 lines
doc/README.bootcount +1 -2
    successfully, thus allowing for more boot cycles.
 
-CONFIG_BOOTCOUNT_EXT
+CONFIG_BOOTCOUNT_FS
    --------------------
 
-This adds support for maintaining boot count in a file on an EXT

filesystem.

Quoted 21 lines
doc/README.bootcount +5 -4
-The file to use is defined by:
+This adds support for maintaining boot count in a file on a filesystem.
+Supported filesystems are FAT and EXT. The file to use is defined by:
 
-CONFIG_SYS_BOOTCOUNT_EXT_INTERFACE
-CONFIG_SYS_BOOTCOUNT_EXT_DEVPART
-CONFIG_SYS_BOOTCOUNT_EXT_NAME
+CONFIG_SYS_BOOTCOUNT_FS_INTERFACE
+CONFIG_SYS_BOOTCOUNT_FS_DEVPART
+CONFIG_SYS_BOOTCOUNT_FS_NAME
 
    The format of the file is:
 
drivers/bootcount/Kconfig +0 -0
index 3c56253b..d3679eb5 100644
@@ -25,10 +25,9 @@ config BOOTCOUNT_GENERIC
    	    Set to the address where the bootcount and bootcount magic
    	    will be stored.
 
Quoted 10 lines

drivers/bootcount/Kconfig config BOOTCOUNT_GENERIC · line 30

Quoted 7 lines
drivers/bootcount/Kconfig +3 -4
-config BOOTCOUNT_EXT
-	bool "Boot counter on EXT filesystem"
-	depends on FS_EXT4
-	select EXT4_WRITE
+config BOOTCOUNT_FS
+	bool "Boot counter on a filesystem"
+	depends on FS_EXT4 || FS_FAT

Do we really need this 'depends on' here? Especially if we have a choice below...

Well, probably this is redundant indeed.

Quoted 4 lines

drivers/bootcount/Kconfig config BOOTCOUNT_GENERIC · line 32

Quoted 2 lines
drivers/bootcount/Kconfig +0 -0
    	help
    	  Add support for maintaining boot count in a file on an EXT

The help text is still mentioning EXT here.

Ahh, I missed that.

Quoted 4 lines

I would recommend removing it, or listing the supported filesystems at the moment. While I assume you tested with FAT, I assume that with FS_ANY, any FS should be supported?

Quoted 6 lines

Well, I tested it with both FAT and EXT4 and it works. AFAIU, due to the implementation of the filesystem handling code in U-Boot, if the fs supports a write a function, then it should work. But I cannot test for other filesystems apart from FAT and EXT4 so I think it's better to limit the option to these two.

I guess we can let people figure things out themselves and add new options for when they have tested them, no strong opinion here.

Quoted 18 lines
Quoted 18 lines
Quoted 18 lines
drivers/bootcount/Kconfig +11 -2
    	  filesystem.
@@ -184,26 +183,48 @@ config SYS_BOOTCOUNT_SINGLEWORD
    	  This option enables packing boot count magic value and boot count
    	  into single word (32 bits).
 
-config SYS_BOOTCOUNT_EXT_INTERFACE
-	string "Interface on which to find boot counter EXT filesystem"
+if BOOTCOUNT_FS
+choice
+	prompt "Filesystem type"
+	default BOOTCOUNT_EXT
+
+config BOOTCOUNT_EXT
+	bool "Boot counter on EXT filesystem"
+	depends on FS_EXT4
+	select EXT4_WRITE
+	help
+	  Add support for maintaing boot counter in a file on EXT filesystem"
Quoted 8 lines
Quoted 8 lines

drivers/bootcount/Kconfig config SYS_BOOTCOUNT_SINGLEWORD · line 204

Quoted 8 lines
drivers/bootcount/Kconfig +8 -0
+
+config BOOTCOUNT_FAT
+	bool "Boot counter on FAT filesystem"
+	depends on FS_FAT
+	select FAT_WRITE
+	help
+	  Add support for maintaing boot counter in a file on FAT filesystem"
+

Seems like I missed a typo here as well:

s/maintaing/maintaining/ ? At least that's what we have in doc/README.bootcount

Quoted 10 lines
Quoted 10 lines

drivers/bootcount/Kconfig config SYS_BOOTCOUNT_SINGLEWORD · line 207

Quoted 3 lines
drivers/bootcount/Kconfig +3 -0
+endchoice
+endif
+

Since we now support FS_ANY, do we really need this choice at all?

Alternatively, should it **really** be a choice and not just a bunch of configs that depends on BOOTCOUNT_FS + whatever's needed to write on that FS instead? I think we could have both BOOTCOUNT_EXT and BOOTCOUNT_FAT set without issue?

Quoted 9 lines
Quoted 2 lines

Cheers,
Quentin

Well, I think I kind of get the point but I am still a bit confused. Do you mean that basically the configuration should be done the other way around? Instead of choosing BOOTCOUNT_FS and then specifically to choose EXT or FAT, to choose one of EXT/FAT and then to select BOOTCOUNT_FS? If yes, what is the advantage of this approach?

I'm suggesting:

"""
config BOOTCOUNT_FS
bool "Boot counter on a filesystem"
help

config BOOTCOUNT_EXT
bool "Boot counter on EXT filesystem"
default y
depends on BOOTCOUNT_FS
depends on FS_EXT4
select EXT4_WRITE
help
Add support for maintaing boot counter in a file on EXT filesystem"

config BOOTCOUNT_FAT
bool "Boot counter on FAT filesystem"
depends on BOOTCOUNT_FS
depends on FS_FAT
select FAT_WRITE
help
Add support for maintaing boot counter in a file on FAT filesystem"
"""

This way we can have defconfigs where BOOTCOUNT_FAT and BOOTCOUNT_EXT are both selected, the user would then be free to decide if the same partition on two different devices but for the same purpose can be either ext2/3/4 or FAT, without recompiling U-Boot just for that.

Quoted 8 lines

However, it would now be possible to have BOOTCOUNT_FS=y but neither BOOTCOUNT_EXT nor BOOTCOUNT_FAT set to y (e.g. if FS_EXT4 or FS_FAT isn't defined).

Finally, the other option was just to NOT have BOOTCOUNT_FAT or BOOTCOUNT_EXT and let people select FS_EXT4/FS_FAT and EXT4_WRITE/FAT_WRITE themselves since the BOOTCOUNT_FAT/EXT aren't actually used in C code. This is less user-friendly though.

Quoted 5 lines

I was thinking that with FS_ANY, we don't need a symbol per filesystem type but can just handle it in the help text with something like "Please ensure that you have enabled write support for the filesystem that you will be used by the partition that you configure this feature for."

Quoted 9 lines

Hi Tom,

I see that both you and Quentin are leaning towards this solution which is totally fine by me. As I said before, the user already needs to specify the device interface and the partition to be used so they can also be responsible to enable the appropriate filesystem write functionality. Indeed if more filesystems are added, it would be quite ugly to have multiple symbols just to choose a config.

I wouldn't be surprised if some time in the future we make the device interface and partition configurable through a U-Boot environment.

Also, there's no need for U-Boot to know the fs to write to since it can be auto-detected, so adding an artificial hurdle isn't necessarily the best design choice.

Basically, I can have two products based on the same HW design. I have one with an EXT4 partition, and another for FAT partition, they both are on the same storage medium (one on one product, the other on the other product) in the same partition number. If we had an exclusive choice, then we would have to have two different U-Boot for essentially the same HW just based on the software design decisions. We cannot always avoid this, but I think we can here, so I think this would be pretty nice to have :)

Quoted 4 lines

Also, if the user forgets to enable the appropriate *_WRITE config, it will trigger an error message in U-Boot that this operation is not supported which will be pretty obvious what needs to be done.

OK, that's good news. I hope the message is explicit enough that users know what to do with the info. It's better than crashing U-Boot, which sometimes happen when in SPL or U-Boot proper pre-reloc for mysterious reasons and make things very frustrating to debug :)

Quoted 2 lines

So I can go with a v3, following your proposals.

Seems to me like this may be the way to go yes.

Cheers,
Quentin

#12 lore raw

Re: [PATCH v2 1/1] drivers: bootcount: Add support for FAT filesystem

Quoted 201 lines · Quentin Schulz

Hi Vasileios,

Quoted 188 lines · Vasileios Amoiridis
Quoted 181 lines · Tom Rini
Quoted 171 lines · Quentin Schulz

Hi Vasileios,

Quoted 76 lines · Vasileios Amoiridis
Quoted 51 lines · Quentin Schulz

Hi Vasileios,

doc/README.bootcount It is the responsibility of some application code

Quoted 16 lines · Vasileios Amoiridis

Add support to save boot count variable in a file in a FAT filesystem.

---
    doc/README.bootcount                          | 12 ++---
    drivers/bootcount/Kconfig                     | 53 +++++++++++++------
    drivers/bootcount/Makefile                    |  2 +-
    .../{bootcount_ext.c => bootcount_fs.c}       | 12 ++---
    4 files changed, 50 insertions(+), 29 deletions(-)

rename drivers/bootcount/{bootcount_ext.c => bootcount_fs.c} (81%)

doc/README.bootcount +0 -0
index f6c5f82f..0f4ffb68 100644
@@ -23,15 +23,15 @@ It is the responsibility of some application code

(typically a Linux

doc/README.bootcount It is the responsibility of some application code · line 23

Quoted 1 line
doc/README.bootcount +0 -0
    application) to reset the variable "bootcount" to 0 when the system

booted

doc/README.bootcount It is the responsibility of some application code · line 29

Quoted 7 lines
doc/README.bootcount +1 -2
    successfully, thus allowing for more boot cycles.
 
-CONFIG_BOOTCOUNT_EXT
+CONFIG_BOOTCOUNT_FS
    --------------------
 
-This adds support for maintaining boot count in a file on an EXT

filesystem.

Quoted 21 lines
doc/README.bootcount +5 -4
-The file to use is defined by:
+This adds support for maintaining boot count in a file on a filesystem.
+Supported filesystems are FAT and EXT. The file to use is defined by:
 
-CONFIG_SYS_BOOTCOUNT_EXT_INTERFACE
-CONFIG_SYS_BOOTCOUNT_EXT_DEVPART
-CONFIG_SYS_BOOTCOUNT_EXT_NAME
+CONFIG_SYS_BOOTCOUNT_FS_INTERFACE
+CONFIG_SYS_BOOTCOUNT_FS_DEVPART
+CONFIG_SYS_BOOTCOUNT_FS_NAME
 
    The format of the file is:
 
drivers/bootcount/Kconfig +0 -0
index 3c56253b..d3679eb5 100644
@@ -25,10 +25,9 @@ config BOOTCOUNT_GENERIC
    	    Set to the address where the bootcount and bootcount magic
    	    will be stored.
 
Quoted 10 lines

drivers/bootcount/Kconfig config BOOTCOUNT_GENERIC · line 30

Quoted 7 lines
drivers/bootcount/Kconfig +3 -4
-config BOOTCOUNT_EXT
-	bool "Boot counter on EXT filesystem"
-	depends on FS_EXT4
-	select EXT4_WRITE
+config BOOTCOUNT_FS
+	bool "Boot counter on a filesystem"
+	depends on FS_EXT4 || FS_FAT

Do we really need this 'depends on' here? Especially if we have a choice below...

Well, probably this is redundant indeed.

Quoted 4 lines

drivers/bootcount/Kconfig config BOOTCOUNT_GENERIC · line 32

Quoted 2 lines
drivers/bootcount/Kconfig +0 -0
    	help
    	  Add support for maintaining boot count in a file on an EXT

The help text is still mentioning EXT here.

Ahh, I missed that.

Quoted 4 lines

I would recommend removing it, or listing the supported filesystems at the moment. While I assume you tested with FAT, I assume that with FS_ANY, any FS should be supported?

Quoted 6 lines

Well, I tested it with both FAT and EXT4 and it works. AFAIU, due to the implementation of the filesystem handling code in U-Boot, if the fs supports a write a function, then it should work. But I cannot test for other filesystems apart from FAT and EXT4 so I think it's better to limit the option to these two.

I guess we can let people figure things out themselves and add new options for when they have tested them, no strong opinion here.

Quoted 18 lines
Quoted 18 lines
Quoted 18 lines
drivers/bootcount/Kconfig +11 -2
    	  filesystem.
@@ -184,26 +183,48 @@ config SYS_BOOTCOUNT_SINGLEWORD
    	  This option enables packing boot count magic value and boot count
    	  into single word (32 bits).
 
-config SYS_BOOTCOUNT_EXT_INTERFACE
-	string "Interface on which to find boot counter EXT filesystem"
+if BOOTCOUNT_FS
+choice
+	prompt "Filesystem type"
+	default BOOTCOUNT_EXT
+
+config BOOTCOUNT_EXT
+	bool "Boot counter on EXT filesystem"
+	depends on FS_EXT4
+	select EXT4_WRITE
+	help
+	  Add support for maintaing boot counter in a file on EXT filesystem"
Quoted 8 lines
Quoted 8 lines

drivers/bootcount/Kconfig config SYS_BOOTCOUNT_SINGLEWORD · line 204

Quoted 8 lines
drivers/bootcount/Kconfig +8 -0
+
+config BOOTCOUNT_FAT
+	bool "Boot counter on FAT filesystem"
+	depends on FS_FAT
+	select FAT_WRITE
+	help
+	  Add support for maintaing boot counter in a file on FAT filesystem"
+

Seems like I missed a typo here as well:

s/maintaing/maintaining/ ? At least that's what we have in doc/README.bootcount

Quoted 10 lines
Quoted 10 lines

drivers/bootcount/Kconfig config SYS_BOOTCOUNT_SINGLEWORD · line 207

Quoted 3 lines
drivers/bootcount/Kconfig +3 -0
+endchoice
+endif
+

Since we now support FS_ANY, do we really need this choice at all?

Alternatively, should it **really** be a choice and not just a bunch of configs that depends on BOOTCOUNT_FS + whatever's needed to write on that FS instead? I think we could have both BOOTCOUNT_EXT and BOOTCOUNT_FAT set without issue?

Quoted 9 lines
Quoted 2 lines

Cheers,
Quentin

Well, I think I kind of get the point but I am still a bit confused. Do you mean that basically the configuration should be done the other way around? Instead of choosing BOOTCOUNT_FS and then specifically to choose EXT or FAT, to choose one of EXT/FAT and then to select BOOTCOUNT_FS? If yes, what is the advantage of this approach?

I'm suggesting:

"""
config BOOTCOUNT_FS
bool "Boot counter on a filesystem"
help

config BOOTCOUNT_EXT
bool "Boot counter on EXT filesystem"
default y
depends on BOOTCOUNT_FS
depends on FS_EXT4
select EXT4_WRITE
help
Add support for maintaing boot counter in a file on EXT filesystem"

config BOOTCOUNT_FAT
bool "Boot counter on FAT filesystem"
depends on BOOTCOUNT_FS
depends on FS_FAT
select FAT_WRITE
help
Add support for maintaing boot counter in a file on FAT filesystem"
"""

This way we can have defconfigs where BOOTCOUNT_FAT and BOOTCOUNT_EXT are both selected, the user would then be free to decide if the same partition on two different devices but for the same purpose can be either ext2/3/4 or FAT, without recompiling U-Boot just for that.

Quoted 8 lines

However, it would now be possible to have BOOTCOUNT_FS=y but neither BOOTCOUNT_EXT nor BOOTCOUNT_FAT set to y (e.g. if FS_EXT4 or FS_FAT isn't defined).

Finally, the other option was just to NOT have BOOTCOUNT_FAT or BOOTCOUNT_EXT and let people select FS_EXT4/FS_FAT and EXT4_WRITE/FAT_WRITE themselves since the BOOTCOUNT_FAT/EXT aren't actually used in C code. This is less user-friendly though.

Quoted 5 lines

I was thinking that with FS_ANY, we don't need a symbol per filesystem type but can just handle it in the help text with something like "Please ensure that you have enabled write support for the filesystem that you will be used by the partition that you configure this feature for."

Quoted 9 lines

Hi Tom,

I see that both you and Quentin are leaning towards this solution which is totally fine by me. As I said before, the user already needs to specify the device interface and the partition to be used so they can also be responsible to enable the appropriate filesystem write functionality. Indeed if more filesystems are added, it would be quite ugly to have multiple symbols just to choose a config.

Quoted 7 lines

I wouldn't be surprised if some time in the future we make the device interface and partition configurable through a U-Boot environment.

Also, there's no need for U-Boot to know the fs to write to since it can be auto-detected, so adding an artificial hurdle isn't necessarily the best design choice.

True.

Quoted 8 lines

Basically, I can have two products based on the same HW design. I have one with an EXT4 partition, and another for FAT partition, they both are on the same storage medium (one on one product, the other on the other product) in the same partition number. If we had an exclusive choice, then we would have to have two different U-Boot for essentially the same HW just based on the software design decisions. We cannot always avoid this, but I think we can here, so I think this would be pretty nice to have :)

Well, that's a good example, so totally understandable, thanks!!!

Quoted 10 lines
Quoted 4 lines

Also, if the user forgets to enable the appropriate *_WRITE config, it will trigger an error message in U-Boot that this operation is not supported which will be pretty obvious what needs to be done.

OK, that's good news. I hope the message is explicit enough that users know what to do with the info. It's better than crashing U-Boot, which sometimes happen when in SPL or U-Boot proper pre-reloc for mysterious reasons and make things very frustrating to debug :)

Quoted 7 lines
Quoted 2 lines

So I can go with a v3, following your proposals.

Seems to me like this may be the way to go yes.

Cheers,
Quentin

Cheers,
Vasilis

#13 lore raw

Re: [PATCH v2 1/1] drivers: bootcount: Add support for FAT filesystem

In reply to Quentin Schulz
Quoted 166 lines · Quentin Schulz

Hi Vasileios,

Quoted 76 lines · Vasileios Amoiridis
Quoted 51 lines · Quentin Schulz

Hi Vasileios,

doc/README.bootcount It is the responsibility of some application code

Quoted 16 lines · Vasileios Amoiridis

Add support to save boot count variable in a file in a FAT filesystem.

---
   doc/README.bootcount                          | 12 ++---
   drivers/bootcount/Kconfig                     | 53 +++++++++++++------
   drivers/bootcount/Makefile                    |  2 +-
   .../{bootcount_ext.c => bootcount_fs.c}       | 12 ++---
   4 files changed, 50 insertions(+), 29 deletions(-)

rename drivers/bootcount/{bootcount_ext.c => bootcount_fs.c} (81%)

doc/README.bootcount +0 -0
index f6c5f82f..0f4ffb68 100644
@@ -23,15 +23,15 @@ It is the responsibility of some application code

(typically a Linux

doc/README.bootcount It is the responsibility of some application code · line 23

Quoted 1 line
doc/README.bootcount +0 -0
   application) to reset the variable "bootcount" to 0 when the system

booted

doc/README.bootcount It is the responsibility of some application code (typically a Linux

Quoted 7 lines
doc/README.bootcount +1 -2
   successfully, thus allowing for more boot cycles.
 
-CONFIG_BOOTCOUNT_EXT
+CONFIG_BOOTCOUNT_FS
   --------------------
 
-This adds support for maintaining boot count in a file on an EXT

filesystem.

Quoted 21 lines
doc/README.bootcount +5 -4
-The file to use is defined by:
+This adds support for maintaining boot count in a file on a filesystem.
+Supported filesystems are FAT and EXT. The file to use is defined by:
 
-CONFIG_SYS_BOOTCOUNT_EXT_INTERFACE
-CONFIG_SYS_BOOTCOUNT_EXT_DEVPART
-CONFIG_SYS_BOOTCOUNT_EXT_NAME
+CONFIG_SYS_BOOTCOUNT_FS_INTERFACE
+CONFIG_SYS_BOOTCOUNT_FS_DEVPART
+CONFIG_SYS_BOOTCOUNT_FS_NAME
 
   The format of the file is:
 
drivers/bootcount/Kconfig +0 -0
index 3c56253b..d3679eb5 100644
@@ -25,10 +25,9 @@ config BOOTCOUNT_GENERIC
   	    Set to the address where the bootcount and bootcount magic
   	    will be stored.
 
Quoted 10 lines

drivers/bootcount/Kconfig config BOOTCOUNT_GENERIC · line 30

Quoted 7 lines
drivers/bootcount/Kconfig +3 -4
-config BOOTCOUNT_EXT
-	bool "Boot counter on EXT filesystem"
-	depends on FS_EXT4
-	select EXT4_WRITE
+config BOOTCOUNT_FS
+	bool "Boot counter on a filesystem"
+	depends on FS_EXT4 || FS_FAT

Do we really need this 'depends on' here? Especially if we have a choice below...

Well, probably this is redundant indeed.

Quoted 4 lines

drivers/bootcount/Kconfig config BOOTCOUNT_GENERIC · line 32

Quoted 2 lines
drivers/bootcount/Kconfig +0 -0
   	help
   	  Add support for maintaining boot count in a file on an EXT

The help text is still mentioning EXT here.

Ahh, I missed that.

Quoted 4 lines

I would recommend removing it, or listing the supported filesystems at the moment. While I assume you tested with FAT, I assume that with FS_ANY, any FS should be supported?

Quoted 6 lines

Well, I tested it with both FAT and EXT4 and it works. AFAIU, due to the implementation of the filesystem handling code in U-Boot, if the fs supports a write a function, then it should work. But I cannot test for other filesystems apart from FAT and EXT4 so I think it's better to limit the option to these two.

I guess we can let people figure things out themselves and add new options for when they have tested them, no strong opinion here.

Quoted 18 lines
Quoted 18 lines
Quoted 18 lines
drivers/bootcount/Kconfig +11 -2
   	  filesystem.
@@ -184,26 +183,48 @@ config SYS_BOOTCOUNT_SINGLEWORD
   	  This option enables packing boot count magic value and boot count
   	  into single word (32 bits).
 
-config SYS_BOOTCOUNT_EXT_INTERFACE
-	string "Interface on which to find boot counter EXT filesystem"
+if BOOTCOUNT_FS
+choice
+	prompt "Filesystem type"
+	default BOOTCOUNT_EXT
+
+config BOOTCOUNT_EXT
+	bool "Boot counter on EXT filesystem"
+	depends on FS_EXT4
+	select EXT4_WRITE
+	help
+	  Add support for maintaing boot counter in a file on EXT filesystem"
Quoted 8 lines
Quoted 8 lines

drivers/bootcount/Kconfig config SYS_BOOTCOUNT_SINGLEWORD · line 204

Quoted 8 lines
drivers/bootcount/Kconfig +8 -0
+
+config BOOTCOUNT_FAT
+	bool "Boot counter on FAT filesystem"
+	depends on FS_FAT
+	select FAT_WRITE
+	help
+	  Add support for maintaing boot counter in a file on FAT filesystem"
+

Seems like I missed a typo here as well:

s/maintaing/maintaining/ ? At least that's what we have in doc/README.bootcount

Quoted 10 lines
Quoted 10 lines

drivers/bootcount/Kconfig config SYS_BOOTCOUNT_SINGLEWORD · line 207

Quoted 3 lines
drivers/bootcount/Kconfig +3 -0
+endchoice
+endif
+

Since we now support FS_ANY, do we really need this choice at all?

Alternatively, should it **really** be a choice and not just a bunch of configs that depends on BOOTCOUNT_FS + whatever's needed to write on that FS instead? I think we could have both BOOTCOUNT_EXT and BOOTCOUNT_FAT set without issue?

Quoted 9 lines
Quoted 2 lines

Cheers,
Quentin

Well, I think I kind of get the point but I am still a bit confused. Do you mean that basically the configuration should be done the other way around? Instead of choosing BOOTCOUNT_FS and then specifically to choose EXT or FAT, to choose one of EXT/FAT and then to select BOOTCOUNT_FS? If yes, what is the advantage of this approach?

I'm suggesting:

"""
config BOOTCOUNT_FS
bool "Boot counter on a filesystem"
help

config BOOTCOUNT_EXT
bool "Boot counter on EXT filesystem"
default y
depends on BOOTCOUNT_FS
depends on FS_EXT4
select EXT4_WRITE
help
Add support for maintaing boot counter in a file on EXT filesystem"

config BOOTCOUNT_FAT
bool "Boot counter on FAT filesystem"
depends on BOOTCOUNT_FS
depends on FS_FAT
select FAT_WRITE
help
Add support for maintaing boot counter in a file on FAT filesystem"
"""

Quoted 9 lines

This way we can have defconfigs where BOOTCOUNT_FAT and BOOTCOUNT_EXT are both selected, the user would then be free to decide if the same partition on two different devices but for the same purpose can be either ext2/3/4 or FAT, without recompiling U-Boot just for that.

However, it would now be possible to have BOOTCOUNT_FS=y but neither BOOTCOUNT_EXT nor BOOTCOUNT_FAT set to y (e.g. if FS_EXT4 or FS_FAT isn't defined).

But why having both *_FAT and *_EXT selected at the same time? You have to specifically mention the device interface and the number of partition to use from that interface. Also, the bootcount is kept in just one place, so having enabled both wouldn't it make it incosistent?

Quoted 5 lines

Finally, the other option was just to NOT have BOOTCOUNT_FAT or BOOTCOUNT_EXT and let people select FS_EXT4/FS_FAT and EXT4_WRITE/FAT_WRITE themselves since the BOOTCOUNT_FAT/EXT aren't actually used in C code. This is less user-friendly though.

This is indeed less user-friendly but on the other hand, the device interface and the partition number have to be set by the user. So leaving also this choice to the user shouldn't be that big of a problem, right?

Quoted 2 lines

Cheers,
Quentin