[PATCH 2/2] console: pbl: correctly handle relocate_to_adr after pbl_set_putc

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



pbl_set_putc may be called by a PBL entry point to store the absolute
address of a routine to be used for printing out a character.

If barebox happens to be located outside of the initially known RAM,
it will be relocated into it by means of relocate_to_adr(), but nothing
will take care to update the function pointer stored by pbl_set_putc.

This will usually continue to work until barebox sets up the MMU and
everything not known to be RAM is marked as eXecute Never. After that,
the next PBL console print will trigger an instruction abort.

Fix this by not storing the putc function pointer, but instead an offset
relative to _text.

This is the second part of fixing barebox hanging on i.MX8M when located
at an address greater than 4G.

This change has been tested on both i.MX8M (AArch64) and i.MX6 (Thumb2).

Signed-off-by: Ahmad Fatoum <a.fatoum@xxxxxxxxxxxxxx>
---
 pbl/console.c | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/pbl/console.c b/pbl/console.c
index 1a6e839c1559..d81bf580d52f 100644
--- a/pbl/console.c
+++ b/pbl/console.c
@@ -2,13 +2,14 @@
 
 #include <common.h>
 #include <debug_ll.h>
+#include <asm/sections.h>
 #include <linux/err.h>
 
 /*
  * Put these in the data section so that they survive the clearing of the
  * BSS segment.
  */
-static __attribute__ ((section(".data"))) void (*__putc)(void *ctx, int c);
+static __attribute__ ((section(".data"))) ulong putc_offset;
 static __attribute__ ((section(".data"))) void *putc_ctx;
 
 /**
@@ -21,13 +22,19 @@ static __attribute__ ((section(".data"))) void *putc_ctx;
  */
 void pbl_set_putc(void (*putcf)(void *ctx, int c), void *ctx)
 {
-	__putc = putcf;
+	putc_offset = (ulong)putcf - (ulong)_text;
 	putc_ctx = ctx;
 }
 
+static void __putc(void *ctx, int c)
+{
+	void (*putc)(void *, int) = (void *)_text + putc_offset;
+	putc(ctx, c);
+}
+
 void console_putc(unsigned int ch, char c)
 {
-	if (__putc)
+	if (putc_offset)
 		__putc(putc_ctx, c);
 	else
 		putc_ll(c);
-- 
2.39.2





[Index of Archives]     [Linux Embedded]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux