Add SysCfg viewer for iPod 6G in the debug menu

Change-Id: I4e142f40777c7f8ae58f2b46fc6a3ec4f12aa530
This commit is contained in:
Vencislav Atanasov 2024-06-23 22:58:26 +03:00 committed by Solomon Peachy
parent c2c8fcb561
commit 4691152f92
3 changed files with 127 additions and 4 deletions

View file

@ -132,6 +132,10 @@
#include "rb-loader.h"
#endif
#if defined(IPOD_6G)
#include "nor-target.h"
#endif
#define SCREEN_MAX_CHARS (LCD_WIDTH / SYSFONT_WIDTH)
static const char* threads_getname(int selected_item, void *data,
@ -2581,6 +2585,95 @@ static bool dbg_boot_data(void)
}
#endif /* defined(HAVE_BOOTDATA) && !defined(SIMULATOR) */
#if defined(IPOD_6G)
#define SYSCFG_MAX_ENTRIES 10 // 9 on iPod Classic/6G
static bool dbg_syscfg(void) {
struct simplelist_info info;
struct SysCfgHeader syscfg_hdr;
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", 1, NULL);
simplelist_set_line_count(0);
bootflash_init(SPI_PORT);
bootflash_read(SPI_PORT, 0, syscfg_hdr_size, &syscfg_hdr);
if (syscfg_hdr.magic != SYSCFG_MAGIC) {
simplelist_addline("SCfg magic not found");
bootflash_close(SPI_PORT);
return simplelist_show_list(&info);
}
simplelist_addline("Total size: %u bytes", syscfg_hdr.size);
simplelist_addline("Entries: %u", syscfg_hdr.num_entries);
size_t calculated_syscfg_size = syscfg_hdr_size + syscfg_entry_size * syscfg_hdr.num_entries;
if (syscfg_hdr.size != calculated_syscfg_size) {
simplelist_addline("Wrong size: expected %u, got %u", calculated_syscfg_size, syscfg_hdr.size);
bootflash_close(SPI_PORT);
return simplelist_show_list(&info);
}
if (syscfg_hdr.num_entries > SYSCFG_MAX_ENTRIES) {
simplelist_addline("Too many entries, showing first %u", syscfg_hdr.num_entries);
}
size_t syscfg_num_entries = MIN(syscfg_hdr.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++) {
struct SysCfgEntry* entry = &syscfg_entries[i];
char* tag = (char *)&entry->tag;
uint32_t* data32 = (uint32_t *)entry->data;
switch (entry->tag) {
case SYSCFG_TAG_SRNM:
simplelist_addline("Serial number (SrNm): %s", entry->data);
break;
case SYSCFG_TAG_FWID:
simplelist_addline("Firmware ID (FwId): %07X", data32[1] & 0x0FFFFFFF);
break;
case SYSCFG_TAG_HWID:
simplelist_addline("Hardware ID (HwId): %08X", data32[0]);
break;
case SYSCFG_TAG_HWVR:
simplelist_addline("Hardware version (HwVr): %06X", data32[1]);
break;
case SYSCFG_TAG_CODC:
simplelist_addline("Codec (Codc): %s", entry->data);
break;
case SYSCFG_TAG_SWVR:
simplelist_addline("Software version (SwVr): %s", entry->data);
break;
case SYSCFG_TAG_MLBN:
simplelist_addline("Logic board serial number (MLBN): %s", entry->data);
break;
case SYSCFG_TAG_MODN:
simplelist_addline("Model number (Mod#): %s", entry->data);
break;
case SYSCFG_TAG_REGN:
simplelist_addline("Sales region (Regn): %08X %08X", data32[0], data32[1]);
break;
default:
simplelist_addline("%c%c%c%c: %08X %08X %08X %08X",
tag[3], tag[2], tag[1], tag[0],
data32[0], data32[1], data32[2], data32[3]
);
break;
}
}
return simplelist_show_list(&info);
}
#endif
/****** The menu *********/
static const struct {
unsigned char *desc; /* string or ID */
@ -2691,6 +2784,9 @@ static const struct {
#if defined(HAVE_BOOTDATA) && !defined(SIMULATOR)
{"Boot data", dbg_boot_data },
#endif
#if defined(IPOD_6G)
{"View SysCfg", dbg_syscfg },
#endif
};
static int menu_action_callback(int btn, struct gui_synclist *lists)

View file

@ -1568,6 +1568,9 @@ target/arm/s5l8702/clocking-s5l8702.c
target/arm/s5l8702/ipod6g/lcd-6g.c
target/arm/s5l8702/ipod6g/lcd-asm-6g.S
target/arm/s5l8702/ipod6g/piezo-6g.c
target/arm/s5l8702/spi-s5l8702.c
target/arm/s5l8702/crypto-s5l8702.c
target/arm/s5l8702/nor-s5l8702.c
#if 0 //TODO
target/arm/s5l8702/postmortemstub.S
#endif
@ -1587,10 +1590,6 @@ target/arm/s5l8702/debug-s5l8702.c
target/arm/s5l8702/pcm-s5l8702.c
target/arm/s5l8702/ipod6g/audio-6g.c
target/arm/s5l8702/ipod6g/cscodec-6g.c
#else
target/arm/s5l8702/spi-s5l8702.c
target/arm/s5l8702/crypto-s5l8702.c
target/arm/s5l8702/nor-s5l8702.c
#endif /* BOOTLOADER */
#endif /* IPOD_6G */

View file

@ -87,6 +87,34 @@ int bootflash_compare(int port, int offset, void* addr, int size);
void bootflash_erase_blocks(int port, int first, int n);
void bootflash_close(int port);
/*
* SysCfg
*/
struct SysCfgHeader {
uint32_t magic; // always 'SCfg'
uint32_t size;
uint32_t unknown1; // 0x00000200 on iPod classic
uint32_t version; // maybe? 0x00010001 on iPod classic
uint32_t unknown2; // 0x00000000 on iPod classic
uint32_t num_entries;
}; // 0x18
struct SysCfgEntry {
uint32_t tag;
uint8_t data[0x10];
};
#define SYSCFG_MAGIC 0x53436667 // SCfg
#define SYSCFG_TAG_SRNM 0x53724e6d // SrNm
#define SYSCFG_TAG_FWID 0x46774964 // FwId
#define SYSCFG_TAG_HWID 0x48774964 // HwId
#define SYSCFG_TAG_HWVR 0x48775672 // HwVr
#define SYSCFG_TAG_CODC 0x436f6463 // Codc
#define SYSCFG_TAG_SWVR 0x53775672 // SwVr
#define SYSCFG_TAG_MLBN 0x4d4c424e // MLBN
#define SYSCFG_TAG_MODN 0x4d6f6423 // Mod#
#define SYSCFG_TAG_REGN 0x5265676e // Regn
/*
* IM3