meta-phosphor: phosphor-mmc-init: Fix commandline parsing for root
From Joel in [1]:
```
It expects a command line string to be in the form:
console=ttyS4,115200n8 rootwait root=PARTLABEL=rofs-a
If booting with root=PARTLABEL=rofs-a at the start of the command line
string (instead of the end), the parsing gets confused:
[ 8.241229] /dev/disk/by-partlabel/root=PARTLABEL=rofs-a: Can't open blockdev
mount: mounting /dev/disk/by-partlabel/root=PARTLABEL=rofs-a on /mnt/rofs failed: No such file or directory
Similarly if the partition is not set, it gets confused:
[ 1.919816] Run /init as init process
Starting version 251.8+
[ 8.219396] /dev/disk/by-partlabel/rootwait: Can't open blockdev
mount: mounting /dev/disk/by-partlabel/rootwait on /mnt/rofs failed: No such file or directory
We should fix get_root so that it checks for the existance of
root=PARTLABEL, and matches on it. We could fall back on rofs-a if it
can't be found?
```
Based on Joel's example I tested the new implementation as follows:
```
$ declare -f old_get_root
old_get_root ()
{
local root="$@";
root="${root##* root=PARTLABEL=}";
root="${root%% *}";
[ "${root}" != "" ] && echo "${root}"
}
$ declare -f new_get_root
new_get_root ()
{
local cmdline="$@";
root=;
for opt in $cmdline;
do
case $opt in
root=PARTLABEL=*)
root=${opt##root=PARTLABEL=}
;;
*)
;;
esac;
done;
[ -n "$root" ] && echo $root
}
```
Comparing the two under various commandline orderings:
```
$ echo $working_cmdline
console=ttyS4,115200n8 rootwait root=PARTLABEL=rofs-a
$ old_get_root $working_cmdline
rofs-a
$ new_get_root $working_cmdline
rofs-a
$
```
```
$ echo $broken_cmdline
root=PARTLABEL=rofs-a console=ttyS4,115200n8 rootwait
$ old_get_root $broken_cmdline
root=PARTLABEL=rofs-a
$ new_get_root $broken_cmdline
rofs-a
$
```
```
$ echo $maybe_cmdline
console=ttyS4,115200n8 root=PARTLABEL=rofs-a rootwait
$ old_get_root $maybe_cmdline
rofs-a
$ new_get_root $maybe_cmdline
rofs-a
$
```
```
$ echo $dev_cmdline
console=ttyS4,115200n8 root=/dev/sda1 rootwait
$ old_get_root $dev_cmdline
console=ttyS4,115200n8
$ new_get_root $dev_cmdline
$
```
In each case new_get_root() gives the expected output.
[1]: https://github.com/openbmc/openbmc/issues/3898
Fixes: 0998d1e4fc58 ("initramfs: Add init script for eMMC")
Change-Id: I68e95d74dd33c54d956d08ae3332ba7bdec9aeeb
Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
diff --git a/meta-phosphor/recipes-phosphor/initrdscripts/phosphor-mmc-init/mmc-init.sh b/meta-phosphor/recipes-phosphor/initrdscripts/phosphor-mmc-init/mmc-init.sh
index ad9748e..316bffc 100644
--- a/meta-phosphor/recipes-phosphor/initrdscripts/phosphor-mmc-init/mmc-init.sh
+++ b/meta-phosphor/recipes-phosphor/initrdscripts/phosphor-mmc-init/mmc-init.sh
@@ -2,10 +2,19 @@
# Get the value of the root env variable found in /proc/cmdline
get_root() {
- local root="$(cat /proc/cmdline)"
- root="${root##* root=PARTLABEL=}"
- root="${root%% *}"
- [ "${root}" != "" ] && echo "${root}"
+ local cmdline="$(cat /proc/cmdline)"
+ root=
+ for opt in $cmdline
+ do
+ case $opt in
+ root=PARTLABEL=*)
+ root=${opt##root=PARTLABEL=}
+ ;;
+ *)
+ ;;
+ esac
+ done
+ [ -n "$root" ] && echo $root
}
fslist="proc sys dev run"