[U-Boot] [PATCH v2 3/5] sunxi: When we've both mmc0 and mmc2, detect from which one we're booting

Ian Campbell ijc at hellion.org.uk
Sat Oct 11 17:43:28 CEST 2014


On Mon, 2014-10-06 at 19:57 +0200, Hans de Goede wrote:
> @@ -108,11 +109,31 @@ static void mmc_pinmux_setup(int sdc)
>  
>  int board_mmc_init(bd_t *bis)
>  {
> +	__maybe_unused struct mmc *mmc0, *mmc1;
> +	__maybe_unused char buf[512];
> +
>  	mmc_pinmux_setup(CONFIG_MMC_SUNXI_SLOT);
> -	sunxi_mmc_init(CONFIG_MMC_SUNXI_SLOT);
> +	mmc0 = sunxi_mmc_init(CONFIG_MMC_SUNXI_SLOT);
>  #if CONFIG_MMC_SUNXI_SLOT_EXTRA != -1
>  	mmc_pinmux_setup(CONFIG_MMC_SUNXI_SLOT_EXTRA);
> -	sunxi_mmc_init(CONFIG_MMC_SUNXI_SLOT_EXTRA);
> +	mmc1 = sunxi_mmc_init(CONFIG_MMC_SUNXI_SLOT_EXTRA);
> +#endif
> +
> +#if CONFIG_MMC_SUNXI_SLOT == 0 && CONFIG_MMC_SUNXI_SLOT_EXTRA == 2
> +	/*
> +	 * Both mmc0 and mmc2 are bootable, figure out where we're booting
> +	 * from. Try mmc0 first, just like the brom does.
> +	 */
> +	if (mmc_getcd(mmc0) && mmc_init(mmc0) == 0 &&

If sunxi_mmx_init failed then mmc0 might be NULL here.

> +	    mmc0->block_dev.block_read(0, 16, 1, buf) == 1) {
> +		buf[12] = 0;
> +		if (strcmp(&buf[4], "eGON.BT0") == 0)
> +			return 0;
> +	}
> +
> +	/* no bootable card in mmc0, so we must be booting from mmc2, swap */
> +	mmc0->block_dev.dev = 1;
> +	mmc1->block_dev.dev = 0;

and mmc1 could be NULL here.

Ian.



More information about the U-Boot mailing list