From 84d28cec7f49b9dabf14892323a6ea421c470fea Mon Sep 17 00:00:00 2001 From: Sascha Hauer Date: Thu, 2 Jul 2015 08:09:03 +0200 Subject: ARM: add a machine number mechanism for boarddata Multi machine barebox builds have to pass information on which board we are running on via boarddata. Usually this will be a pointer to a device tree. Some boards might not have a device tree available though because they are either not ported over to device tree yet, or are running in some limited first state environment which does not offer enough space for a device tree. For these cases this patch adds a mechanism to embed a machine number into a struct type along with a magic number. This makes it possible to check for a specific machine later during regular runtime. Signed-off-by: Sascha Hauer --- arch/arm/cpu/start.c | 43 ++++++++++++++++++++++++-------------- arch/arm/include/asm/barebox-arm.h | 27 +++++++++++++++++++++++- 2 files changed, 53 insertions(+), 17 deletions(-) diff --git a/arch/arm/cpu/start.c b/arch/arm/cpu/start.c index 304ed0cee7..91badc97b3 100644 --- a/arch/arm/cpu/start.c +++ b/arch/arm/cpu/start.c @@ -28,17 +28,22 @@ #include #include +#include #include "mmu-early.h" unsigned long arm_stack_top; static void *barebox_boarddata; -/* - * return the boarddata variable passed to barebox_arm_entry - */ -void *barebox_arm_boarddata(void) +u32 barebox_arm_machine(void) { - return barebox_boarddata; + struct barebox_arm_boarddata *bd; + + if (!barebox_boarddata) + return 0; + + bd = barebox_boarddata; + + return bd->machine; } static void *barebox_boot_dtb; @@ -81,17 +86,23 @@ static noinline __noreturn void __start(unsigned long membase, } } - /* - * If boarddata is a pointer inside valid memory and contains a - * FDT magic then use it as later to probe devices - */ - if (boarddata && get_unaligned_be32(boarddata) == FDT_MAGIC) { - uint32_t totalsize = get_unaligned_be32(boarddata + 4); - endmem -= ALIGN(totalsize, 64); - barebox_boot_dtb = (void *)endmem; - pr_debug("found DTB in boarddata, copying to 0x%p\n", - barebox_boot_dtb); - memcpy(barebox_boot_dtb, boarddata, totalsize); + if (boarddata) { + if (get_unaligned_be32(boarddata) == FDT_MAGIC) { + uint32_t totalsize = get_unaligned_be32(boarddata + 4); + endmem -= ALIGN(totalsize, 64); + barebox_boot_dtb = (void *)endmem; + pr_debug("found DTB in boarddata, copying to 0x%p\n", + barebox_boot_dtb); + memcpy(barebox_boot_dtb, boarddata, totalsize); + } else if (((struct barebox_arm_boarddata *)boarddata)->magic == + BAREBOX_ARM_BOARDDATA_MAGIC) { + endmem -= ALIGN(sizeof(struct barebox_arm_boarddata), 64); + barebox_boarddata = (void *)endmem; + pr_debug("found machine type in boarddata, copying to 0x%p\n", + barebox_boarddata); + memcpy(barebox_boarddata, boarddata, + sizeof(struct barebox_arm_boarddata)); + } } if ((unsigned long)_text > membase + memsize || diff --git a/arch/arm/include/asm/barebox-arm.h b/arch/arm/include/asm/barebox-arm.h index dbc8aaaba7..0b8acb8b8e 100644 --- a/arch/arm/include/asm/barebox-arm.h +++ b/arch/arm/include/asm/barebox-arm.h @@ -48,7 +48,32 @@ void setup_c(void); void relocate_to_current_adr(void); void relocate_to_adr(unsigned long target); void __noreturn barebox_arm_entry(unsigned long membase, unsigned long memsize, void *boarddata); -void *barebox_arm_boarddata(void); + +struct barebox_arm_boarddata { +#define BAREBOX_ARM_BOARDDATA_MAGIC 0xabe742c3 + u32 magic; + u32 machine; /* machine number to pass to barebox. This may or may + * not be a ARM machine number registered on arm.linux.org.uk. + * It must only be unique across barebox. Please use a number + * that do not potientially clashes with registered machines, + * i.e. use a number > 0x10000. + */ +}; + +/* + * Create a boarddata struct at given address. Suitable to be passed + * as boarddata to barebox_arm_entry(). The machine can be retrieved + * later with barebox_arm_machine(). + */ +static inline void boarddata_create(void *adr, u32 machine) +{ + struct barebox_arm_boarddata *bd = adr; + + bd->magic = BAREBOX_ARM_BOARDDATA_MAGIC; + bd->machine = machine; +} + +u32 barebox_arm_machine(void); #if defined(CONFIG_RELOCATABLE) && defined(CONFIG_ARM_EXCEPTIONS) void arm_fixup_vectors(void); -- cgit v1.2.3