mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 0/8] i.MX8 EVK patches
@ 2019-08-22 12:51 Sascha Hauer
  2019-08-22 12:51 ` [PATCH 1/8] ARM: aarch64: Fixup relocation table for the second relocation Sascha Hauer
                   ` (8 more replies)
  0 siblings, 9 replies; 20+ messages in thread
From: Sascha Hauer @ 2019-08-22 12:51 UTC (permalink / raw)
  To: Barebox List

Here are several patches for ARM aarch64 in general and more
specifically for the i.MX8 EVK which currently is not bootable.
Currently relocation on ARM aarch64 doesn't work correctly and
the i.MX8 EVK code exploits some of the oddities for its boot
process. This series aims to fix that up.

Sascha

Sascha Hauer (8):
  ARM: aarch64: Fixup relocation table for the second relocation
  ARM: aarch64: Fix get_runtime_offset after relocation
  pbl: Move piggy verification into pbl_barebox_uncompress()
  ARM: i.MX: imx8-ddrc: Remove debug code
  ARM: nxp-imx8mq-evk: Remove duplicate call to
    imx8mq_cpu_lowlevel_init()
  ARM: nxp-imx8mq-evk: Replace trampoline
  ARM: i.MX8: Fix piggydata loading
  ARM: nxp-imx8mq-evk: Update comments

 arch/arm/boards/nxp-imx8mq-evk/Makefile     |  2 +-
 arch/arm/boards/nxp-imx8mq-evk/lowlevel.c   | 38 +++++----------------
 arch/arm/boards/nxp-imx8mq-evk/trampoline.S | 10 ------
 arch/arm/cpu/common.c                       |  2 ++
 arch/arm/cpu/uncompress.c                   | 17 +--------
 arch/arm/lib64/runtime-offset.S             | 18 ++--------
 arch/arm/mach-imx/imx8-ddrc.c               | 20 ++---------
 drivers/mci/imx-esdhc-pbl.c                 | 21 +++++++-----
 pbl/decomp.c                                | 17 +++++++++
 9 files changed, 48 insertions(+), 97 deletions(-)
 delete mode 100644 arch/arm/boards/nxp-imx8mq-evk/trampoline.S

-- 
2.20.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 20+ messages in thread

* [PATCH 1/8] ARM: aarch64: Fixup relocation table for the second relocation
  2019-08-22 12:51 [PATCH 0/8] i.MX8 EVK patches Sascha Hauer
@ 2019-08-22 12:51 ` Sascha Hauer
  2019-08-22 13:09   ` Rouven Czerwinski
  2019-08-22 12:51 ` [PATCH 2/8] ARM: aarch64: Fix get_runtime_offset after relocation Sascha Hauer
                   ` (7 subsequent siblings)
  8 siblings, 1 reply; 20+ messages in thread
From: Sascha Hauer @ 2019-08-22 12:51 UTC (permalink / raw)
  To: Barebox List

In case we want to relocate the binary multiple times we have to
adjust the relocation table itself for any further relocations.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 arch/arm/cpu/common.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/arch/arm/cpu/common.c b/arch/arm/cpu/common.c
index 4d957da1dc..c81b2b3791 100644
--- a/arch/arm/cpu/common.c
+++ b/arch/arm/cpu/common.c
@@ -84,6 +84,8 @@ void relocate_to_current_adr(void)
 			unsigned long *fixup = (unsigned long *)(rel->r_offset + offset);
 
 			*fixup = rel->r_addend + offset;
+			rel->r_addend += offset;
+			rel->r_offset += offset;
 		} else {
 			putc_ll('>');
 			puthex_ll(rel->r_info);
-- 
2.20.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 20+ messages in thread

* [PATCH 2/8] ARM: aarch64: Fix get_runtime_offset after relocation
  2019-08-22 12:51 [PATCH 0/8] i.MX8 EVK patches Sascha Hauer
  2019-08-22 12:51 ` [PATCH 1/8] ARM: aarch64: Fixup relocation table for the second relocation Sascha Hauer
@ 2019-08-22 12:51 ` Sascha Hauer
  2019-08-22 13:08   ` Rouven Czerwinski
  2019-08-22 20:14   ` Andrey Smirnov
  2019-08-22 12:51 ` [PATCH 3/8] pbl: Move piggy verification into pbl_barebox_uncompress() Sascha Hauer
                   ` (6 subsequent siblings)
  8 siblings, 2 replies; 20+ messages in thread
From: Sascha Hauer @ 2019-08-22 12:51 UTC (permalink / raw)
  To: Barebox List

get_runtime_offset shall return the offset between the address we are
running at and the address we are linked at. This value obviously
changes when we relocate the binary. cf3b09737b tried to avoid using
R_AARCH64_RELATIVE relocations, but in fact this is exactly what the
function needs to work. Consider barebox starting at 0x10000000
when we are linked at 0x0 then get_runtime_offset() should return
0x10000000 before relocate_to_current_adr(), but afterwards it should
return 0x0.

This patch brings back the previously removed "a" flag. Since gcc5
doesn't put the values of R_AARCH64_RELATIVE fixup'd relocations
into the binary but zeroes instead, we help ourselves by basing
get_runtime_offset on an address which actually is zero. With
CONFIG_RELOCATABLE=y the binary is always linked to 0x0, so _text
is initially zero.

Tested with gcc-5.4.0 (which was "fixed" by cf3b09737b) and gcc-8.2.1.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 arch/arm/lib64/runtime-offset.S | 18 +++---------------
 1 file changed, 3 insertions(+), 15 deletions(-)

diff --git a/arch/arm/lib64/runtime-offset.S b/arch/arm/lib64/runtime-offset.S
index 6624fdfa15..d1b8bdac3c 100644
--- a/arch/arm/lib64/runtime-offset.S
+++ b/arch/arm/lib64/runtime-offset.S
@@ -1,31 +1,19 @@
 #include <linux/linkage.h>
 #include <asm/assembler.h>
 
-/*
- * The .section directive below intentionally omits "a", since that
- * appears to be the simplest way to force assembler to not generate
- * R_AARCH64_RELATIVE relocation for
- *
- * linkadr:
- *	.quad get_runtime_offset
- *
- * statement below. While having that relocating was relatively
- * harmless with GCC8, builging the code with GCC5 resulted in
- * "linkaddr" being initialized to 0 causing complete boot breakdown
- */
-.section ".text_bare_init","x"
+.section ".text_bare_init","ax"
 
 /*
  * Get the offset between the link address and the address
  * we are currently running at.
  */
 ENTRY(get_runtime_offset)
-1:	adr x0, 1b
+1:	adr x0, _text
 	ldr x1, linkadr
 	subs x0, x0, x1
 	ret
 
 .align 3
 linkadr:
-.quad get_runtime_offset
+.quad _text
 ENDPROC(get_runtime_offset)
-- 
2.20.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 20+ messages in thread

* [PATCH 3/8] pbl: Move piggy verification into pbl_barebox_uncompress()
  2019-08-22 12:51 [PATCH 0/8] i.MX8 EVK patches Sascha Hauer
  2019-08-22 12:51 ` [PATCH 1/8] ARM: aarch64: Fixup relocation table for the second relocation Sascha Hauer
  2019-08-22 12:51 ` [PATCH 2/8] ARM: aarch64: Fix get_runtime_offset after relocation Sascha Hauer
@ 2019-08-22 12:51 ` Sascha Hauer
  2019-08-22 13:07   ` Rouven Czerwinski
  2019-08-22 12:51 ` [PATCH 4/8] ARM: i.MX: imx8-ddrc: Remove debug code Sascha Hauer
                   ` (5 subsequent siblings)
  8 siblings, 1 reply; 20+ messages in thread
From: Sascha Hauer @ 2019-08-22 12:51 UTC (permalink / raw)
  To: Barebox List

piggy verification is a direct prerequisite of uncompressing the
piggydata, so move the verification there.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 arch/arm/cpu/uncompress.c | 17 +----------------
 pbl/decomp.c              | 17 +++++++++++++++++
 2 files changed, 18 insertions(+), 16 deletions(-)

diff --git a/arch/arm/cpu/uncompress.c b/arch/arm/cpu/uncompress.c
index 9cc3b358b0..4f16af22f8 100644
--- a/arch/arm/cpu/uncompress.c
+++ b/arch/arm/cpu/uncompress.c
@@ -42,18 +42,14 @@ unsigned long free_mem_end_ptr;
 extern unsigned char input_data[];
 extern unsigned char input_data_end[];
 
-extern unsigned char sha_sum[];
-extern unsigned char sha_sum_end[];
-
 void __noreturn barebox_multi_pbl_start(unsigned long membase,
 		unsigned long memsize, void *boarddata)
 {
-	uint32_t pg_len, uncompressed_len, pbl_hash_len;
+	uint32_t pg_len, uncompressed_len;
 	void __noreturn (*barebox)(unsigned long, unsigned long, void *);
 	unsigned long endmem = membase + memsize;
 	unsigned long barebox_base;
 	void *pg_start, *pg_end;
-	void *pbl_hash_start, *pbl_hash_end;
 	unsigned long pc = get_pc();
 
 	pg_start = input_data + global_variable_offset();
@@ -96,17 +92,6 @@ void __noreturn barebox_multi_pbl_start(unsigned long membase,
 	pr_debug("uncompressing barebox binary at 0x%p (size 0x%08x) to 0x%08lx (uncompressed size: 0x%08x)\n",
 			pg_start, pg_len, barebox_base, uncompressed_len);
 
-	if (IS_ENABLED(CONFIG_PBL_VERIFY_PIGGY)) {
-		pbl_hash_start = sha_sum;
-		pbl_hash_end = sha_sum_end;
-		pbl_hash_len = pbl_hash_end - pbl_hash_start;
-		if (pbl_barebox_verify(pg_start, pg_len, pbl_hash_start,
-				       pbl_hash_len) != 0) {
-			putc_ll('!');
-			panic("hash mismatch, refusing to decompress");
-		}
-	}
-
 	pbl_barebox_uncompress((void*)barebox_base, pg_start, pg_len);
 
 	sync_caches_for_execution();
diff --git a/pbl/decomp.c b/pbl/decomp.c
index ef713a6c74..8767f9fa7e 100644
--- a/pbl/decomp.c
+++ b/pbl/decomp.c
@@ -51,8 +51,25 @@ static void noinline errorfn(char *error)
 	while (1);
 }
 
+extern unsigned char sha_sum[];
+extern unsigned char sha_sum_end[];
+
 void pbl_barebox_uncompress(void *dest, void *compressed_start, unsigned int len)
 {
+	uint32_t pbl_hash_len;
+	void *pbl_hash_start, *pbl_hash_end;
+
+	if (IS_ENABLED(CONFIG_PBL_VERIFY_PIGGY)) {
+		pbl_hash_start = sha_sum;
+		pbl_hash_end = sha_sum_end;
+		pbl_hash_len = pbl_hash_end - pbl_hash_start;
+		if (pbl_barebox_verify(compressed_start, len, pbl_hash_start,
+				       pbl_hash_len) != 0) {
+			putc_ll('!');
+			panic("hash mismatch, refusing to decompress");
+		}
+	}
+
 	decompress((void *)compressed_start,
 			len,
 			NULL, NULL,
-- 
2.20.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 20+ messages in thread

* [PATCH 4/8] ARM: i.MX: imx8-ddrc: Remove debug code
  2019-08-22 12:51 [PATCH 0/8] i.MX8 EVK patches Sascha Hauer
                   ` (2 preceding siblings ...)
  2019-08-22 12:51 ` [PATCH 3/8] pbl: Move piggy verification into pbl_barebox_uncompress() Sascha Hauer
@ 2019-08-22 12:51 ` Sascha Hauer
  2019-08-22 13:04   ` Rouven Czerwinski
  2019-08-22 12:51 ` [PATCH 5/8] ARM: nxp-imx8mq-evk: Remove duplicate call to imx8mq_cpu_lowlevel_init() Sascha Hauer
                   ` (4 subsequent siblings)
  8 siblings, 1 reply; 20+ messages in thread
From: Sascha Hauer @ 2019-08-22 12:51 UTC (permalink / raw)
  To: Barebox List

various puthex_ll() printed values without any context are not helpful when
debugging unrelated stuff, so remove them. When they are really needed
they should be added with proper pr_debug() statements.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 arch/arm/mach-imx/imx8-ddrc.c | 20 ++------------------
 1 file changed, 2 insertions(+), 18 deletions(-)

diff --git a/arch/arm/mach-imx/imx8-ddrc.c b/arch/arm/mach-imx/imx8-ddrc.c
index 736865eb6f..8bb2672102 100644
--- a/arch/arm/mach-imx/imx8-ddrc.c
+++ b/arch/arm/mach-imx/imx8-ddrc.c
@@ -69,15 +69,8 @@ static void ddrc_phy_fetch_streaming_message(void __iomem *phy)
 	const u16 index = ddrc_phy_get_message(phy, PMC_MESSAGE_STREAM);
 	u16 i;
 
-	putc_ll('|');
-	puthex_ll(index);
-
-	for (i = 0; i < index; i++) {
-		const u32 arg = ddrc_phy_get_message(phy, PMC_MESSAGE_STREAM);
-
-		putc_ll('|');
-		puthex_ll(arg);
-	}
+	for (i = 0; i < index; i++)
+		ddrc_phy_get_message(phy, PMC_MESSAGE_STREAM);
 }
 
 void ddrc_phy_wait_training_complete(void __iomem *phy)
@@ -85,23 +78,14 @@ void ddrc_phy_wait_training_complete(void __iomem *phy)
 	for (;;) {
 		const u32 m = ddrc_phy_get_message(phy, PMC_MESSAGE_ID);
 
-		puthex_ll(m);
-
 		switch (m) {
 		case PMC_TRAIN_STREAM_START:
 			ddrc_phy_fetch_streaming_message(phy);
 			break;
 		case PMC_TRAIN_SUCCESS:
-			putc_ll('P');
-			putc_ll('\r');
-			putc_ll('\n');
 			return;
 		case PMC_TRAIN_FAIL:
-			putc_ll('F');
 			hang();
 		}
-
-		putc_ll('\r');
-		putc_ll('\n');
 	}
 }
-- 
2.20.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 20+ messages in thread

* [PATCH 5/8] ARM: nxp-imx8mq-evk: Remove duplicate call to imx8mq_cpu_lowlevel_init()
  2019-08-22 12:51 [PATCH 0/8] i.MX8 EVK patches Sascha Hauer
                   ` (3 preceding siblings ...)
  2019-08-22 12:51 ` [PATCH 4/8] ARM: i.MX: imx8-ddrc: Remove debug code Sascha Hauer
@ 2019-08-22 12:51 ` Sascha Hauer
  2019-08-22 13:03   ` Rouven Czerwinski
  2019-08-22 12:51 ` [PATCH 6/8] ARM: nxp-imx8mq-evk: Replace trampoline Sascha Hauer
                   ` (3 subsequent siblings)
  8 siblings, 1 reply; 20+ messages in thread
From: Sascha Hauer @ 2019-08-22 12:51 UTC (permalink / raw)
  To: Barebox List

imx8mq_cpu_lowlevel_init() is called twice. Remove the second call.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 arch/arm/boards/nxp-imx8mq-evk/lowlevel.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/arch/arm/boards/nxp-imx8mq-evk/lowlevel.c b/arch/arm/boards/nxp-imx8mq-evk/lowlevel.c
index a74171e5e5..cb1c499cb0 100644
--- a/arch/arm/boards/nxp-imx8mq-evk/lowlevel.c
+++ b/arch/arm/boards/nxp-imx8mq-evk/lowlevel.c
@@ -105,8 +105,6 @@ static __noreturn noinline void nxp_imx8mq_evk_start(void)
 	const u8 *bl31;
 	size_t bl31_size;
 
-	imx8mq_cpu_lowlevel_init();
-
 	if (IS_ENABLED(CONFIG_DEBUG_LL))
 		setup_uart();
 
-- 
2.20.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 20+ messages in thread

* [PATCH 6/8] ARM: nxp-imx8mq-evk: Replace trampoline
  2019-08-22 12:51 [PATCH 0/8] i.MX8 EVK patches Sascha Hauer
                   ` (4 preceding siblings ...)
  2019-08-22 12:51 ` [PATCH 5/8] ARM: nxp-imx8mq-evk: Remove duplicate call to imx8mq_cpu_lowlevel_init() Sascha Hauer
@ 2019-08-22 12:51 ` Sascha Hauer
  2019-08-22 13:03   ` Rouven Czerwinski
  2019-08-22 12:51 ` [PATCH 7/8] ARM: i.MX8: Fix piggydata loading Sascha Hauer
                   ` (2 subsequent siblings)
  8 siblings, 1 reply; 20+ messages in thread
From: Sascha Hauer @ 2019-08-22 12:51 UTC (permalink / raw)
  To: Barebox List

When the TF-A finishes it jumps to a hardcoded address in DRAM. We used
to put a trampoline there which brings us back to our image in SRAM.
Instead of putting a trampoline into DRAM just copy the image there
which simplifies things a bit.

Note that currently imx8_esdhc_load_piggy() uses that very same address
as a temporary buffer. This is changed in the next patch. Currently the
board is broken anyway, so we don't break bisectability.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 arch/arm/boards/nxp-imx8mq-evk/Makefile     |  2 +-
 arch/arm/boards/nxp-imx8mq-evk/lowlevel.c   | 27 ++++-----------------
 arch/arm/boards/nxp-imx8mq-evk/trampoline.S | 10 --------
 3 files changed, 6 insertions(+), 33 deletions(-)
 delete mode 100644 arch/arm/boards/nxp-imx8mq-evk/trampoline.S

diff --git a/arch/arm/boards/nxp-imx8mq-evk/Makefile b/arch/arm/boards/nxp-imx8mq-evk/Makefile
index 7907de411f..2995f06f0f 100644
--- a/arch/arm/boards/nxp-imx8mq-evk/Makefile
+++ b/arch/arm/boards/nxp-imx8mq-evk/Makefile
@@ -1,2 +1,2 @@
 obj-y += board.o
-lwl-y += lowlevel.o ddr_init.o ddrphy_train.o trampoline.o
+lwl-y += lowlevel.o ddr_init.o ddrphy_train.o
diff --git a/arch/arm/boards/nxp-imx8mq-evk/lowlevel.c b/arch/arm/boards/nxp-imx8mq-evk/lowlevel.c
index cb1c499cb0..46dba16ec3 100644
--- a/arch/arm/boards/nxp-imx8mq-evk/lowlevel.c
+++ b/arch/arm/boards/nxp-imx8mq-evk/lowlevel.c
@@ -56,27 +56,6 @@ static void nxp_imx8mq_evk_sram_setup(void)
 	ddr_init();
 }
 
-extern unsigned char trampoline_start[];
-extern unsigned char trampoline_end[];
-
-static void nxp_imx8mq_evk_install_tfa_trampoline(void)
-{
-	unsigned int tramp_len;
-	unsigned int offset;
-	/*
-	 * Create a trampoline which is places in DRAM and calls back into the
-	 * PBL entry function found in the TCRAM. Register x0 is set to 1 to
-	 * indicate that DRAM setup was already run.
-	 */
-	tramp_len = (void *)trampoline_end - (void *)trampoline_start;
-	memcpy((void *)MX8MQ_ATF_BL33_BASE_ADDR, (void *)trampoline_start,
-	       tramp_len);
-
-	offset = get_runtime_offset();
-	memcpy((void *)MX8MQ_ATF_BL33_BASE_ADDR + tramp_len, &offset,
-	       sizeof(offset));
-}
-
 /*
  * Power-on execution flow of start_nxp_imx8mq_evk() might not be
  * obvious for a very first read, so here's, hopefully helpful,
@@ -117,8 +96,12 @@ static __noreturn noinline void nxp_imx8mq_evk_start(void)
 	 */
 	if (current_el() == 3) {
 		nxp_imx8mq_evk_sram_setup();
-		nxp_imx8mq_evk_install_tfa_trampoline();
 		get_builtin_firmware(imx8mq_bl31_bin, &bl31, &bl31_size);
+		/*
+		 * On completion the TF-A will jump to MX8MQ_ATF_BL33_BASE_ADDR in
+		 * EL2. Copy ourselves there.
+		 */
+		memcpy((void *)MX8MQ_ATF_BL33_BASE_ADDR, _text, __bss_start - _text);
 		imx8mq_atf_load_bl31(bl31, bl31_size);
 	}
 
diff --git a/arch/arm/boards/nxp-imx8mq-evk/trampoline.S b/arch/arm/boards/nxp-imx8mq-evk/trampoline.S
deleted file mode 100644
index 54a1b76518..0000000000
--- a/arch/arm/boards/nxp-imx8mq-evk/trampoline.S
+++ /dev/null
@@ -1,10 +0,0 @@
-/* SPDX-License-Identifier: (GPL-2.0) */
-#include <linux/linkage.h>
-#include <asm/sections.h>
-	.section .trampoline,"a"
-	.globl  trampoline_start
-trampoline_start:
-	ldr	w19, trampoline_end
-	br      x19
-	.globl  trampoline_end
-trampoline_end:
-- 
2.20.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 20+ messages in thread

* [PATCH 7/8] ARM: i.MX8: Fix piggydata loading
  2019-08-22 12:51 [PATCH 0/8] i.MX8 EVK patches Sascha Hauer
                   ` (5 preceding siblings ...)
  2019-08-22 12:51 ` [PATCH 6/8] ARM: nxp-imx8mq-evk: Replace trampoline Sascha Hauer
@ 2019-08-22 12:51 ` Sascha Hauer
  2019-08-22 13:02   ` Rouven Czerwinski
  2019-08-22 12:51 ` [PATCH 8/8] ARM: nxp-imx8mq-evk: Update comments Sascha Hauer
  2019-08-22 13:19 ` [PATCH 0/8] i.MX8 EVK patches Rouven Czerwinski
  8 siblings, 1 reply; 20+ messages in thread
From: Sascha Hauer @ 2019-08-22 12:51 UTC (permalink / raw)
  To: Barebox List

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/mci/imx-esdhc-pbl.c | 21 +++++++++++++--------
 1 file changed, 13 insertions(+), 8 deletions(-)

diff --git a/drivers/mci/imx-esdhc-pbl.c b/drivers/mci/imx-esdhc-pbl.c
index fb27c84163..aa93af656c 100644
--- a/drivers/mci/imx-esdhc-pbl.c
+++ b/drivers/mci/imx-esdhc-pbl.c
@@ -428,14 +428,12 @@ int imx8_esdhc_start_image(int instance)
 
 int imx8_esdhc_load_piggy(int instance)
 {
-	void *buf = (void *)MX8MQ_ATF_BL33_BASE_ADDR;
+	void *buf, *piggy;
 	struct imx_flash_header_v2 *hdr = NULL;
-	void *bb = 0;
 	struct esdhc esdhc;
 	int ret, len;
 	int offset = SZ_32K;
 
-
 	switch (instance) {
 	case 0:
 		esdhc.regs = IOMEM(MX8MQ_USDHC1_BASE_ADDR);
@@ -450,6 +448,13 @@ int imx8_esdhc_load_piggy(int instance)
 	esdhc.is_be = 0;
 	esdhc.is_mx6 = 1;
 
+	/*
+	 * We expect to be running at MX8MQ_ATF_BL33_BASE_ADDR where the atf
+	 * has jumped to. Use a temporary buffer where we won't overwrite
+	 * ourselves.
+	 */
+	buf = (void *)MX8MQ_ATF_BL33_BASE_ADDR + SZ_32M;
+
 	ret = esdhc_search_header(&esdhc, &hdr, buf, &offset);
 	if (ret)
 		return ret;
@@ -462,13 +467,13 @@ int imx8_esdhc_load_piggy(int instance)
 	/*
 	 * Calculate location of the piggydata at the offset loaded into RAM
 	 */
-	buf = buf + offset + hdr->boot_data.size;
+	piggy = buf + offset + hdr->boot_data.size;
+
 	/*
-	 * Barebox expects the piggydata right behind the PBL in the beginning
-	 * of RAM.
+	 * Copy the piggydata where the uncompressing code expects it
 	 */
-	bb = (void *) MX8MQ_DDR_CSD1_BASE_ADDR + barebox_pbl_size;
-	memcpy(bb, buf, piggydata_size());
+	memcpy(input_data, piggy, piggydata_size());
+
 	return ret;
 }
 #endif
-- 
2.20.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 20+ messages in thread

* [PATCH 8/8] ARM: nxp-imx8mq-evk: Update comments
  2019-08-22 12:51 [PATCH 0/8] i.MX8 EVK patches Sascha Hauer
                   ` (6 preceding siblings ...)
  2019-08-22 12:51 ` [PATCH 7/8] ARM: i.MX8: Fix piggydata loading Sascha Hauer
@ 2019-08-22 12:51 ` Sascha Hauer
  2019-08-22 12:59   ` Rouven Czerwinski
  2019-08-22 13:19 ` [PATCH 0/8] i.MX8 EVK patches Rouven Czerwinski
  8 siblings, 1 reply; 20+ messages in thread
From: Sascha Hauer @ 2019-08-22 12:51 UTC (permalink / raw)
  To: Barebox List

The comments mention contents of register r0, this is outdated. We
base our decisions on the current EL. Update the comments.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 arch/arm/boards/nxp-imx8mq-evk/lowlevel.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/arch/arm/boards/nxp-imx8mq-evk/lowlevel.c b/arch/arm/boards/nxp-imx8mq-evk/lowlevel.c
index 46dba16ec3..9d060fb589 100644
--- a/arch/arm/boards/nxp-imx8mq-evk/lowlevel.c
+++ b/arch/arm/boards/nxp-imx8mq-evk/lowlevel.c
@@ -88,11 +88,9 @@ static __noreturn noinline void nxp_imx8mq_evk_start(void)
 		setup_uart();
 
 	/*
-	 * if register r0 does not contain 1, we are running for the first time
-	 * and need to initialize the DRAM, install the trampoline and run TF-A
-	 * (BL31).
-	 * Otherwise the 1 indicates that the DRAM setup and trampoline are
-	 * already installed and TF-A has been run. In this case we can skip
+	 * If we are in EL3 we are running for the first time and need to
+	 * initialize the DRAM and run TF-A (BL31). The TF-A will then jump
+	 * to DRAM in EL2.
 	 */
 	if (current_el() == 3) {
 		nxp_imx8mq_evk_sram_setup();
@@ -103,6 +101,7 @@ static __noreturn noinline void nxp_imx8mq_evk_start(void)
 		 */
 		memcpy((void *)MX8MQ_ATF_BL33_BASE_ADDR, _text, __bss_start - _text);
 		imx8mq_atf_load_bl31(bl31, bl31_size);
+		/* not reached */
 	}
 
 	imx8_get_boot_source(&src, &instance);
-- 
2.20.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH 8/8] ARM: nxp-imx8mq-evk: Update comments
  2019-08-22 12:51 ` [PATCH 8/8] ARM: nxp-imx8mq-evk: Update comments Sascha Hauer
@ 2019-08-22 12:59   ` Rouven Czerwinski
  0 siblings, 0 replies; 20+ messages in thread
From: Rouven Czerwinski @ 2019-08-22 12:59 UTC (permalink / raw)
  To: Sascha Hauer, Barebox List

On Thu, 2019-08-22 at 14:51 +0200, Sascha Hauer wrote:
> The comments mention contents of register r0, this is outdated. We
> base our decisions on the current EL. Update the comments.
> 
> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
> ---
>  arch/arm/boards/nxp-imx8mq-evk/lowlevel.c | 9 ++++-----
>  1 file changed, 4 insertions(+), 5 deletions(-)
> 
> diff --git a/arch/arm/boards/nxp-imx8mq-evk/lowlevel.c b/arch/arm/boards/nxp-imx8mq-evk/lowlevel.c
> index 46dba16ec3..9d060fb589 100644
> --- a/arch/arm/boards/nxp-imx8mq-evk/lowlevel.c
> +++ b/arch/arm/boards/nxp-imx8mq-evk/lowlevel.c
> @@ -88,11 +88,9 @@ static __noreturn noinline void nxp_imx8mq_evk_start(void)
>  		setup_uart();
>  
>  	/*
> -	 * if register r0 does not contain 1, we are running for the first time
> -	 * and need to initialize the DRAM, install the trampoline and run TF-A
> -	 * (BL31).
> -	 * Otherwise the 1 indicates that the DRAM setup and trampoline are
> -	 * already installed and TF-A has been run. In this case we can skip
> +	 * If we are in EL3 we are running for the first time and need to
> +	 * initialize the DRAM and run TF-A (BL31). The TF-A will then jump
> +	 * to DRAM in EL2.
>  	 */
>  	if (current_el() == 3) {
>  		nxp_imx8mq_evk_sram_setup();
> @@ -103,6 +101,7 @@ static __noreturn noinline void nxp_imx8mq_evk_start(void)
>  		 */
>  		memcpy((void *)MX8MQ_ATF_BL33_BASE_ADDR, _text, __bss_start - _text);
>  		imx8mq_atf_load_bl31(bl31, bl31_size);
> +		/* not reached */
>  	}
>  
>  	imx8_get_boot_source(&src, &instance);

Reviewed-by: Rouven Czerwinski <r.czerwinski@pengutronix.de>

- rcz


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH 7/8] ARM: i.MX8: Fix piggydata loading
  2019-08-22 12:51 ` [PATCH 7/8] ARM: i.MX8: Fix piggydata loading Sascha Hauer
@ 2019-08-22 13:02   ` Rouven Czerwinski
  0 siblings, 0 replies; 20+ messages in thread
From: Rouven Czerwinski @ 2019-08-22 13:02 UTC (permalink / raw)
  To: Sascha Hauer, Barebox List

On Thu, 2019-08-22 at 14:51 +0200, Sascha Hauer wrote:
> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
> ---
>  drivers/mci/imx-esdhc-pbl.c | 21 +++++++++++++--------
>  1 file changed, 13 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/mci/imx-esdhc-pbl.c b/drivers/mci/imx-esdhc-
> pbl.c
> index fb27c84163..aa93af656c 100644
> --- a/drivers/mci/imx-esdhc-pbl.c
> +++ b/drivers/mci/imx-esdhc-pbl.c
> @@ -428,14 +428,12 @@ int imx8_esdhc_start_image(int instance)
>  
>  int imx8_esdhc_load_piggy(int instance)
>  {
> -	void *buf = (void *)MX8MQ_ATF_BL33_BASE_ADDR;
> +	void *buf, *piggy;
>  	struct imx_flash_header_v2 *hdr = NULL;
> -	void *bb = 0;
>  	struct esdhc esdhc;
>  	int ret, len;
>  	int offset = SZ_32K;
>  
> -
>  	switch (instance) {
>  	case 0:
>  		esdhc.regs = IOMEM(MX8MQ_USDHC1_BASE_ADDR);
> @@ -450,6 +448,13 @@ int imx8_esdhc_load_piggy(int instance)
>  	esdhc.is_be = 0;
>  	esdhc.is_mx6 = 1;
>  
> +	/*
> +	 * We expect to be running at MX8MQ_ATF_BL33_BASE_ADDR where
> the atf
> +	 * has jumped to. Use a temporary buffer where we won't
> overwrite
> +	 * ourselves.
> +	 */
> +	buf = (void *)MX8MQ_ATF_BL33_BASE_ADDR + SZ_32M;
> +
>  	ret = esdhc_search_header(&esdhc, &hdr, buf, &offset);
>  	if (ret)
>  		return ret;
> @@ -462,13 +467,13 @@ int imx8_esdhc_load_piggy(int instance)
>  	/*
>  	 * Calculate location of the piggydata at the offset loaded
> into RAM
>  	 */
> -	buf = buf + offset + hdr->boot_data.size;
> +	piggy = buf + offset + hdr->boot_data.size;
> +
>  	/*
> -	 * Barebox expects the piggydata right behind the PBL in the
> beginning
> -	 * of RAM.
> +	 * Copy the piggydata where the uncompressing code expects it
>  	 */
> -	bb = (void *) MX8MQ_DDR_CSD1_BASE_ADDR + barebox_pbl_size;
> -	memcpy(bb, buf, piggydata_size());
> +	memcpy(input_data, piggy, piggydata_size());
> +
>  	return ret;
>  }
>  #endif

Reviewed-by: Rouven Czerwinski <r.czerwinski@pengutronix.de>

- rcz


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH 6/8] ARM: nxp-imx8mq-evk: Replace trampoline
  2019-08-22 12:51 ` [PATCH 6/8] ARM: nxp-imx8mq-evk: Replace trampoline Sascha Hauer
@ 2019-08-22 13:03   ` Rouven Czerwinski
  0 siblings, 0 replies; 20+ messages in thread
From: Rouven Czerwinski @ 2019-08-22 13:03 UTC (permalink / raw)
  To: Sascha Hauer, Barebox List

On Thu, 2019-08-22 at 14:51 +0200, Sascha Hauer wrote:
> When the TF-A finishes it jumps to a hardcoded address in DRAM. We
> used
> to put a trampoline there which brings us back to our image in SRAM.
> Instead of putting a trampoline into DRAM just copy the image there
> which simplifies things a bit.
> 
> Note that currently imx8_esdhc_load_piggy() uses that very same
> address
> as a temporary buffer. This is changed in the next patch. Currently
> the
> board is broken anyway, so we don't break bisectability.
> 
> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
> ---
>  arch/arm/boards/nxp-imx8mq-evk/Makefile     |  2 +-
>  arch/arm/boards/nxp-imx8mq-evk/lowlevel.c   | 27 ++++---------------
> --
>  arch/arm/boards/nxp-imx8mq-evk/trampoline.S | 10 --------
>  3 files changed, 6 insertions(+), 33 deletions(-)
>  delete mode 100644 arch/arm/boards/nxp-imx8mq-evk/trampoline.S
> 
> diff --git a/arch/arm/boards/nxp-imx8mq-evk/Makefile
> b/arch/arm/boards/nxp-imx8mq-evk/Makefile
> index 7907de411f..2995f06f0f 100644
> --- a/arch/arm/boards/nxp-imx8mq-evk/Makefile
> +++ b/arch/arm/boards/nxp-imx8mq-evk/Makefile
> @@ -1,2 +1,2 @@
>  obj-y += board.o
> -lwl-y += lowlevel.o ddr_init.o ddrphy_train.o trampoline.o
> +lwl-y += lowlevel.o ddr_init.o ddrphy_train.o
> diff --git a/arch/arm/boards/nxp-imx8mq-evk/lowlevel.c
> b/arch/arm/boards/nxp-imx8mq-evk/lowlevel.c
> index cb1c499cb0..46dba16ec3 100644
> --- a/arch/arm/boards/nxp-imx8mq-evk/lowlevel.c
> +++ b/arch/arm/boards/nxp-imx8mq-evk/lowlevel.c
> @@ -56,27 +56,6 @@ static void nxp_imx8mq_evk_sram_setup(void)
>  	ddr_init();
>  }
>  
> -extern unsigned char trampoline_start[];
> -extern unsigned char trampoline_end[];
> -
> -static void nxp_imx8mq_evk_install_tfa_trampoline(void)
> -{
> -	unsigned int tramp_len;
> -	unsigned int offset;
> -	/*
> -	 * Create a trampoline which is places in DRAM and calls back
> into the
> -	 * PBL entry function found in the TCRAM. Register x0 is set to
> 1 to
> -	 * indicate that DRAM setup was already run.
> -	 */
> -	tramp_len = (void *)trampoline_end - (void *)trampoline_start;
> -	memcpy((void *)MX8MQ_ATF_BL33_BASE_ADDR, (void
> *)trampoline_start,
> -	       tramp_len);
> -
> -	offset = get_runtime_offset();
> -	memcpy((void *)MX8MQ_ATF_BL33_BASE_ADDR + tramp_len, &offset,
> -	       sizeof(offset));
> -}
> -
>  /*
>   * Power-on execution flow of start_nxp_imx8mq_evk() might not be
>   * obvious for a very first read, so here's, hopefully helpful,
> @@ -117,8 +96,12 @@ static __noreturn noinline void
> nxp_imx8mq_evk_start(void)
>  	 */
>  	if (current_el() == 3) {
>  		nxp_imx8mq_evk_sram_setup();
> -		nxp_imx8mq_evk_install_tfa_trampoline();
>  		get_builtin_firmware(imx8mq_bl31_bin, &bl31,
> &bl31_size);
> +		/*
> +		 * On completion the TF-A will jump to
> MX8MQ_ATF_BL33_BASE_ADDR in
> +		 * EL2. Copy ourselves there.
> +		 */
> +		memcpy((void *)MX8MQ_ATF_BL33_BASE_ADDR, _text,
> __bss_start - _text);
>  		imx8mq_atf_load_bl31(bl31, bl31_size);
>  	}
>  
> diff --git a/arch/arm/boards/nxp-imx8mq-evk/trampoline.S
> b/arch/arm/boards/nxp-imx8mq-evk/trampoline.S
> deleted file mode 100644
> index 54a1b76518..0000000000
> --- a/arch/arm/boards/nxp-imx8mq-evk/trampoline.S
> +++ /dev/null
> @@ -1,10 +0,0 @@
> -/* SPDX-License-Identifier: (GPL-2.0) */
> -#include <linux/linkage.h>
> -#include <asm/sections.h>
> -	.section .trampoline,"a"
> -	.globl  trampoline_start
> -trampoline_start:
> -	ldr	w19, trampoline_end
> -	br      x19
> -	.globl  trampoline_end
> -trampoline_end:

Reviewed-by: Rouven Czerwinski <r.czerwinski@pengutronix.de>

- rcz


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH 5/8] ARM: nxp-imx8mq-evk: Remove duplicate call to imx8mq_cpu_lowlevel_init()
  2019-08-22 12:51 ` [PATCH 5/8] ARM: nxp-imx8mq-evk: Remove duplicate call to imx8mq_cpu_lowlevel_init() Sascha Hauer
@ 2019-08-22 13:03   ` Rouven Czerwinski
  0 siblings, 0 replies; 20+ messages in thread
From: Rouven Czerwinski @ 2019-08-22 13:03 UTC (permalink / raw)
  To: Sascha Hauer, Barebox List

On Thu, 2019-08-22 at 14:51 +0200, Sascha Hauer wrote:
> imx8mq_cpu_lowlevel_init() is called twice. Remove the second call.
> 
> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
> ---
>  arch/arm/boards/nxp-imx8mq-evk/lowlevel.c | 2 --
>  1 file changed, 2 deletions(-)
> 
> diff --git a/arch/arm/boards/nxp-imx8mq-evk/lowlevel.c
> b/arch/arm/boards/nxp-imx8mq-evk/lowlevel.c
> index a74171e5e5..cb1c499cb0 100644
> --- a/arch/arm/boards/nxp-imx8mq-evk/lowlevel.c
> +++ b/arch/arm/boards/nxp-imx8mq-evk/lowlevel.c
> @@ -105,8 +105,6 @@ static __noreturn noinline void
> nxp_imx8mq_evk_start(void)
>  	const u8 *bl31;
>  	size_t bl31_size;
>  
> -	imx8mq_cpu_lowlevel_init();
> -
>  	if (IS_ENABLED(CONFIG_DEBUG_LL))
>  		setup_uart();
>  

Reviewed-by: Rouven Czerwinski <r.czerwinski@pengutronix.de>

- rcz


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH 4/8] ARM: i.MX: imx8-ddrc: Remove debug code
  2019-08-22 12:51 ` [PATCH 4/8] ARM: i.MX: imx8-ddrc: Remove debug code Sascha Hauer
@ 2019-08-22 13:04   ` Rouven Czerwinski
  0 siblings, 0 replies; 20+ messages in thread
From: Rouven Czerwinski @ 2019-08-22 13:04 UTC (permalink / raw)
  To: Sascha Hauer, Barebox List

On Thu, 2019-08-22 at 14:51 +0200, Sascha Hauer wrote:
> various puthex_ll() printed values without any context are not
> helpful when
> debugging unrelated stuff, so remove them. When they are really
> needed
> they should be added with proper pr_debug() statements.
> 
> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
> ---
>  arch/arm/mach-imx/imx8-ddrc.c | 20 ++------------------
>  1 file changed, 2 insertions(+), 18 deletions(-)
> 
> diff --git a/arch/arm/mach-imx/imx8-ddrc.c b/arch/arm/mach-imx/imx8-
> ddrc.c
> index 736865eb6f..8bb2672102 100644
> --- a/arch/arm/mach-imx/imx8-ddrc.c
> +++ b/arch/arm/mach-imx/imx8-ddrc.c
> @@ -69,15 +69,8 @@ static void ddrc_phy_fetch_streaming_message(void
> __iomem *phy)
>  	const u16 index = ddrc_phy_get_message(phy,
> PMC_MESSAGE_STREAM);
>  	u16 i;
>  
> -	putc_ll('|');
> -	puthex_ll(index);
> -
> -	for (i = 0; i < index; i++) {
> -		const u32 arg = ddrc_phy_get_message(phy,
> PMC_MESSAGE_STREAM);
> -
> -		putc_ll('|');
> -		puthex_ll(arg);
> -	}
> +	for (i = 0; i < index; i++)
> +		ddrc_phy_get_message(phy, PMC_MESSAGE_STREAM);
>  }
>  
>  void ddrc_phy_wait_training_complete(void __iomem *phy)
> @@ -85,23 +78,14 @@ void ddrc_phy_wait_training_complete(void __iomem
> *phy)
>  	for (;;) {
>  		const u32 m = ddrc_phy_get_message(phy,
> PMC_MESSAGE_ID);
>  
> -		puthex_ll(m);
> -
>  		switch (m) {
>  		case PMC_TRAIN_STREAM_START:
>  			ddrc_phy_fetch_streaming_message(phy);
>  			break;
>  		case PMC_TRAIN_SUCCESS:
> -			putc_ll('P');
> -			putc_ll('\r');
> -			putc_ll('\n');
>  			return;
>  		case PMC_TRAIN_FAIL:
> -			putc_ll('F');
>  			hang();
>  		}
> -
> -		putc_ll('\r');
> -		putc_ll('\n');
>  	}
>  }

Acked-by: Rouven Czerwinski <r.czerwinski@pengutronix.de>

- rcz


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH 3/8] pbl: Move piggy verification into pbl_barebox_uncompress()
  2019-08-22 12:51 ` [PATCH 3/8] pbl: Move piggy verification into pbl_barebox_uncompress() Sascha Hauer
@ 2019-08-22 13:07   ` Rouven Czerwinski
  0 siblings, 0 replies; 20+ messages in thread
From: Rouven Czerwinski @ 2019-08-22 13:07 UTC (permalink / raw)
  To: Sascha Hauer, Barebox List

On Thu, 2019-08-22 at 14:51 +0200, Sascha Hauer wrote:
> piggy verification is a direct prerequisite of uncompressing the
> piggydata, so move the verification there.
> 
> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
> ---
>  arch/arm/cpu/uncompress.c | 17 +----------------
>  pbl/decomp.c              | 17 +++++++++++++++++
>  2 files changed, 18 insertions(+), 16 deletions(-)
> 
> diff --git a/arch/arm/cpu/uncompress.c b/arch/arm/cpu/uncompress.c
> index 9cc3b358b0..4f16af22f8 100644
> --- a/arch/arm/cpu/uncompress.c
> +++ b/arch/arm/cpu/uncompress.c
> @@ -42,18 +42,14 @@ unsigned long free_mem_end_ptr;
>  extern unsigned char input_data[];
>  extern unsigned char input_data_end[];
>  
> -extern unsigned char sha_sum[];
> -extern unsigned char sha_sum_end[];
> -
>  void __noreturn barebox_multi_pbl_start(unsigned long membase,
>  		unsigned long memsize, void *boarddata)
>  {
> -	uint32_t pg_len, uncompressed_len, pbl_hash_len;
> +	uint32_t pg_len, uncompressed_len;
>  	void __noreturn (*barebox)(unsigned long, unsigned long, void *);
>  	unsigned long endmem = membase + memsize;
>  	unsigned long barebox_base;
>  	void *pg_start, *pg_end;
> -	void *pbl_hash_start, *pbl_hash_end;
>  	unsigned long pc = get_pc();
>  
>  	pg_start = input_data + global_variable_offset();
> @@ -96,17 +92,6 @@ void __noreturn barebox_multi_pbl_start(unsigned long membase,
>  	pr_debug("uncompressing barebox binary at 0x%p (size 0x%08x) to 0x%08lx (uncompressed size: 0x%08x)\n",
>  			pg_start, pg_len, barebox_base, uncompressed_len);
>  
> -	if (IS_ENABLED(CONFIG_PBL_VERIFY_PIGGY)) {
> -		pbl_hash_start = sha_sum;
> -		pbl_hash_end = sha_sum_end;
> -		pbl_hash_len = pbl_hash_end - pbl_hash_start;
> -		if (pbl_barebox_verify(pg_start, pg_len, pbl_hash_start,
> -				       pbl_hash_len) != 0) {
> -			putc_ll('!');
> -			panic("hash mismatch, refusing to decompress");
> -		}
> -	}
> -
>  	pbl_barebox_uncompress((void*)barebox_base, pg_start, pg_len);
>  
>  	sync_caches_for_execution();
> diff --git a/pbl/decomp.c b/pbl/decomp.c
> index ef713a6c74..8767f9fa7e 100644
> --- a/pbl/decomp.c
> +++ b/pbl/decomp.c
> @@ -51,8 +51,25 @@ static void noinline errorfn(char *error)
>  	while (1);
>  }
>  
> +extern unsigned char sha_sum[];
> +extern unsigned char sha_sum_end[];
> +
>  void pbl_barebox_uncompress(void *dest, void *compressed_start, unsigned int len)
>  {
> +	uint32_t pbl_hash_len;
> +	void *pbl_hash_start, *pbl_hash_end;
> +
> +	if (IS_ENABLED(CONFIG_PBL_VERIFY_PIGGY)) {
> +		pbl_hash_start = sha_sum;
> +		pbl_hash_end = sha_sum_end;
> +		pbl_hash_len = pbl_hash_end - pbl_hash_start;
> +		if (pbl_barebox_verify(compressed_start, len, pbl_hash_start,
> +				       pbl_hash_len) != 0) {

pbl_barebox_verify() can be made static now and removed from the header
file.

> +			putc_ll('!');
> +			panic("hash mismatch, refusing to decompress");
> +		}
> +	}
> +
>  	decompress((void *)compressed_start,
>  			len,
>  			NULL, NULL,

With the comment addressed:

Reviewed-by: Rouven Czerwinski <r.czerwinski@pengutronix.de>

- rcz


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH 2/8] ARM: aarch64: Fix get_runtime_offset after relocation
  2019-08-22 12:51 ` [PATCH 2/8] ARM: aarch64: Fix get_runtime_offset after relocation Sascha Hauer
@ 2019-08-22 13:08   ` Rouven Czerwinski
  2019-08-22 20:14   ` Andrey Smirnov
  1 sibling, 0 replies; 20+ messages in thread
From: Rouven Czerwinski @ 2019-08-22 13:08 UTC (permalink / raw)
  To: Sascha Hauer, Barebox List

On Thu, 2019-08-22 at 14:51 +0200, Sascha Hauer wrote:
> get_runtime_offset shall return the offset between the address we are
> running at and the address we are linked at. This value obviously
> changes when we relocate the binary. cf3b09737b tried to avoid using
> R_AARCH64_RELATIVE relocations, but in fact this is exactly what the
> function needs to work. Consider barebox starting at 0x10000000
> when we are linked at 0x0 then get_runtime_offset() should return
> 0x10000000 before relocate_to_current_adr(), but afterwards it should
> return 0x0.
> 
> This patch brings back the previously removed "a" flag. Since gcc5
> doesn't put the values of R_AARCH64_RELATIVE fixup'd relocations
> into the binary but zeroes instead, we help ourselves by basing
> get_runtime_offset on an address which actually is zero. With
> CONFIG_RELOCATABLE=y the binary is always linked to 0x0, so _text
> is initially zero.
> 
> Tested with gcc-5.4.0 (which was "fixed" by cf3b09737b) and gcc-
> 8.2.1.
> 
> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
> ---
>  arch/arm/lib64/runtime-offset.S | 18 +++---------------
>  1 file changed, 3 insertions(+), 15 deletions(-)
> 
> diff --git a/arch/arm/lib64/runtime-offset.S
> b/arch/arm/lib64/runtime-offset.S
> index 6624fdfa15..d1b8bdac3c 100644
> --- a/arch/arm/lib64/runtime-offset.S
> +++ b/arch/arm/lib64/runtime-offset.S
> @@ -1,31 +1,19 @@
>  #include <linux/linkage.h>
>  #include <asm/assembler.h>
>  
> -/*
> - * The .section directive below intentionally omits "a", since that
> - * appears to be the simplest way to force assembler to not generate
> - * R_AARCH64_RELATIVE relocation for
> - *
> - * linkadr:
> - *	.quad get_runtime_offset
> - *
> - * statement below. While having that relocating was relatively
> - * harmless with GCC8, builging the code with GCC5 resulted in
> - * "linkaddr" being initialized to 0 causing complete boot breakdown
> - */
> -.section ".text_bare_init","x"
> +.section ".text_bare_init","ax"
>  
>  /*
>   * Get the offset between the link address and the address
>   * we are currently running at.
>   */
>  ENTRY(get_runtime_offset)
> -1:	adr x0, 1b
> +1:	adr x0, _text
>  	ldr x1, linkadr
>  	subs x0, x0, x1
>  	ret
>  
>  .align 3
>  linkadr:
> -.quad get_runtime_offset
> +.quad _text
>  ENDPROC(get_runtime_offset)

Acked-by: Rouven Czerwinski <r.czerwinski@pengutronix.de>

- rcz


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH 1/8] ARM: aarch64: Fixup relocation table for the second relocation
  2019-08-22 12:51 ` [PATCH 1/8] ARM: aarch64: Fixup relocation table for the second relocation Sascha Hauer
@ 2019-08-22 13:09   ` Rouven Czerwinski
  0 siblings, 0 replies; 20+ messages in thread
From: Rouven Czerwinski @ 2019-08-22 13:09 UTC (permalink / raw)
  To: Sascha Hauer, Barebox List

On Thu, 2019-08-22 at 14:51 +0200, Sascha Hauer wrote:
> In case we want to relocate the binary multiple times we have to
> adjust the relocation table itself for any further relocations.
> 
> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
> ---
>  arch/arm/cpu/common.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/arch/arm/cpu/common.c b/arch/arm/cpu/common.c
> index 4d957da1dc..c81b2b3791 100644
> --- a/arch/arm/cpu/common.c
> +++ b/arch/arm/cpu/common.c
> @@ -84,6 +84,8 @@ void relocate_to_current_adr(void)
>  			unsigned long *fixup = (unsigned long *)(rel-
> >r_offset + offset);
>  
>  			*fixup = rel->r_addend + offset;
> +			rel->r_addend += offset;
> +			rel->r_offset += offset;
>  		} else {
>  			putc_ll('>');
>  			puthex_ll(rel->r_info);

Acked-by: Rouven Czerwinski <r.czerwinski@pengutronix.de>

- rcz


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH 0/8] i.MX8 EVK patches
  2019-08-22 12:51 [PATCH 0/8] i.MX8 EVK patches Sascha Hauer
                   ` (7 preceding siblings ...)
  2019-08-22 12:51 ` [PATCH 8/8] ARM: nxp-imx8mq-evk: Update comments Sascha Hauer
@ 2019-08-22 13:19 ` Rouven Czerwinski
  8 siblings, 0 replies; 20+ messages in thread
From: Rouven Czerwinski @ 2019-08-22 13:19 UTC (permalink / raw)
  To: Sascha Hauer, Barebox List

On Thu, 2019-08-22 at 14:51 +0200, Sascha Hauer wrote:
> Here are several patches for ARM aarch64 in general and more
> specifically for the i.MX8 EVK which currently is not bootable.
> Currently relocation on ARM aarch64 doesn't work correctly and
> the i.MX8 EVK code exploits some of the oddities for its boot
> process. This series aims to fix that up.

Tested with enabled HAB and the development keys fused to my board,
you can add a:

Tested-by: Rouven Czerwinski <r.czerwinski@pengutronix.de>

for the whole series

- rcz


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH 2/8] ARM: aarch64: Fix get_runtime_offset after relocation
  2019-08-22 12:51 ` [PATCH 2/8] ARM: aarch64: Fix get_runtime_offset after relocation Sascha Hauer
  2019-08-22 13:08   ` Rouven Czerwinski
@ 2019-08-22 20:14   ` Andrey Smirnov
  2019-08-23  8:11     ` Sascha Hauer
  1 sibling, 1 reply; 20+ messages in thread
From: Andrey Smirnov @ 2019-08-22 20:14 UTC (permalink / raw)
  To: Sascha Hauer; +Cc: Barebox List

On Thu, Aug 22, 2019 at 5:52 AM Sascha Hauer <s.hauer@pengutronix.de> wrote:
>
> get_runtime_offset shall return the offset between the address we are
> running at and the address we are linked at. This value obviously
> changes when we relocate the binary. cf3b09737b tried to avoid using
> R_AARCH64_RELATIVE relocations, but in fact this is exactly what the
> function needs to work. Consider barebox starting at 0x10000000
> when we are linked at 0x0 then get_runtime_offset() should return
> 0x10000000 before relocate_to_current_adr(), but afterwards it should
> return 0x0.
>
> This patch brings back the previously removed "a" flag. Since gcc5
> doesn't put the values of R_AARCH64_RELATIVE fixup'd relocations
> into the binary but zeroes instead, we help ourselves by basing
> get_runtime_offset on an address which actually is zero. With
> CONFIG_RELOCATABLE=y the binary is always linked to 0x0, so _text
> is initially zero.
>

This paragraph might be worth putting in the comment as well to
document some cleverness that is still required to deal with GCC5.

Thanks,
Andrey Smirnov

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH 2/8] ARM: aarch64: Fix get_runtime_offset after relocation
  2019-08-22 20:14   ` Andrey Smirnov
@ 2019-08-23  8:11     ` Sascha Hauer
  0 siblings, 0 replies; 20+ messages in thread
From: Sascha Hauer @ 2019-08-23  8:11 UTC (permalink / raw)
  To: Andrey Smirnov; +Cc: Barebox List

On Thu, Aug 22, 2019 at 01:14:23PM -0700, Andrey Smirnov wrote:
> On Thu, Aug 22, 2019 at 5:52 AM Sascha Hauer <s.hauer@pengutronix.de> wrote:
> >
> > get_runtime_offset shall return the offset between the address we are
> > running at and the address we are linked at. This value obviously
> > changes when we relocate the binary. cf3b09737b tried to avoid using
> > R_AARCH64_RELATIVE relocations, but in fact this is exactly what the
> > function needs to work. Consider barebox starting at 0x10000000
> > when we are linked at 0x0 then get_runtime_offset() should return
> > 0x10000000 before relocate_to_current_adr(), but afterwards it should
> > return 0x0.
> >
> > This patch brings back the previously removed "a" flag. Since gcc5
> > doesn't put the values of R_AARCH64_RELATIVE fixup'd relocations
> > into the binary but zeroes instead, we help ourselves by basing
> > get_runtime_offset on an address which actually is zero. With
> > CONFIG_RELOCATABLE=y the binary is always linked to 0x0, so _text
> > is initially zero.
> >
> 
> This paragraph might be worth putting in the comment as well to
> document some cleverness that is still required to deal with GCC5.

Makes sence. Added this:

/*
 * With older gcc versions (gcc5) function pointers will not be filled
 * into the binary during compile time and instead rely on relocation
 * during runtime. In the binary we'll always have 0x0 here. We deliberately
 * use _text here since that is 0x0 and is correct without relocation.
 */

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 20+ messages in thread

end of thread, other threads:[~2019-08-23  8:11 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-22 12:51 [PATCH 0/8] i.MX8 EVK patches Sascha Hauer
2019-08-22 12:51 ` [PATCH 1/8] ARM: aarch64: Fixup relocation table for the second relocation Sascha Hauer
2019-08-22 13:09   ` Rouven Czerwinski
2019-08-22 12:51 ` [PATCH 2/8] ARM: aarch64: Fix get_runtime_offset after relocation Sascha Hauer
2019-08-22 13:08   ` Rouven Czerwinski
2019-08-22 20:14   ` Andrey Smirnov
2019-08-23  8:11     ` Sascha Hauer
2019-08-22 12:51 ` [PATCH 3/8] pbl: Move piggy verification into pbl_barebox_uncompress() Sascha Hauer
2019-08-22 13:07   ` Rouven Czerwinski
2019-08-22 12:51 ` [PATCH 4/8] ARM: i.MX: imx8-ddrc: Remove debug code Sascha Hauer
2019-08-22 13:04   ` Rouven Czerwinski
2019-08-22 12:51 ` [PATCH 5/8] ARM: nxp-imx8mq-evk: Remove duplicate call to imx8mq_cpu_lowlevel_init() Sascha Hauer
2019-08-22 13:03   ` Rouven Czerwinski
2019-08-22 12:51 ` [PATCH 6/8] ARM: nxp-imx8mq-evk: Replace trampoline Sascha Hauer
2019-08-22 13:03   ` Rouven Czerwinski
2019-08-22 12:51 ` [PATCH 7/8] ARM: i.MX8: Fix piggydata loading Sascha Hauer
2019-08-22 13:02   ` Rouven Czerwinski
2019-08-22 12:51 ` [PATCH 8/8] ARM: nxp-imx8mq-evk: Update comments Sascha Hauer
2019-08-22 12:59   ` Rouven Czerwinski
2019-08-22 13:19 ` [PATCH 0/8] i.MX8 EVK patches Rouven Czerwinski

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox