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

Hans de Goede hdegoede at redhat.com
Sun Oct 5 17:10:41 CEST 2014



On 10/04/2014 10:35 AM, Ian Campbell wrote:
> On Fri, 2014-10-03 at 17:05 +0200, Hans de Goede wrote:
>> sunxi SOCs can boot from both mmc0 and mmc2, detect from which one we're
>> booting, and make that one "mmc dev 0" so that a single u-boot binary can
>> be used for both the onboard eMMC and for external sdcards.
> 
> Where does the dependency on dev 0 being the boot device come from? Is
> it just the env via CONFIG_SYS_MMC_ENV_DEV?

No, the main reason why we need dev 0 to be the mmc we're actually booting
from is because that is where the SPL will load the tertiary payload
(the actual u-boot binary in our case) from, see:

common/spl/spl_mmc.c

Which has dev 0 hardcoded everywhere.

> If it's just that then is it allowable to define CONFIG_SYS_MMC_ENV_DEV
> as a call to a function which returns the appropriate number?
> 
> Or maybe mmc->block_dev.dev already doesn't correspond to the h/w
> controller number? So dev==0 is completely arbitrary?

Right, if we add mmc3 and then mmc0 for example, then the block_dev.dev field
will be 0 for mmc3 and 1 for mmc1, the dev field is just an incrementing
integer giving each controller added a unique id as it gets added.

>> +#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 &&
>> +	    mmc0->block_dev.block_read(0, 16, 1, buf) == 1) {
>> +		buf[12] = 0;
>> +		if (strcmp(&buf[4], "eGON.BT0") == 0)
>> +			return 0;
> 
> This just checks if the mmc is bootable, not necessarily that we booted
> from it, does it?

Correct, unfortunately the brom is very good in cleaning up after itself,
once we enter the SPL the mux for all involved pins have been reset to
0 (gpio input), all the involved clocks have been disabled, and all the
mmc controllers have been reset, so there is no way to really tell where
we're bootint from.

> Or is "just like the brom does" implying that the
> bootrom would always have booted mmc0 if this signature was there?

Yes.

> is that check sufficient or does the brom check other stuff, e.g.
> signatures etc.

AFAIK that check is all it does.

> or have a fallback path if mmc0 fails to boot somehow?

There is no fallback path, if you insert a sdcard with a bad
u-boot build, things will just hang, the brom is not smart enough
to switch over to an internal boot medium in this case. So I believe
that the check which I'm adding should be sufficient to determine whether
or not we're booting from mmc0. I really don't expect people to leave
a bootable sdcard in slot0, they could have a sdcard there to store data,
but in that case I would expect it to not have the magic boot signature.

Regards,

Hans


More information about the U-Boot mailing list