riscv: Introduce CONFIG_XIP to support booting from flash
authorRick Chen <rick@andestech.com>
Tue, 30 Apr 2019 05:49:33 +0000 (13:49 +0800)
committerAndes <uboot@andestech.com>
Thu, 9 May 2019 08:46:46 +0000 (16:46 +0800)
When U-Boot boots from flash, during the boot process,
hart_lottery and available_harts_lock variable addresses
point to flash which is not writable. This causes boot
failures on AE350. Introduce a config option CONFIG_XIP
to support such configuration.

Signed-off-by: Rick Chen <rick@andestech.com>
Cc: Greentime Hu <greentime@andestech.com>
Reviewed-by: Lukas Auer <lukas.auer@aisec.fraunhofer.de>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
arch/riscv/Kconfig
arch/riscv/cpu/cpu.c
arch/riscv/cpu/start.S
arch/riscv/include/asm/global_data.h
arch/riscv/lib/asm-offsets.c
arch/riscv/lib/smp.c

index ae8ff7b765786841971eedfa06cb4257418e375d..362f3cdc6558bb1c51ca839225ccafbabcc6d0b5 100644 (file)
@@ -162,6 +162,13 @@ config SBI_IPI
        default y if RISCV_SMODE
        depends on SMP
 
+config XIP
+       bool "XIP mode"
+       help
+         XIP (eXecute In Place) is a method for executing code directly
+         from a NOR flash memory without copying the code to ram.
+         Say yes here if U-Boot boots from flash directly.
+
 config STACK_SIZE_SHIFT
        int
        default 13
index c32de8a4c3e64acec63b86dc8845683e6192fbc2..0cfd7d61a78fde1214db13322b3a803ae09d52e7 100644 (file)
@@ -16,6 +16,7 @@
  * before the bss section is available.
  */
 phys_addr_t prior_stage_fdt_address __attribute__((section(".data")));
+#ifndef CONFIG_XIP
 u32 hart_lottery __attribute__((section(".data"))) = 0;
 
 /*
@@ -23,6 +24,7 @@ u32 hart_lottery __attribute__((section(".data"))) = 0;
  * finished initialization of global data.
  */
 u32 available_harts_lock = 1;
+#endif
 
 static inline bool supports_extension(char ext)
 {
index a4433fbd6ba1b3689961c8bc64b4c2f0f0aa26c5..3402d09a05426ebeb86dd4935b13432fd1d70c19 100644 (file)
@@ -98,6 +98,7 @@ call_board_init_f_0:
        mv      sp, a0
 #endif
 
+#ifndef CONFIG_XIP
        /*
         * Pick hart to initialize global data and run U-Boot. The other harts
         * wait for initialization to complete.
@@ -106,6 +107,9 @@ call_board_init_f_0:
        li      s2, 1
        amoswap.w s2, t1, 0(t0)
        bnez    s2, wait_for_gd_init
+#else
+       bnez    tp, secondary_hart_loop
+#endif
 
        la      t0, prior_stage_fdt_address
        SREG    s1, 0(t0)
@@ -115,6 +119,7 @@ call_board_init_f_0:
        /* save the boot hart id to global_data */
        SREG    tp, GD_BOOT_HART(gp)
 
+#ifndef CONFIG_XIP
        la      t0, available_harts_lock
        fence   rw, w
        amoswap.w zero, zero, 0(t0)
@@ -141,6 +146,7 @@ wait_for_gd_init:
         * secondary_hart_loop.
         */
        bnez    s2, secondary_hart_loop
+#endif
 
        /* Enable cache */
        jal     icache_enable
index dffcd45bf01393888509db20c1bea2021ede3a32..b74bd7e738bb778d964f78823f0ced5f18282db5 100644 (file)
@@ -27,7 +27,9 @@ struct arch_global_data {
 #ifdef CONFIG_SMP
        struct ipi_data ipi[CONFIG_NR_CPUS];
 #endif
+#ifndef CONFIG_XIP
        ulong available_harts;
+#endif
 };
 
 #include <asm-generic/global_data.h>
index f998402bd1bf398f7b6b757f8e921dffb3727a06..4fa4fd371473baa140a893e7a9d367ca967d63c1 100644 (file)
@@ -14,7 +14,9 @@
 int main(void)
 {
        DEFINE(GD_BOOT_HART, offsetof(gd_t, arch.boot_hart));
+#ifndef CONFIG_XIP
        DEFINE(GD_AVAILABLE_HARTS, offsetof(gd_t, arch.available_harts));
+#endif
 
        return 0;
 }
index caa292ccd204da48e0f322283945128284ddfb9d..cc66f15567a4f3b6fcd766b64c5bfbfd848538fe 100644 (file)
@@ -63,9 +63,11 @@ static int send_ipi_many(struct ipi_data *ipi)
                        continue;
                }
 
+#ifndef CONFIG_XIP
                /* skip if hart is not available */
                if (!(gd->arch.available_harts & (1 << reg)))
                        continue;
+#endif
 
                gd->arch.ipi[reg].addr = ipi->addr;
                gd->arch.ipi[reg].arg0 = ipi->arg0;