[U-Boot] [PATCH v2 2/2] hello_world.c: fix entry point in case of arm thumb binary

Max Krummenacher max.oss.09 at gmail.com
Mon Aug 14 16:27:20 UTC 2017


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.

Signed-off-by: Max Krummenacher <max.krummenacher at toradex.com>

---

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(+)

diff --git a/examples/standalone/hello_world.c b/examples/standalone/hello_world.c
index bd8b392315..3b58b147ff 100644
--- a/examples/standalone/hello_world.c
+++ b/examples/standalone/hello_world.c
@@ -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;
 
-- 
2.13.1



More information about the U-Boot mailing list