mirror of
https://github.com/AsahiLinux/u-boot
synced 2024-11-29 08:01:08 +00:00
sunxi: board.c: refactor SPL header checks
So far we have two users which want to look at the SPL header. We will get more in the future. Refactor the existing SPL header checks into a common function, to simplify reusing the code. Now that this is easy, add proper version checks to the DT name parsing. Signed-off-by: Andre Przywara <andre.przywara@arm.com> Signed-off-by: Icenowy Zheng <icenowy@aosc.io> Acked-by: Maxime Ripard <maxime.ripard@bootlin.com> Acked-by: Jagan Teki <jagan@openedev.com>
This commit is contained in:
parent
55d481d201
commit
cff5c13849
1 changed files with 30 additions and 11 deletions
|
@ -255,6 +255,30 @@ int board_init(void)
|
||||||
return soft_i2c_board_init();
|
return soft_i2c_board_init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* On older SoCs the SPL is actually at address zero, so using NULL as
|
||||||
|
* an error value does not work.
|
||||||
|
*/
|
||||||
|
#define INVALID_SPL_HEADER ((void *)~0UL)
|
||||||
|
|
||||||
|
static struct boot_file_head * get_spl_header(uint8_t req_version)
|
||||||
|
{
|
||||||
|
struct boot_file_head *spl = (void *)(ulong)SPL_ADDR;
|
||||||
|
uint8_t spl_header_version = spl->spl_signature[3];
|
||||||
|
|
||||||
|
/* Is there really the SPL header (still) there? */
|
||||||
|
if (memcmp(spl->spl_signature, SPL_SIGNATURE, 3) != 0)
|
||||||
|
return INVALID_SPL_HEADER;
|
||||||
|
|
||||||
|
if (spl_header_version < req_version) {
|
||||||
|
printf("sunxi SPL version mismatch: expected %u, got %u\n",
|
||||||
|
req_version, spl_header_version);
|
||||||
|
return INVALID_SPL_HEADER;
|
||||||
|
}
|
||||||
|
|
||||||
|
return spl;
|
||||||
|
}
|
||||||
|
|
||||||
int dram_init(void)
|
int dram_init(void)
|
||||||
{
|
{
|
||||||
gd->ram_size = get_ram_size((long *)PHYS_SDRAM_0, PHYS_SDRAM_0_SIZE);
|
gd->ram_size = get_ram_size((long *)PHYS_SDRAM_0, PHYS_SDRAM_0_SIZE);
|
||||||
|
@ -662,16 +686,11 @@ void get_board_serial(struct tag_serialnr *serialnr)
|
||||||
*/
|
*/
|
||||||
static void parse_spl_header(const uint32_t spl_addr)
|
static void parse_spl_header(const uint32_t spl_addr)
|
||||||
{
|
{
|
||||||
struct boot_file_head *spl = (void *)(ulong)spl_addr;
|
struct boot_file_head *spl = get_spl_header(SPL_ENV_HEADER_VERSION);
|
||||||
if (memcmp(spl->spl_signature, SPL_SIGNATURE, 3) != 0)
|
|
||||||
return; /* signature mismatch, no usable header */
|
|
||||||
|
|
||||||
uint8_t spl_header_version = spl->spl_signature[3];
|
if (spl == INVALID_SPL_HEADER)
|
||||||
if (spl_header_version < SPL_ENV_HEADER_VERSION) {
|
|
||||||
printf("sunxi SPL version mismatch: expected %u, got %u\n",
|
|
||||||
SPL_ENV_HEADER_VERSION, spl_header_version);
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
if (!spl->fel_script_address)
|
if (!spl->fel_script_address)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -806,11 +825,11 @@ int ft_board_setup(void *blob, bd_t *bd)
|
||||||
#ifdef CONFIG_SPL_LOAD_FIT
|
#ifdef CONFIG_SPL_LOAD_FIT
|
||||||
int board_fit_config_name_match(const char *name)
|
int board_fit_config_name_match(const char *name)
|
||||||
{
|
{
|
||||||
struct boot_file_head *spl = (void *)(ulong)SPL_ADDR;
|
struct boot_file_head *spl = get_spl_header(SPL_DT_HEADER_VERSION);
|
||||||
const char *cmp_str = (void *)(ulong)SPL_ADDR;
|
const char *cmp_str = (const char *)spl;
|
||||||
|
|
||||||
/* Check if there is a DT name stored in the SPL header and use that. */
|
/* Check if there is a DT name stored in the SPL header and use that. */
|
||||||
if (spl->dt_name_offset) {
|
if (spl != INVALID_SPL_HEADER && spl->dt_name_offset) {
|
||||||
cmp_str += spl->dt_name_offset;
|
cmp_str += spl->dt_name_offset;
|
||||||
} else {
|
} else {
|
||||||
#ifdef CONFIG_DEFAULT_DEVICE_TREE
|
#ifdef CONFIG_DEFAULT_DEVICE_TREE
|
||||||
|
|
Loading…
Reference in a new issue