From e85f7645d88364bc1cf1ef0e235ef9d4de1a2065 Mon Sep 17 00:00:00 2001 From: Calin Crisan Date: Sun, 12 Mar 2017 13:09:35 +0200 Subject: [PATCH] /dev/mmcblk0 disk dev is no longer hardcoded everywhere --- board/common/overlay-initramfs/init | 28 +++++++++++++++------ board/common/overlay/etc/init.d/S00datapart | 19 +++++++++++--- board/common/overlay/sbin/fwupdate | 2 +- 3 files changed, 37 insertions(+), 12 deletions(-) diff --git a/board/common/overlay-initramfs/init b/board/common/overlay-initramfs/init index 575d668787..d29c2408fe 100755 --- a/board/common/overlay-initramfs/init +++ b/board/common/overlay-initramfs/init @@ -2,9 +2,27 @@ PATH=/bin:/sbin:/usr/bin:/usr/sbin -BOOT_DEV=/dev/mmcblk0p1 -ROOT_DEV=/dev/mmcblk0p2 -DATA_DEV=/dev/mmcblk0p3 +msg() { + echo "* $1" +} + +ROOT_DEV=$(cat /proc/cmdline | grep -oE 'root=[/a-z0-9]+' | cut -d '=' -f 2) +if [[ "$ROOT_DEV" =~ ^([/a-z0-9]+)(p[0-9])$ ]]; then # e.g. /dev/mmcblk0p2 + DISK_DEV=${BASH_REMATCH[1]} + BOOT_DEV=${DISK_DEV}p1 + DATA_DEV=${DISK_DEV}p3 +else # e.g. /dev/sdc2 + [[ "$ROOT_DEV" =~ ^([/a-z0-9]+)([0-9])$ ]] + DISK_DEV=${BASH_REMATCH[1]} + BOOT_DEV=${DISK_DEV}1 + DATA_DEV=${DISK_DEV}3 +fi + +msg "Disk device is $DISK_DEV" +msg "Boot device is $BOOT_DEV" +msg "Root device is $ROOT_DEV" +msg "Data device is $DATA_DEV" + FW_DIR=/data/.fwupdate FW_FILE=firmware.img.gz @@ -15,10 +33,6 @@ LEGACY_FW_FILE_EXTR=firmware ROOT_INFO_FILE=root_info -msg() { - echo "* $1" -} - on_exit() { msg "Switching to normal boot" /remove_initramfs diff --git a/board/common/overlay/etc/init.d/S00datapart b/board/common/overlay/etc/init.d/S00datapart index d69d2d37a3..833548572e 100755 --- a/board/common/overlay/etc/init.d/S00datapart +++ b/board/common/overlay/etc/init.d/S00datapart @@ -1,12 +1,23 @@ #!/bin/bash -disk_dev="/dev/mmcblk0" -data_dev="${disk_dev}p3" +test -n "$os_version" || source /etc/init.d/base + +msg_begin "Detecting disk device" +root_part=$(cat /proc/cmdline | grep -oE 'root=[/a-z0-9]+' | cut -d '=' -f 2) +if [[ "$root_part" =~ ^([/a-z0-9]+)(p[0-9])$ ]]; then # e.g. /dev/mmcblk0p2 + disk_dev=${BASH_REMATCH[1]} + data_dev=${disk_dev}p3 +elif [[ "$root_part" =~ ^([/a-z0-9]+)([0-9])$ ]]; then # e.g. /dev/sdc2 + disk_dev=${BASH_REMATCH[1]} + data_dev=${disk_dev}3 +else + msg_fail "unknown ($root_part)" + exit 1 +fi +msg_done "$disk_dev" test -b $data_dev && exit 0 -test -n "$os_version" || source /etc/init.d/base - case "$1" in start) msg_begin "Creating data partition" diff --git a/board/common/overlay/sbin/fwupdate b/board/common/overlay/sbin/fwupdate index ba1ce32651..196fec76b7 100755 --- a/board/common/overlay/sbin/fwupdate +++ b/board/common/overlay/sbin/fwupdate @@ -36,7 +36,7 @@ SYS_VERSION_FILE=/etc/version SYS_BOARD_FILE=/etc/board OS_CONF=/data/etc/os.conf -BOOT_DEV=/dev/mmcblk0p1 +BOOT_DEV=$(mount | grep /boot | cut -d ' ' -f 1) MIN_FREE_DISK=$((500*1024)) # 500 MB VER_FILE=version ROOT_INFO_FILE=root_info