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

@ -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

View file

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