diff mbox series

[3/7] stm32mp: cmd_stm32key: handle error in fuse_hash_value

Message ID 20210628145519.3.Id13cccdd894c43f0df0833fc71e3ff084eb4cc1d@changeid
State Accepted
Commit fe24090eb7f7cfe33a964a7966e78b7ed954ee98
Delegated to: Patrick Delaunay
Headers show
Series stm32mp: cmd_stm32key: updates | expand

Commit Message

Patrick Delaunay June 28, 2021, 12:55 p.m. UTC
Handle errors in fuse_hash_value function.

Signed-off-by: Patrick Delaunay <patrick.delaunay@foss.st.com>
---

 arch/arm/mach-stm32mp/cmd_stm32key.c | 24 +++++++++++++++---------
 1 file changed, 15 insertions(+), 9 deletions(-)

Comments

Patrice CHOTARD July 1, 2021, 7:35 a.m. UTC | #1
Hi Patrick

On 6/28/21 2:55 PM, Patrick Delaunay wrote:
> Handle errors in fuse_hash_value function.
> 
> Signed-off-by: Patrick Delaunay <patrick.delaunay@foss.st.com>
> ---
> 
>  arch/arm/mach-stm32mp/cmd_stm32key.c | 24 +++++++++++++++---------
>  1 file changed, 15 insertions(+), 9 deletions(-)
> 
> diff --git a/arch/arm/mach-stm32mp/cmd_stm32key.c b/arch/arm/mach-stm32mp/cmd_stm32key.c
> index d2045a5983..2529139ebc 100644
> --- a/arch/arm/mach-stm32mp/cmd_stm32key.c
> +++ b/arch/arm/mach-stm32mp/cmd_stm32key.c
> @@ -25,7 +25,7 @@ static void read_hash_value(u32 addr)
>  	}
>  }
>  
> -static void fuse_hash_value(u32 addr, bool print)
> +static int fuse_hash_value(u32 addr, bool print)
>  {
>  	struct udevice *dev;
>  	u32 word, val;
> @@ -36,21 +36,25 @@ static void fuse_hash_value(u32 addr, bool print)
>  					  &dev);
>  	if (ret) {
>  		log_err("Can't find stm32mp_bsec driver\n");
> -		return;
> +		return ret;
>  	}
>  
>  	for (i = 0; i < STM32_OTP_HASH_KEY_SIZE; i++) {
> -		if (print)
> -			printf("Fuse OTP %i : %x\n",
> -			       STM32_OTP_HASH_KEY_START + i,
> -			       __be32_to_cpu(*(u32 *)addr));
> -
>  		word = STM32_OTP_HASH_KEY_START + i;
>  		val = __be32_to_cpu(*(u32 *)addr);
> -		misc_write(dev, STM32_BSEC_OTP(word), &val, 4);
> +		if (print)
> +			printf("Fuse OTP %i : %x\n", word, val);
> +
> +		ret = misc_write(dev, STM32_BSEC_OTP(word), &val, 4);
> +		if (ret != 4) {
> +			log_err("Fuse OTP %i failed\n", word);
> +			return ret;
> +		}
>  
>  		addr += 4;
>  	}
> +
> +	return 0;
>  }
>  
>  static int confirm_prog(void)
> @@ -104,7 +108,9 @@ static int do_stm32key_fuse(struct cmd_tbl *cmdtp, int flag, int argc, char *con
>  	if (!yes && !confirm_prog())
>  		return CMD_RET_FAILURE;
>  
> -	fuse_hash_value(addr, !yes);
> +	if (fuse_hash_value(addr, !yes))
> +		return CMD_RET_FAILURE;
> +
>  	printf("Hash key updated !\n");
>  
>  	return CMD_RET_SUCCESS;
> 
Reviewed-by: Patrice Chotard <patrice.chotard@foss.st.com>

Thanks
Patrice
Patrick Delaunay July 16, 2021, 8:28 a.m. UTC | #2
Hi,

On 6/28/21 2:55 PM, Patrick Delaunay wrote:
> Handle errors in fuse_hash_value function.
>
> Signed-off-by: Patrick Delaunay <patrick.delaunay@foss.st.com>
> ---
>
>   arch/arm/mach-stm32mp/cmd_stm32key.c | 24 +++++++++++++++---------
>   1 file changed, 15 insertions(+), 9 deletions(-)
>

Applied to u-boot-stm/master, thanks!

Regards
Patrick
diff mbox series

Patch

diff --git a/arch/arm/mach-stm32mp/cmd_stm32key.c b/arch/arm/mach-stm32mp/cmd_stm32key.c
index d2045a5983..2529139ebc 100644
--- a/arch/arm/mach-stm32mp/cmd_stm32key.c
+++ b/arch/arm/mach-stm32mp/cmd_stm32key.c
@@ -25,7 +25,7 @@  static void read_hash_value(u32 addr)
 	}
 }
 
-static void fuse_hash_value(u32 addr, bool print)
+static int fuse_hash_value(u32 addr, bool print)
 {
 	struct udevice *dev;
 	u32 word, val;
@@ -36,21 +36,25 @@  static void fuse_hash_value(u32 addr, bool print)
 					  &dev);
 	if (ret) {
 		log_err("Can't find stm32mp_bsec driver\n");
-		return;
+		return ret;
 	}
 
 	for (i = 0; i < STM32_OTP_HASH_KEY_SIZE; i++) {
-		if (print)
-			printf("Fuse OTP %i : %x\n",
-			       STM32_OTP_HASH_KEY_START + i,
-			       __be32_to_cpu(*(u32 *)addr));
-
 		word = STM32_OTP_HASH_KEY_START + i;
 		val = __be32_to_cpu(*(u32 *)addr);
-		misc_write(dev, STM32_BSEC_OTP(word), &val, 4);
+		if (print)
+			printf("Fuse OTP %i : %x\n", word, val);
+
+		ret = misc_write(dev, STM32_BSEC_OTP(word), &val, 4);
+		if (ret != 4) {
+			log_err("Fuse OTP %i failed\n", word);
+			return ret;
+		}
 
 		addr += 4;
 	}
+
+	return 0;
 }
 
 static int confirm_prog(void)
@@ -104,7 +108,9 @@  static int do_stm32key_fuse(struct cmd_tbl *cmdtp, int flag, int argc, char *con
 	if (!yes && !confirm_prog())
 		return CMD_RET_FAILURE;
 
-	fuse_hash_value(addr, !yes);
+	if (fuse_hash_value(addr, !yes))
+		return CMD_RET_FAILURE;
+
 	printf("Hash key updated !\n");
 
 	return CMD_RET_SUCCESS;