diff options
Diffstat (limited to 'arch/arm/cpu/start.c')
-rw-r--r-- | arch/arm/cpu/start.c | 121 |
1 files changed, 51 insertions, 70 deletions
diff --git a/arch/arm/cpu/start.c b/arch/arm/cpu/start.c index d99dd147b0..0351dcb927 100644 --- a/arch/arm/cpu/start.c +++ b/arch/arm/cpu/start.c @@ -1,21 +1,12 @@ -/* - * Copyright (c) 2010 Sascha Hauer <s.hauer@pengutronix.de>, Pengutronix - * - * See file CREDITS for list of people who contributed to this - * project. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - */ +// SPDX-License-Identifier: GPL-2.0-only +// SPDX-FileCopyrightText: 2010 Sascha Hauer <s.hauer@pengutronix.de>, Pengutronix + #define pr_fmt(fmt) "start.c: " fmt +#ifdef CONFIG_DEBUG_INITCALLS +#define DEBUG +#endif + #include <common.h> #include <init.h> #include <linux/sizes.h> @@ -28,8 +19,10 @@ #include <asm/unaligned.h> #include <asm/cache.h> #include <asm/mmu.h> +#include <linux/kasan.h> #include <memory.h> #include <uncompress.h> +#include <compressed-dtb.h> #include <malloc.h> #include <debug_ll.h> @@ -39,44 +32,36 @@ unsigned long arm_stack_top; static unsigned long arm_barebox_size; static unsigned long arm_endmem; +static unsigned long arm_membase; static void *barebox_boarddata; static unsigned long barebox_boarddata_size; -static bool blob_is_fdt(const void *blob) -{ - return get_unaligned_be32(blob) == FDT_MAGIC; -} - -static bool blob_is_compressed_fdt(const void *blob) +static bool blob_is_arm_boarddata(const void *blob) { - const struct barebox_arm_boarddata_compressed_dtb *dtb = blob; + const struct barebox_arm_boarddata *bd = blob; - return dtb->magic == BAREBOX_ARM_BOARDDATA_COMPRESSED_DTB_MAGIC; + return bd->magic == BAREBOX_ARM_BOARDDATA_MAGIC; } -static bool blob_is_arm_boarddata(const void *blob) +const struct barebox_boarddata *barebox_get_boarddata(void) { - const struct barebox_arm_boarddata *bd = blob; + if (!barebox_boarddata || !blob_is_arm_boarddata(barebox_boarddata)) + return NULL; - return bd->magic == BAREBOX_ARM_BOARDDATA_MAGIC; + return barebox_boarddata; } u32 barebox_arm_machine(void) { - if (barebox_boarddata && blob_is_arm_boarddata(barebox_boarddata)) { - const struct barebox_arm_boarddata *bd = barebox_boarddata; - return bd->machine; - } else { - return 0; - } + const struct barebox_boarddata *bd = barebox_get_boarddata(); + return bd ? bd->machine : 0; } void *barebox_arm_boot_dtb(void) { void *dtb; - void *data; - int ret; - struct barebox_arm_boarddata_compressed_dtb *compressed_dtb; + int ret = 0; + struct barebox_boarddata_compressed_dtb *compressed_dtb; static void *boot_dtb; if (boot_dtb) @@ -87,8 +72,7 @@ void *barebox_arm_boot_dtb(void) return barebox_boarddata; } - if (!IS_ENABLED(CONFIG_ARM_USE_COMPRESSED_DTB) || !barebox_boarddata - || !blob_is_compressed_fdt(barebox_boarddata)) + if (!fdt_blob_can_be_decompressed(barebox_boarddata)) return NULL; compressed_dtb = barebox_boarddata; @@ -99,10 +83,13 @@ void *barebox_arm_boot_dtb(void) if (!dtb) return NULL; - data = compressed_dtb + 1; + if (IS_ENABLED(CONFIG_IMAGE_COMPRESSION_NONE)) + memcpy(dtb, compressed_dtb->data, + compressed_dtb->datalen_uncompressed); + else + ret = uncompress(compressed_dtb->data, compressed_dtb->datalen, + NULL, NULL, dtb, NULL, NULL); - ret = uncompress(data, compressed_dtb->datalen, NULL, NULL, - dtb, NULL, NULL); if (ret) { pr_err("uncompressing dtb failed\n"); free(dtb); @@ -128,7 +115,7 @@ static inline unsigned long arm_mem_boarddata(unsigned long membase, unsigned long arm_mem_ramoops_get(void) { - return arm_mem_ramoops(0, arm_stack_top); + return arm_mem_ramoops(arm_stack_top); } EXPORT_SYMBOL_GPL(arm_mem_ramoops_get); @@ -138,17 +125,27 @@ unsigned long arm_mem_endmem_get(void) } EXPORT_SYMBOL_GPL(arm_mem_endmem_get); +unsigned long arm_mem_membase_get(void) +{ + return arm_membase; +} +EXPORT_SYMBOL_GPL(arm_mem_membase_get); + static int barebox_memory_areas_init(void) { if(barebox_boarddata) request_sdram_region("board data", (unsigned long)barebox_boarddata, barebox_boarddata_size); + if (IS_ENABLED(CONFIG_KASAN)) + request_sdram_region("kasan shadow", kasan_shadow_base, + mem_malloc_start() - kasan_shadow_base); + return 0; } device_initcall(barebox_memory_areas_init); -__noreturn void barebox_non_pbl_start(unsigned long membase, +__noreturn __prereloc void barebox_non_pbl_start(unsigned long membase, unsigned long memsize, void *boarddata) { unsigned long endmem = membase + memsize; @@ -172,23 +169,12 @@ __noreturn void barebox_non_pbl_start(unsigned long membase, pr_debug("memory at 0x%08lx, size 0x%08lx\n", membase, memsize); + arm_membase = membase; arm_endmem = endmem; - arm_stack_top = arm_mem_stack_top(membase, endmem); + arm_stack_top = arm_mem_stack_top(endmem); arm_barebox_size = barebox_size; malloc_end = barebox_base; - if (IS_ENABLED(CONFIG_MMU_EARLY)) { - unsigned long ttb = arm_mem_ttb(membase, endmem); - - if (IS_ENABLED(CONFIG_PBL_IMAGE)) { - arm_set_cache_functions(); - } else { - pr_debug("enabling MMU, ttb @ 0x%08lx\n", ttb); - arm_early_mmu_cache_invalidate(); - mmu_early_enable(membase, memsize, ttb); - } - } - if (boarddata) { uint32_t totalsize = 0; const char *name; @@ -197,24 +183,12 @@ __noreturn void barebox_non_pbl_start(unsigned long membase, totalsize = get_unaligned_be32(boarddata + 4); name = "DTB"; } else if (blob_is_compressed_fdt(boarddata)) { - struct barebox_arm_boarddata_compressed_dtb *bd = boarddata; + struct barebox_boarddata_compressed_dtb *bd = boarddata; totalsize = bd->datalen + sizeof(*bd); name = "Compressed DTB"; } else if (blob_is_arm_boarddata(boarddata)) { totalsize = sizeof(struct barebox_arm_boarddata); name = "machine type"; - } else if ((unsigned long)boarddata < 8192) { - struct barebox_arm_boarddata *bd; - uint32_t machine_type = (unsigned long)boarddata; - unsigned long mem = arm_mem_boarddata(membase, endmem, - sizeof(*bd)); - pr_debug("found machine type %d in boarddata\n", - machine_type); - bd = barebox_boarddata = (void *)mem; - barebox_boarddata_size = sizeof(*bd); - bd->magic = BAREBOX_ARM_BOARDDATA_MAGIC; - bd->machine = machine_type; - malloc_end = mem; } if (totalsize) { @@ -246,8 +220,15 @@ __noreturn void barebox_non_pbl_start(unsigned long membase, pr_debug("initializing malloc pool at 0x%08lx (size 0x%08lx)\n", malloc_start, malloc_end - malloc_start); + kasan_init(membase, memsize, malloc_start - (memsize >> KASAN_SHADOW_SCALE_SHIFT)); + mem_malloc_init((void *)malloc_start, (void *)malloc_end - 1); + if (IS_ENABLED(CONFIG_MMU) && !IS_ENABLED(CONFIG_PBL_IMAGE)) { + arm_early_mmu_cache_invalidate(); + mmu_early_enable(membase, memsize); + } + if (IS_ENABLED(CONFIG_BOOTM_OPTEE)) of_add_reserve_entry(endmem - OPTEE_SIZE, endmem - 1); @@ -272,7 +253,7 @@ void start(unsigned long membase, unsigned long memsize, void *boarddata); * First function in the uncompressed image. We get here from * the pbl. The stack already has been set up by the pbl. */ -void NAKED __section(.text_entry) start(unsigned long membase, +void NAKED __prereloc __section(.text_entry) start(unsigned long membase, unsigned long memsize, void *boarddata) { barebox_non_pbl_start(membase, memsize, boarddata); |