From 17bbd2574ba9374566967dd3cfefb49c24528359 Mon Sep 17 00:00:00 2001 From: Robert Nelson Date: Fri, 21 Jun 2013 11:35:16 -0500 Subject: [PATCH] mmc: with bootloader in flash, there is chance the boot device is not /dev/mmcblk0 Signed-off-by: Robert Nelson --- lib/debian-finish.sh | 14 +++++--- lib/ubuntu-finish.sh | 16 ++++++--- mk_mmc.sh | 79 ++++++++++++++++++++++++++++++++++++-------- 3 files changed, 86 insertions(+), 23 deletions(-) diff --git a/lib/debian-finish.sh b/lib/debian-finish.sh index 4ed5c5c..a289cad 100644 --- a/lib/debian-finish.sh +++ b/lib/debian-finish.sh @@ -12,6 +12,12 @@ if [ ! -f /boot/uboot/SOC.sh ] ; then fi . /boot/uboot/SOC.sh +if [ -f /boot/uboot/bootdrive ] ; then + bootdrive=$(cat /boot/uboot/bootdrive) +else + bootdrive=/dev/mmcblk0 +fi + if [ ! -d /boot/uboot/backup/ ] ; then mkdir -p /boot/uboot/backup/ fi @@ -22,9 +28,9 @@ fdisk -l >> /var/log/netinstall.log #Set boot flag on: /dev/mmcblk0: if [ -f /sbin/parted ] ; then - /sbin/parted /dev/mmcblk0 set 1 boot on || true + /sbin/parted ${bootdrive} set 1 boot on || true else - echo "ERROR: [/sbin/parted /dev/mmcblk0 set 1 boot on] failed" >> /var/log/netinstall.log + echo "ERROR: [/sbin/parted ${bootdrive} set 1 boot on] failed" >> /var/log/netinstall.log fi #Find Target Partition and FileSystem @@ -78,9 +84,9 @@ else fi if [ "x${boot_fstype}" = "xext2" ] ; then - echo "/dev/mmcblk0p1 /boot/uboot ext2 defaults 0 2" >> /etc/fstab + echo "${bootdrive}p1 /boot/uboot ext2 defaults 0 2" >> /etc/fstab else - echo "/dev/mmcblk0p1 /boot/uboot auto defaults 0 0" >> /etc/fstab + echo "${bootdrive}p1 /boot/uboot auto defaults 0 0" >> /etc/fstab fi if [ "x${usbnet_mem}" != "x" ] ; then diff --git a/lib/ubuntu-finish.sh b/lib/ubuntu-finish.sh index 183f0d5..88b7754 100644 --- a/lib/ubuntu-finish.sh +++ b/lib/ubuntu-finish.sh @@ -12,6 +12,12 @@ if [ ! -f /boot/uboot/SOC.sh ] ; then fi . /boot/uboot/SOC.sh +if [ -f /boot/uboot/bootdrive ] ; then + bootdrive=$(cat /boot/uboot/bootdrive) +else + bootdrive=/dev/mmcblk0 +fi + if [ ! -d /boot/uboot/backup/ ] ; then mkdir -p /boot/uboot/backup/ fi @@ -22,9 +28,9 @@ fdisk -l >> /var/log/netinstall.log #Set boot flag on: /dev/mmcblk0: if [ -f /sbin/parted ] ; then - /sbin/parted /dev/mmcblk0 set 1 boot on || true + /sbin/parted ${bootdrive} set 1 boot on || true else - echo "ERROR: [/sbin/parted /dev/mmcblk0 set 1 boot on] failed" >> /var/log/netinstall.log + echo "ERROR: [/sbin/parted ${bootdrive} set 1 boot on] failed" >> /var/log/netinstall.log fi #Find Target Partition and FileSystem @@ -89,7 +95,7 @@ fi if [ "${dd_uboot_seek}" ] && [ "${dd_uboot_bs}" ] ; then if [ -f /boot/uboot/backup/u-boot.imx ] ; then - dd if=/boot/uboot/backup/u-boot.imx of=/dev/mmcblk0 seek=${dd_uboot_seek} bs=${dd_uboot_bs} + dd if=/boot/uboot/backup/u-boot.imx of=${bootdrive} seek=${dd_uboot_seek} bs=${dd_uboot_bs} fi fi @@ -129,9 +135,9 @@ else fi if [ "x${boot_fstype}" = "xext2" ] ; then - echo "/dev/mmcblk0p1 /boot/uboot ext2 defaults 0 2" >> /etc/fstab + echo "${bootdrive}p1 /boot/uboot ext2 defaults 0 2" >> /etc/fstab else - echo "/dev/mmcblk0p1 /boot/uboot auto defaults 0 0" >> /etc/fstab + echo "${bootdrive}p1 /boot/uboot auto defaults 0 0" >> /etc/fstab fi if [ "x${usbnet_mem}" != "x" ] ; then diff --git a/mk_mmc.sh b/mk_mmc.sh index 871c143..68bdd2d 100755 --- a/mk_mmc.sh +++ b/mk_mmc.sh @@ -803,23 +803,48 @@ flash_kernel_base_installer () { mkdir -p /target/boot/uboot || true mkdir -p /target/lib/modules/\$(uname -r) || true - mount /dev/mmcblk0p1 /target/boot/uboot + #Some devices may have mmc cards in both slots... + unset got_boot_drive + + if [ ! ${got_boot_drive} ] ; then + if [ -b /dev/mmcblk0p1 ] ; then + mount /dev/mmcblk0p1 /target/boot/uboot + if [ -f /target/boot/uboot/SOC.sh ] ; then + got_boot_drive=1 + else + umount /target/boot/uboot + fi + fi + fi - #z = gzip (busybox tar) - tar -xzv -f /target/boot/uboot/\$(uname -r)-modules.tar.gz -C /target/lib/modules/\$(uname -r) + if [ ! ${got_boot_drive} ] ; then + if [ -b /dev/mmcblk1p1 ] ; then + mount /dev/mmcblk1p1 /target/boot/uboot + if [ -f /target/boot/uboot/SOC.sh ] ; then + got_boot_drive=1 + else + umount /target/boot/uboot + fi + fi + fi - mount -o bind /sys /target/sys - cat /proc/mounts > /target/mounts - chroot /target update-initramfs -c -k \$(uname -r) - rm -f /target/mounts || true - umount /target/sys + if [ ${got_boot_drive} ] ; then + #z = gzip (busybox tar) + tar -xzv -f /target/boot/uboot/\$(uname -r)-modules.tar.gz -C /target/lib/modules/\$(uname -r) - cp /target/boot/uboot/${fki_vmlinuz} /target/boot/${fki_vmlinuz} - cp /target/boot/initrd.img-\$(uname -r) /target/boot/${fki_initrd} - sync - umount /target/boot/uboot + mount -o bind /sys /target/sys + cat /proc/mounts > /target/mounts + chroot /target update-initramfs -c -k \$(uname -r) + rm -f /target/mounts || true + umount /target/sys - export FLASH_KERNEL_SKIP=true + cp /target/boot/uboot/${fki_vmlinuz} /target/boot/${fki_vmlinuz} + cp /target/boot/initrd.img-\$(uname -r) /target/boot/${fki_initrd} + sync + umount /target/boot/uboot + + export FLASH_KERNEL_SKIP=true + fi __EOF__ @@ -850,7 +875,33 @@ finish_installing_device () { if [ -f /etc/rcn.conf ]; then mkdir -p /target/boot/uboot || true - mount /dev/mmcblk0p1 /target/boot/uboot + + #Some devices may have mmc cards in both slots... + unset got_boot_drive + + if [ ! ${got_boot_drive} ] ; then + if [ -b /dev/mmcblk0p1 ] ; then + mount /dev/mmcblk0p1 /target/boot/uboot + if [ -f /target/boot/uboot/SOC.sh ] ; then + got_boot_drive=1 + echo "/dev/mmcblk0" > /target/boot/uboot/bootdrive + else + umount /target/boot/uboot + fi + fi + fi + + if [ ! ${got_boot_drive} ] ; then + if [ -b /dev/mmcblk1p1 ] ; then + mount /dev/mmcblk1p1 /target/boot/uboot + if [ -f /target/boot/uboot/SOC.sh ] ; then + got_boot_drive=1 + echo "/dev/mmcblk1" > /target/boot/uboot/bootdrive + else + umount /target/boot/uboot + fi + fi + fi if [ -d /lib/firmware/ ] ; then cp -rf /lib/firmware/ /target/lib/ || true