Until now, ubldr has been trying to locate the U-Boot API using a hint address (U-Boot's current stack pointer), aligning it to 1MiB and going over a 3MiB (or 1MiB in case of MIPS) memory region searching for a valid API signature.
This change proposes an alternative way of doing this, namely the following:
- both U-Boot's bootelf and go commands actually pass argc and argv to the entry point (e.g., ubldr's start function, but they should also be passed over to main() transparently)
- so, instead of trying to go and look for a valid API signature, we look at the parameters passed to main()
- if there's an option '-a' with argument, which is a valid hexadecimal unsigned long number (x), we try to verify whether we have a valid API signature at address x. If so - we use it. If not - we fallback to the original way of locating the API signature.
This requires the following one-line change to U-Boot's master branch as of today:
diff --git a/api/api.c b/api/api.c
index ae1160c..92dff3e 100644
--- a/api/api.c
+++ b/api/api.c
@@ -661,6 +661,7 @@ void api_init(void)
return;
}
+ setenv_hex("api_address", (unsigned long)sig);
debugf("API sig @ 0x%lX\n", (unsigned long)sig);
memcpy(sig->magic, API_SIG_MAGIC, 8);
sig->version = API_SIG_VERSION;
This makes U-Boot export an environment variable called api_address upon API initialization, which is later (see below) used as a command line parameter when starting ubldr.
For older U-Boot versions, which do not have setenv_hex() the change is similarly trivial.
Then, in order to boot, the following line:
# go ffffffff80800000
needs to be replaced with:
# go ffffffff80800000 -a ${api_address}
(the above is from a mips64el under qemu).
If we decide to go forward with this change, I will try to send it to upstream U-Boot.