Rockbox open source high quality audio player as a Music Player Daemon
mpris rockbox mpd libadwaita audio rust zig deno
2
fork

Configure Feed

Select the types of activity you want to include in your feed.

Add DeviceData to bootloaders

same vein as bootdata but for devices that need to pass info back to a
running firmware

Change-Id: I0cdcdc0475804dfbbee415ab487104ae8fc8ac69

authored by

William Wilgus and committed by
William Wilgus
a2cc7546 c16dbbfd

+274 -1
+36
apps/debug_menu.c
··· 124 124 125 125 #include "talk.h" 126 126 127 + #if defined(HAVE_DEVICEDATA)// && !defined(SIMULATOR) 128 + #include "devicedata.h" 129 + #endif 130 + 127 131 #if defined(HAVE_BOOTDATA) && !defined(SIMULATOR) 128 132 #include "bootdata.h" 129 133 #include "multiboot.h" ··· 2625 2629 } 2626 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 2659 #if defined(IPOD_6G) && !defined(SIMULATOR) 2629 2660 #define SYSCFG_MAX_ENTRIES 9 // 9 on iPod Classic/6G 2630 2661 ··· 2823 2854 #if defined(HAVE_BOOTDATA) && !defined(SIMULATOR) 2824 2855 {"Boot data", dbg_boot_data }, 2825 2856 #endif 2857 + 2858 + #if defined(HAVE_DEVICEDATA)// && !defined(SIMULATOR) 2859 + {"Device data", dbg_device_data }, 2860 + #endif 2861 + 2826 2862 #if defined(IPOD_6G) && !defined(SIMULATOR) 2827 2863 {"View SysCfg", dbg_syscfg }, 2828 2864 #endif
+11
apps/main.c
··· 78 78 #include "bootchart.h" 79 79 #include "logdiskf.h" 80 80 #include "bootdata.h" 81 + #if defined(HAVE_DEVICEDATA) 82 + #include "devicedata.h" 83 + #endif 84 + 81 85 #if (CONFIG_PLATFORM & PLATFORM_ANDROID) 82 86 #include "notification.h" 83 87 #endif ··· 176 180 } 177 181 list_init(); 178 182 tree_init(); 183 + #if defined(HAVE_DEVICEDATA) && !defined(BOOTLOADER) /* SIMULATOR */ 184 + verify_device_data(); 185 + #endif 179 186 /* Keep the order of this 3 180 187 * Must be done before any code uses the multi-screen API */ 181 188 #ifdef HAVE_USBSTACK ··· 457 464 458 465 #if defined(HAVE_BOOTDATA) && !defined(BOOTLOADER) 459 466 verify_boot_data(); 467 + #endif 468 + 469 + #if defined(HAVE_DEVICEDATA) && !defined(BOOTLOADER) 470 + verify_device_data(); 460 471 #endif 461 472 462 473 /* early early early! */
+4
firmware/SOURCES
··· 62 62 #endif 63 63 #endif 64 64 65 + #if defined(HAVE_DEVICEDATA) 66 + common/devicedata.c 67 + #endif 68 + 65 69 #ifdef HAVE_SDL 66 70 target/hosted/sdl/button-sdl.c 67 71 target/hosted/sdl/kernel-sdl.c
+88
firmware/common/devicedata.c
··· 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 +
+7 -1
firmware/common/rb-loader.c
··· 30 30 #include "multiboot.h" 31 31 #endif 32 32 33 + #ifdef HAVE_DEVICEDATA 34 + #include "devicedata.h" 35 + #endif 33 36 /* loads a firmware file from supplied filename 34 37 * file opened, checks firmware size and checksum 35 38 * if no error, firmware loaded to supplied buffer ··· 118 121 /* if ret is valid breaks from loop to continue loading */ 119 122 } 120 123 #endif 121 - 122 124 if (ret < 0) /* Check default volume, no valid firmware file loaded yet */ 123 125 { 124 126 /* First check in BOOTDIR */ ··· 140 142 } 141 143 else /* full path passed ROLO etc.*/ 142 144 ret = load_firmware_filename(buf, firmware, buffer_size); 145 + 146 + #ifdef HAVE_DEVICEDATA 147 + write_devicedata(buf, ret); 148 + #endif 143 149 144 150 return ret; 145 151 }
+3
firmware/export/config/erosqnative.h
··· 106 106 #define HAVE_BOOTDATA 107 107 #define BOOT_REDIR "rockbox_main.aigo_erosqn" 108 108 109 + /* DeviceData */ 110 + #define HAVE_DEVICEDATA 111 + 109 112 /* USB support */ 110 113 #ifndef SIMULATOR 111 114 #define CONFIG_USBOTG USBOTG_DESIGNWARE
+94
firmware/export/devicedata.h
··· 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__ */
+4
firmware/rolo.c
··· 274 274 } 275 275 #endif 276 276 277 + #if defined(HAVE_DEVICEDATA) 278 + write_devicedata(filebuf, filebuf_size); 279 + #endif 280 + 277 281 if (err <= 0) 278 282 { 279 283 rolo_error(loader_strerror(err));
+7
firmware/target/mips/ingenic_x1000/crt0.S
··· 23 23 #include "mips.h" 24 24 #include "bootdata.h" 25 25 26 + #if defined(HAVE_DEVICEDATA) && !defined(BOOTLOADER) 27 + #include "devicedata.h" 28 + #endif 29 + 26 30 .text 27 31 .extern main 28 32 .extern system_early_init ··· 52 56 #ifndef BOOTLOADER 53 57 /* Multiboot support header; this is not part of the above header. */ 54 58 put_boot_data_here 59 + #ifdef HAVE_DEVICEDATA 60 + put_device_data_here 61 + #endif 55 62 #endif 56 63 57 64 _realstart:
+14
firmware/target/mips/ingenic_x1000/system-x1000.c
··· 81 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 98 /* First thing called from Rockbox main() */ 85 99 void system_init(void) 86 100 {
+6
uisimulator/common/stubs.c
··· 35 35 36 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 44 int fat_startsector(void) 39 45 { 40 46 return 63;