Skip to contentSkip to conversation

improve hello_world standalone application for arm

PATCH New Max Krummenacher 2 participants 4 messages Aug 14, 2017 Arm (32-bit)

lore
Share & tools
lore
#0 lore raw

v2 cover improve hello_world standalone application for arm

This series addresses
- hardcoded load address, use LOADADDR if available as the entry point instead
- fix thumb build, jumping with 'go' to the entry point expects arm code

Note that in addition to the two fixes I've seen random freezes or 'random' printed stuff when using an early linaro gcc 6 compiler. Adding an initialized variable helped in that case
static int dummy_var_in_text = 1;
I assume that this forces alignment of some linker sections. (e.g. I see that __bss_start points to 0x1201027e, with the variable this moves to 0x12010280)

However with the current linaro compilers this does not happen so I don't propose a patch for this issue.
Linaro GCC 5.4-2017.05 5.4.1 20170404
Linaro GCC 6.3-2017.05 6.3.1 20170404
Linaro GCC 7.1-2017.05 7.1.1 20170510

This series is available at http://git.toradex.com/cgit/u-boot-toradex.git/log/?h=for-next

Changes in v2:
- Don't confuse loadaddr with entry point as reported by Wolfgang.
- Change the assembly magic to a C function and use __attribute__ to force arm instruction set.
- Keep the entry point name hello_world as reported by Wolfgang.

Max Krummenacher (2):
arm: use LOADADDR as the default for STANDALONE_LOAD_ADDR hello_world.c: fix entry point in case of arm thumb binary

 arch/arm/config.mk                |  4 ++++
 doc/README.standalone             |  2 +-
 examples/standalone/hello_world.c | 18 ++++++++++++++++++
 3 files changed, 23 insertions(+), 1 deletion(-)
Signature · 1 line
2.13.1
#1 lore raw

PATCH v2 1/2 arm: use LOADADDR as the default for STANDALONE_LOAD_ADDR

Different SoCs have different RAM layouts, so using $(CONFIG_LOADADDR) instead of the constant 0xc100000 for CONFIG_STANDALONE_LOAD_ADDR is probably more appropriate.

---

Changes in v2:
- Don't confuse loadaddr with entry point as reported by Wolfgang.

 arch/arm/config.mk    | 4 ++++
 doc/README.standalone | 2 +-
 2 files changed, 5 insertions(+), 1 deletion(-)
arch/arm/config.mk +4 -0
index 1a77779db4..8f56c7433f 100644
@@ -9,7 +9,11 @@ ifndef CONFIG_STANDALONE_LOAD_ADDR
 ifneq ($(CONFIG_ARCH_OMAP2PLUS),)
 CONFIG_STANDALONE_LOAD_ADDR = 0x80300000
 else
+ifndef CONFIG_LOADADDR
 CONFIG_STANDALONE_LOAD_ADDR = 0xc100000
+else
+CONFIG_STANDALONE_LOAD_ADDR = $(CONFIG_LOADADDR)
+endif
 endif
 endif
 
doc/README.standalone +1 -1
index 659a12f6cb..17d740c44b 100644
@@ -53,7 +53,7 @@ Design Notes on Exporting U-Boot Functions to Standalone Applications:
 			Load address	Start address
 	x86		0x00040000	0x00040000
 	PowerPC		0x00040000	0x00040004
-	ARM		0x0c100000	0x0c100000
+	ARM		CONFIG_LOADADDR	CONFIG_LOADADDR
 	MIPS		0x80200000	0x80200000
 	Blackfin	0x00001000	0x00001000
 	NDS32		0x00300000	0x00300000
Signature · 1 line
2.13.1
#2 lore raw

PATCH v2 1/2 arm: use LOADADDR as the default for STANDALONE_LOAD_ADDR

Quoted 6 lines · Max Krummenacher

Different SoCs have different RAM layouts, so using $(CONFIG_LOADADDR) instead of the constant 0xc100000 for CONFIG_STANDALONE_LOAD_ADDR is probably more appropriate.

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20170814/d9ae7f06/attachment.sig>
#3 lore raw

PATCH v2 2/2 hello_world.c: fix entry point in case of arm thumb binary

In reply to Max Krummenacher

For the ARM architecture the U-Boot 'go' command can not jump to code compiled for thumb instruction set. Thus provide a forwarder function to be used as the entry point and have the forwarder deal with how to jump to thumb code.

Note that code which is calling back into the U-Boot binary needs to be compiled in the same instruction set as the U-Boot binary is compiled with.

---

Changes in v2:
- Don't confuse loadaddr with entry point as reported by Wolfgang.
- Change the assembly magic to a C function and use __attribute__ to force arm instruction set.
- Keep the entry point name hello_world as reported by Wolfgang.

 examples/standalone/hello_world.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
examples/standalone/hello_world.c +18 -0
index bd8b392315..3b58b147ff 100644
@@ -8,7 +8,25 @@
 #include <common.h>
 #include <exports.h>
 
+/*
+ * Make thumb work by compiling the entry function for arm.
+ * Only do this if the target CPU is able to execute arm code.
+ * Note that code which calls back into the U-Boot binary
+ * must be compiled for thumb.
+ */
+#if defined(__thumb__) && defined(__ARM_ARCH_ISA_ARM)
+static int _hello_world(int argc, char * const argv[]);
+
+__attribute__((target("arm")))
+int hello_world(int argc, char * const argv[])
+{
+	return _hello_world(argc, argv);
+}
+
+static noinline int _hello_world(int argc, char * const argv[])
+#else
 int hello_world (int argc, char * const argv[])
+#endif
 {
 	int i;
 
Signature · 1 line
2.13.1