···11+/***************************************************************************
22+ * __________ __ ___.
33+ * Open \______ \ ____ ____ | | _\_ |__ _______ ___
44+ * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
55+ * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
66+ * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
77+ * \/ \/ \/ \/ \/
88+ *
99+ * Copyright (C) 2024 by William Wilgus
1010+ *
1111+ * This program is free software; you can redistribute it and/or
1212+ * modify it under the terms of the GNU General Public License
1313+ * as published by the Free Software Foundation; either version 2
1414+ * of the License, or (at your option) any later version.
1515+ *
1616+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
1717+ * KIND, either express or implied.
1818+ *
1919+ ****************************************************************************/
2020+2121+#include "devicedata.h"
2222+#include "crc32.h"
2323+#include <stddef.h>
2424+#include <string.h>
2525+#include "debug.h"
2626+2727+#ifndef BOOTLOADER
2828+void verify_device_data(void) INIT_ATTR;
2929+void verify_device_data(void)
3030+{
3131+ DEBUGF("%s", __func__);
3232+ /* verify payload with checksum */
3333+ uint32_t crc = crc_32(device_data.payload, device_data.length, 0xffffffff);
3434+ if (crc == device_data.crc)
3535+ return; /* return if data is valid */
3636+3737+ /* Write the default if data is invalid */
3838+ memset(device_data.payload, 0xff, DEVICE_DATA_PAYLOAD_SIZE); /* Invalid data */
3939+ device_data.length = DEVICE_DATA_PAYLOAD_SIZE;
4040+ device_data.crc = crc_32(device_data.payload, device_data.length, 0xffffffff);
4141+4242+}
4343+4444+/******************************************************************************/
4545+#endif /* ndef BOOTLOADER ******************************************************/
4646+/******************************************************************************/
4747+4848+#if defined(HAVE_DEVICEDATA)
4949+void __attribute__((weak)) fill_devicedata(struct device_data_t *data)
5050+{
5151+ memset(data->payload, 0xff, data->length);
5252+}
5353+#endif
5454+5555+/* Write bootdata into location in FIRMWARE marked by magic header
5656+ * Assumes buffer is already loaded with the firmware image
5757+ * We just need to find the location and write data into the
5858+ * payload region along with the crc for later verification and use.
5959+ * Returns payload len on success,
6060+ * On error returns false
6161+ */
6262+bool write_devicedata(unsigned char* buf, int len)
6363+{
6464+ int search_len = MIN(len, DEVICE_DATA_SEARCH_SIZE) - sizeof(struct device_data_t);
6565+6666+ /* search for decvice data header prior to search_len */
6767+ for(int i = 0; i < search_len; i++)
6868+ {
6969+ struct device_data_t *data = (struct device_data_t *)&buf[i];
7070+ if (data->magic[0] != DEVICE_DATA_MAGIC0 ||
7171+ data->magic[1] != DEVICE_DATA_MAGIC1)
7272+ continue;
7373+7474+ /* Ignore it if the length extends past the end of the buffer. */
7575+ int data_len = offsetof(struct device_data_t, payload) + data->length;
7676+ if (i + data_len > len)
7777+ continue;
7878+7979+ fill_devicedata(data);
8080+8181+ /* Calculate payload CRC */
8282+ data->crc = crc_32(data->payload, data->length, 0xffffffff);
8383+ return true;
8484+ }
8585+8686+ return false;
8787+}
8888+
+7-1
firmware/common/rb-loader.c
···3030#include "multiboot.h"
3131#endif
32323333+#ifdef HAVE_DEVICEDATA
3434+#include "devicedata.h"
3535+#endif
3336/* loads a firmware file from supplied filename
3437 * file opened, checks firmware size and checksum
3538 * if no error, firmware loaded to supplied buffer
···118121 /* if ret is valid breaks from loop to continue loading */
119122 }
120123#endif
121121-122124 if (ret < 0) /* Check default volume, no valid firmware file loaded yet */
123125 {
124126 /* First check in BOOTDIR */
···140142 }
141143 else /* full path passed ROLO etc.*/
142144 ret = load_firmware_filename(buf, firmware, buffer_size);
145145+146146+#ifdef HAVE_DEVICEDATA
147147+ write_devicedata(buf, ret);
148148+#endif
143149144150 return ret;
145151}
+3
firmware/export/config/erosqnative.h
···106106#define HAVE_BOOTDATA
107107#define BOOT_REDIR "rockbox_main.aigo_erosqn"
108108109109+/* DeviceData */
110110+#define HAVE_DEVICEDATA
111111+109112/* USB support */
110113#ifndef SIMULATOR
111114#define CONFIG_USBOTG USBOTG_DESIGNWARE
+94
firmware/export/devicedata.h
···11+/***************************************************************************
22+ * __________ __ ___.
33+ * Open \______ \ ____ ____ | | _\_ |__ _______ ___
44+ * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
55+ * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
66+ * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
77+ * \/ \/ \/ \/ \/
88+ *
99+ * Copyright (C) 2017 by Amaury Pouly
1010+ *
1111+ * This program is free software; you can redistribute it and/or
1212+ * modify it under the terms of the GNU General Public License
1313+ * as published by the Free Software Foundation; either version 2
1414+ * of the License, or (at your option) any later version.
1515+ *
1616+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
1717+ * KIND, either express or implied.
1818+ *
1919+ ****************************************************************************/
2020+#ifndef __RB_DEVICEDATA__
2121+#define __RB_DEVICEDATA__
2222+2323+#ifndef __ASSEMBLER__
2424+#include <stdint.h>
2525+#include "system.h"
2626+#endif
2727+2828+/* /!\ This file can be included in assembly files /!\ */
2929+3030+/** The device data will be filled by the bootloader with information that might
3131+ * be relevant for Rockbox. The bootloader will search for the structure using
3232+ * the magic header within the first DEVICE_DATA_SEARCH_SIZE bytes of the binary.
3333+ * Typically, this structure should be as close as possible to the entry point */
3434+3535+/* Search size for the data structure after entry point */
3636+#define DEVICE_DATA_SEARCH_SIZE 1024
3737+3838+#define DEVICE_DATA_MAGIC0 ('r' | 'b' << 8 | 'd' << 16 | 'e' << 24)
3939+#define DEVICE_DATA_MAGIC1 ('v' | 'i' << 8 | 'c' << 16 | 'e' << 24)
4040+4141+/* maximum size of payload */
4242+#define DEVICE_DATA_PAYLOAD_SIZE 4
4343+4444+#ifndef __ASSEMBLER__
4545+/* This is the C structure */
4646+struct device_data_t
4747+{
4848+ union
4949+ {
5050+ uint32_t crc; /* crc of payload data (CRC32 with 0xffffffff for initial value) */
5151+ uint32_t magic[2]; /* DEVICE_DATA_MAGIC0/1 */
5252+ };
5353+5454+ uint32_t length; /* length of the payload */
5555+5656+ /* add fields here */
5757+ union
5858+ {
5959+ struct
6060+ {
6161+#if defined(EROS_QN)
6262+ uint8_t lcd_version;
6363+#endif
6464+ };
6565+ uint8_t payload[DEVICE_DATA_PAYLOAD_SIZE];
6666+ };
6767+} __attribute__((packed));
6868+6969+7070+void fill_devicedata(struct device_data_t *data);
7171+bool write_devicedata(unsigned char* buf, int len);
7272+#ifndef BOOTLOADER
7373+extern struct device_data_t device_data;
7474+7575+void verify_device_data(void) INIT_ATTR;
7676+7777+#endif
7878+7979+#else /* __ASSEMBLER__ */
8080+8181+/* This assembler macro implements an empty device data structure with just the magic
8282+ * string and payload size */
8383+.macro put_device_data_here
8484+.global device_data
8585+device_data:
8686+ .word DEVICE_DATA_MAGIC0
8787+ .word DEVICE_DATA_MAGIC1
8888+ .word DEVICE_DATA_PAYLOAD_SIZE
8989+ .space BOOT_DATA_PAYLOAD_SIZE, 0xff /* payload, initialised with value 0xff */
9090+.endm
9191+9292+#endif
9393+9494+#endif /* __RB_DEVICEDATA__ */