cmd: fuse: Introduce fuse writebuff sub-system and clean up
cover cmd: fuse: Introduce fuse writebuff sub-system and clean up
This patch series introduces the fuse writebuff sub-system command and makes improvements to the existing fuse implementation by removing the custom string functions. The patches are required to be applied in sequence.
The series consists of the following changes:
Patch 1 removes custom string functions and replaces them with standard string functions.
Patch 2 introduces fuse.rst documentation for fuse commands. Patch 3 introduces the fuse writebuff sub-system command, allowing to write a structured buffer in memory to fuses, and implementing the necessary function calls.
Patch 4 enables the fuse sub-system in the K3 platform. Patch 5 updates the fuse.rst documentation to include details about the new fuse writebuff command.
These changes aim to improve the fuse sub-system by the removal of custom string functions and the addition of the fuse writebuff command improves fuse programming workflows by allowing to write a structured buffer in memory to efuses.
Changes in non-RFC patch series:
Drop the explicit u32 typecast throughout in patch #1.
Link to RFC v3 patch series: https://lore.kernel.org/u-boot/20250318140932.GY2640854@bill-the-cat/T/#m79236044732c410b0281973ef03c11e4d3e31991
Harsha Vardhan V M (5):
cmd: fuse: Remove custom string functions
doc: cmd: Add documentation for fuse command
cmd: fuse: Add fuse writebuff sub-system command
drivers: k3_fuse: Add fuse sub-system func calls
doc: cmd: Add fuse writebuff cmd documentation
cmd/Kconfig | 8 ++ cmd/fuse.c | 63 +++++++++------ doc/README.fuse | 67 ---------------- doc/usage/cmd/fuse.rst | 176 +++++++++++++++++++++++++++++++++++++++++ doc/usage/index.rst | 1 + drivers/misc/Kconfig | 7 ++ drivers/misc/Makefile | 1 + drivers/misc/k3_fuse.c | 78 ++++++++++++++++++ include/fuse.h | 9 +++ 9 files changed, 320 insertions(+), 90 deletions(-) delete mode 100644 doc/README.fuse create mode 100644 doc/usage/cmd/fuse.rst create mode 100644 drivers/misc/k3_fuse.c
Signature · 1 line
2.34.1
PATCH 1/5 cmd: fuse: Remove custom string functions
Remove custom string functions and replace them with normal string functions. Remove the custom strtou32 and replace it with simple_strtoul.
--- cmd/fuse.c | 39 ++++++++++++++++++--------------------- 1 file changed, 18 insertions(+), 21 deletions(-)
cmd/fuse.c +18 -21
@@ -15,17 +15,6 @@#include <vsprintf.h> #include <linux/errno.h> -static int strtou32 (const char *str,unsigned int base,u32 *result) -{ -char *ep; - - *result =simple_strtoul (str, &ep, base); -if (ep == str || *ep !='\0' ) -return -EINVAL ; - -return 0 ; -} -static int confirm_prog (void ) { puts("Warning: Programming fuses is an irreversible operation!\n"
@@ -54,14 +43,18 @@ static int do_fuse(struct cmd_tbl *cmdtp, int flag, int argc, argc -=2 + confirmed; argv +=2 + confirmed; -if (argc <2 ||strtou32 (argv[0 ],0 , &bank) || -strtou32 (argv[1 ],0 , &word)) +if (argc <2 )return CMD_RET_USAGE ; + bank =simple_strtoul (argv[0 ],NULL ,0 ); + word =simple_strtoul (argv[1 ],NULL ,0 ); +if (!strcmp (op,"read" )) {if (argc ==2 ) cnt =1 ; -else if (argc !=3 ||strtou32 (argv[2 ],0 , &cnt)) +else if (argc ==3 ) + cnt =simple_strtoul (argv[2 ],NULL ,0 ); +else return CMD_RET_USAGE ;printf ("Reading bank %u:\n" , bank);
@@ -79,7 +72,9 @@ static int do_fuse(struct cmd_tbl *cmdtp, int flag, int argc, }else if (!strcmp (op,"readm" )) {if (argc ==3 ) cnt =1 ; -else if (argc !=4 ||strtou32 (argv[3 ],0 , &cnt)) +else if (argc ==4 ) + cnt =simple_strtoul (argv[3 ],NULL ,0 ); +else return CMD_RET_USAGE ; addr =simple_strtoul (argv[2 ],NULL ,16 );
@@ -99,7 +94,9 @@ static int do_fuse(struct cmd_tbl *cmdtp, int flag, int argc,unmap_sysmem (start); }else if (!strcmp (op,"cmp" )) { -if (argc !=3 ||strtou32 (argv[2 ],0 , &cmp)) +if (argc ==3 ) + cmp =simple_strtoul (argv[2 ],NULL ,0 ); +else return CMD_RET_USAGE ;printf ("Comparing bank %u:\n" , bank);
@@ -119,7 +116,9 @@ static int do_fuse(struct cmd_tbl *cmdtp, int flag, int argc, }else if (!strcmp (op,"sense" )) {if (argc ==2 ) cnt =1 ; -else if (argc !=3 ||strtou32 (argv[2 ],0 , &cnt)) +else if (argc ==3 ) + cnt =simple_strtoul (argv[2 ],NULL ,0 ); +else return CMD_RET_USAGE ;printf ("Sensing bank %u:\n" , bank);
@@ -139,8 +138,7 @@ static int do_fuse(struct cmd_tbl *cmdtp, int flag, int argc,return CMD_RET_USAGE ;for (i =2 ; i < argc; i++, word++) { -if (strtou32 (argv[i],16 , &val)) -return CMD_RET_USAGE ; + val =simple_strtoul (argv[i],NULL ,16 );printf ("Programming bank %u word 0x%.8x to 0x%.8x...\n" , bank, word, val);
@@ -155,8 +153,7 @@ static int do_fuse(struct cmd_tbl *cmdtp, int flag, int argc,return CMD_RET_USAGE ;for (i =2 ; i < argc; i++, word++) { -if (strtou32 (argv[i],16 , &val)) -return CMD_RET_USAGE ; + val =simple_strtoul (argv[i],NULL ,16 );printf ("Overriding bank %u word 0x%.8x with " "0x%.8x...\n" , bank, word, val);
Signature · 1 line
2.34.1
Re: [PATCH 1/5] cmd: fuse: Remove custom string functions
Quoted 5 lines · Harsha Vardhan V M
Remove custom string functions and replace them with normal string functions. Remove the custom strtou32 and replace it with
simple_strtoul.Signed-off-by Harsha Vardhan V M <[email protected]>
Signature · 1 line
Tom
PATCH 2/5 doc: cmd: Add documentation for fuse command
In reply to Harsha Vardhan V MAdd documentation for the 'fuse' sub-system commands in doc/usage/cmd/fuse.rst file.
Remove doc/README.fuse file.
--- doc/README.fuse | 67 ------------------ doc/usage/cmd/fuse.rst | 156 +++++++++++++++++++++++++++++++++++++++++ doc/usage/index.rst | 1 + 3 files changed, 157 insertions(+), 67 deletions(-) delete mode 100644 doc/README.fuse create mode 100644 doc/usage/cmd/fuse.rst
doc/README.fuse deleted +0 -67
@@ -1,67 +0,0 @@ -Fuse API functions and commands - -The fuse API allows to control a fusebox and how it is used by the upper -hardware layers. - -A fuse corresponds to a single non-volatile memory bit that can be programmed -(i.e. blown, set to 1) only once. The programming operation is irreversible. A -fuse that has not been programmed reads 0. - -Fuses can be used by SoCs to store various permanent configuration and data, -e.g. boot configuration, security configuration, MAC addresses, etc. - -A fuse word is the smallest group of fuses that can be read at once from the -fusebox control IP registers. This is limited to 32 bits with the current API. - -A fuse bank is the smallest group of fuse words having a common ID, as defined -by each SoC. - -Upon startup, the fusebox control IP reads the fuse values and stores them to a -volatile shadow cache. - -See the README files of the drivers implementing this API in order to know the -SoC- and implementation-specific details. - -Functions / commands: - - int fuse_read(u32 bank, u32 word, u32 *val); - fuse read <bank> <word> [<cnt>] - Read fuse words from the shadow cache. - - int fuse_sense(u32 bank, u32 word, u32 *val); - fuse sense <bank> <word> [<cnt>] - Sense - i.e. read directly from the fusebox, skipping the shadow cache - - fuse words. This operation does not update the shadow cache. - - This is useful to know the true value of fuses if an override has been - performed (see below). - - int fuse_prog(u32 bank, u32 word, u32 val); - fuse prog [-y] <bank> <word> <hexval> [<hexval>...] - Program fuse words. This operation directly affects the fusebox and is - irreversible. The shadow cache is updated accordingly or not, depending on - each IP. - - Only the bits to be programmed should be set in the input value (i.e. for - fuse bits that have already been programmed and hence should be left - unchanged by a further programming, it is preferable to clear the - corresponding bits in the input value in order not to perform a new - hardware programming operation on these fuse bits). - - int fuse_override(u32 bank, u32 word, u32 val); - fuse override <bank> <word> <hexval> [<hexval>...] - Override fuse words in the shadow cache. - - The fusebox is unaffected, so following this operation, the shadow cache - may differ from the fusebox values. Read or sense operations can then be - used to get the values from the shadow cache or from the fusebox. - - This is useful to change the behaviors linked to some cached fuse values, - either because this is needed only temporarily, or because some of the - fuses have already been programmed or are locked (if the SoC allows to - override a locked fuse). - -Configuration: - - CONFIG_CMD_FUSE - Define this to enable the fuse commands.
doc/usage/cmd/fuse.rst new file +156 -0
156 lines not on this page · raw message
doc/usage/index.rst +1 -0
@@ -72,6 +72,7 @@ Shell commands cmd/fdt cmd/font cmd/for + cmd/fuse cmd/fwu_mdata cmd/gpio cmd/gpt
Signature · 1 line
2.34.1
PATCH 3/5 cmd: fuse: Add fuse writebuff sub-system command
In reply to Harsha Vardhan V MAdd CMD_FUSE_WRITEBUFF config option to add and enable fuse writebuff sub-system command. Add fuse_writebuff function to be invoked on writebuff command.
--- cmd/Kconfig | 8 ++++++++ cmd/fuse.c | 30 +++++++++++++++++++++++++----- include/fuse.h | 9 +++++++++ 3 files changed, 42 insertions(+), 5 deletions(-)
cmd/Kconfig +8 -0
@@ -1236,6 +1236,14 @@ config CMD_FUSE which control the behaviour of the device. The command uses the fuse_...() API. +config CMD_FUSE_WRITEBUFF + bool "Support for the fuse writebuff" + depends on CMD_FUSE + help + This allows programming fuses, which control the behaviour of + the device, using a structured buffer in memory. The command + uses the fuse_writebuff() API. + config CMD_GPIO bool "gpio" help
cmd/fuse.c +25 -5
@@ -43,11 +43,18 @@ static int do_fuse(struct cmd_tbl *cmdtp, int flag, int argc, argc -=2 + confirmed; argv +=2 + confirmed; -if (argc <2 ) -return CMD_RET_USAGE ; +if (IS_ENABLED (CONFIG_CMD_FUSE_WRITEBUFF ) && !strcmp (op,"writebuff" )) { +if (argc ==1 ) + addr =simple_strtoul (argv[0 ],NULL ,16 ); +else +return CMD_RET_USAGE ; + }else { +if (argc <2 ) +return CMD_RET_USAGE ; - bank =simple_strtoul (argv[0 ],NULL ,0 ); - word =simple_strtoul (argv[1 ],NULL ,0 ); + bank =simple_strtoul (argv[0 ],NULL ,0 ); + word =simple_strtoul (argv[1 ],NULL ,0 ); + }if (!strcmp (op,"read" )) {if (argc ==2 )
@@ -161,6 +168,15 @@ static int do_fuse(struct cmd_tbl *cmdtp, int flag, int argc,if (ret) goto err; } + }else if (IS_ENABLED (CONFIG_CMD_FUSE_WRITEBUFF ) && !strcmp (op,"writebuff" )) { +printf ("Programming fuses using a structured buffer in memory " +"starting at addr 0x%lx\n" , addr); +if (!confirmed && !confirm_prog ()) +return CMD_RET_FAILURE ; + + ret =fuse_writebuff (addr); +if (ret) + goto err; }else {return CMD_RET_USAGE ; }
@@ -186,5 +202,9 @@ U_BOOT_CMD("fuse prog [-y] <bank> <word> <hexval> [<hexval>...] - program 1 or\n" " several fuse words, starting at 'word' (PERMANENT)\n" "fuse override <bank> <word> <hexval> [<hexval>...] - override 1 or\n" -" several fuse words, starting at 'word'" +" several fuse words, starting at 'word'\n" +#ifdef CONFIG_CMD_FUSE_WRITEBUFF +"fuse writebuff [-y] <addr> - program fuse data\n" +" using a structured buffer in memory starting at 'addr'\n" +#endif /* CONFIG_CMD_FUSE_WRITEBUFF */ );
include/fuse.h +9 -0
@@ -12,6 +12,7 @@#define _FUSE_H_#include <linux/types.h> +#include <linux/errno.h> /* * Read/Sense/Program/Override interface:
@@ -25,5 +26,13 @@ int fuse_read(u32 bank, u32 word, u32 *val);int fuse_sense (u32 bank,u32 word,u32 *val);int fuse_prog (u32 bank,u32 word,u32 val);int fuse_override (u32 bank,u32 word,u32 val); +#ifdef CONFIG_CMD_FUSE_WRITEBUFF +int fuse_writebuff (ulong addr); +#else +static inline int fuse_writebuff (ulong addr) +{ +return -EPERM ; +} +#endif /* CONFIG_CMD_FUSE_WRITEBUFF */ #endif /* _FUSE_H_ */
Signature · 1 line
2.34.1
PATCH 4/5 drivers: k3_fuse: Add fuse sub-system func calls
In reply to Harsha Vardhan V MAdd K3_FUSE config option to add and enable fuse sub-system implementation function calls.
--- drivers/misc/Kconfig | 7 ++++ drivers/misc/Makefile | 1 + drivers/misc/k3_fuse.c | 78 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 86 insertions(+) create mode 100644 drivers/misc/k3_fuse.c
drivers/misc/Kconfig +7 -0
@@ -468,6 +468,13 @@ config STM32MP_FUSE for STM32MP architecture. This API is needed for CMD_FUSE. +config K3_FUSE + bool "Enable TI K3 fuse wrapper providing the fuse API" + depends on MISC && CMD_FUSE && CMD_FUSE_WRITEBUFF + help + If you say Y here, you will get support for the fuse API (OTP) + for TI K3 architecture. + config STM32_RCC bool "Enable RCC driver for the STM32 SoC's family" depends on (ARCH_STM32 || ARCH_STM32MP) && MISC
drivers/misc/Makefile +1 -0
@@ -48,6 +48,7 @@ obj-$(CONFIG_$(XPL_)I2C_EEPROM) += i2c_eeprom.o obj-$(CONFIG_IHS_FPGA) += ihs_fpga.o obj-$(CONFIG_IMX8) += imx8/ obj-$(CONFIG_IMX_ELE) += imx_ele/ +obj-$(CONFIG_K3_FUSE) += k3_fuse.o obj-$(CONFIG_LED_STATUS) += status_led.o obj-$(CONFIG_LED_STATUS_GPIO) += gpio_led.o obj-$(CONFIG_MPC83XX_SERDES) += mpc83xx_serdes.o
drivers/misc/k3_fuse.c new file +78 -0
78 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH 5/5 doc: cmd: Add fuse writebuff cmd documentation
In reply to Harsha Vardhan V MAdd fuse writebuff sub-system command documentation.
--- doc/usage/cmd/fuse.rst | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)
doc/usage/cmd/fuse.rst +20 -0
@@ -17,6 +17,7 @@ Synopsis fuse sense <bank> <word> [<cnt>] fuse prog [-y] <bank> <word> <hexval> [<hexval>...] fuse override <bank> <word> <hexval> [<hexval>...] + fuse writebuff [-y] <addr> Description -----------
@@ -79,6 +80,16 @@ Commands fuses have already been programmed or are locked (if the SoC allows to override a locked fuse). +- **fuse writebuff [-y] <addr>** + Programs fuse data using a structured buffer in memory starting at 'addr'. + This operation directly affects the fusebox and is irreversible. + + The structure of the buffer should contain all necessary details for + programming fuses, such as the values to be written to the fuse, optional + metadata for validation or programming constraints and any configuration + data required for the operation. Define CONFIG_CMD_FUSE_WRITEBUFF to + enable the fuse writebuff command. + Examples --------
@@ -144,10 +155,19 @@ fuse override u-boot=> fuse override 0 1 0x00000003 Overriding bank 0 word 0x00000001 with 0x00000003... +fuse writebuff +~~~~~~~~~~~~~~ + +:: + + u-boot=> fuse writebuff -y 0x84000000 + Programming fuses with buffer at addr 0x84000000 + Configuration ------------- The fuse commands are available if CONFIG_CMD_FUSE=y. +The fuse writebuff command is available if CONFIG_CMD_FUSE_WRITEBUFF=y. Return code -----------
Signature · 1 line
2.34.1
Quoted 16 lines · Harsha Vardhan V M
This patch series introduces the fuse writebuff sub-system command and makes improvements to the existing fuse implementation by removing the custom string functions. The patches are required to be applied in sequence.
The series consists of the following changes:
Patch 1 removes custom string functions and replaces them with standard string functions.
Patch 2 introducesfuse.rstdocumentation for fuse commands. Patch 3 introduces the fuse writebuff sub-system command, allowing to write a structured buffer in memory to fuses, and implementing the necessary function calls.
Patch 4 enables the fuse sub-system in the K3 platform. Patch 5 updates thefuse.rstdocumentation to include details about the new fuse writebuff command.
Quoted 1 line
[...]
Applied to u-boot/next, thanks!
[1/5] cmd: fuse: Remove custom string functions
commit: 005eeda378b4897577eb82b30e5c260014c5e727
[2/5] doc: cmd: Add documentation for fuse command
commit: 833c05ea272a086b5428166552ceb021b50c4cda
[3/5] cmd: fuse: Add fuse writebuff sub-system command
commit: 578e7882bfb79848ff91cd65a5ebf4e795d26bb5
[4/5] drivers: k3_fuse: Add fuse sub-system func calls
commit: ed5f2e5bed91b6daa4f051b5e11efbaebfec9cb1
[5/5] doc: cmd: Add fuse writebuff cmd documentation
commit: 9f6b1ff8d08a92bbddf3c6226b8c2fdaf8df9515Signature · 1 line
Tom