From 204fdda6a16f4ea7d90f627048593799afdf8b63 Mon Sep 17 00:00:00 2001 From: Kent McLeod Date: Thu, 15 Feb 2024 23:30:48 +1100 Subject: [PATCH 1/6] elfloader: Add driver callback for non-boot core This is to support core-specific driver init handling. Signed-off-by: Kent McLeod --- elfloader-tool/include/drivers.h | 1 + elfloader-tool/include/drivers/common.h | 1 + elfloader-tool/src/arch-arm/smp_boot.c | 1 + elfloader-tool/src/drivers/driver.c | 29 +++++++++++++++++++++++++ 4 files changed, 32 insertions(+) diff --git a/elfloader-tool/include/drivers.h b/elfloader-tool/include/drivers.h index 2e4a7c1a..28a697d0 100644 --- a/elfloader-tool/include/drivers.h +++ b/elfloader-tool/include/drivers.h @@ -7,3 +7,4 @@ #pragma once int initialise_devices(void); +int initialise_devices_non_boot(void); diff --git a/elfloader-tool/include/drivers/common.h b/elfloader-tool/include/drivers/common.h index 75a483bd..1aba204a 100644 --- a/elfloader-tool/include/drivers/common.h +++ b/elfloader-tool/include/drivers/common.h @@ -33,6 +33,7 @@ struct elfloader_driver { const struct dtb_match_table *match_table; enum driver_type type; driver_init_t init; + driver_init_t init_on_secondary_cores; /* ops struct, type depends on driver type. */ const void *ops; }; diff --git a/elfloader-tool/src/arch-arm/smp_boot.c b/elfloader-tool/src/arch-arm/smp_boot.c index e25b5612..ad3a440b 100644 --- a/elfloader-tool/src/arch-arm/smp_boot.c +++ b/elfloader-tool/src/arch-arm/smp_boot.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include diff --git a/elfloader-tool/src/drivers/driver.c b/elfloader-tool/src/drivers/driver.c index 9b56c796..5edd00ab 100644 --- a/elfloader-tool/src/drivers/driver.c +++ b/elfloader-tool/src/drivers/driver.c @@ -53,3 +53,32 @@ int initialise_devices(void) return 0; } + +static int init_device_non_boot(struct elfloader_device *dev) +{ + struct elfloader_driver **drvp = __start__driver_list; + + while (drvp < __stop__driver_list) { + struct elfloader_driver *drv = *drvp; + if (drv->init_on_secondary_cores) { + int ret = table_has_match(dev->compat, drv->match_table); + if (ret >= 0) { + dev->drv = drv; + drv->init_on_secondary_cores(dev, drv->match_table[ret].match_data); + } + } + drvp++; + } + return 0; +} + +int initialise_devices_non_boot(void) +{ + for (unsigned int i = 0; i < ARRAY_SIZE(elfloader_devices); i++) { + int ret = init_device_non_boot(&elfloader_devices[i]); + if (ret) { + return ret; + } + } + return 0; +} From b69faf3d307e75a05cf280fadf308cbf03a4b2a4 Mon Sep 17 00:00:00 2001 From: Kent McLeod Date: Tue, 30 May 2023 16:42:55 +1000 Subject: [PATCH 2/6] elfloader: Add generic-timer driver This driver just sets CNTVOFF_El2 to 0 if possible. This can only be done if the elfloader is in hyp-mode, otherwise nothing happens. Signed-off-by: Kent McLeod --- elfloader-tool/CMakeLists.txt | 1 + elfloader-tool/include/drivers/common.h | 1 + elfloader-tool/src/arch-arm/smp_boot.c | 3 ++ .../src/drivers/timer/arm_generic_timer.c | 34 +++++++++++++++++++ 4 files changed, 39 insertions(+) create mode 100644 elfloader-tool/src/drivers/timer/arm_generic_timer.c diff --git a/elfloader-tool/CMakeLists.txt b/elfloader-tool/CMakeLists.txt index 2a4d7884..ac747c94 100644 --- a/elfloader-tool/CMakeLists.txt +++ b/elfloader-tool/CMakeLists.txt @@ -171,6 +171,7 @@ file( src/drivers/*.c src/drivers/smp/*.c src/drivers/uart/*.c + src/drivers/timer/*.c src/utils/*.c src/arch-${KernelArch}/*.c src/arch-${KernelArch}/*.S diff --git a/elfloader-tool/include/drivers/common.h b/elfloader-tool/include/drivers/common.h index 1aba204a..ef7a7319 100644 --- a/elfloader-tool/include/drivers/common.h +++ b/elfloader-tool/include/drivers/common.h @@ -26,6 +26,7 @@ enum driver_type { DRIVER_INVALID = 0, DRIVER_SMP, DRIVER_UART, + DRIVER_TIMER, DRIVER_MAX }; diff --git a/elfloader-tool/src/arch-arm/smp_boot.c b/elfloader-tool/src/arch-arm/smp_boot.c index ad3a440b..3acb88cb 100644 --- a/elfloader-tool/src/arch-arm/smp_boot.c +++ b/elfloader-tool/src/arch-arm/smp_boot.c @@ -44,6 +44,9 @@ void non_boot_main(void) /* Initialise any platform-specific per-core state */ non_boot_init(); + /* Do any driver specific non_boot core init */ + initialise_devices_non_boot(); + #ifndef CONFIG_ARM_HYPERVISOR_SUPPORT if (is_hyp_mode()) { extern void leave_hyp(void); diff --git a/elfloader-tool/src/drivers/timer/arm_generic_timer.c b/elfloader-tool/src/drivers/timer/arm_generic_timer.c new file mode 100644 index 00000000..b19f909c --- /dev/null +++ b/elfloader-tool/src/drivers/timer/arm_generic_timer.c @@ -0,0 +1,34 @@ +/* + * Copyright 2020, Data61, CSIRO (ABN 41 687 119 230) + * + * SPDX-License-Identifier: GPL-2.0-only + */ + +#include +#include +#include + +#include + + +static int generic_timer_init(UNUSED struct elfloader_device *dev, UNUSED void *match_data) +{ + reset_cntvoff(); + return 0; +} + +static const struct dtb_match_table generic_timer_matches[] = { + { .compatible = "arm,armv7-timer" }, + { .compatible = "arm,armv8-timer" }, + { .compatible = NULL /* sentinel */ }, +}; + +static const struct elfloader_driver generic_timer = { + .match_table = generic_timer_matches, + .type = DRIVER_TIMER, + .init = &generic_timer_init, + .init_on_secondary_cores = &generic_timer_init, + .ops = NULL, +}; + +ELFLOADER_DRIVER(generic_timer); From 08b31b2151613a400e4703681e83fee6fe282b9f Mon Sep 17 00:00:00 2001 From: Kent McLeod Date: Tue, 30 May 2023 17:02:41 +1000 Subject: [PATCH 3/6] elfloader: Replace calls to reset_cntvoff These calls can now be implemented via binding the /timer driver in the elfloader's device tree configuration (located in the kernel's platform directory). Signed-off-by: Kent McLeod --- .../src/plat/apq8064/platform_init.c | 21 ------------------ .../src/plat/bcm2711/platform_init.c | 21 ------------------ .../src/plat/bcm2837/platform_init.c | 21 ------------------ .../src/plat/exynos5/platform_init.c | 12 ---------- elfloader-tool/src/plat/fvp/platform_init.c | 11 ---------- elfloader-tool/src/plat/hikey/platform_init.c | 21 ------------------ elfloader-tool/src/plat/imx7/platform_init.c | 21 ------------------ .../src/plat/imx8m-evk/platform_init.c | 21 ------------------ .../src/plat/maaxboard/platform_init.c | 22 ------------------- .../src/plat/odroidc2/platform_init.c | 21 ------------------ .../src/plat/odroidc4/platform_init.c | 21 ------------------ .../src/plat/qemu-arm-virt/platform_init.c | 21 ------------------ .../src/plat/quartz64/platform_init.c | 21 ------------------ .../src/plat/rockpro64/platform_init.c | 21 ------------------ elfloader-tool/src/plat/tk1/platform_init.c | 11 ---------- .../src/plat/tqma8xqp1gb/platform_init.c | 21 ------------------ elfloader-tool/src/plat/tx1/platform_init.c | 21 ------------------ elfloader-tool/src/plat/tx2/platform_init.c | 12 ---------- .../src/plat/zynqmp/platform_init.c | 21 ------------------ 19 files changed, 362 deletions(-) delete mode 100644 elfloader-tool/src/plat/apq8064/platform_init.c delete mode 100644 elfloader-tool/src/plat/bcm2711/platform_init.c delete mode 100644 elfloader-tool/src/plat/bcm2837/platform_init.c delete mode 100644 elfloader-tool/src/plat/hikey/platform_init.c delete mode 100644 elfloader-tool/src/plat/imx7/platform_init.c delete mode 100644 elfloader-tool/src/plat/imx8m-evk/platform_init.c delete mode 100644 elfloader-tool/src/plat/maaxboard/platform_init.c delete mode 100644 elfloader-tool/src/plat/odroidc2/platform_init.c delete mode 100644 elfloader-tool/src/plat/odroidc4/platform_init.c delete mode 100644 elfloader-tool/src/plat/qemu-arm-virt/platform_init.c delete mode 100644 elfloader-tool/src/plat/quartz64/platform_init.c delete mode 100644 elfloader-tool/src/plat/rockpro64/platform_init.c delete mode 100644 elfloader-tool/src/plat/tqma8xqp1gb/platform_init.c delete mode 100644 elfloader-tool/src/plat/tx1/platform_init.c delete mode 100644 elfloader-tool/src/plat/zynqmp/platform_init.c diff --git a/elfloader-tool/src/plat/apq8064/platform_init.c b/elfloader-tool/src/plat/apq8064/platform_init.c deleted file mode 100644 index 42dabfa0..00000000 --- a/elfloader-tool/src/plat/apq8064/platform_init.c +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright 2021, Data61, CSIRO (ABN 41 687 119 230) - * - * SPDX-License-Identifier: GPL-2.0-only - */ - -#include -#include - -/* Reset the virtual offset for the platform timer to 0 */ -void platform_init(void) -{ - reset_cntvoff(); -} - -#if CONFIG_MAX_NUM_NODES > 1 -void non_boot_init(void) -{ - reset_cntvoff(); -} -#endif diff --git a/elfloader-tool/src/plat/bcm2711/platform_init.c b/elfloader-tool/src/plat/bcm2711/platform_init.c deleted file mode 100644 index 42dabfa0..00000000 --- a/elfloader-tool/src/plat/bcm2711/platform_init.c +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright 2021, Data61, CSIRO (ABN 41 687 119 230) - * - * SPDX-License-Identifier: GPL-2.0-only - */ - -#include -#include - -/* Reset the virtual offset for the platform timer to 0 */ -void platform_init(void) -{ - reset_cntvoff(); -} - -#if CONFIG_MAX_NUM_NODES > 1 -void non_boot_init(void) -{ - reset_cntvoff(); -} -#endif diff --git a/elfloader-tool/src/plat/bcm2837/platform_init.c b/elfloader-tool/src/plat/bcm2837/platform_init.c deleted file mode 100644 index 42dabfa0..00000000 --- a/elfloader-tool/src/plat/bcm2837/platform_init.c +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright 2021, Data61, CSIRO (ABN 41 687 119 230) - * - * SPDX-License-Identifier: GPL-2.0-only - */ - -#include -#include - -/* Reset the virtual offset for the platform timer to 0 */ -void platform_init(void) -{ - reset_cntvoff(); -} - -#if CONFIG_MAX_NUM_NODES > 1 -void non_boot_init(void) -{ - reset_cntvoff(); -} -#endif diff --git a/elfloader-tool/src/plat/exynos5/platform_init.c b/elfloader-tool/src/plat/exynos5/platform_init.c index 4ae24903..5425461f 100644 --- a/elfloader-tool/src/plat/exynos5/platform_init.c +++ b/elfloader-tool/src/plat/exynos5/platform_init.c @@ -8,7 +8,6 @@ #include #include #include -#include #include @@ -92,15 +91,4 @@ void platform_init(void) nsscode->cpu1_boot_reg = 0; smc(SMC_DISABLE_TRUSTZONE, 0, 0, 0); } - - /* Reset the virtual offset for the platform timer to 0 */ - reset_cntvoff(); -} - -#if CONFIG_MAX_NUM_NODES > 1 -void non_boot_init(void) -{ - /* Reset the virtual offset for the platform timer to 0 */ - reset_cntvoff(); } -#endif diff --git a/elfloader-tool/src/plat/fvp/platform_init.c b/elfloader-tool/src/plat/fvp/platform_init.c index 161c994b..f4204198 100644 --- a/elfloader-tool/src/plat/fvp/platform_init.c +++ b/elfloader-tool/src/plat/fvp/platform_init.c @@ -5,7 +5,6 @@ */ #include -#include void platform_init(void) { @@ -21,14 +20,4 @@ void platform_init(void) "msr tpidr_el0, x0\n" ::: "x0"); - /* Reset the virtual offset for the platform timer to 0 */ - reset_cntvoff(); } - -#if CONFIG_MAX_NUM_NODES > 1 -void non_boot_init(void) -{ - /* Reset the virtual offset for the platform timer to 0 */ - reset_cntvoff(); -} -#endif diff --git a/elfloader-tool/src/plat/hikey/platform_init.c b/elfloader-tool/src/plat/hikey/platform_init.c deleted file mode 100644 index 42dabfa0..00000000 --- a/elfloader-tool/src/plat/hikey/platform_init.c +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright 2021, Data61, CSIRO (ABN 41 687 119 230) - * - * SPDX-License-Identifier: GPL-2.0-only - */ - -#include -#include - -/* Reset the virtual offset for the platform timer to 0 */ -void platform_init(void) -{ - reset_cntvoff(); -} - -#if CONFIG_MAX_NUM_NODES > 1 -void non_boot_init(void) -{ - reset_cntvoff(); -} -#endif diff --git a/elfloader-tool/src/plat/imx7/platform_init.c b/elfloader-tool/src/plat/imx7/platform_init.c deleted file mode 100644 index 42dabfa0..00000000 --- a/elfloader-tool/src/plat/imx7/platform_init.c +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright 2021, Data61, CSIRO (ABN 41 687 119 230) - * - * SPDX-License-Identifier: GPL-2.0-only - */ - -#include -#include - -/* Reset the virtual offset for the platform timer to 0 */ -void platform_init(void) -{ - reset_cntvoff(); -} - -#if CONFIG_MAX_NUM_NODES > 1 -void non_boot_init(void) -{ - reset_cntvoff(); -} -#endif diff --git a/elfloader-tool/src/plat/imx8m-evk/platform_init.c b/elfloader-tool/src/plat/imx8m-evk/platform_init.c deleted file mode 100644 index 42dabfa0..00000000 --- a/elfloader-tool/src/plat/imx8m-evk/platform_init.c +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright 2021, Data61, CSIRO (ABN 41 687 119 230) - * - * SPDX-License-Identifier: GPL-2.0-only - */ - -#include -#include - -/* Reset the virtual offset for the platform timer to 0 */ -void platform_init(void) -{ - reset_cntvoff(); -} - -#if CONFIG_MAX_NUM_NODES > 1 -void non_boot_init(void) -{ - reset_cntvoff(); -} -#endif diff --git a/elfloader-tool/src/plat/maaxboard/platform_init.c b/elfloader-tool/src/plat/maaxboard/platform_init.c deleted file mode 100644 index 78302edf..00000000 --- a/elfloader-tool/src/plat/maaxboard/platform_init.c +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright 2021, Data61, CSIRO (ABN 41 687 119 230) - * Copyright 2022, Capgemini Engineering - * - * SPDX-License-Identifier: GPL-2.0-only - */ - -#include -#include - -/* Reset the virtual offset for the platform timer to 0 */ -void platform_init(void) -{ - reset_cntvoff(); -} - -#if CONFIG_MAX_NUM_NODES > 1 -void non_boot_init(void) -{ - reset_cntvoff(); -} -#endif diff --git a/elfloader-tool/src/plat/odroidc2/platform_init.c b/elfloader-tool/src/plat/odroidc2/platform_init.c deleted file mode 100644 index 42dabfa0..00000000 --- a/elfloader-tool/src/plat/odroidc2/platform_init.c +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright 2021, Data61, CSIRO (ABN 41 687 119 230) - * - * SPDX-License-Identifier: GPL-2.0-only - */ - -#include -#include - -/* Reset the virtual offset for the platform timer to 0 */ -void platform_init(void) -{ - reset_cntvoff(); -} - -#if CONFIG_MAX_NUM_NODES > 1 -void non_boot_init(void) -{ - reset_cntvoff(); -} -#endif diff --git a/elfloader-tool/src/plat/odroidc4/platform_init.c b/elfloader-tool/src/plat/odroidc4/platform_init.c deleted file mode 100644 index 42dabfa0..00000000 --- a/elfloader-tool/src/plat/odroidc4/platform_init.c +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright 2021, Data61, CSIRO (ABN 41 687 119 230) - * - * SPDX-License-Identifier: GPL-2.0-only - */ - -#include -#include - -/* Reset the virtual offset for the platform timer to 0 */ -void platform_init(void) -{ - reset_cntvoff(); -} - -#if CONFIG_MAX_NUM_NODES > 1 -void non_boot_init(void) -{ - reset_cntvoff(); -} -#endif diff --git a/elfloader-tool/src/plat/qemu-arm-virt/platform_init.c b/elfloader-tool/src/plat/qemu-arm-virt/platform_init.c deleted file mode 100644 index 42dabfa0..00000000 --- a/elfloader-tool/src/plat/qemu-arm-virt/platform_init.c +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright 2021, Data61, CSIRO (ABN 41 687 119 230) - * - * SPDX-License-Identifier: GPL-2.0-only - */ - -#include -#include - -/* Reset the virtual offset for the platform timer to 0 */ -void platform_init(void) -{ - reset_cntvoff(); -} - -#if CONFIG_MAX_NUM_NODES > 1 -void non_boot_init(void) -{ - reset_cntvoff(); -} -#endif diff --git a/elfloader-tool/src/plat/quartz64/platform_init.c b/elfloader-tool/src/plat/quartz64/platform_init.c deleted file mode 100644 index 42dabfa0..00000000 --- a/elfloader-tool/src/plat/quartz64/platform_init.c +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright 2021, Data61, CSIRO (ABN 41 687 119 230) - * - * SPDX-License-Identifier: GPL-2.0-only - */ - -#include -#include - -/* Reset the virtual offset for the platform timer to 0 */ -void platform_init(void) -{ - reset_cntvoff(); -} - -#if CONFIG_MAX_NUM_NODES > 1 -void non_boot_init(void) -{ - reset_cntvoff(); -} -#endif diff --git a/elfloader-tool/src/plat/rockpro64/platform_init.c b/elfloader-tool/src/plat/rockpro64/platform_init.c deleted file mode 100644 index 42dabfa0..00000000 --- a/elfloader-tool/src/plat/rockpro64/platform_init.c +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright 2021, Data61, CSIRO (ABN 41 687 119 230) - * - * SPDX-License-Identifier: GPL-2.0-only - */ - -#include -#include - -/* Reset the virtual offset for the platform timer to 0 */ -void platform_init(void) -{ - reset_cntvoff(); -} - -#if CONFIG_MAX_NUM_NODES > 1 -void non_boot_init(void) -{ - reset_cntvoff(); -} -#endif diff --git a/elfloader-tool/src/plat/tk1/platform_init.c b/elfloader-tool/src/plat/tk1/platform_init.c index 4ea6da26..d3daa369 100644 --- a/elfloader-tool/src/plat/tk1/platform_init.c +++ b/elfloader-tool/src/plat/tk1/platform_init.c @@ -5,7 +5,6 @@ */ #include -#include #include #include #include @@ -309,14 +308,4 @@ void platform_init(void) switch_to_mon_mode(); #endif - /* Reset the virtual offset for the platform timer to 0 */ - reset_cntvoff(); } - -#if CONFIG_MAX_NUM_NODES > 1 -void non_boot_init(void) -{ - /* Reset the virtual offset for the platform timer to 0 */ - reset_cntvoff(); -} -#endif diff --git a/elfloader-tool/src/plat/tqma8xqp1gb/platform_init.c b/elfloader-tool/src/plat/tqma8xqp1gb/platform_init.c deleted file mode 100644 index 42dabfa0..00000000 --- a/elfloader-tool/src/plat/tqma8xqp1gb/platform_init.c +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright 2021, Data61, CSIRO (ABN 41 687 119 230) - * - * SPDX-License-Identifier: GPL-2.0-only - */ - -#include -#include - -/* Reset the virtual offset for the platform timer to 0 */ -void platform_init(void) -{ - reset_cntvoff(); -} - -#if CONFIG_MAX_NUM_NODES > 1 -void non_boot_init(void) -{ - reset_cntvoff(); -} -#endif diff --git a/elfloader-tool/src/plat/tx1/platform_init.c b/elfloader-tool/src/plat/tx1/platform_init.c deleted file mode 100644 index 42dabfa0..00000000 --- a/elfloader-tool/src/plat/tx1/platform_init.c +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright 2021, Data61, CSIRO (ABN 41 687 119 230) - * - * SPDX-License-Identifier: GPL-2.0-only - */ - -#include -#include - -/* Reset the virtual offset for the platform timer to 0 */ -void platform_init(void) -{ - reset_cntvoff(); -} - -#if CONFIG_MAX_NUM_NODES > 1 -void non_boot_init(void) -{ - reset_cntvoff(); -} -#endif diff --git a/elfloader-tool/src/plat/tx2/platform_init.c b/elfloader-tool/src/plat/tx2/platform_init.c index d6432094..9f9118af 100644 --- a/elfloader-tool/src/plat/tx2/platform_init.c +++ b/elfloader-tool/src/plat/tx2/platform_init.c @@ -5,7 +5,6 @@ */ #include -#include #include #include @@ -84,15 +83,4 @@ static void enable_serr(void) void platform_init(void) { enable_serr(); - - /* Reset the virtual offset for the platform timer to 0 */ - reset_cntvoff(); -} - -#if CONFIG_MAX_NUM_NODES > 1 -void non_boot_init(void) -{ - /* Reset the virtual offset for the platform timer to 0 */ - reset_cntvoff(); } -#endif diff --git a/elfloader-tool/src/plat/zynqmp/platform_init.c b/elfloader-tool/src/plat/zynqmp/platform_init.c deleted file mode 100644 index 42dabfa0..00000000 --- a/elfloader-tool/src/plat/zynqmp/platform_init.c +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright 2021, Data61, CSIRO (ABN 41 687 119 230) - * - * SPDX-License-Identifier: GPL-2.0-only - */ - -#include -#include - -/* Reset the virtual offset for the platform timer to 0 */ -void platform_init(void) -{ - reset_cntvoff(); -} - -#if CONFIG_MAX_NUM_NODES > 1 -void non_boot_init(void) -{ - reset_cntvoff(); -} -#endif From ecc9b6266764f2118374f49554383054b335a6dd Mon Sep 17 00:00:00 2001 From: Kent McLeod Date: Thu, 15 Feb 2024 23:09:06 +1100 Subject: [PATCH 4/6] elfloader: Only include driver source on arm RISC-V platforms don't use any extension drivers currently so it's not useful to compile and link them in when not building for arm. Signed-off-by: Kent McLeod --- elfloader-tool/CMakeLists.txt | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/elfloader-tool/CMakeLists.txt b/elfloader-tool/CMakeLists.txt index ac747c94..99bf0997 100644 --- a/elfloader-tool/CMakeLists.txt +++ b/elfloader-tool/CMakeLists.txt @@ -164,14 +164,22 @@ elseif(KernelSel4ArchAarch32) add_compile_options(-mno-unaligned-access) endif() -file( - GLOB - files - src/*.c +if(KernelArchARM) + # Only the Arm arch uses extension drivers. + set( + driver_file_globs src/drivers/*.c src/drivers/smp/*.c src/drivers/uart/*.c src/drivers/timer/*.c + ) +endif() + +file( + GLOB + files + src/*.c + ${driver_file_globs} src/utils/*.c src/arch-${KernelArch}/*.c src/arch-${KernelArch}/*.S From 66b3de4e92ac9997077c774353395e455bfa0f09 Mon Sep 17 00:00:00 2001 From: Kent McLeod Date: Fri, 16 Feb 2024 07:42:30 +1100 Subject: [PATCH 5/6] elfloader: Remove non_boot_init() interface This was previously added to handle per-core initialization of the generic timer. Now that a generic driver mechanism is used to perform this initialization the old interface is redundant. Signed-off-by: Kent McLeod --- elfloader-tool/src/arch-arm/smp_boot.c | 5 ----- 1 file changed, 5 deletions(-) diff --git a/elfloader-tool/src/arch-arm/smp_boot.c b/elfloader-tool/src/arch-arm/smp_boot.c index 3acb88cb..2745211c 100644 --- a/elfloader-tool/src/arch-arm/smp_boot.c +++ b/elfloader-tool/src/arch-arm/smp_boot.c @@ -26,8 +26,6 @@ void arm_disable_dcaches(void); extern void const *dtb; extern uint32_t dtb_size; -WEAK void non_boot_init(void) {} - /* Entry point for all CPUs other than the initial. */ void non_boot_main(void) { @@ -41,9 +39,6 @@ void non_boot_main(void) #endif } - /* Initialise any platform-specific per-core state */ - non_boot_init(); - /* Do any driver specific non_boot core init */ initialise_devices_non_boot(); From 6dae7890c18159f19da9a539f843489961644e29 Mon Sep 17 00:00:00 2001 From: Kent McLeod Date: Fri, 16 Feb 2024 07:45:44 +1100 Subject: [PATCH 6/6] elfloader: Check return code of device init Device initialization returns early if an error is encountered. Handle this error by printing an Error message and aborting the booting process. Signed-off-by: Kent McLeod --- elfloader-tool/src/arch-arm/smp_boot.c | 5 ++++- elfloader-tool/src/arch-arm/sys_boot.c | 11 +++++++++-- elfloader-tool/src/drivers/driver.c | 10 ++++++++-- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/elfloader-tool/src/arch-arm/smp_boot.c b/elfloader-tool/src/arch-arm/smp_boot.c index 2745211c..d429d113 100644 --- a/elfloader-tool/src/arch-arm/smp_boot.c +++ b/elfloader-tool/src/arch-arm/smp_boot.c @@ -40,7 +40,10 @@ void non_boot_main(void) } /* Do any driver specific non_boot core init */ - initialise_devices_non_boot(); + if (initialise_devices_non_boot()) { + printf("ERROR: Did not successfully return from initialise_devices_non_boot()\n"); + abort(); + } #ifndef CONFIG_ARM_HYPERVISOR_SUPPORT if (is_hyp_mode()) { diff --git a/elfloader-tool/src/arch-arm/sys_boot.c b/elfloader-tool/src/arch-arm/sys_boot.c index 9f6b17a0..bf98aaf2 100644 --- a/elfloader-tool/src/arch-arm/sys_boot.c +++ b/elfloader-tool/src/arch-arm/sys_boot.c @@ -104,7 +104,11 @@ void main(UNUSED void *arg) void *bootloader_dtb = NULL; /* initialize platform to a state where we can print to a UART */ - initialise_devices(); + if (initialise_devices()) { + printf("ERROR: Did not successfully return from initialise_devices()\n"); + abort(); + } + platform_init(); /* Print welcome message. */ @@ -175,7 +179,10 @@ void continue_boot(int was_relocated) * driver model so all its pointers are set up properly. */ if (was_relocated) { - initialise_devices(); + if (initialise_devices()) { + printf("ERROR: Did not successfully return from initialise_devices()\n"); + abort(); + } } #if (defined(CONFIG_ARCH_ARM_V7A) || defined(CONFIG_ARCH_ARM_V8A)) && !defined(CONFIG_ARM_HYPERVISOR_SUPPORT) diff --git a/elfloader-tool/src/drivers/driver.c b/elfloader-tool/src/drivers/driver.c index 5edd00ab..e433dc16 100644 --- a/elfloader-tool/src/drivers/driver.c +++ b/elfloader-tool/src/drivers/driver.c @@ -33,7 +33,10 @@ static int init_device(struct elfloader_device *dev) int ret = table_has_match(dev->compat, drv->match_table); if (ret >= 0) { dev->drv = drv; - drv->init(dev, drv->match_table[ret].match_data); + ret = drv->init(dev, drv->match_table[ret].match_data); + if (ret) { + return ret; + } } drvp++; } @@ -64,7 +67,10 @@ static int init_device_non_boot(struct elfloader_device *dev) int ret = table_has_match(dev->compat, drv->match_table); if (ret >= 0) { dev->drv = drv; - drv->init_on_secondary_cores(dev, drv->match_table[ret].match_data); + ret = drv->init_on_secondary_cores(dev, drv->match_table[ret].match_data); + if (ret) { + return ret; + } } } drvp++;