diff options
author | William Wilgus <wilgus.william@gmail.com> | 2024-08-25 11:37:30 -0400 |
---|---|---|
committer | William Wilgus <me.theuser@yahoo.com> | 2024-09-02 13:29:43 -0400 |
commit | a2cc7546d88bf9c4071f0f56f6c43d59654fc212 (patch) | |
tree | ed009cf793dd1b99048a50ebd3e2c55c00ed1d9e /firmware | |
parent | c16dbbfd1fb7bf4bc268a4693bbed21497456b30 (diff) | |
download | rockbox-a2cc7546d88bf9c4071f0f56f6c43d59654fc212.tar.gz rockbox-a2cc7546d88bf9c4071f0f56f6c43d59654fc212.zip |
Add DeviceData to bootloaders
same vein as bootdata but for devices that need to pass info back to a
running firmware
Change-Id: I0cdcdc0475804dfbbee415ab487104ae8fc8ac69
Diffstat (limited to 'firmware')
-rw-r--r-- | firmware/SOURCES | 4 | ||||
-rw-r--r-- | firmware/common/devicedata.c | 88 | ||||
-rw-r--r-- | firmware/common/rb-loader.c | 8 | ||||
-rw-r--r-- | firmware/export/config/erosqnative.h | 3 | ||||
-rw-r--r-- | firmware/export/devicedata.h | 94 | ||||
-rw-r--r-- | firmware/rolo.c | 4 | ||||
-rw-r--r-- | firmware/target/mips/ingenic_x1000/crt0.S | 7 | ||||
-rw-r--r-- | firmware/target/mips/ingenic_x1000/system-x1000.c | 14 |
8 files changed, 221 insertions, 1 deletions
diff --git a/firmware/SOURCES b/firmware/SOURCES index 4e6fcbf70c..192cdb711d 100644 --- a/firmware/SOURCES +++ b/firmware/SOURCES | |||
@@ -62,6 +62,10 @@ common/bootdata.c | |||
62 | #endif | 62 | #endif |
63 | #endif | 63 | #endif |
64 | 64 | ||
65 | #if defined(HAVE_DEVICEDATA) | ||
66 | common/devicedata.c | ||
67 | #endif | ||
68 | |||
65 | #ifdef HAVE_SDL | 69 | #ifdef HAVE_SDL |
66 | target/hosted/sdl/button-sdl.c | 70 | target/hosted/sdl/button-sdl.c |
67 | target/hosted/sdl/kernel-sdl.c | 71 | target/hosted/sdl/kernel-sdl.c |
diff --git a/firmware/common/devicedata.c b/firmware/common/devicedata.c new file mode 100644 index 0000000000..75fe79d7fa --- /dev/null +++ b/firmware/common/devicedata.c | |||
@@ -0,0 +1,88 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * | ||
9 | * Copyright (C) 2024 by William Wilgus | ||
10 | * | ||
11 | * This program is free software; you can redistribute it and/or | ||
12 | * modify it under the terms of the GNU General Public License | ||
13 | * as published by the Free Software Foundation; either version 2 | ||
14 | * of the License, or (at your option) any later version. | ||
15 | * | ||
16 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
17 | * KIND, either express or implied. | ||
18 | * | ||
19 | ****************************************************************************/ | ||
20 | |||
21 | #include "devicedata.h" | ||
22 | #include "crc32.h" | ||
23 | #include <stddef.h> | ||
24 | #include <string.h> | ||
25 | #include "debug.h" | ||
26 | |||
27 | #ifndef BOOTLOADER | ||
28 | void verify_device_data(void) INIT_ATTR; | ||
29 | void verify_device_data(void) | ||
30 | { | ||
31 | DEBUGF("%s", __func__); | ||
32 | /* verify payload with checksum */ | ||
33 | uint32_t crc = crc_32(device_data.payload, device_data.length, 0xffffffff); | ||
34 | if (crc == device_data.crc) | ||
35 | return; /* return if data is valid */ | ||
36 | |||
37 | /* Write the default if data is invalid */ | ||
38 | memset(device_data.payload, 0xff, DEVICE_DATA_PAYLOAD_SIZE); /* Invalid data */ | ||
39 | device_data.length = DEVICE_DATA_PAYLOAD_SIZE; | ||
40 | device_data.crc = crc_32(device_data.payload, device_data.length, 0xffffffff); | ||
41 | |||
42 | } | ||
43 | |||
44 | /******************************************************************************/ | ||
45 | #endif /* ndef BOOTLOADER ******************************************************/ | ||
46 | /******************************************************************************/ | ||
47 | |||
48 | #if defined(HAVE_DEVICEDATA) | ||
49 | void __attribute__((weak)) fill_devicedata(struct device_data_t *data) | ||
50 | { | ||
51 | memset(data->payload, 0xff, data->length); | ||
52 | } | ||
53 | #endif | ||
54 | |||
55 | /* Write bootdata into location in FIRMWARE marked by magic header | ||
56 | * Assumes buffer is already loaded with the firmware image | ||
57 | * We just need to find the location and write data into the | ||
58 | * payload region along with the crc for later verification and use. | ||
59 | * Returns payload len on success, | ||
60 | * On error returns false | ||
61 | */ | ||
62 | bool write_devicedata(unsigned char* buf, int len) | ||
63 | { | ||
64 | int search_len = MIN(len, DEVICE_DATA_SEARCH_SIZE) - sizeof(struct device_data_t); | ||
65 | |||
66 | /* search for decvice data header prior to search_len */ | ||
67 | for(int i = 0; i < search_len; i++) | ||
68 | { | ||
69 | struct device_data_t *data = (struct device_data_t *)&buf[i]; | ||
70 | if (data->magic[0] != DEVICE_DATA_MAGIC0 || | ||
71 | data->magic[1] != DEVICE_DATA_MAGIC1) | ||
72 | continue; | ||
73 | |||
74 | /* Ignore it if the length extends past the end of the buffer. */ | ||
75 | int data_len = offsetof(struct device_data_t, payload) + data->length; | ||
76 | if (i + data_len > len) | ||
77 | continue; | ||
78 | |||
79 | fill_devicedata(data); | ||
80 | |||
81 | /* Calculate payload CRC */ | ||
82 | data->crc = crc_32(data->payload, data->length, 0xffffffff); | ||
83 | return true; | ||
84 | } | ||
85 | |||
86 | return false; | ||
87 | } | ||
88 | |||
diff --git a/firmware/common/rb-loader.c b/firmware/common/rb-loader.c index 61d8b1ddd2..2f5e06e165 100644 --- a/firmware/common/rb-loader.c +++ b/firmware/common/rb-loader.c | |||
@@ -30,6 +30,9 @@ | |||
30 | #include "multiboot.h" | 30 | #include "multiboot.h" |
31 | #endif | 31 | #endif |
32 | 32 | ||
33 | #ifdef HAVE_DEVICEDATA | ||
34 | #include "devicedata.h" | ||
35 | #endif | ||
33 | /* loads a firmware file from supplied filename | 36 | /* loads a firmware file from supplied filename |
34 | * file opened, checks firmware size and checksum | 37 | * file opened, checks firmware size and checksum |
35 | * if no error, firmware loaded to supplied buffer | 38 | * if no error, firmware loaded to supplied buffer |
@@ -118,7 +121,6 @@ int load_firmware(unsigned char* buf, const char* firmware, int buffer_size) | |||
118 | /* if ret is valid breaks from loop to continue loading */ | 121 | /* if ret is valid breaks from loop to continue loading */ |
119 | } | 122 | } |
120 | #endif | 123 | #endif |
121 | |||
122 | if (ret < 0) /* Check default volume, no valid firmware file loaded yet */ | 124 | if (ret < 0) /* Check default volume, no valid firmware file loaded yet */ |
123 | { | 125 | { |
124 | /* First check in BOOTDIR */ | 126 | /* First check in BOOTDIR */ |
@@ -141,5 +143,9 @@ int load_firmware(unsigned char* buf, const char* firmware, int buffer_size) | |||
141 | else /* full path passed ROLO etc.*/ | 143 | else /* full path passed ROLO etc.*/ |
142 | ret = load_firmware_filename(buf, firmware, buffer_size); | 144 | ret = load_firmware_filename(buf, firmware, buffer_size); |
143 | 145 | ||
146 | #ifdef HAVE_DEVICEDATA | ||
147 | write_devicedata(buf, ret); | ||
148 | #endif | ||
149 | |||
144 | return ret; | 150 | return ret; |
145 | } | 151 | } |
diff --git a/firmware/export/config/erosqnative.h b/firmware/export/config/erosqnative.h index 26073a5f34..75ead37ba8 100644 --- a/firmware/export/config/erosqnative.h +++ b/firmware/export/config/erosqnative.h | |||
@@ -106,6 +106,9 @@ | |||
106 | #define HAVE_BOOTDATA | 106 | #define HAVE_BOOTDATA |
107 | #define BOOT_REDIR "rockbox_main.aigo_erosqn" | 107 | #define BOOT_REDIR "rockbox_main.aigo_erosqn" |
108 | 108 | ||
109 | /* DeviceData */ | ||
110 | #define HAVE_DEVICEDATA | ||
111 | |||
109 | /* USB support */ | 112 | /* USB support */ |
110 | #ifndef SIMULATOR | 113 | #ifndef SIMULATOR |
111 | #define CONFIG_USBOTG USBOTG_DESIGNWARE | 114 | #define CONFIG_USBOTG USBOTG_DESIGNWARE |
diff --git a/firmware/export/devicedata.h b/firmware/export/devicedata.h new file mode 100644 index 0000000000..c19b0ca25d --- /dev/null +++ b/firmware/export/devicedata.h | |||
@@ -0,0 +1,94 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * | ||
9 | * Copyright (C) 2017 by Amaury Pouly | ||
10 | * | ||
11 | * This program is free software; you can redistribute it and/or | ||
12 | * modify it under the terms of the GNU General Public License | ||
13 | * as published by the Free Software Foundation; either version 2 | ||
14 | * of the License, or (at your option) any later version. | ||
15 | * | ||
16 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
17 | * KIND, either express or implied. | ||
18 | * | ||
19 | ****************************************************************************/ | ||
20 | #ifndef __RB_DEVICEDATA__ | ||
21 | #define __RB_DEVICEDATA__ | ||
22 | |||
23 | #ifndef __ASSEMBLER__ | ||
24 | #include <stdint.h> | ||
25 | #include "system.h" | ||
26 | #endif | ||
27 | |||
28 | /* /!\ This file can be included in assembly files /!\ */ | ||
29 | |||
30 | /** The device data will be filled by the bootloader with information that might | ||
31 | * be relevant for Rockbox. The bootloader will search for the structure using | ||
32 | * the magic header within the first DEVICE_DATA_SEARCH_SIZE bytes of the binary. | ||
33 | * Typically, this structure should be as close as possible to the entry point */ | ||
34 | |||
35 | /* Search size for the data structure after entry point */ | ||
36 | #define DEVICE_DATA_SEARCH_SIZE 1024 | ||
37 | |||
38 | #define DEVICE_DATA_MAGIC0 ('r' | 'b' << 8 | 'd' << 16 | 'e' << 24) | ||
39 | #define DEVICE_DATA_MAGIC1 ('v' | 'i' << 8 | 'c' << 16 | 'e' << 24) | ||
40 | |||
41 | /* maximum size of payload */ | ||
42 | #define DEVICE_DATA_PAYLOAD_SIZE 4 | ||
43 | |||
44 | #ifndef __ASSEMBLER__ | ||
45 | /* This is the C structure */ | ||
46 | struct device_data_t | ||
47 | { | ||
48 | union | ||
49 | { | ||
50 | uint32_t crc; /* crc of payload data (CRC32 with 0xffffffff for initial value) */ | ||
51 | uint32_t magic[2]; /* DEVICE_DATA_MAGIC0/1 */ | ||
52 | }; | ||
53 | |||
54 | uint32_t length; /* length of the payload */ | ||
55 | |||
56 | /* add fields here */ | ||
57 | union | ||
58 | { | ||
59 | struct | ||
60 | { | ||
61 | #if defined(EROS_QN) | ||
62 | uint8_t lcd_version; | ||
63 | #endif | ||
64 | }; | ||
65 | uint8_t payload[DEVICE_DATA_PAYLOAD_SIZE]; | ||
66 | }; | ||
67 | } __attribute__((packed)); | ||
68 | |||
69 | |||
70 | void fill_devicedata(struct device_data_t *data); | ||
71 | bool write_devicedata(unsigned char* buf, int len); | ||
72 | #ifndef BOOTLOADER | ||
73 | extern struct device_data_t device_data; | ||
74 | |||
75 | void verify_device_data(void) INIT_ATTR; | ||
76 | |||
77 | #endif | ||
78 | |||
79 | #else /* __ASSEMBLER__ */ | ||
80 | |||
81 | /* This assembler macro implements an empty device data structure with just the magic | ||
82 | * string and payload size */ | ||
83 | .macro put_device_data_here | ||
84 | .global device_data | ||
85 | device_data: | ||
86 | .word DEVICE_DATA_MAGIC0 | ||
87 | .word DEVICE_DATA_MAGIC1 | ||
88 | .word DEVICE_DATA_PAYLOAD_SIZE | ||
89 | .space BOOT_DATA_PAYLOAD_SIZE, 0xff /* payload, initialised with value 0xff */ | ||
90 | .endm | ||
91 | |||
92 | #endif | ||
93 | |||
94 | #endif /* __RB_DEVICEDATA__ */ | ||
diff --git a/firmware/rolo.c b/firmware/rolo.c index 0990b2732f..7be78f8a49 100644 --- a/firmware/rolo.c +++ b/firmware/rolo.c | |||
@@ -274,6 +274,10 @@ int rolo_load(const char* filename) | |||
274 | } | 274 | } |
275 | #endif | 275 | #endif |
276 | 276 | ||
277 | #if defined(HAVE_DEVICEDATA) | ||
278 | write_devicedata(filebuf, filebuf_size); | ||
279 | #endif | ||
280 | |||
277 | if (err <= 0) | 281 | if (err <= 0) |
278 | { | 282 | { |
279 | rolo_error(loader_strerror(err)); | 283 | rolo_error(loader_strerror(err)); |
diff --git a/firmware/target/mips/ingenic_x1000/crt0.S b/firmware/target/mips/ingenic_x1000/crt0.S index 6c0942b0db..23daaefb5e 100644 --- a/firmware/target/mips/ingenic_x1000/crt0.S +++ b/firmware/target/mips/ingenic_x1000/crt0.S | |||
@@ -23,6 +23,10 @@ | |||
23 | #include "mips.h" | 23 | #include "mips.h" |
24 | #include "bootdata.h" | 24 | #include "bootdata.h" |
25 | 25 | ||
26 | #if defined(HAVE_DEVICEDATA) && !defined(BOOTLOADER) | ||
27 | #include "devicedata.h" | ||
28 | #endif | ||
29 | |||
26 | .text | 30 | .text |
27 | .extern main | 31 | .extern main |
28 | .extern system_early_init | 32 | .extern system_early_init |
@@ -52,6 +56,9 @@ _header: | |||
52 | #ifndef BOOTLOADER | 56 | #ifndef BOOTLOADER |
53 | /* Multiboot support header; this is not part of the above header. */ | 57 | /* Multiboot support header; this is not part of the above header. */ |
54 | put_boot_data_here | 58 | put_boot_data_here |
59 | #ifdef HAVE_DEVICEDATA | ||
60 | put_device_data_here | ||
61 | #endif | ||
55 | #endif | 62 | #endif |
56 | 63 | ||
57 | _realstart: | 64 | _realstart: |
diff --git a/firmware/target/mips/ingenic_x1000/system-x1000.c b/firmware/target/mips/ingenic_x1000/system-x1000.c index 64890a6c3a..32ac66ec92 100644 --- a/firmware/target/mips/ingenic_x1000/system-x1000.c +++ b/firmware/target/mips/ingenic_x1000/system-x1000.c | |||
@@ -81,6 +81,20 @@ void system_early_init(void) | |||
81 | clk_init(); | 81 | clk_init(); |
82 | } | 82 | } |
83 | 83 | ||
84 | #if defined (HAVE_DEVICEDATA) && defined(EROS_QN) | ||
85 | void fill_devicedata(struct device_data_t *data) | ||
86 | { | ||
87 | #ifdef BOOTLOADER | ||
88 | memset(data->payload, 0xff, data->length); | ||
89 | data->lcd_version = EROSQN_VER; | ||
90 | #else | ||
91 | uint8_t lcd_version = data->lcd_version; | ||
92 | memset(data->payload, 0xff, data->length); | ||
93 | data->lcd_version = lcd_version; | ||
94 | #endif | ||
95 | } | ||
96 | #endif | ||
97 | |||
84 | /* First thing called from Rockbox main() */ | 98 | /* First thing called from Rockbox main() */ |
85 | void system_init(void) | 99 | void system_init(void) |
86 | { | 100 | { |