public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Alexander Holler <holler@ahsoftware.de>
To: u-boot@lists.denx.de
Subject: [U-Boot] Magically determining the correct root
Date: Thu, 14 Aug 2014 22:28:41 +0200	[thread overview]
Message-ID: <53ED1BF9.5090901@ahsoftware.de> (raw)

Hello,

Over the years I've seen many error message from beginners because root= 
wasn't set or was set wrong. Often they call the cryptic message from 
the Linux kernel memory error or something similiar (because they just 
look at the stuff after the "init not found").

One of the reason they run into that is because they use a different 
partition layout than which is enforced by the board-config.

So here are my 2? to give people some more freedom in regard to the 
partition layout:

---------------------
	...
        "find_root=" \
                "setenv stdout nulldev;" \
                "for i in 0 1 2; do " \
                        "setexpr rootpart $part + $i;" \
                        "if ls $hw $dev:$rootpart dev; then " \
                                "setenv stderr serial;" \
                                "setenv stdout serial;" \
                                "exit;" \
                        "fi;" \
                "done;" \
                "setenv stdout serial;" \
                "setenv rootpart\0" \
        "linuxmmc=mmcblk0p\0" \
        "set_root=" \
                "run find_root;" \
                "if test -z \"$rootpart\"; then " \
                        "echo \"NO ROOT FOUND! (no partition with 
directory /dev)\";" \
                        "setexpr rootpart $part + 1;" \
                "fi;" \
                "if test $hw = mmc; then " \
                        "setenv root /dev/${linuxmmc}${rootpart};" \
                 "else " \
                        "setenv root /dev/sda${rootpart};" \
                "fi;" \
                "echo \"root is $root\"\0" \
	...
---------------------

What it does is the following:

It uses the variable $hw, $dev, $part and $linuxmmc as input and
$root as output.

- $hw might be mmc, usb or sata (or whatever "ls" does understand
- $dev is the device number (usually 0)
- $part is the partition number where the kernel is loaded from (most of 
the time 1 for the first partition)
- $linuxmmc is the linux-name of the mmc-device (e.g. mmcblk0p).

It then searches the partition from which the kernel was loaded from and 
the following two partitions for a "/dev" and assumes that will be the 
correct root partition.

So, assuming /dev does only exist on the root partition that little 
magic supports parition layouts like the following:

- boot (with kernel), root, something else
- root (with kernel), something else
- swap, boot (with kernel), root, something else
- boot (with kernel), swap, root, something else
...

Maybe someone does find usefull.

Regards,

Alexander Holler

                 reply	other threads:[~2014-08-14 20:28 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=53ED1BF9.5090901@ahsoftware.de \
    --to=holler@ahsoftware.de \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox