From 5359c3caeb610573f417cf315c0e0f97e095f5a9 Mon Sep 17 00:00:00 2001 From: Ivaylo Ivanov Date: Thu, 10 Jul 2025 21:08:16 +0300 Subject: [PATCH] board: rework the board data structure Since we don't have to worry about writing positionally-independent code, we can safely pass around globally defined structures and have more fun with pointers without falling into UB. --- board/amazon/board-pw3.c | 30 +++++++++------------ board/apple/board-n61ap.c | 38 ++++++++++++-------------- board/samsung/board-a105f.c | 30 +++++++++------------ board/samsung/board-a127f.c | 26 +++++++++--------- board/samsung/board-a336b.c | 30 +++++++++------------ board/samsung/board-c1s.c | 32 +++++++++------------- board/samsung/board-dreamlte.c | 46 ++++++++++++++------------------ board/samsung/board-g0s.c | 40 ++++++++++++--------------- board/samsung/board-gta4xl.c | 30 +++++++++------------ board/samsung/board-j4lte.c | 30 +++++++++------------ board/samsung/board-j5lte.c | 39 ++++++++++++--------------- board/samsung/board-jackpotlte.c | 30 +++++++++------------ board/samsung/board-noblelte.c | 30 +++++++++------------ board/samsung/board-r8s.c | 30 +++++++++------------ board/samsung/board-starlte.c | 30 +++++++++------------ board/samsung/board-x1s.c | 30 +++++++++------------ board/samsung/board-zeroflte.c | 30 +++++++++------------ board/volla/board-algiz.c | 42 +++++++++++++---------------- include/board.h | 40 +++++---------------------- main/main.c | 36 ++++++++++--------------- 20 files changed, 278 insertions(+), 391 deletions(-) diff --git a/board/amazon/board-pw3.c b/board/amazon/board-pw3.c index 0855eff..dbe85a9 100644 --- a/board/amazon/board-pw3.c +++ b/board/amazon/board-pw3.c @@ -34,31 +34,27 @@ void uart_puts(const char *s) } } -void init_board_funcs(void *board) -{ - /* - * Parsing the struct directly without restructing is - * broken as of Sep 29 2024 - */ - struct { - const char *name; - int ops[BOARD_OP_EXIT]; - } *board_restruct = board; - - board_restruct->name = "PW3"; -} - -int board_init(void) +int pw3_init(void) { return 0; } -int board_late_init(void) +int pw3_late_init(void) { return 0; } -int board_driver_setup(void) +int pw3_drv(void) { return 0; } + +struct board_data board_ops = { + .name = "amazon-paperwhite3", + .ops = { + .early_init = pw3_init, + .drivers_init = pw3_drv, + .late_init = pw3_late_init, + }, + .quirks = 0 +}; diff --git a/board/apple/board-n61ap.c b/board/apple/board-n61ap.c index e0b3347..51d9ff1 100644 --- a/board/apple/board-n61ap.c +++ b/board/apple/board-n61ap.c @@ -6,31 +6,12 @@ #include #include -void init_board_funcs(void *board) -{ - /* - * Parsing the struct directly without restructing is - * broken as of Sep 29 2024 - */ - struct { - const char *name; - int ops[BOARD_OP_EXIT]; - } *board_restruct = board; - - board_restruct->name = "N61AP"; -} - -int board_init(void) +int n61ap_init(void) { return 0; } -int board_late_init(void) -{ - return 0; -} - -int board_driver_setup(void) +int n61ap_drv(void) { struct { int width; @@ -47,3 +28,18 @@ int board_driver_setup(void) REGISTER_DRIVER("simplefb", simplefb_probe, &simplefb_data); return 0; } + +int n61ap_late_init(void) +{ + return 0; +} + +struct board_data board_ops = { + .name = "apple-iphone6", + .ops = { + .early_init = n61ap_init, + .drivers_init = n61ap_drv, + .late_init = n61ap_late_init, + }, + .quirks = 0 +}; diff --git a/board/samsung/board-a105f.c b/board/samsung/board-a105f.c index 76f8998..69b11ee 100644 --- a/board/samsung/board-a105f.c +++ b/board/samsung/board-a105f.c @@ -8,22 +8,8 @@ #include #include -void init_board_funcs(void *board) -{ - /* - * Parsing the struct directly without restructing is - * broken as of Sep 29 2024 - */ - struct { - const char *name; - int ops[BOARD_OP_EXIT]; - } *board_restruct = board; - - board_restruct->name = "A105F"; -} - // Early initialization -int board_init(void) +int a105f_init(void) { /* Allow framebuffer to be written to */ *(int*) (DECON_F_BASE + HW_SW_TRIG_CONTROL) = 0x1281; @@ -31,12 +17,12 @@ int board_init(void) } // Late initialization -int board_late_init(void) +int a105f_late_init(void) { return 0; } -int board_driver_setup(void) +int a105f_drv(void) { struct { int width; @@ -53,3 +39,13 @@ int board_driver_setup(void) REGISTER_DRIVER("simplefb", simplefb_probe, &simplefb_data); return 0; } + +struct board_data board_ops = { + .name = "samsung-a105f", + .ops = { + .early_init = a105f_init, + .drivers_init = a105f_drv, + .late_init = a105f_late_init, + }, + .quirks = 0 +}; diff --git a/board/samsung/board-a127f.c b/board/samsung/board-a127f.c index 9bdccf6..5f2d3f1 100644 --- a/board/samsung/board-a127f.c +++ b/board/samsung/board-a127f.c @@ -9,28 +9,18 @@ #include #include -void init_board_funcs(void *board) -{ - struct { - const char *name; - int ops[BOARD_OP_EXIT]; - } *board_restruct = board; - - board_restruct->name = "A127F"; -} - -int board_init(void) +int a127f_init(void) { *(int*) (DECON_F_BASE + HW_SW_TRIG_CONTROL) = 0x1281; return 0; } -int board_late_init(void) +int a127f_late_init(void) { return 0; } -int board_driver_setup(void) +int a127f_drv(void) { struct { int width; @@ -47,3 +37,13 @@ int board_driver_setup(void) REGISTER_DRIVER("simplefb", simplefb_probe, &simplefb_data); return 0; } + +struct board_data board_ops = { + .name = "samsung-a127f", + .ops = { + .early_init = a127f_init, + .drivers_init = a127f_drv, + .late_init = a127f_late_init, + }, + .quirks = 0 +}; diff --git a/board/samsung/board-a336b.c b/board/samsung/board-a336b.c index 1e6087f..35f330a 100644 --- a/board/samsung/board-a336b.c +++ b/board/samsung/board-a336b.c @@ -7,22 +7,8 @@ #include #include -void init_board_funcs(void *board) -{ - /* - * Parsing the struct directly without restructing is - * broken as of Sep 29 2024 - */ - struct { - const char *name; - int ops[BOARD_OP_EXIT]; - } *board_restruct = board; - - board_restruct->name = "A33x"; -} - // Early initialization -int board_init(void) +int a33x_init(void) { /* Allow framebuffer to be written to */ *(int*) (DECON_F_BASE + HW_SW_TRIG_CONTROL) = 0x1281; @@ -31,12 +17,12 @@ int board_init(void) } // Late initialization -int board_late_init(void) +int a33x_late_init(void) { return 0; } -int board_driver_setup(void) +int a33x_drv(void) { struct { int width; @@ -53,3 +39,13 @@ int board_driver_setup(void) REGISTER_DRIVER("simplefb", simplefb_probe, &simplefb_data); return 0; } + +struct board_data board_ops = { + .name = "samsung-a33x", + .ops = { + .early_init = a33x_init, + .drivers_init = a33x_drv, + .late_init = a33x_late_init, + }, + .quirks = 0 +}; diff --git a/board/samsung/board-c1s.c b/board/samsung/board-c1s.c index 7fbafb5..34e79c6 100755 --- a/board/samsung/board-c1s.c +++ b/board/samsung/board-c1s.c @@ -10,35 +10,19 @@ #define DECON_F_BASE 0x19050000 #define HW_SW_TRIG_CONTROL 0x70 -void init_board_funcs(void *board) -{ - /* - * Parsing the struct directly without restructing is - * broken as of Sep 29 2024 - */ - struct { - const char *name; - int ops[BOARD_OP_EXIT]; - } *board_restruct = board; - - board_restruct->name = "C1S"; -} - -// Early initialization -int board_init(void) +int c1s_init(void) { /* Allow framebuffer to be written to */ *(int*) (DECON_F_BASE + HW_SW_TRIG_CONTROL) = 0x1281; return 0; } -// Late initialization -int board_late_init(void) +int c1s_late_init(void) { return 0; } -int board_driver_setup(void) +int c1s_drv(void) { struct { int width; @@ -55,3 +39,13 @@ int board_driver_setup(void) REGISTER_DRIVER("simplefb", simplefb_probe, &simplefb_data); return 0; } + +struct board_data board_ops = { + .name = "samsung-c1s", + .ops = { + .early_init = c1s_init, + .drivers_init = c1s_drv, + .late_init = c1s_late_init, + }, + .quirks = 0 +}; diff --git a/board/samsung/board-dreamlte.c b/board/samsung/board-dreamlte.c index 1db9598..3d52532 100644 --- a/board/samsung/board-dreamlte.c +++ b/board/samsung/board-dreamlte.c @@ -18,20 +18,6 @@ #define DECON_F_BASE 0x12860000 #define SPEEDY_BASE 0x15b50000 -void init_board_funcs(void *board) -{ - /* - * Parsing the struct directly without restructing is - * broken as of Sep 29 2024 - */ - struct { - const char *name; - int ops[BOARD_OP_EXIT]; - } *board_restruct = board; - - board_restruct->name = "DREAMLTE"; -} - enum s2mps17_ldos { S2MPS17_LDO2, S2MPS17_LDO34, @@ -120,23 +106,14 @@ static void s2mps17_setup(void) return; } -// Early initialization -int board_init(void) +int dreamlte_init(void) { - /* Allow framebuffer to be written to */ + /* allow framebuffer to be written to */ *(int*) (DECON_F_BASE + HW_SW_TRIG_CONTROL) = 0x1281; return 0; } -// Late initialization -int board_late_init(void) -{ - s2mps17_setup(); - - return 0; -} - -int board_driver_setup(void) +int dreamlte_drv(void) { struct { int width; @@ -153,3 +130,20 @@ int board_driver_setup(void) REGISTER_DRIVER("simplefb", simplefb_probe, &simplefb_data); return 0; } + +int dreamlte_late_init(void) +{ + s2mps17_setup(); + + return 0; +} + +struct board_data board_ops = { + .name = "samsung-dreamlte", + .ops = { + .early_init = dreamlte_init, + .drivers_init = dreamlte_drv, + .late_init = dreamlte_late_init, + }, + .quirks = 0 +}; diff --git a/board/samsung/board-g0s.c b/board/samsung/board-g0s.c index 7ebb08f..cf67a42 100755 --- a/board/samsung/board-g0s.c +++ b/board/samsung/board-g0s.c @@ -15,20 +15,6 @@ #define EXYNOS_MAILBOX_AP2APM 0x15900000 #define DECON_F_BASE 0x19f00000 -void init_board_funcs(void *board) -{ - /* - * Parsing the struct directly without restructing is - * broken as of Sep 29 2024 - */ - struct { - const char *name; - int ops[BOARD_OP_EXIT]; - } *board_restruct = board; - - board_restruct->name = "G0S"; -} - /* WDT Register MAP */ #define S5E9925_WDT_BASE 0x10050000 #define S5E9925_WDT_WTCON (S5E9925_WDT_BASE + 0x0000) @@ -85,8 +71,7 @@ void pmic_init(void) spmi_write(mailbox_base, 0, S2MPS25_PM1_ADDR, S2MPS25_REG_LDO28M_CTRL, reg); } -// Early initialization -int board_init(void) +int g0s_init(void) { /* Allow framebuffer to be written to */ *(int*) (DECON_F_BASE + HW_SW_TRIG_CONTROL) = 0x1281; @@ -97,13 +82,7 @@ int board_init(void) return 0; } -// Late initialization -int board_late_init(void) -{ - return 0; -} - -int board_driver_setup(void) +int g0s_drv(void) { struct { int width; @@ -120,3 +99,18 @@ int board_driver_setup(void) REGISTER_DRIVER("simplefb", simplefb_probe, &simplefb_data); return 0; } + +int g0s_late_init(void) +{ + return 0; +} + +struct board_data board_ops = { + .name = "samsung-g0s", + .ops = { + .early_init = g0s_init, + .drivers_init = g0s_drv, + .late_init = g0s_late_init, + }, + .quirks = 0 +}; diff --git a/board/samsung/board-gta4xl.c b/board/samsung/board-gta4xl.c index cb23129..168bac7 100644 --- a/board/samsung/board-gta4xl.c +++ b/board/samsung/board-gta4xl.c @@ -10,22 +10,8 @@ #define DECON_F_BASE 0x148b0000 #define HW_SW_TRIG_CONTROL 0x70 -void init_board_funcs(void *board) -{ - /* - * Parsing the struct directly without restructing is - * broken as of Sep 29 2024 - */ - struct { - const char *name; - int ops[BOARD_OP_EXIT]; - } *board_restruct = board; - - board_restruct->name = "GTA4XL"; -} - // Early initialization -int board_init(void) +int gta4xl_init(void) { /* Allow framebuffer to be written to */ *(int*) (DECON_F_BASE + HW_SW_TRIG_CONTROL) = 0x1281; @@ -33,12 +19,12 @@ int board_init(void) } // Late initialization -int board_late_init(void) +int gta4xl_late_init(void) { return 0; } -int board_driver_setup(void) +int gta4xl_drv(void) { struct { int width; @@ -55,3 +41,13 @@ int board_driver_setup(void) REGISTER_DRIVER("simplefb", simplefb_probe, &simplefb_data); return 0; } + +struct board_data board_ops = { + .name = "samsung-gta4xl", + .ops = { + .early_init = gta4xl_init, + .drivers_init = gta4xl_drv, + .late_init = gta4xl_late_init, + }, + .quirks = 0 +}; diff --git a/board/samsung/board-j4lte.c b/board/samsung/board-j4lte.c index 2560868..2e966a4 100644 --- a/board/samsung/board-j4lte.c +++ b/board/samsung/board-j4lte.c @@ -10,22 +10,8 @@ #define DECON_F_BASE 0x14830000 #define HW_SW_TRIG_CONTROL 0x70 -void init_board_funcs(void *board) -{ - /* - * Parsing the struct directly without restructing is - * broken as of Sep 29 2024 - */ - struct { - const char *name; - int ops[BOARD_OP_EXIT]; - } *board_restruct = board; - - board_restruct->name = "J4LTE"; -} - // Early initialization -int board_init(void) +int j4lte_init(void) { /* Allow framebuffer to be written to */ *(int*) (DECON_F_BASE + HW_SW_TRIG_CONTROL) = 0x1281; @@ -33,12 +19,12 @@ int board_init(void) } // Late initialization -int board_late_init(void) +int j4lte_late_init(void) { return 0; } -int board_driver_setup(void) +int j4lte_drv(void) { struct { int width; @@ -55,3 +41,13 @@ int board_driver_setup(void) REGISTER_DRIVER("simplefb", simplefb_probe, &simplefb_data); return 0; } + +struct board_data board_ops = { + .name = "samsung-j4lte", + .ops = { + .early_init = j4lte_init, + .drivers_init = j4lte_drv, + .late_init = j4lte_late_init, + }, + .quirks = 0 +}; diff --git a/board/samsung/board-j5lte.c b/board/samsung/board-j5lte.c index 5caf1ef..eeb5c73 100644 --- a/board/samsung/board-j5lte.c +++ b/board/samsung/board-j5lte.c @@ -16,21 +16,7 @@ #define MDP_CTL_0_BASE 0x1A02000 #define MDP_CTL_FLUSH 0x18 -void init_board_funcs(void *board) -{ - /* - * Parsing the struct directly without restructing is - * broken as of Sep 29 2024 - */ - struct { - const char *name; - int ops[BOARD_OP_EXIT]; - } *board_restruct = board; - - board_restruct->name = "J5LTE"; -} - -int board_init(void) +int j5lte_init(void) { /* TODO: Doesn't really work :P */ writel(0x000236FF, PIPE_BASE + PIPE_SSPP_SRC_FORMAT); @@ -41,13 +27,7 @@ int board_init(void) return 0; } -// Late initialization -int board_late_init(void) -{ - return 0; -} - -int board_driver_setup(void) +int j5lte_drv(void) { struct { int width; @@ -64,3 +44,18 @@ int board_driver_setup(void) REGISTER_DRIVER("simplefb", simplefb_probe, &simplefb_data); return 0; } + +int j5lte_late_init(void) +{ + return 0; +} + +struct board_data board_ops = { + .name = "samsung-j5lte", + .ops = { + .early_init = j5lte_init, + .drivers_init = j5lte_drv, + .late_init = j5lte_late_init, + }, + .quirks = 0 +}; diff --git a/board/samsung/board-jackpotlte.c b/board/samsung/board-jackpotlte.c index 25cff15..db6ad6e 100644 --- a/board/samsung/board-jackpotlte.c +++ b/board/samsung/board-jackpotlte.c @@ -10,22 +10,8 @@ #define DECON_F_BASE 0x14860000 #define HW_SW_TRIG_CONTROL 0x70 -void init_board_funcs(void *board) -{ - /* - * Parsing the struct directly without restructing is - * broken as of Sep 29 2024 - */ - struct { - const char *name; - int ops[BOARD_OP_EXIT]; - } *board_restruct = board; - - board_restruct->name = "JACKPOTLTE"; -} - // Early initialization -int board_init(void) +int jackpotlte_init(void) { /* Allow framebuffer to be written to */ *(int*) (DECON_F_BASE + HW_SW_TRIG_CONTROL) = 0x1281; @@ -33,12 +19,12 @@ int board_init(void) } // Late initialization -int board_late_init(void) +int jackpotlte_late_init(void) { return 0; } -int board_driver_setup(void) +int jackpotlte_drv(void) { struct { int width; @@ -55,3 +41,13 @@ int board_driver_setup(void) REGISTER_DRIVER("simplefb", simplefb_probe, &simplefb_data); return 0; } + +struct board_data board_ops = { + .name = "samsung-jackpotlte", + .ops = { + .early_init = jackpotlte_init, + .drivers_init = jackpotlte_drv, + .late_init = jackpotlte_late_init, + }, + .quirks = 0 +}; diff --git a/board/samsung/board-noblelte.c b/board/samsung/board-noblelte.c index 5fd45d5..c3a92c6 100644 --- a/board/samsung/board-noblelte.c +++ b/board/samsung/board-noblelte.c @@ -10,22 +10,8 @@ #define DECON_F_BASE 0x13930000 #define HW_SW_TRIG_CONTROL 0x6b0 -void init_board_funcs(void *board) -{ - /* - * Parsing the struct directly without restructing is - * broken as of Sep 29 2024 - */ - struct { - const char *name; - int ops[BOARD_OP_EXIT]; - } *board_restruct = board; - - board_restruct->name = "NOBLELTE"; -} - // Early initialization -int board_init(void) +int noblelte_init(void) { /* Allow framebuffer to be written to */ *(int*) (DECON_F_BASE + HW_SW_TRIG_CONTROL) = 0x2058; @@ -33,12 +19,12 @@ int board_init(void) } // Late initialization -int board_late_init(void) +int noblelte_late_init(void) { return 0; } -int board_driver_setup(void) +int noblelte_drv(void) { struct { int width; @@ -55,3 +41,13 @@ int board_driver_setup(void) REGISTER_DRIVER("simplefb", simplefb_probe, &simplefb_data); return 0; } + +struct board_data board_ops = { + .name = "samsung-noblelte", + .ops = { + .early_init = noblelte_init, + .drivers_init = noblelte_drv, + .late_init = noblelte_late_init, + }, + .quirks = 0 +}; diff --git a/board/samsung/board-r8s.c b/board/samsung/board-r8s.c index ab58b84..114fe7d 100644 --- a/board/samsung/board-r8s.c +++ b/board/samsung/board-r8s.c @@ -10,22 +10,8 @@ #define DECON_F_BASE 0x19050000 #define HW_SW_TRIG_CONTROL 0x70 -void init_board_funcs(void *board) -{ - /* - * Parsing the struct directly without restructing is - * broken as of Sep 29 2024 - */ - struct { - const char *name; - int ops[BOARD_OP_EXIT]; - } *board_restruct = board; - - board_restruct->name = "R8S"; -} - // Early initialization -int board_init(void) +int r8s_init(void) { /* Allow framebuffer to be written to */ *(int*) (DECON_F_BASE + HW_SW_TRIG_CONTROL) = 0x1281; @@ -33,12 +19,12 @@ int board_init(void) } // Late initialization -int board_late_init(void) +int r8s_late_init(void) { return 0; } -int board_driver_setup(void) +int r8s_drv(void) { struct { int width; @@ -55,3 +41,13 @@ int board_driver_setup(void) REGISTER_DRIVER("simplefb", simplefb_probe, &simplefb_data); return 0; } + +struct board_data board_ops = { + .name = "samsung-r8s", + .ops = { + .early_init = r8s_init, + .drivers_init = r8s_drv, + .late_init = r8s_late_init, + }, + .quirks = 0 +}; diff --git a/board/samsung/board-starlte.c b/board/samsung/board-starlte.c index 94a03e3..1cf1a0b 100644 --- a/board/samsung/board-starlte.c +++ b/board/samsung/board-starlte.c @@ -10,22 +10,8 @@ #define DECON_F_BASE 0x16030000 #define HW_SW_TRIG_CONTROL 0x70 -void init_board_funcs(void *board) -{ - /* - * Parsing the struct directly without restructing is - * broken as of Sep 29 2024 - */ - struct { - const char *name; - int ops[BOARD_OP_EXIT]; - } *board_restruct = board; - - board_restruct->name = "STARLTE"; -} - // Early initialization -int board_init(void) +int starlte_init(void) { /* Allow framebuffer to be written to */ *(int*) (DECON_F_BASE + HW_SW_TRIG_CONTROL) = 0x1281; @@ -33,12 +19,12 @@ int board_init(void) } // Late initialization -int board_late_init(void) +int starlte_late_init(void) { return 0; } -int board_driver_setup(void) +int starlte_drv(void) { struct { int width; @@ -55,3 +41,13 @@ int board_driver_setup(void) REGISTER_DRIVER("simplefb", simplefb_probe, &simplefb_data); return 0; } + +struct board_data board_ops = { + .name = "samsung-starlte", + .ops = { + .early_init = starlte_init, + .drivers_init = starlte_drv, + .late_init = starlte_late_init, + }, + .quirks = 0 +}; diff --git a/board/samsung/board-x1s.c b/board/samsung/board-x1s.c index ecf09a8..c8fcac8 100644 --- a/board/samsung/board-x1s.c +++ b/board/samsung/board-x1s.c @@ -10,22 +10,8 @@ #define DECON_F_BASE 0x19050000 #define HW_SW_TRIG_CONTROL 0x70 -void init_board_funcs(void *board) -{ - /* - * Parsing the struct directly without restructing is - * broken as of Sep 29 2024 - */ - struct { - const char *name; - int ops[BOARD_OP_EXIT]; - } *board_restruct = board; - - board_restruct->name = "X1S"; -} - // Early initialization -int board_init(void) +int x1s_init(void) { /* Allow framebuffer to be written to */ *(int*) (DECON_F_BASE + HW_SW_TRIG_CONTROL) = 0x1281; @@ -33,12 +19,12 @@ int board_init(void) } // Late initialization -int board_late_init(void) +int x1s_late_init(void) { return 0; } -int board_driver_setup(void) +int x1s_drv(void) { struct { int width; @@ -55,3 +41,13 @@ int board_driver_setup(void) REGISTER_DRIVER("simplefb", simplefb_probe, &simplefb_data); return 0; } + +struct board_data board_ops = { + .name = "samsung-x1s", + .ops = { + .early_init = x1s_init, + .drivers_init = x1s_drv, + .late_init = x1s_late_init, + }, + .quirks = 0 +}; diff --git a/board/samsung/board-zeroflte.c b/board/samsung/board-zeroflte.c index 02760fd..dbf01f5 100644 --- a/board/samsung/board-zeroflte.c +++ b/board/samsung/board-zeroflte.c @@ -10,22 +10,8 @@ #define DECON_F_BASE 0x13930000 #define HW_SW_TRIG_CONTROL 0x6b0 -void init_board_funcs(void *board) -{ - /* - * Parsing the struct directly without restructing is - * broken as of Sep 29 2024 - */ - struct { - const char *name; - int ops[BOARD_OP_EXIT]; - } *board_restruct = board; - - board_restruct->name = "ZEROFLTE"; -} - // Early initialization -int board_init(void) +int zeroflte_init(void) { /* Allow framebuffer to be written to */ *(int*) (DECON_F_BASE + HW_SW_TRIG_CONTROL) = 0x2058; @@ -33,12 +19,12 @@ int board_init(void) } // Late initialization -int board_late_init(void) +int zeroflte_late_init(void) { return 0; } -int board_driver_setup(void) +int zeroflte_drv(void) { struct { int width; @@ -55,3 +41,13 @@ int board_driver_setup(void) REGISTER_DRIVER("simplefb", simplefb_probe, &simplefb_data); return 0; } + +struct board_data board_ops = { + .name = "samsung-zeroflte", + .ops = { + .early_init = zeroflte_init, + .drivers_init = zeroflte_drv, + .late_init = zeroflte_late_init, + }, + .quirks = 0 +}; diff --git a/board/volla/board-algiz.c b/board/volla/board-algiz.c index 8efbf03..32eae46 100755 --- a/board/volla/board-algiz.c +++ b/board/volla/board-algiz.c @@ -6,34 +6,13 @@ #include #include -void init_board_funcs(void *board) +int algiz_init(void) { - /* - * Parsing the struct directly without restructing is - * broken as of Sep 29 2024 - */ - struct { - const char *name; - int ops[BOARD_OP_EXIT]; - } *board_restruct = board; - - board_restruct->name = "ALGIZ"; -} - -// Early initialization -int board_init(void) -{ - /* TODO: Deal with framebuffer refreshing here */ + /* TODO: deal with framebuffer refreshing here */ return 0; } -// Late initialization -int board_late_init(void) -{ - return 0; -} - -int board_driver_setup(void) +int algiz_drv(void) { struct { int width; @@ -50,3 +29,18 @@ int board_driver_setup(void) REGISTER_DRIVER("simplefb", simplefb_probe, &simplefb_data); return 0; } + +int algiz_late_init(void) +{ + return 0; +} + +struct board_data board_ops = { + .name = "volla-quintus", + .ops = { + .early_init = algiz_init, + .drivers_init = algiz_drv, + .late_init = algiz_late_init, + }, + .quirks = 0 +}; diff --git a/include/board.h b/include/board.h index 6ab6636..750b6ce 100644 --- a/include/board.h +++ b/include/board.h @@ -8,26 +8,16 @@ #include -/* - * Well, well, well. We come back to this style again. - * TODO: Implement libfdt once we have C libs all sorted out. - * - * BOARD_OP_INIT -> initialization as soon as we hit C - * BOARD_OP_LATE_INIT -> late initialization - * BOARD_OP_DRIVER_SETUP -> drivers setup - * BOARD_OP_EXIT -> the last op, currently unused - */ -enum board_ops { - BOARD_OP_INIT, - BOARD_OP_LATE_INIT, - BOARD_OP_DRIVER_SETUP, - BOARD_OP_EXIT +struct board_ops { + int (*early_init)(void); + int (*drivers_init)(void); + int (*late_init)(void); }; -// Hold board data WITHOUT POINTERS struct board_data { const char *name; - int ops[BOARD_OP_EXIT]; + struct board_ops ops; + unsigned int quirks; }; extern void init_board_funcs(void *board); @@ -36,22 +26,4 @@ extern int board_driver_setup(void); extern int board_init(void); extern int board_late_init(void); -// Macro definitions for board operations -#define EXECUTE_BOARD_OP(op_id) \ - do { \ - switch (op_id) { \ - case BOARD_OP_INIT: \ - board_init(); \ - break; \ - case BOARD_OP_LATE_INIT: \ - board_late_init(); \ - break; \ - case BOARD_OP_DRIVER_SETUP: \ - board_driver_setup(); \ - break; \ - default: \ - break; \ - } \ - } while (0) - #endif // BOARD_H_ diff --git a/main/main.c b/main/main.c index 4b92e5e..493b862 100644 --- a/main/main.c +++ b/main/main.c @@ -8,29 +8,15 @@ #include #include +extern struct board_data board_ops; + void main(void* dt, void* kernel, void* ramdisk) { - /* - * Provide an empty board config that has - * to be filled in the board files - * TODO: figure out why having it in - * the board files makes devices reboot. - */ - struct board_data board = { - .name = "default", - .ops = { - [BOARD_OP_INIT] = BOARD_OP_INIT, - [BOARD_OP_LATE_INIT] = BOARD_OP_LATE_INIT, - [BOARD_OP_DRIVER_SETUP] = BOARD_OP_DRIVER_SETUP, - } - }; + if (board_ops.ops.early_init()) + goto err; - /* Initialize SoC and Board specific peripherals/quirks */ - init_board_funcs(&board); - - EXECUTE_BOARD_OP(board.ops[BOARD_OP_INIT]); - EXECUTE_BOARD_OP(board.ops[BOARD_OP_DRIVER_SETUP]); - EXECUTE_BOARD_OP(board.ops[BOARD_OP_LATE_INIT]); + if (board_ops.ops.drivers_init()) + goto err; printk(-1, " .__.____ .___\n"); printk(-1, " __ __ ____ |__| | _________ __| _/___________\n"); @@ -42,7 +28,10 @@ void main(void* dt, void* kernel, void* ramdisk) printk(-1, "passed board initialization\n"); printk(-1, "welcome to uniLoader %s\n", VER_TAG); - /* Copy kernel to memory and boot */ + if (board_ops.ops.late_init()) + goto err; + + /* copy kernel to memory and boot */ printk(-1, "booting linux...\n"); #ifdef __aarch64__ memcpy((void*)CONFIG_PAYLOAD_ENTRY, kernel, (unsigned long) &kernel_size); @@ -53,7 +42,10 @@ void main(void* dt, void* kernel, void* ramdisk) memcpy((void*)CONFIG_RAMDISK_ENTRY, ramdisk, (unsigned long) ramdisk_size); load_kernel_and_jump(0, 0, dt, (void*)CONFIG_PAYLOAD_ENTRY); #endif - /* We shouldn't get there */ + + err: + /* we shouldn't get there */ + /* TODO: make this a per-board reset */ printk(KERN_WARNING, "Something wrong happened, we shouldn't be here. Hanging....\n"); while(1) {} }