diff mbox series

[1/4] imx: hab: Add routine to set HAB IVT address

Message ID 1520616949-11879-2-git-send-email-bryan.odonoghue@linaro.org
State New
Headers show
Series imx: hab: Add helper functions for scripted HAB auth | expand

Commit Message

Bryan O'Donoghue March 9, 2018, 5:35 p.m. UTC
This patch takes a given address applies a plus or minus offset to locate
the putative address of an IVT given a non-IVT link location.

It then sets hab_ivt_address to allow for further logic/scripting based on
the calculated address.

This routine is useful when scripting hab_auth_img calls from boot.scr.
Subsequent patches will illustrate its utility in a board-port.

Signed-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
Cc: Utkarsh Gupta <utkarsh.gupta@nxp.com>
Cc: Breno Lima <breno.lima@nxp.com>
Cc: Fabio Estevam <fabio.estevam@nxp.com>
---
 arch/arm/mach-imx/hab.c | 33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)

Comments

Breno Matheus Lima March 15, 2018, 4:37 p.m. UTC | #1
Hi Bryan,

2018-03-09 14:35 GMT-03:00 Bryan O'Donoghue <bryan.odonoghue@linaro.org>:
> This patch takes a given address applies a plus or minus offset to locate
> the putative address of an IVT given a non-IVT link location.
>
> It then sets hab_ivt_address to allow for further logic/scripting based on
> the calculated address.
>
> This routine is useful when scripting hab_auth_img calls from boot.scr.
> Subsequent patches will illustrate its utility in a board-port.
>
> Signed-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
> Cc: Utkarsh Gupta <utkarsh.gupta@nxp.com>
> Cc: Breno Lima <breno.lima@nxp.com>
> Cc: Fabio Estevam <fabio.estevam@nxp.com>

Tested-by: <breno.lima@nxp.com>

Thanks,
Breno Lima
Lothar Waßmann March 16, 2018, 8:17 a.m. UTC | #2
Hi,

On Fri,  9 Mar 2018 17:35:46 +0000 Bryan O'Donoghue wrote:
> This patch takes a given address applies a plus or minus offset to locate
> the putative address of an IVT given a non-IVT link location.
> 
> It then sets hab_ivt_address to allow for further logic/scripting based on
> the calculated address.
> 
> This routine is useful when scripting hab_auth_img calls from boot.scr.
> Subsequent patches will illustrate its utility in a board-port.
> 
> Signed-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
> Cc: Utkarsh Gupta <utkarsh.gupta@nxp.com>
> Cc: Breno Lima <breno.lima@nxp.com>
> Cc: Fabio Estevam <fabio.estevam@nxp.com>
> ---
>  arch/arm/mach-imx/hab.c | 33 +++++++++++++++++++++++++++++++++
>  1 file changed, 33 insertions(+)
> 
> diff --git a/arch/arm/mach-imx/hab.c b/arch/arm/mach-imx/hab.c
> index c730c8f..0c18b2e 100644
> --- a/arch/arm/mach-imx/hab.c
> +++ b/arch/arm/mach-imx/hab.c
> @@ -341,6 +341,31 @@ static int do_hab_failsafe(cmd_tbl_t *cmdtp, int flag, int argc,
>  	return 0;
>  }
>  
> +/*
> + * This routine takes a given address and applies a plus or minus offset to that
> + * address.
> + */
> +static int do_hab_get_ivt_addr(cmd_tbl_t *cmdtp, int flag, int argc,
> +			       char * const argv[])
> +{
> +	ulong	addr;
> +	long	ivt_offset;
> +
> +	if (argc < 3)
> +		return CMD_RET_USAGE;
> +
> +	if (!imx_hab_is_enabled())
> +		return CMD_RET_FAILURE;
> +
> +	addr = simple_strtoul(argv[1], NULL, 16);
> +	ivt_offset = simple_strtol(argv[2], NULL, 16);
> +	addr += ivt_offset;
> +
> +	env_set_hex("hab_ivt_addr", addr);
> +
> +	return CMD_RET_SUCCESS;
> +}
> +
>  U_BOOT_CMD(
>  		hab_status, CONFIG_SYS_MAXARGS, 1, do_hab_status,
>  		"display HAB status",
>
What does this function offer, that a
'setexpr hab_ivt_addr ${loadaddr} + 0x400' could not do as well?


Lothar Waßmann
Bryan O'Donoghue March 17, 2018, 10:55 a.m. UTC | #3
On 16/03/18 08:17, Lothar Waßmann wrote:
> 'setexpr hab_ivt_addr ${loadaddr} + 0x400' could not do as well?

That might work too. I'll check.
diff mbox series

Patch

diff --git a/arch/arm/mach-imx/hab.c b/arch/arm/mach-imx/hab.c
index c730c8f..0c18b2e 100644
--- a/arch/arm/mach-imx/hab.c
+++ b/arch/arm/mach-imx/hab.c
@@ -341,6 +341,31 @@  static int do_hab_failsafe(cmd_tbl_t *cmdtp, int flag, int argc,
 	return 0;
 }
 
+/*
+ * This routine takes a given address and applies a plus or minus offset to that
+ * address.
+ */
+static int do_hab_get_ivt_addr(cmd_tbl_t *cmdtp, int flag, int argc,
+			       char * const argv[])
+{
+	ulong	addr;
+	long	ivt_offset;
+
+	if (argc < 3)
+		return CMD_RET_USAGE;
+
+	if (!imx_hab_is_enabled())
+		return CMD_RET_FAILURE;
+
+	addr = simple_strtoul(argv[1], NULL, 16);
+	ivt_offset = simple_strtol(argv[2], NULL, 16);
+	addr += ivt_offset;
+
+	env_set_hex("hab_ivt_addr", addr);
+
+	return CMD_RET_SUCCESS;
+}
+
 U_BOOT_CMD(
 		hab_status, CONFIG_SYS_MAXARGS, 1, do_hab_status,
 		"display HAB status",
@@ -362,6 +387,14 @@  U_BOOT_CMD(
 		""
 	  );
 
+U_BOOT_CMD(
+		hab_get_ivt_addr, 3, 0, do_hab_get_ivt_addr,
+		"determine IVT header location and store in $hab_ivt_addr",
+		"addr ivt_offset\n"
+		"addr - image hex address\n"
+		"ivt_offset - hex offset of IVT in the image"
+	  );
+
 #endif /* !defined(CONFIG_SPL_BUILD) */
 
 /* Get CSF Header length */