mirror of
https://github.com/Rockbox/rockbox.git
synced 2025-11-09 13:12:37 -05:00
Add DeviceData to bootloaders
same vein as bootdata but for devices that need to pass info back to a running firmware Change-Id: I0cdcdc0475804dfbbee415ab487104ae8fc8ac69
This commit is contained in:
parent
c16dbbfd1f
commit
a2cc7546d8
11 changed files with 274 additions and 1 deletions
88
firmware/common/devicedata.c
Normal file
88
firmware/common/devicedata.c
Normal file
|
|
@ -0,0 +1,88 @@
|
|||
/***************************************************************************
|
||||
* __________ __ ___.
|
||||
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
||||
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
||||
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
||||
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
||||
* \/ \/ \/ \/ \/
|
||||
*
|
||||
* Copyright (C) 2024 by William Wilgus
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
||||
* KIND, either express or implied.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#include "devicedata.h"
|
||||
#include "crc32.h"
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
#include "debug.h"
|
||||
|
||||
#ifndef BOOTLOADER
|
||||
void verify_device_data(void) INIT_ATTR;
|
||||
void verify_device_data(void)
|
||||
{
|
||||
DEBUGF("%s", __func__);
|
||||
/* verify payload with checksum */
|
||||
uint32_t crc = crc_32(device_data.payload, device_data.length, 0xffffffff);
|
||||
if (crc == device_data.crc)
|
||||
return; /* return if data is valid */
|
||||
|
||||
/* Write the default if data is invalid */
|
||||
memset(device_data.payload, 0xff, DEVICE_DATA_PAYLOAD_SIZE); /* Invalid data */
|
||||
device_data.length = DEVICE_DATA_PAYLOAD_SIZE;
|
||||
device_data.crc = crc_32(device_data.payload, device_data.length, 0xffffffff);
|
||||
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
#endif /* ndef BOOTLOADER ******************************************************/
|
||||
/******************************************************************************/
|
||||
|
||||
#if defined(HAVE_DEVICEDATA)
|
||||
void __attribute__((weak)) fill_devicedata(struct device_data_t *data)
|
||||
{
|
||||
memset(data->payload, 0xff, data->length);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Write bootdata into location in FIRMWARE marked by magic header
|
||||
* Assumes buffer is already loaded with the firmware image
|
||||
* We just need to find the location and write data into the
|
||||
* payload region along with the crc for later verification and use.
|
||||
* Returns payload len on success,
|
||||
* On error returns false
|
||||
*/
|
||||
bool write_devicedata(unsigned char* buf, int len)
|
||||
{
|
||||
int search_len = MIN(len, DEVICE_DATA_SEARCH_SIZE) - sizeof(struct device_data_t);
|
||||
|
||||
/* search for decvice data header prior to search_len */
|
||||
for(int i = 0; i < search_len; i++)
|
||||
{
|
||||
struct device_data_t *data = (struct device_data_t *)&buf[i];
|
||||
if (data->magic[0] != DEVICE_DATA_MAGIC0 ||
|
||||
data->magic[1] != DEVICE_DATA_MAGIC1)
|
||||
continue;
|
||||
|
||||
/* Ignore it if the length extends past the end of the buffer. */
|
||||
int data_len = offsetof(struct device_data_t, payload) + data->length;
|
||||
if (i + data_len > len)
|
||||
continue;
|
||||
|
||||
fill_devicedata(data);
|
||||
|
||||
/* Calculate payload CRC */
|
||||
data->crc = crc_32(data->payload, data->length, 0xffffffff);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -30,6 +30,9 @@
|
|||
#include "multiboot.h"
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_DEVICEDATA
|
||||
#include "devicedata.h"
|
||||
#endif
|
||||
/* loads a firmware file from supplied filename
|
||||
* file opened, checks firmware size and checksum
|
||||
* if no error, firmware loaded to supplied buffer
|
||||
|
|
@ -118,7 +121,6 @@ int load_firmware(unsigned char* buf, const char* firmware, int buffer_size)
|
|||
/* if ret is valid breaks from loop to continue loading */
|
||||
}
|
||||
#endif
|
||||
|
||||
if (ret < 0) /* Check default volume, no valid firmware file loaded yet */
|
||||
{
|
||||
/* First check in BOOTDIR */
|
||||
|
|
@ -141,5 +143,9 @@ int load_firmware(unsigned char* buf, const char* firmware, int buffer_size)
|
|||
else /* full path passed ROLO etc.*/
|
||||
ret = load_firmware_filename(buf, firmware, buffer_size);
|
||||
|
||||
#ifdef HAVE_DEVICEDATA
|
||||
write_devicedata(buf, ret);
|
||||
#endif
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue