1
0
Fork 0
forked from len0rd/rockbox

S5L8702: Introduce syscfg_read() and use it in the debug menu

This makes it possible to reuse the SysCfg reading logic in other places.

Tested on ipod6g (normal + bootloader).

Change-Id: Iae6de2ee671bce4edb0153d26c57579ad47d0335
This commit is contained in:
Vencislav Atanasov 2024-12-17 23:22:01 +02:00 committed by Solomon Peachy
parent e27f778fb6
commit cf4bf5439e
3 changed files with 52 additions and 25 deletions

View file

@ -2642,51 +2642,37 @@ static bool dbg_device_data(void)
#if defined(IPOD_6G) && !defined(SIMULATOR) #if defined(IPOD_6G) && !defined(SIMULATOR)
#define SYSCFG_MAX_ENTRIES 9 // 9 on iPod Classic/6G
static bool dbg_syscfg(void) { static bool dbg_syscfg(void) {
struct simplelist_info info; struct simplelist_info info;
struct SysCfgHeader syscfg_hdr; struct SysCfg syscfg;
size_t syscfg_hdr_size = sizeof(struct SysCfgHeader);
size_t syscfg_entry_size = sizeof(struct SysCfgEntry);
struct SysCfgEntry syscfg_entries[SYSCFG_MAX_ENTRIES];
simplelist_info_init(&info, "SysCfg NOR contents", 0, NULL); simplelist_info_init(&info, "SysCfg NOR contents", 0, NULL);
simplelist_reset_lines(); simplelist_reset_lines();
bootflash_init(SPI_PORT); const ssize_t result = syscfg_read(&syscfg);
bootflash_read(SPI_PORT, 0, syscfg_hdr_size, &syscfg_hdr);
if (syscfg_hdr.magic != SYSCFG_MAGIC) { if (result == -1) {
simplelist_setline("SCfg magic not found"); simplelist_setline("SCfg magic not found");
bootflash_close(SPI_PORT);
return simplelist_show_list(&info); return simplelist_show_list(&info);
} }
simplelist_addline("Total size: %lu bytes, %lu entries", syscfg_hdr.size, syscfg_hdr.num_entries); simplelist_addline("Total size: %lu bytes, %lu entries", syscfg.header.size, syscfg.header.num_entries);
size_t calculated_syscfg_size = syscfg_hdr_size + syscfg_entry_size * syscfg_hdr.num_entries; if (result > 0) {
simplelist_addline("Wrong size: expected %ld, got %lu", result, syscfg.header.size);
if (syscfg_hdr.size != calculated_syscfg_size) {
simplelist_addline("Wrong size: expected %zu, got %lu", calculated_syscfg_size, syscfg_hdr.size);
bootflash_close(SPI_PORT);
return simplelist_show_list(&info); return simplelist_show_list(&info);
} }
if (syscfg_hdr.num_entries > SYSCFG_MAX_ENTRIES) { if (syscfg.header.num_entries > SYSCFG_MAX_ENTRIES) {
simplelist_addline("Too many entries, showing only first %u", SYSCFG_MAX_ENTRIES); simplelist_addline("Too many entries, showing only first %u", SYSCFG_MAX_ENTRIES);
} }
size_t syscfg_num_entries = MIN(syscfg_hdr.num_entries, SYSCFG_MAX_ENTRIES); const size_t syscfg_num_entries = MIN(syscfg.header.num_entries, SYSCFG_MAX_ENTRIES);
size_t syscfg_entries_size = syscfg_entry_size * syscfg_num_entries;
bootflash_read(SPI_PORT, syscfg_hdr_size, syscfg_entries_size, &syscfg_entries);
bootflash_close(SPI_PORT);
for (size_t i = 0; i < syscfg_num_entries; i++) { for (size_t i = 0; i < syscfg_num_entries; i++) {
struct SysCfgEntry* entry = &syscfg_entries[i]; const struct SysCfgEntry* entry = &syscfg.entries[i];
char* tag = (char *)&entry->tag; const char* tag = (char *)&entry->tag;
uint32_t* data32 = (uint32_t *)entry->data; const uint32_t* data32 = (uint32_t *)entry->data;
switch (entry->tag) { switch (entry->tag) {
case SYSCFG_TAG_SRNM: case SYSCFG_TAG_SRNM:

View file

@ -202,6 +202,37 @@ void bootflash_write(int port, int offset, void* addr, int size)
} }
} }
/*
* SysCfg
*/
ssize_t syscfg_read(struct SysCfg* syscfg)
{
const size_t syscfg_hdr_size = sizeof(struct SysCfgHeader);
const size_t syscfg_entry_size = sizeof(struct SysCfgEntry);
bootflash_init(SPI_PORT);
bootflash_read(SPI_PORT, 0, syscfg_hdr_size, &syscfg->header);
if (syscfg->header.magic != SYSCFG_MAGIC) {
bootflash_close(SPI_PORT);
return -1;
}
const size_t calculated_syscfg_size = syscfg_hdr_size + syscfg_entry_size * syscfg->header.num_entries;
if (syscfg->header.size != calculated_syscfg_size) {
bootflash_close(SPI_PORT);
return calculated_syscfg_size;
}
const size_t syscfg_num_entries = MIN(syscfg->header.num_entries, SYSCFG_MAX_ENTRIES);
const size_t syscfg_entries_size = syscfg_entry_size * syscfg_num_entries;
bootflash_read(SPI_PORT, syscfg_hdr_size, syscfg_entries_size, &syscfg->entries);
bootflash_close(SPI_PORT);
return 0;
}
/* /*
* IM3 * IM3

View file

@ -23,6 +23,7 @@
#include <stdint.h> #include <stdint.h>
#include <stdbool.h> #include <stdbool.h>
#include <sys/types.h>
#include "config.h" #include "config.h"
#include "crypto-s5l8702.h" #include "crypto-s5l8702.h"
@ -90,6 +91,8 @@ void bootflash_close(int port);
/* /*
* SysCfg * SysCfg
*/ */
#define SYSCFG_MAX_ENTRIES 9 // 9 on iPod Classic/6G
struct SysCfgHeader { struct SysCfgHeader {
uint32_t magic; // always 'SCfg' uint32_t magic; // always 'SCfg'
uint32_t size; uint32_t size;
@ -104,6 +107,11 @@ struct SysCfgEntry {
uint8_t data[0x10]; uint8_t data[0x10];
}; };
struct SysCfg {
struct SysCfgHeader header;
struct SysCfgEntry entries[SYSCFG_MAX_ENTRIES];
};
#define SYSCFG_MAGIC 0x53436667 // SCfg #define SYSCFG_MAGIC 0x53436667 // SCfg
#define SYSCFG_TAG_SRNM 0x53724e6d // SrNm #define SYSCFG_TAG_SRNM 0x53724e6d // SrNm
@ -116,6 +124,8 @@ struct SysCfgEntry {
#define SYSCFG_TAG_MODN 0x4d6f6423 // Mod# #define SYSCFG_TAG_MODN 0x4d6f6423 // Mod#
#define SYSCFG_TAG_REGN 0x5265676e // Regn #define SYSCFG_TAG_REGN 0x5265676e // Regn
ssize_t syscfg_read(struct SysCfg* syscfg);
/* /*
* IM3 * IM3
*/ */