mach-sunxi: Separate boot device and boot position

While MMC1 and MMC2 each currently have only one upper byte possibility,
SPI NAND has quite a few. To solve this, split up the byte handling across
two functions in preparation for SPI NAND support.

I have not tested this patch to validate that MMC SPL offsets are working.
It looks like it should work though.
This commit is contained in:
Jookia 2023-12-08 08:20:29 +11:00
parent bea38baf59
commit cd95fd413d
2 changed files with 13 additions and 10 deletions

View File

@ -16,8 +16,6 @@
#define SUNXI_BOOTED_FROM_NAND 1
#define SUNXI_BOOTED_FROM_MMC2 2
#define SUNXI_BOOTED_FROM_SPI 3
#define SUNXI_BOOTED_FROM_MMC0_HIGH 0x10
#define SUNXI_BOOTED_FROM_MMC2_HIGH 0x12
/*
* Values taken from the F1C200s BootROM stack

View File

@ -288,6 +288,7 @@ static int sunxi_get_boot_source(void)
uint32_t sunxi_get_boot_device(void)
{
int boot_source = sunxi_get_boot_source();
int boot_dev = (boot_source & 0xF); /* Low nibble is device */
/*
* When booting from the SD card or NAND memory, the "eGON.BT0"
@ -305,16 +306,15 @@ uint32_t sunxi_get_boot_device(void)
* binary over USB. If it is found, it determines where SPL was
* read from.
*/
switch (boot_source) {
case SUNXI_INVALID_BOOT_SOURCE:
if (boot_source == SUNXI_INVALID_BOOT_SOURCE)
return BOOT_DEVICE_BOARD;
switch (boot_dev) {
case SUNXI_BOOTED_FROM_MMC0:
case SUNXI_BOOTED_FROM_MMC0_HIGH:
return BOOT_DEVICE_MMC1;
case SUNXI_BOOTED_FROM_NAND:
return BOOT_DEVICE_NAND;
case SUNXI_BOOTED_FROM_MMC2:
case SUNXI_BOOTED_FROM_MMC2_HIGH:
return BOOT_DEVICE_MMC2;
case SUNXI_BOOTED_FROM_SPI:
return BOOT_DEVICE_SPI;
@ -324,6 +324,14 @@ uint32_t sunxi_get_boot_device(void)
return -1; /* Never reached */
}
uint32_t sunxi_get_boot_position(void)
{
int boot_source = sunxi_get_boot_source();
int boot_pos = ((boot_source >> 8) & 0xF); /* High nibble is position */
return boot_pos;
}
#ifdef CONFIG_SPL_BUILD
uint32_t sunxi_get_spl_size(void)
{
@ -355,11 +363,8 @@ unsigned long board_spl_mmc_get_uboot_raw_sector(struct mmc *mmc,
sector = max(raw_sect, spl_size / 512);
switch (sunxi_get_boot_source()) {
case SUNXI_BOOTED_FROM_MMC0_HIGH:
case SUNXI_BOOTED_FROM_MMC2_HIGH:
if (sunxi_get_boot_position() == 1) {
sector += (128 - 8) * 2;
break;
}
return sector;