base-files: functions: introduce new helper functions
Introduce cmdline_get_var() to /lib/function.sh and make use of it in export_rootdev() in /lib/upgrade/common.sh, making the code more simple and removing one level of indentation. Introduce get_partition_by_name() to /lib/upgrade/common.sh which is useful on non-EFI GPT platforms like mt7622. Remove some dead-code while at it. Signed-off-by: Daniel Golle <daniel@makrotopia.org>
This commit is contained in:
parent
0bc5ecf2d0
commit
bb107ad9c1
2 changed files with 67 additions and 62 deletions
|
@ -384,4 +384,14 @@ board_name() {
|
|||
[ -e /tmp/sysinfo/board_name ] && cat /tmp/sysinfo/board_name || echo "generic"
|
||||
}
|
||||
|
||||
cmdline_get_var() {
|
||||
local var=$1
|
||||
local cmdlinevar tmp
|
||||
|
||||
for cmdlinevar in $(cat /proc/cmdline); do
|
||||
tmp=${cmdlinevar##${var}}
|
||||
[ "=" = "${tmp:0:1}" ] && echo ${tmp:1}
|
||||
done
|
||||
}
|
||||
|
||||
[ -z "$IPKG_INSTROOT" ] && [ -f /lib/config/uci.sh ] && . /lib/config/uci.sh
|
||||
|
|
|
@ -147,22 +147,9 @@ part_magic_fat() {
|
|||
}
|
||||
|
||||
export_bootdevice() {
|
||||
local cmdline bootdisk rootpart uuid blockdev uevent line class
|
||||
local cmdline uuid blockdev uevent line class
|
||||
local MAJOR MINOR DEVNAME DEVTYPE
|
||||
|
||||
if read cmdline < /proc/cmdline; then
|
||||
case "$cmdline" in
|
||||
*root=*)
|
||||
rootpart="${cmdline##*root=}"
|
||||
rootpart="${rootpart%% *}"
|
||||
;;
|
||||
esac
|
||||
|
||||
case "$bootdisk" in
|
||||
/dev/*)
|
||||
uevent="/sys/class/block/${bootdisk##*/}/uevent"
|
||||
;;
|
||||
esac
|
||||
local rootpart="$(cmdline_get_var root)"
|
||||
|
||||
case "$rootpart" in
|
||||
PARTUUID=[a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9]-[a-f0-9][a-f0-9])
|
||||
|
@ -212,7 +199,6 @@ export_bootdevice() {
|
|||
export BOOTDEV_MINOR=$MINOR
|
||||
return 0
|
||||
fi
|
||||
fi
|
||||
|
||||
return 1
|
||||
}
|
||||
|
@ -242,6 +228,15 @@ hex_le32_to_cpu() {
|
|||
echo "$@"
|
||||
}
|
||||
|
||||
get_partition_by_name() {
|
||||
for partname in /sys/class/block/$1/*/name; do
|
||||
[ "$(cat ${partname})" = "$2" ] && {
|
||||
basename ${partname%%/name}
|
||||
break
|
||||
}
|
||||
done
|
||||
}
|
||||
|
||||
get_partitions() { # <device> <filename>
|
||||
local disk="$1"
|
||||
local filename="$2"
|
||||
|
|
Loading…
Reference in a new issue