imx: spl: fix imx8m secure boot
Subsystems (3)
PATCH 1/1 imx: spl: fix imx8m secure boot
inspired from NXP code:719d665a87c6: ("MLK-20467 imx8m: Fix issue for booting signed image through uuu")
fix loading FIT buffer address to fix position CONFIG_SYS_TEXT_BASE - CONFIG_FIT_EXTERNAL_OFFSET
and fix secure boot on imx8m based boards. Problem was that FIT header and so IVT header too, was loaded to memallocated address. So the ivt header address coded in IVT itself does not fit with the real position.
---
replaces Series:
https://lists.denx.de/pipermail/u-boot/2021-August/457308.html
@Tim: could you please test this version on your hardware?
azure build:
https://dev.azure.com/hs0298/hs/_build/results?buildId=71&view=results
(fetch error for rockchip, but this should be no problem for this
patch. How do I restart one specific job on azure?)
Works on sdcard and QSPI NOR boot on phycore-imx8mp board.
arch/arm/mach-imx/spl.c | 11 +++++++++++ common/spl/spl_fit.c | 7 ++++++- 2 files changed, 17 insertions(+), 1 deletion(-)
arch/arm/mach-imx/spl.c +11 -0
@@ -334,6 +334,17 @@ void board_spl_fit_post_load(const void *fit) }#endif +#if defined(CONFIG_FIT_EXTERNAL_OFFSET ) +void *board_spl_fit_buffer_addr (ulong fit_size,int bl_len) +{ +/* +* use fix position +* TEXT_BASE - FIT_EXTERNAL_OFFSET +*/ +return (void *)((CONFIG_SYS_TEXT_BASE -CONFIG_FIT_EXTERNAL_OFFSET )); +} +#endif +#endif #if defined(CONFIG_MX6 ) && defined(CONFIG_SPL_OS_BOOT )
common/spl/spl_fit.c +6 -1
@@ -538,6 +538,11 @@ static void *spl_get_fit_load_buffer(size_t size)return buf; } +__weak void *board_spl_fit_buffer_addr (ulong fit_size,int sectors,int bl_len) +{ +return spl_get_fit_load_buffer (sectors * bl_len); +} +/* * Weak default function to allow customizing SPL fit loading for load-only * use cases by allowing to skip the parsing/processing of the FIT contents
@@ -631,7 +636,7 @@ static int spl_simple_fit_read(struct spl_fit_info *ctx,* For FIT with external data, data is not loaded in this step. */ sectors =get_aligned_image_size (info, size,0 ); - buf =spl_get_fit_load_buffer (sectors * info->bl_len); + buf =board_spl_fit_buffer_addr (size, sectors, info->bl_len); count = info->read (info, sector, sectors, buf); ctx->fit = buf;
Signature · 1 line
2.31.1
Hi Heiko,
Quoted 42 lines · Heiko Schocher
Caution: EXT Email
inspired from NXP code:
719d665a87c6: ("MLK-20467 imx8m: Fix issue for booting signed image through uuu")fix loading FIT buffer address to fix position
CONFIG_SYS_TEXT_BASE-CONFIG_FIT_EXTERNAL_OFFSETand fix secure boot on imx8m based boards. Problem was that FIT header and so IVT header too, was loaded to memallocated address. So the ivt header address coded in IVT itself does not fit with the real position.
Signed-off-by Heiko Schocher <[email protected]>---
replaces Series:
https://lists.denx.de/pipermail/u-boot/2021-August/457308.html@Tim: could you please test this version on your hardware?
azure build:
https://dev.azure.com/hs0298/hs/_build/results?buildId=71&view=result
s
(fetch error for rockchip, but this should be no problem for this patch. How do I restart one specific job on azure?)Works on sdcard and QSPI NOR boot on phycore-imx8mp board.
arch/arm/mach-imx/spl.c | 11 +++++++++++
common/spl/spl_fit.c | 7 ++++++-2 files changed, 17 insertions(+), 1 deletion(-)arch/arm/mach-imx/spl.c +0
-0@@ -334,6 +334,17 @@ void board_spl_fit_post_load(const void *fit) } #endif
arch/arm/mach-imx/spl.c void board_spl_fit_post_load(const void *fit) · line 345
Quoted 10 lines
arch/arm/mach-imx/spl.c +8
-0+#if defined(CONFIG_FIT_EXTERNAL_OFFSET ) +void *board_spl_fit_buffer_addr (ulong fit_size,int bl_len) +{ + /* + * use fix position + * TEXT_BASE - FIT_EXTERNAL_OFFSET + */ + return (void *)((CONFIG_SYS_TEXT_BASE - CONFIG_FIT_EXTERNAL_OFFSET));
It looks odd to use CONFIG_FIT_EXTERNAL_OFFSET. This config is used to designate the image offset inside the FIT. It is irrelevant here. Please follow the patch 719d665a87c6: ("MLK-20467 imx8m: Fix issue for booting signed image through uuu") to fix the issue, which also keep the HAB block aligned.
Best regards,
Ye Li
Quoted 40 lines
arch/arm/mach-imx/spl.c +3
-0+} +#endif + #endif#if
defined(CONFIG_MX6)&&defined(CONFIG_SPL_OS_BOOT)common/spl/spl_fit.c +5
-0@@ -538,6 +538,11 @@ static void *spl_get_fit_load_buffer(size_t size) return buf; } +__weak void *board_spl_fit_buffer_addr (ulong fit_size,int sectors,int bl_len) +{ + return spl_get_fit_load_buffer(sectors * bl_len); +} + /** Weak default function to allow customizing SPL fit loading for load-only
* use cases by allowing to skip the parsing/processing of the FIT contentscommon/spl/spl_fit.c +0
-0@@ -631,7 +636,7 @@ static int spl_simple_fit_read(structspl_fit_info *ctx, * For FIT with external data, data is not loaded in thisstep.
*/
sectors =get_aligned_image_size(info, size, 0);
- buf =spl_get_fit_load_buffer(sectors * info->bl_len); + buf =board_spl_fit_buffer_addr(size, sectors, info->bl_len);count =
info->read(info, sector, sectors, buf);ctx->fit= buf;
--
2.31.1
Hello Li,
Quoted 46 lines · Ye Li
Hi Heiko,
Quoted 43 lines · Heiko Schocher
Caution: EXT Email
inspired from NXP code:
719d665a87c6: ("MLK-20467 imx8m: Fix issue for booting signed image through uuu")fix loading FIT buffer address to fix position
CONFIG_SYS_TEXT_BASE-CONFIG_FIT_EXTERNAL_OFFSETand fix secure boot on imx8m based boards. Problem was that FIT header and so IVT header too, was loaded to memallocated address. So the ivt header address coded in IVT itself does not fit with the real position.
Signed-off-by Heiko Schocher <[email protected]>---
replaces Series:
https://lists.denx.de/pipermail/u-boot/2021-August/457308.html@Tim: could you please test this version on your hardware?
azure build:
https://dev.azure.com/hs0298/hs/_build/results?buildId=71&view=result
s
(fetch error for rockchip, but this should be no problem for this patch. How do I restart one specific job on azure?)Works on sdcard and QSPI NOR boot on phycore-imx8mp board.
arch/arm/mach-imx/spl.c | 11 +++++++++++
common/spl/spl_fit.c | 7 ++++++-2 files changed, 17 insertions(+), 1 deletion(-)arch/arm/mach-imx/spl.c +0
-0@@ -334,6 +334,17 @@ void board_spl_fit_post_load(const void *fit) } #endif
Quoted 15 lines
arch/arm/mach-imx/spl.c void board_spl_fit_post_load(const void *fit)
Quoted 9 lines
arch/arm/mach-imx/spl.c +8
-0+#if defined(CONFIG_FIT_EXTERNAL_OFFSET ) +void *board_spl_fit_buffer_addr (ulong fit_size,int bl_len) +{ + /* + * use fix position + * TEXT_BASE - FIT_EXTERNAL_OFFSET + */ + return (void *)((CONFIG_SYS_TEXT_BASE - CONFIG_FIT_EXTERNAL_OFFSET));It looks odd to use CONFIG_FIT_EXTERNAL_OFFSET. This config is used to designate the image offset inside the FIT. It is irrelevant here. Please follow the patch
719d665a87c6: ("MLK-20467 imx8m: Fix issue for booting signed image through uuu") to fix the issue, which also keep the HAB block aligned.
Hmm.. ok, I can change...
bye,
Heiko
Quoted 43 lines
Best regards,
Ye LiQuoted 39 lines
arch/arm/mach-imx/spl.c +3
-0+} +#endif + #endif#if
defined(CONFIG_MX6)&&defined(CONFIG_SPL_OS_BOOT)common/spl/spl_fit.c +5
-0@@ -538,6 +538,11 @@ static void *spl_get_fit_load_buffer(size_t size) return buf; } +__weak void *board_spl_fit_buffer_addr (ulong fit_size,int sectors,int bl_len) +{ + return spl_get_fit_load_buffer(sectors * bl_len); +} + /** Weak default function to allow customizing SPL fit loading for load-only
* use cases by allowing to skip the parsing/processing of the FIT contentscommon/spl/spl_fit.c +0
-0@@ -631,7 +636,7 @@ static int spl_simple_fit_read(structspl_fit_info *ctx, * For FIT with external data, data is not loaded in thisstep.
*/
sectors =get_aligned_image_size(info, size, 0);
- buf =spl_get_fit_load_buffer(sectors * info->bl_len); + buf =board_spl_fit_buffer_addr(size, sectors, info->bl_len);count =
info->read(info, sector, sectors, buf);ctx->fit= buf;
--
2.31.1
Signature · 3 lines
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: +49-8142-66989-52 Fax: +49-8142-66989-80 Email: [email protected]