mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] fixup! scripts: gen-dtb-s: reference OF IMD entries automatically
@ 2023-04-14 14:11 Ahmad Fatoum
  2023-04-17  7:00 ` Sascha Hauer
  0 siblings, 1 reply; 5+ messages in thread
From: Ahmad Fatoum @ 2023-04-14 14:11 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

While the reference is just there, so linker garbage collection doesn't
remove it, it's still a reference and it will be relocated.

This means it must be aligned, otherwise we will crash doing an unaligned
access during relocation if device tree size isn't evenly divisible by
pointer length...

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 scripts/gen-dtb-s | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/scripts/gen-dtb-s b/scripts/gen-dtb-s
index 6a624e0bd5d0..f6fa1525933e 100755
--- a/scripts/gen-dtb-s
+++ b/scripts/gen-dtb-s
@@ -51,6 +51,7 @@ echo ".incbin \"$dtb\""
 echo "__dtb_${name}_end:"
 echo ".global __dtb_${name}_end"
 if [ "$imd" = "y" ]; then
+	echo ".balign ASM_SZPTR"
 	echo "ASM_PTR __barebox_imd_OF_${name}"
 fi
 echo ".balign STRUCT_ALIGNMENT"
@@ -70,6 +71,7 @@ echo ".incbin \"$dtb.z\""
 echo "__dtb_z_${name}_end:"
 echo ".global __dtb_z_${name}_end"
 if [ "$imd" = "y" ]; then
+	echo ".balign ASM_SZPTR"
 	echo "ASM_PTR __barebox_imd_OF_${name}"
 fi
 echo ".balign STRUCT_ALIGNMENT"
-- 
2.39.2




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

* Re: [PATCH] fixup! scripts: gen-dtb-s: reference OF IMD entries automatically
  2023-04-14 14:11 [PATCH] fixup! scripts: gen-dtb-s: reference OF IMD entries automatically Ahmad Fatoum
@ 2023-04-17  7:00 ` Sascha Hauer
  0 siblings, 0 replies; 5+ messages in thread
From: Sascha Hauer @ 2023-04-17  7:00 UTC (permalink / raw)
  To: Ahmad Fatoum; +Cc: barebox

On Fri, Apr 14, 2023 at 04:11:54PM +0200, Ahmad Fatoum wrote:
> While the reference is just there, so linker garbage collection doesn't
> remove it, it's still a reference and it will be relocated.
> 
> This means it must be aligned, otherwise we will crash doing an unaligned
> access during relocation if device tree size isn't evenly divisible by
> pointer length...
> 
> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
> ---
>  scripts/gen-dtb-s | 2 ++
>  1 file changed, 2 insertions(+)

Applied, thanks

Sascha

> 
> diff --git a/scripts/gen-dtb-s b/scripts/gen-dtb-s
> index 6a624e0bd5d0..f6fa1525933e 100755
> --- a/scripts/gen-dtb-s
> +++ b/scripts/gen-dtb-s
> @@ -51,6 +51,7 @@ echo ".incbin \"$dtb\""
>  echo "__dtb_${name}_end:"
>  echo ".global __dtb_${name}_end"
>  if [ "$imd" = "y" ]; then
> +	echo ".balign ASM_SZPTR"
>  	echo "ASM_PTR __barebox_imd_OF_${name}"
>  fi
>  echo ".balign STRUCT_ALIGNMENT"
> @@ -70,6 +71,7 @@ echo ".incbin \"$dtb.z\""
>  echo "__dtb_z_${name}_end:"
>  echo ".global __dtb_z_${name}_end"
>  if [ "$imd" = "y" ]; then
> +	echo ".balign ASM_SZPTR"
>  	echo "ASM_PTR __barebox_imd_OF_${name}"
>  fi
>  echo ".balign STRUCT_ALIGNMENT"
> -- 
> 2.39.2
> 
> 
> 

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |



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

* Re: [PATCH] fixup! scripts: gen-dtb-s: reference OF IMD entries automatically
  2023-04-12 11:22 ` [PATCH] fixup! " Ahmad Fatoum
  2023-04-12 14:12   ` Sascha Hauer
@ 2023-04-13  7:26   ` Sascha Hauer
  1 sibling, 0 replies; 5+ messages in thread
From: Sascha Hauer @ 2023-04-13  7:26 UTC (permalink / raw)
  To: Ahmad Fatoum; +Cc: barebox

On Wed, Apr 12, 2023 at 01:22:32PM +0200, Ahmad Fatoum wrote:
> Apparently, .dword is not supported for 32-bit ARM builds.
> 
> Let's define ASM_PTR that expands to either .dword or .word and use
> that instead.
> 
> The definition is taken from RISCV_PTR in arch/riscv/include/asm/asm.h.
> 
> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
> ---
> Sascha, how about this?
> ---
>  include/asm-generic/pointer.h | 30 ++++++++++++++++++++++++++++++
>  scripts/gen-dtb-s             |  5 +++--
>  2 files changed, 33 insertions(+), 2 deletions(-)
>  create mode 100644 include/asm-generic/pointer.h
> 
> diff --git a/include/asm-generic/pointer.h b/include/asm-generic/pointer.h
> new file mode 100644
> index 000000000000..a0ea084b983c
> --- /dev/null
> +++ b/include/asm-generic/pointer.h
> @@ -0,0 +1,30 @@
> +/* SPDX-License-Identifier: GPL-2.0-only */
> +
> +#ifndef __ASM_GENERIC_PTR_H___
> +#define __ASM_GENERIC_PTR_H___
> +
> +#if __SIZEOF_POINTER__ == 8
> +#ifdef __ASSEMBLY__
> +#define ASM_PTR		.dword
> +#define ASM_SZPTR	8
> +#define ASM_LGPTR	3
> +#else
> +#define ASM_PTR		".dword"

We're still not there. .dword is not known by x86. I changed to .quad
now.

Sascha

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |



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

* Re: [PATCH] fixup! scripts: gen-dtb-s: reference OF IMD entries automatically
  2023-04-12 11:22 ` [PATCH] fixup! " Ahmad Fatoum
@ 2023-04-12 14:12   ` Sascha Hauer
  2023-04-13  7:26   ` Sascha Hauer
  1 sibling, 0 replies; 5+ messages in thread
From: Sascha Hauer @ 2023-04-12 14:12 UTC (permalink / raw)
  To: Ahmad Fatoum; +Cc: barebox

On Wed, Apr 12, 2023 at 01:22:32PM +0200, Ahmad Fatoum wrote:
> Apparently, .dword is not supported for 32-bit ARM builds.
> 
> Let's define ASM_PTR that expands to either .dword or .word and use
> that instead.
> 
> The definition is taken from RISCV_PTR in arch/riscv/include/asm/asm.h.
> 
> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
> ---
> Sascha, how about this?

Ok, let's give it a try.

Sascha

> ---
>  include/asm-generic/pointer.h | 30 ++++++++++++++++++++++++++++++
>  scripts/gen-dtb-s             |  5 +++--
>  2 files changed, 33 insertions(+), 2 deletions(-)
>  create mode 100644 include/asm-generic/pointer.h
> 
> diff --git a/include/asm-generic/pointer.h b/include/asm-generic/pointer.h
> new file mode 100644
> index 000000000000..a0ea084b983c
> --- /dev/null
> +++ b/include/asm-generic/pointer.h
> @@ -0,0 +1,30 @@
> +/* SPDX-License-Identifier: GPL-2.0-only */
> +
> +#ifndef __ASM_GENERIC_PTR_H___
> +#define __ASM_GENERIC_PTR_H___
> +
> +#if __SIZEOF_POINTER__ == 8
> +#ifdef __ASSEMBLY__
> +#define ASM_PTR		.dword
> +#define ASM_SZPTR	8
> +#define ASM_LGPTR	3
> +#else
> +#define ASM_PTR		".dword"
> +#define ASM_SZPTR	"8"
> +#define ASM_LGPTR	"3"
> +#endif
> +#elif __SIZEOF_POINTER__ == 4
> +#ifdef __ASSEMBLY__
> +#define ASM_PTR		.word
> +#define ASM_SZPTR	4
> +#define ASM_LGPTR	2
> +#else
> +#define ASM_PTR		".word"
> +#define ASM_SZPTR	"4"
> +#define ASM_LGPTR	"2"
> +#endif
> +#else
> +#error "Unexpected __SIZEOF_POINTER__"
> +#endif
> +
> +#endif /* __ASM_GENERIC_PTR_H___ */
> diff --git a/scripts/gen-dtb-s b/scripts/gen-dtb-s
> index 6309a814a483..6a624e0bd5d0 100755
> --- a/scripts/gen-dtb-s
> +++ b/scripts/gen-dtb-s
> @@ -5,6 +5,7 @@ dtb=$2
>  imd=$3
>  
>  echo "#include <asm/barebox.lds.h>"
> +echo "#include <asm-generic/pointer.h>"
>  
>  le32() {
>  	printf ".byte 0x%02x, 0x%02x, 0x%02x, 0x%02x\n" \
> @@ -50,7 +51,7 @@ echo ".incbin \"$dtb\""
>  echo "__dtb_${name}_end:"
>  echo ".global __dtb_${name}_end"
>  if [ "$imd" = "y" ]; then
> -	echo ".dword __barebox_imd_OF_${name}"
> +	echo "ASM_PTR __barebox_imd_OF_${name}"
>  fi
>  echo ".balign STRUCT_ALIGNMENT"
>  
> @@ -69,7 +70,7 @@ echo ".incbin \"$dtb.z\""
>  echo "__dtb_z_${name}_end:"
>  echo ".global __dtb_z_${name}_end"
>  if [ "$imd" = "y" ]; then
> -	echo ".dword __barebox_imd_OF_${name}"
> +	echo "ASM_PTR __barebox_imd_OF_${name}"
>  fi
>  echo ".balign STRUCT_ALIGNMENT"
>  echo "#endif"
> -- 
> 2.39.2
> 
> 
> 

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |



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

* [PATCH] fixup! scripts: gen-dtb-s: reference OF IMD entries automatically
  2023-04-12 10:58 [PATCH v2 1/2] " Sascha Hauer
@ 2023-04-12 11:22 ` Ahmad Fatoum
  2023-04-12 14:12   ` Sascha Hauer
  2023-04-13  7:26   ` Sascha Hauer
  0 siblings, 2 replies; 5+ messages in thread
From: Ahmad Fatoum @ 2023-04-12 11:22 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

Apparently, .dword is not supported for 32-bit ARM builds.

Let's define ASM_PTR that expands to either .dword or .word and use
that instead.

The definition is taken from RISCV_PTR in arch/riscv/include/asm/asm.h.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
Sascha, how about this?
---
 include/asm-generic/pointer.h | 30 ++++++++++++++++++++++++++++++
 scripts/gen-dtb-s             |  5 +++--
 2 files changed, 33 insertions(+), 2 deletions(-)
 create mode 100644 include/asm-generic/pointer.h

diff --git a/include/asm-generic/pointer.h b/include/asm-generic/pointer.h
new file mode 100644
index 000000000000..a0ea084b983c
--- /dev/null
+++ b/include/asm-generic/pointer.h
@@ -0,0 +1,30 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+
+#ifndef __ASM_GENERIC_PTR_H___
+#define __ASM_GENERIC_PTR_H___
+
+#if __SIZEOF_POINTER__ == 8
+#ifdef __ASSEMBLY__
+#define ASM_PTR		.dword
+#define ASM_SZPTR	8
+#define ASM_LGPTR	3
+#else
+#define ASM_PTR		".dword"
+#define ASM_SZPTR	"8"
+#define ASM_LGPTR	"3"
+#endif
+#elif __SIZEOF_POINTER__ == 4
+#ifdef __ASSEMBLY__
+#define ASM_PTR		.word
+#define ASM_SZPTR	4
+#define ASM_LGPTR	2
+#else
+#define ASM_PTR		".word"
+#define ASM_SZPTR	"4"
+#define ASM_LGPTR	"2"
+#endif
+#else
+#error "Unexpected __SIZEOF_POINTER__"
+#endif
+
+#endif /* __ASM_GENERIC_PTR_H___ */
diff --git a/scripts/gen-dtb-s b/scripts/gen-dtb-s
index 6309a814a483..6a624e0bd5d0 100755
--- a/scripts/gen-dtb-s
+++ b/scripts/gen-dtb-s
@@ -5,6 +5,7 @@ dtb=$2
 imd=$3
 
 echo "#include <asm/barebox.lds.h>"
+echo "#include <asm-generic/pointer.h>"
 
 le32() {
 	printf ".byte 0x%02x, 0x%02x, 0x%02x, 0x%02x\n" \
@@ -50,7 +51,7 @@ echo ".incbin \"$dtb\""
 echo "__dtb_${name}_end:"
 echo ".global __dtb_${name}_end"
 if [ "$imd" = "y" ]; then
-	echo ".dword __barebox_imd_OF_${name}"
+	echo "ASM_PTR __barebox_imd_OF_${name}"
 fi
 echo ".balign STRUCT_ALIGNMENT"
 
@@ -69,7 +70,7 @@ echo ".incbin \"$dtb.z\""
 echo "__dtb_z_${name}_end:"
 echo ".global __dtb_z_${name}_end"
 if [ "$imd" = "y" ]; then
-	echo ".dword __barebox_imd_OF_${name}"
+	echo "ASM_PTR __barebox_imd_OF_${name}"
 fi
 echo ".balign STRUCT_ALIGNMENT"
 echo "#endif"
-- 
2.39.2




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

end of thread, other threads:[~2023-04-17  7:02 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-04-14 14:11 [PATCH] fixup! scripts: gen-dtb-s: reference OF IMD entries automatically Ahmad Fatoum
2023-04-17  7:00 ` Sascha Hauer
  -- strict thread matches above, loose matches on Subject: below --
2023-04-12 10:58 [PATCH v2 1/2] " Sascha Hauer
2023-04-12 11:22 ` [PATCH] fixup! " Ahmad Fatoum
2023-04-12 14:12   ` Sascha Hauer
2023-04-13  7:26   ` Sascha Hauer

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