nand: Add %R for path to rootfs

On a device with raw NAND, the root= argument in the kernel command
line (or the base that dm-verity is put on top of) needs to be
different based on whether boot is from NAND or USB:
* If booting from NAND, /dev/ubiblock%P_0
* If booting from disk, PARTUUID=%U/PARTNROFF=1
However, the same kernel image with the same unsubstituted kernel
commandline has to be used for both. initramfs is not available
for security reasons. Therefore, depthcharge has to make the
subsititution.

This patch add %R syntax to substitute one of those two strings
based on whether the disk that booted has an external GPT.

In another pair of upcoming patches, the kernel command-line just
for Storm is updated to use %R as the root. (Other kernel
command-lines are left the same to remain compatible with
older firmware.)

An alternate possibility to this patch is that depthcharge could
just directly pass in the value of external_gpt to a kernel
command-line option, and a linked-in kernel module could translate
by itself from that to the appropriate root parameter. However,
this would be a lot more complicated (given that you can turn
dm-verity on or off with the kernel command line), and we would
have to pass %P with a different parameter, so the code cleanliness
benefits seem dubious to me. Therefore this patch just substitutes
in the whole description of the disk.

TEST=Used this in a kernel commandline on a Storm board with NAND and
found that the same kernel can boot from both USB and NAND.
BRANCH=none
BUG=chromium:442784

Change-Id: I9c999a87ef1030cdce651c26b7086de9169a60c7
Signed-off-by: Dan Ehrenberg <dehrenberg@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/236070
Reviewed-by: Julius Werner <jwerner@chromium.org>
Reviewed-by: Gwendal Grignou <gwendal@chromium.org>
3 files changed