cmd: fuse: Introduce fuse writebuff sub-system and clean up
v2 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 v2:
1.Convert doc/README.fuse to doc/usage/cmd/fuse.rst as patch #2, as requested by [email protected].
2.Add fuse writebuff documentation in fuse.rst in the final patch.
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 | 49 +++++++----- doc/usage/cmd/fuse.rst | 176 +++++++++++++++++++++++++++++++++++++++++ drivers/misc/Kconfig | 7 ++ drivers/misc/Makefile | 1 + drivers/misc/k3_fuse.c | 78 ++++++++++++++++++ include/fuse.h | 9 +++ 7 files changed, 307 insertions(+), 21 deletions(-) create mode 100644 doc/usage/cmd/fuse.rst create mode 100644 drivers/misc/k3_fuse.c
Signature · 1 line
2.34.1
RFC PATCH v2 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 str2long.
--- cmd/fuse.c | 27 ++++++++------------------- 1 file changed, 8 insertions(+), 19 deletions(-)
cmd/fuse.c +8 -19
@@ -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,14 @@ 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 || !(str2long (argv[0 ], (ulong *)&bank)) || + !(str2long (argv[1 ], (ulong *)&word)))return CMD_RET_USAGE ;if (!strcmp (op,"read" )) {if (argc ==2 ) cnt =1 ; -else if (argc !=3 ||strtou32 (argv[2 ],0 , &cnt)) +else if (argc !=3 || !(str2long (argv[2 ], (ulong *)&cnt)))return CMD_RET_USAGE ;printf ("Reading bank %u:\n" , bank);
@@ -79,7 +68,7 @@ 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 || !(str2long (argv[3 ], (ulong *)&cnt)))return CMD_RET_USAGE ; addr =simple_strtoul (argv[2 ],NULL ,16 );
@@ -99,7 +88,7 @@ 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 || !(str2long (argv[2 ], (ulong *)&cmp)))return CMD_RET_USAGE ;printf ("Comparing bank %u:\n" , bank);
@@ -119,7 +108,7 @@ 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 || !(str2long (argv[2 ], (ulong *)&cnt)))return CMD_RET_USAGE ;printf ("Sensing bank %u:\n" , bank);
@@ -139,7 +128,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)) +if (!(str2long (argv[i], (ulong *)&val)))return CMD_RET_USAGE ; printf("Programming bank %u word 0x%.8x to 0x%.8x...\n",
@@ -155,7 +144,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)) +if (!(str2long (argv[i], (ulong *)&val)))return CMD_RET_USAGE ; printf("Overriding bank %u word 0x%.8x with "
Signature · 1 line
2.34.1
RFC PATCH v2 2/5 doc: cmd: add documentation for fuse command
In reply to Harsha Vardhan V MAdd documentation for the 'fuse' sub-system commands.
--- doc/usage/cmd/fuse.rst | 156 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 156 insertions(+) create mode 100644 doc/usage/cmd/fuse.rst
doc/usage/cmd/fuse.rst new file +156 -0
@@ -0,0 +1,156 @@ +.. SPDX-License-Identifier: GPL-2.0+ + +.. index:: + single: fuse (command) + +fuse command +============ + +Synopsis +-------- + +:: + + fuse read <bank> <word> [<cnt>] + fuse cmp <bank> <word> <hexval> + fuse readm <bank> <word> <addr> [<cnt>] + fuse sense <bank> <word> [<cnt>] + fuse prog [-y] <bank> <word> <hexval> [<hexval>...] + fuse override <bank> <word> <hexval> [<hexval>...] + +Description +----------- + +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 as 0. + +Fuses can be used by SoCs to store various permanent configurations and data, +such as boot configurations, security settings, MAC addresses, etc. + +A fuse 'word' is the smallest group of fuses that can be read at once from +the fusebox control IP registers. In the current API, this is limited to 32 bits. + +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 in a +volatile shadow cache. + +Commands +-------- + +- **fuse read <bank> <word> [<cnt>]** + Reads 1 or 'cnt' fuse words, starting at 'word' from the shadow cache. + +- **fuse cmp <bank> <word> <hexval>** + Compares 'hexval' to fuse at 'word'. + +- **fuse readm <bank> <word> <addr> [<cnt>]** + Reads 1 or 'cnt' fuse words, starting at 'word' into memory at 'addr'. + +- **fuse sense <bank> <word> [<cnt>]** + Sense 1 or 'cnt' fuse words, starting at 'word'. + 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). + +- **fuse prog [-y] <bank> <word> <hexval> [<hexval>...]** + Permanently programs 1 or several fuse words, starting at 'word'. + 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). + +- **fuse override <bank> <word> <hexval> [<hexval>...]** + Override 1 or several fuse words, starting at 'word' 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 behaviours 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). + +Examples +-------- + +fuse read +~~~~~~~~~ + +:: + + u-boot=> fuse read 0 1 + Reading bank 0: + + Word 0x00000001: 00000001 + +fuse cmp +~~~~~~~~ + +:: + + u-boot=> fuse cmp 0 1 0x1 + Comparing bank 0: + + Word 0x00000001: + Value 0x00000001:0x00000001 + passed + +fuse readm +~~~~~~~~~~ + +:: + + u-boot=> fuse readm 0 1 0x83000000 + Reading bank 0 len 1 to 0x83000000 + +fuse sense +~~~~~~~~~~ + +:: + + u-boot=> fuse sense 0 1 + Sensing bank 0: + + Word 0x00000001: 00000001 + +fuse prog +~~~~~~~~~ + +:: + + u-boot=> fuse prog 0 1 0x00000002 + Programming bank 0 word 0x00000001 to 0x00000002... + Warning: Programming fuses is an irreversible operation! + This may brick your system. + Use this command only if you are sure of what you are doing! + + Really perform this fuse programming? <y/N> + y + +fuse override +~~~~~~~~~~~~~ + +:: + + u-boot=> fuse override 0 1 0x00000003 + Overriding bank 0 word 0x00000001 with 0x00000003... + +Configuration +------------- + +The fuse commands are available if CONFIG_CMD_FUSE=y. + +Return code +----------- + +The return value $? is set to 0 (true) if the command is successful, +1 (false) otherwise.
Signature · 1 line
2.34.1
Re: [RFC PATCH v2 2/5] doc: cmd: add documentation for fuse command
Quoted 7 lines · Harsha Vardhan V M
Add documentation for the 'fuse' sub-system commands.
Signed-off-by Harsha Vardhan V M <[email protected]>--- doc/usage/cmd/fuse.rst | 156 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 156 insertions(+) create mode 100644 doc/usage/cmd/fuse.rst
This should delete the old doc/ file as well. Also please run:
make htmldocs KDOC_WERROR=1
As this will fail due to not including this in the index at a minimum. Thanks.
Signature · 1 line
Tom
Re: [RFC PATCH v2 2/5] doc: cmd: add documentation for fuse command
Quoted 10 lines · Tom Rini
Quoted 7 lines · Harsha Vardhan V M
Add documentation for the 'fuse' sub-system commands.
Signed-off-by Harsha Vardhan V M <[email protected]>--- doc/usage/cmd/fuse.rst | 156 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 156 insertions(+)create mode 100644
doc/usage/cmd/fuse.rst
Quoted 6 lines
This should delete the old doc/ file as well. Also please run:
make htmldocs KDOC_WERROR=1As this will fail due to not including this in the index at a minimum. Thanks.
Thanks, Will remove the doc/README.fuse file and add the fuse index in doc/usage/index.rst
RFC PATCH v2 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 | 26 ++++++++++++++++++++++---- include/fuse.h | 9 +++++++++ 3 files changed, 39 insertions(+), 4 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 +22 -4
@@ -43,9 +43,14 @@ static int do_fuse(struct cmd_tbl *cmdtp, int flag, int argc, argc -=2 + confirmed; argv +=2 + confirmed; -if (argc <2 || !(str2long (argv[0 ], (ulong *)&bank)) || - !(str2long (argv[1 ], (ulong *)&word))) -return CMD_RET_USAGE ; +if (IS_ENABLED (CONFIG_CMD_FUSE_WRITEBUFF ) && !strcmp (op,"writebuff" )) { +if (argc !=1 || !(str2long (argv[0 ], &addr))) +return CMD_RET_USAGE ; + }else { +if (argc <2 || !(str2long (argv[0 ], (ulong *)&bank)) || + !(str2long (argv[1 ], (ulong *)&word))) +return CMD_RET_USAGE ; + }if (!strcmp (op,"read" )) {if (argc ==2 )
@@ -153,6 +158,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 ; }
@@ -178,5 +192,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
RFC PATCH v2 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
RFC PATCH v2 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