diff options
-rw-r--r-- | apps/debug_menu.c | 36 | ||||
-rw-r--r-- | apps/main.c | 11 | ||||
-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 | ||||
-rw-r--r-- | uisimulator/common/stubs.c | 6 |
11 files changed, 274 insertions, 1 deletions
diff --git a/apps/debug_menu.c b/apps/debug_menu.c index a101097004..8e16ff1c21 100644 --- a/apps/debug_menu.c +++ b/apps/debug_menu.c | |||
@@ -124,6 +124,10 @@ | |||
124 | 124 | ||
125 | #include "talk.h" | 125 | #include "talk.h" |
126 | 126 | ||
127 | #if defined(HAVE_DEVICEDATA)// && !defined(SIMULATOR) | ||
128 | #include "devicedata.h" | ||
129 | #endif | ||
130 | |||
127 | #if defined(HAVE_BOOTDATA) && !defined(SIMULATOR) | 131 | #if defined(HAVE_BOOTDATA) && !defined(SIMULATOR) |
128 | #include "bootdata.h" | 132 | #include "bootdata.h" |
129 | #include "multiboot.h" | 133 | #include "multiboot.h" |
@@ -2625,6 +2629,33 @@ static bool dbg_boot_data(void) | |||
2625 | } | 2629 | } |
2626 | #endif /* defined(HAVE_BOOTDATA) && !defined(SIMULATOR) */ | 2630 | #endif /* defined(HAVE_BOOTDATA) && !defined(SIMULATOR) */ |
2627 | 2631 | ||
2632 | #if defined(HAVE_DEVICEDATA)// && !defined(SIMULATOR) | ||
2633 | static bool dbg_device_data(void) | ||
2634 | { | ||
2635 | struct simplelist_info info; | ||
2636 | info.scroll_all = true; | ||
2637 | simplelist_info_init(&info, "Device data", 1, NULL); | ||
2638 | simplelist_set_line_count(0); | ||
2639 | |||
2640 | simplelist_addline("Device data"); | ||
2641 | |||
2642 | #if defined(EROS_QN) | ||
2643 | simplelist_addline("Lcd Version: %d", (int)device_data.lcd_version); | ||
2644 | #endif | ||
2645 | |||
2646 | simplelist_addline("Device data RAW:"); | ||
2647 | for (size_t i = 0; i < device_data.length; i += 4) | ||
2648 | { | ||
2649 | simplelist_addline("%02x: %02x %02x %02x %02x", i, | ||
2650 | device_data.payload[i + 0], device_data.payload[i + 1], | ||
2651 | device_data.payload[i + 2], device_data.payload[i + 3]); | ||
2652 | } | ||
2653 | |||
2654 | return simplelist_show_list(&info); | ||
2655 | } | ||
2656 | #endif /* defined(HAVE_DEVICEDATA)*/ | ||
2657 | |||
2658 | |||
2628 | #if defined(IPOD_6G) && !defined(SIMULATOR) | 2659 | #if defined(IPOD_6G) && !defined(SIMULATOR) |
2629 | #define SYSCFG_MAX_ENTRIES 9 // 9 on iPod Classic/6G | 2660 | #define SYSCFG_MAX_ENTRIES 9 // 9 on iPod Classic/6G |
2630 | 2661 | ||
@@ -2823,6 +2854,11 @@ static const struct { | |||
2823 | #if defined(HAVE_BOOTDATA) && !defined(SIMULATOR) | 2854 | #if defined(HAVE_BOOTDATA) && !defined(SIMULATOR) |
2824 | {"Boot data", dbg_boot_data }, | 2855 | {"Boot data", dbg_boot_data }, |
2825 | #endif | 2856 | #endif |
2857 | |||
2858 | #if defined(HAVE_DEVICEDATA)// && !defined(SIMULATOR) | ||
2859 | {"Device data", dbg_device_data }, | ||
2860 | #endif | ||
2861 | |||
2826 | #if defined(IPOD_6G) && !defined(SIMULATOR) | 2862 | #if defined(IPOD_6G) && !defined(SIMULATOR) |
2827 | {"View SysCfg", dbg_syscfg }, | 2863 | {"View SysCfg", dbg_syscfg }, |
2828 | #endif | 2864 | #endif |
diff --git a/apps/main.c b/apps/main.c index 4c7689ce8c..1e8e872296 100644 --- a/apps/main.c +++ b/apps/main.c | |||
@@ -78,6 +78,10 @@ | |||
78 | #include "bootchart.h" | 78 | #include "bootchart.h" |
79 | #include "logdiskf.h" | 79 | #include "logdiskf.h" |
80 | #include "bootdata.h" | 80 | #include "bootdata.h" |
81 | #if defined(HAVE_DEVICEDATA) | ||
82 | #include "devicedata.h" | ||
83 | #endif | ||
84 | |||
81 | #if (CONFIG_PLATFORM & PLATFORM_ANDROID) | 85 | #if (CONFIG_PLATFORM & PLATFORM_ANDROID) |
82 | #include "notification.h" | 86 | #include "notification.h" |
83 | #endif | 87 | #endif |
@@ -176,6 +180,9 @@ int main(void) | |||
176 | } | 180 | } |
177 | list_init(); | 181 | list_init(); |
178 | tree_init(); | 182 | tree_init(); |
183 | #if defined(HAVE_DEVICEDATA) && !defined(BOOTLOADER) /* SIMULATOR */ | ||
184 | verify_device_data(); | ||
185 | #endif | ||
179 | /* Keep the order of this 3 | 186 | /* Keep the order of this 3 |
180 | * Must be done before any code uses the multi-screen API */ | 187 | * Must be done before any code uses the multi-screen API */ |
181 | #ifdef HAVE_USBSTACK | 188 | #ifdef HAVE_USBSTACK |
@@ -459,6 +466,10 @@ static void init(void) | |||
459 | verify_boot_data(); | 466 | verify_boot_data(); |
460 | #endif | 467 | #endif |
461 | 468 | ||
469 | #if defined(HAVE_DEVICEDATA) && !defined(BOOTLOADER) | ||
470 | verify_device_data(); | ||
471 | #endif | ||
472 | |||
462 | /* early early early! */ | 473 | /* early early early! */ |
463 | filesystem_init(); | 474 | filesystem_init(); |
464 | 475 | ||
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 | { |
diff --git a/uisimulator/common/stubs.c b/uisimulator/common/stubs.c index bce7e07227..ba5e2c9908 100644 --- a/uisimulator/common/stubs.c +++ b/uisimulator/common/stubs.c | |||
@@ -35,6 +35,12 @@ | |||
35 | 35 | ||
36 | static bool storage_spinning = false; | 36 | static bool storage_spinning = false; |
37 | 37 | ||
38 | #if defined(HAVE_DEVICEDATA) | ||
39 | #include "devicedata.h" | ||
40 | struct device_data_t device_data = | ||
41 | {.length = DEVICE_DATA_PAYLOAD_SIZE}; | ||
42 | #endif /* def HAVE_DEVICEDATA */ | ||
43 | |||
38 | int fat_startsector(void) | 44 | int fat_startsector(void) |
39 | { | 45 | { |
40 | return 63; | 46 | return 63; |