Skip to contentSkip to conversation

U-boot runtime detection

U-Boot-Users New Florian Fainelli 3 participants 6 messages May 30, 2007 – Jun 6, 2007

lore
Share & tools
lore
#0 lore raw

Hi all,

I am currently working on the adm5120 target under Linux and this board is available with at least 4 bootloaders, including U-boot.

We manage getting runtime bootloader detection working using the fw_arg0-3 values for CFE, RouterBoot, Bootbase. Now I would like to do so for U-boot and I could not find any informations if U-boot fills the fw_arg0-3 with some specific values that could let us identify it at runtime. Can you indicate me if such identification is possible ? If not, would another method (like reading the first flash block) work ?

Thank you very much in advance for your answer.

Signature · 2 lines
Cordialement, Florian Fainelli
---------------------------------------------
#1 lore raw
Quoted 3 lines · In message <[email protected]> you wrote:

I am currently working on the adm5120 target under Linux and this board is available with at least 4 bootloaders, including U-boot.

4 different boot loaderss on one board? What a waste of effort...

Quoted 6 lines

We manage getting runtime bootloader detection working using the fw_arg0-3 values for CFE, RouterBoot, Bootbase. Now I would like to do so for U-boot and I could not find any informations if U-boot fills the fw_arg0-3 with some specific values that could let us identify it at runtime. Can you indicate me if such identification is possible ? If not, would another method (like reading the first flash block) work ?

You may want to check "lib_mips/mips_linux.c" to see which arguments get passed to a Linux kernel by U-Boot. Search for "theKernel()" call.

Best regards,

Wolfgang Denk

Signature · 6 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
"Nobody will ever need more than 640k RAM!"       -- Bill Gates, 1981
"Windows 95 needs at least 8 MB RAM."             -- Bill Gates, 1996
"Nobody will ever need Windows 95."             -- logical conclusion
#2 lore raw

Hello Wolfgang,

Thank you very much for your answer. Looks like reading linux_env in fw_arg2 and 0 in fw_arg3 should be pretty efficient in saying it is U-boot we were booted from.

Any reasons why fw_arg3 receives 0 instead of a magic number ? Broadcom's CFE passes the string "CFE1" in here, why not passing "UBOO" for instance ?

Le jeudi 31 mai 2007, Wolfgang Denk a ?crit?:

Quoted 19 lines
Quoted 2 lines · In message <[email protected]> you wrote:

I am currently working on the adm5120 target under Linux and this board is available with at least 4 bootloaders, including U-boot.

4 different boot loaderss on one board? What a waste of effort...

Quoted 6 lines

We manage getting runtime bootloader detection working using the fw_arg0-3 values for CFE, RouterBoot, Bootbase. Now I would like to do so for U-boot and I could not find any informations if U-boot fills the fw_arg0-3 with some specific values that could let us identify it at runtime. Can you indicate me if such identification is possible ? If not, would another method (like reading the first flash block) work ?

You may want to check "lib_mips/mips_linux.c" to see which arguments get passed to a Linux kernel by U-Boot. Search for "theKernel()" call.

Best regards,

Wolfgang Denk

Signature · 9 lines
Cordialement, Florian Fainelli
---------------------------------------------
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://lists.denx.de/pipermail/u-boot/attachments/20070606/5744a6d6/attachment.pgp 
#3 lore raw

PATCH 1/1 Fill fw_arg3

Hello,

This patch allows MIPS based Linux kernels to do runtime bootloader detection by reading Linux's fw_arg3 in the PROM code (for instance) filled with the magic number "UBOO". This may not be really useful for other boards than MIPS and in particular those that use several different bootloaders (like ADM5120).

--
-------------- next part --------------

lib_mips/mips_linux.c +3 -1
index 952d5a9..0823bc0 100644
@@ -33,6 +33,8 @@ DECLARE_GLOBAL_DATA_PTR;
 #define	LINUX_MAX_ENVS		256
 #define	LINUX_MAX_ARGS		256
 
+#define UBOOT_MAGIC_NUMBER	0x55424F4F	/* UBOO */
+
 #ifdef CONFIG_SHOW_BOOT_PROGRESS
 # include <status_led.h>
 # define SHOW_BOOT_PROGRESS(arg)	show_boot_progress(arg)
@@ -213,7 +215,7 @@ void do_bootm_linux (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[],
 	/* we assume that the kernel is in place */
 	printf ("\nStarting kernel ...\n\n");
 
-	theKernel (linux_argc, linux_argv, linux_env, 0);
+	theKernel (linux_argc, linux_argv, linux_env, UBOOT_MAGIC_NUMBER);
 }
 
 static void linux_params_init (ulong start, char *line)

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://lists.denx.de/pipermail/u-boot/attachments/20070606/1127143a/attachment.pgp

#4 lore raw

PATCH 1/1 Fill fw_arg3

Hi Florian,

Quoted 23 lines

This patch allows MIPS based Linux kernels to do runtime bootloader detection by reading Linux's fw_arg3 in the PROM code (for instance) filled with the magic number "UBOO". This may not be really useful for other boards than MIPS and in particular those that use several different bootloaders (like ADM5120).

--

lib_mips/mips_linux.c +2 -0
index 952d5a9..0823bc0 100644
@@ -33,6 +33,8 @@ DECLARE_GLOBAL_DATA_PTR;
 #define	LINUX_MAX_ENVS		256
 #define	LINUX_MAX_ARGS		256
 
+#define UBOOT_MAGIC_NUMBER	0x55424F4F	/* UBOO */
+
 #ifdef CONFIG_SHOW_BOOT_PROGRESS
 # include <status_led.h>
 # define SHOW_BOOT_PROGRESS(arg)	show_boot_progress(arg)

lib_mips/mips_linux.c void do_bootm_linux (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[], · line 221

Quoted 8 lines
lib_mips/mips_linux.c +1 -1
@@ -213,7 +215,7 @@ void do_bootm_linux (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[],
 	/* we assume that the kernel is in place */
 	printf ("\nStarting kernel ...\n\n");
 
-	theKernel (linux_argc, linux_argv, linux_env, 0);
+	theKernel (linux_argc, linux_argv, linux_env, UBOOT_MAGIC_NUMBER);
 }
 
 static void linux_params_init (ulong start, char *line)

I know U-Boot is magic - but why have more than needed?

[dzu at pollux u-boot]$ grep IH_MAGIC include/*
include/image.h:#define IH_MAGIC 0x27051956 /* Image Magic Number */
[dzu at pollux u-boot]$ grep 27051956 /usr/share/magic
0 belong 0x27051956 u-boot/PPCBoot image

Cheers
Detlev

Signature · 8 lines
... does Linux have a better [security] track record than MS? Damn right it
does. We've had fewer problems, and I think there are more people out there
standing up for what's right anyway. Less PR people deathly afraid of rocking
the boat. Better technology, and fewer horrid design mistakes. [Linus Torvalds]
--
DENX Software Engineering GmbH,      MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich,  Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-40 Fax: (+49)-8142-66989-80 Email: dzu at denx.de
#5 lore raw
In reply to Florian Fainelli
Quoted 4 lines · In message <[email protected]> you wrote:

Thank you very much for your answer. Looks like reading linux_env in fw_arg2 and 0 in fw_arg3 should be pretty efficient in saying it is U-boot we were booted from.

I have to admit that I don't understand the rationale of all that. IMHO the Linux kernel should never have to know how it was booted and which bootloader might have been used. The kernel has a well-defined interface and expects a certain set of hardware initializations been done before it gets started, but that's it. It should not need any additional information outside this

Quoted 2 lines

Any reasons why fw_arg3 receives 0 instead of a magic number ? Broadcom's C> FE passes the string "CFE1" in here, why not passing "UBOO" for instance ?

Because nobody ever cared?

Quoted 4 lines

Le jeudi 31 mai 2007, Wolfgang Denk a ?crit?:

Quoted 3 lines
Quoted 2 lines · In message <[email protected]> you wrote:

I am currently working on the adm5120 target under Linux and this board is available with at least 4 bootloaders, including U-boot.

...
Please don't top post / full quote.
Please see http://www.netmeister.org/news/learn2quote.html

Best regards,

Wolfgang Denk

Signature · 5 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
Technology is dominated by those who manage what they do  not  under-
stand.