diff mbox

[U-Boot] sunxi: add an environment variable for boot media

Message ID 20161221215326.30218-1-icenowy@aosc.xyz
State Rejected
Delegated to: Jagannadha Sutradharudu Teki
Headers show

Commit Message

Icenowy Zheng Dec. 21, 2016, 9:53 p.m. UTC
Some board features different medias available for boot, for example, a
MicroSD slot and an eMMC or two MicroSD slots.

Add an environment variable which indicates the boot media during boot,
so that the boot script can choose the kernel parameter, device tree
property, etc. according to this environment variable.

Tested on Lichee Pi One, which features two MicroSD slots (MMC0 and
MMC2)

Signed-off-by: Icenowy Zheng <icenowy@aosc.xyz>
---
 board/sunxi/board.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

Comments

Maxime Ripard Dec. 22, 2016, 3:20 p.m. UTC | #1
On Thu, Dec 22, 2016 at 05:53:26AM +0800, Icenowy Zheng wrote:
> Some board features different medias available for boot, for example, a
> MicroSD slot and an eMMC or two MicroSD slots.
> 
> Add an environment variable which indicates the boot media during boot,
> so that the boot script can choose the kernel parameter, device tree
> property, etc. according to this environment variable.
> 
> Tested on Lichee Pi One, which features two MicroSD slots (MMC0 and
> MMC2)
> 
> Signed-off-by: Icenowy Zheng <icenowy@aosc.xyz>
> ---
>  board/sunxi/board.c | 18 ++++++++++++++++++
>  1 file changed, 18 insertions(+)
> 
> diff --git a/board/sunxi/board.c b/board/sunxi/board.c
> index 53656383d5..81ca27e16b 100644
> --- a/board/sunxi/board.c
> +++ b/board/sunxi/board.c
> @@ -694,8 +694,26 @@ int misc_init_r(void)
>  	/* determine if we are running in FEL mode */
>  	if (!is_boot0_magic(SPL_ADDR + 4)) { /* eGON.BT0 */
>  		setenv("fel_booted", "1");
> +		setenv("boot_media", "fel");
>  		parse_spl_header(SPL_ADDR);
>  	}
> +	else switch (readb(SPL_ADDR + 0x28)) {
> +	case SUNXI_BOOTED_FROM_MMC0:
> +		setenv("boot_media", "mmc0");
> +		break;
> +	case SUNXI_BOOTED_FROM_NAND:
> +		setenv("boot_media", "nand");
> +		break;
> +	case SUNXI_BOOTED_FROM_MMC2:
> +		setenv("boot_media", "mmc2");
> +		break;
> +	case SUNXI_BOOTED_FROM_SPI:
> +		setenv("boot_media", "spi");
> +		break;
> +	default:
> +		setenv("boot_media", "unknown");
> +		break;
> +	}

There's really nothing really sunxi-specific about that. This is
something that should be made generic, and is kind of redundant with
spl_boot_device. I think a good solution could reuse that function to
set that variable.

Maxime
diff mbox

Patch

diff --git a/board/sunxi/board.c b/board/sunxi/board.c
index 53656383d5..81ca27e16b 100644
--- a/board/sunxi/board.c
+++ b/board/sunxi/board.c
@@ -694,8 +694,26 @@  int misc_init_r(void)
 	/* determine if we are running in FEL mode */
 	if (!is_boot0_magic(SPL_ADDR + 4)) { /* eGON.BT0 */
 		setenv("fel_booted", "1");
+		setenv("boot_media", "fel");
 		parse_spl_header(SPL_ADDR);
 	}
+	else switch (readb(SPL_ADDR + 0x28)) {
+	case SUNXI_BOOTED_FROM_MMC0:
+		setenv("boot_media", "mmc0");
+		break;
+	case SUNXI_BOOTED_FROM_NAND:
+		setenv("boot_media", "nand");
+		break;
+	case SUNXI_BOOTED_FROM_MMC2:
+		setenv("boot_media", "mmc2");
+		break;
+	case SUNXI_BOOTED_FROM_SPI:
+		setenv("boot_media", "spi");
+		break;
+	default:
+		setenv("boot_media", "unknown");
+		break;
+	}
 
 	setup_environment(gd->fdt_blob);