summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJesse Gilles <jgilles@multitech.com>2015-03-30 14:46:43 -0500
committerJesse Gilles <jgilles@multitech.com>2015-03-30 14:46:43 -0500
commitbb625077dad62fd11dd3a20c9b230c7efb8eaba4 (patch)
tree1f390ba7c83a2d43fc02bc29508109803fafc386
parente3b07917e30c64ace9ee042c0b2065501b31967e (diff)
downloadmeta-mlinux-bb625077dad62fd11dd3a20c9b230c7efb8eaba4.tar.gz
meta-mlinux-bb625077dad62fd11dd3a20c9b230c7efb8eaba4.tar.bz2
meta-mlinux-bb625077dad62fd11dd3a20c9b230c7efb8eaba4.zip
initscripts: added enhanced flash on reboot using upgrade.bin file
-rw-r--r--recipes-core/initscripts/initscripts-1.0/umountfs176
-rw-r--r--recipes-core/initscripts/initscripts_1.0.bbappend2
2 files changed, 137 insertions, 41 deletions
diff --git a/recipes-core/initscripts/initscripts-1.0/umountfs b/recipes-core/initscripts/initscripts-1.0/umountfs
index f555aba..3403cca 100644
--- a/recipes-core/initscripts/initscripts-1.0/umountfs
+++ b/recipes-core/initscripts/initscripts-1.0/umountfs
@@ -58,14 +58,25 @@ flash_upgrade() {
local flash_root=${1}
local flash_dir=${flash_root}/flash-upgrade
- local uImage_file=${flash_dir}/uImage.bin
- local rootfs_file=${flash_dir}/rootfs.jffs2
+ local upgrade_file=${flash_dir}/upgrade.bin
+ local kernel_solo_file=${flash_dir}/uImage.bin
+ local rootfs_solo_file=${flash_dir}/rootfs.jffs2
local reboot_cmd=/usr/sbin/upgrade-reboot
local nandwrite_cmd=/usr/bin/nandwrite.static
local mode=
- local uImage_mtd=
+ local bootstrap_mtd=
+ local config_mtd=
+ local oem_mtd=
local rootfs_mtd=
+ local kernel_mtd=
+ local uboot_mtd=
+ local bootstrap_file=bstrap.bin
+ local config_file=config.jffs2
+ local oem_file=oem.jffs2
+ local rootfs_file=rootfs.jffs2
+ local kernel_file=uImage.bin
+ local uboot_file=uboot.bin
if [ ! -d "${flash_dir}" ]; then
echo "${flash_dir} not present, skipping"
@@ -93,60 +104,145 @@ flash_upgrade() {
return
fi
- uImage_mtd="/dev/$(cat /proc/mtd | grep uImage | cut -d : -f 1)"
- if [ ! -c "${uImage_mtd}" ]; then
- echo "No valid MTD partition is labeled uImage"
+ bootstrap_mtd="/dev/$(cat /proc/mtd | grep '\"at91bootstrap\"' | cut -d : -f 1)"
+ if [ ! -c "${bootstrap_mtd}" ]; then
+ echo "No valid MTD partition is labeled at91bootstrap"
return
fi
- rootfs_mtd="/dev/$(cat /proc/mtd | grep Rootfs | cut -d : -f 1)"
- if [ ! -c "${rootfs_mtd}" ]; then
- echo "No valid MTD partition is labeled Rootfs"
+ config_mtd="/dev/$(cat /proc/mtd | grep '\"Config\"' | cut -d : -f 1)"
+ if [ ! -c "${config_mtd}" ]; then
+ echo "No valid MTD partition is labeled Config"
return
fi
- echo ""
- echo "Starting flash upgrade from ${flash_dir}..."
-
- blink_leds
-
- if [ -f ${uImage_file} ]; then
- echo "Flashing ${uImage_mtd} (uImage) with ${uImage_file}..."
+ oem_mtd="/dev/$(cat /proc/mtd | grep '\"OEM Config\"' | cut -d : -f 1)"
+ if [ ! -c "${oem_mtd}" ]; then
+ echo "No valid MTD partition is labeled OEM Config"
+ return
+ fi
- flash_erase ${uImage_mtd} 0 0
- nandwrite -p ${uImage_mtd} ${uImage_file}
- else
- echo "uImage file ${uImage_file} not found"
+ kernel_mtd="/dev/$(cat /proc/mtd | grep '\"uImage\"' | cut -d : -f 1)"
+ if [ ! -c "${kernel_mtd}" ]; then
+ echo "No valid MTD partition is labeled uImage"
+ return
fi
- if [ -f ${rootfs_file} ]; then
- echo "Flashing ${rootfs_mtd} (rootfs) with ${rootfs_file}..."
+ uboot_mtd="/dev/$(cat /proc/mtd | grep '\"u-Boot\"' | cut -d : -f 1)"
+ if [ ! -c "${uboot_mtd}" ]; then
+ echo "No valid MTD partition is labeled u-Boot"
+ return
+ fi
- cp ${reboot_cmd} ${flash_dir}/upgrade-reboot
- cp ${nandwrite_cmd} ${flash_dir}/nandwrite.static
+ rootfs_mtd="/dev/$(cat /proc/mtd | grep '\"Rootfs\"' | cut -d : -f 1)"
+ if [ ! -c "${rootfs_mtd}" ]; then
+ echo "No valid MTD partition is labeled Rootfs"
+ return
+ fi
- sync
- sleep 2
- mount -o remount,ro ${flash_root}
+ cd /var/volatile
+
+ # rootfs should always be flashed last, so always keep it last here
+ local files=(${bootstrap_file} ${uboot_file} ${config_file} ${oem_file} ${kernel_file} ${rootfs_file})
+ local devs=(${bootstrap_mtd} ${uboot_mtd} ${config_mtd} ${oem_mtd} ${kernel_mtd} ${rootfs_mtd})
+
+ if [ -f "${upgrade_file}" ]; then
+ echo "Found ${upgrade_file}"
+ # make sure firmware is for this device
+ shopt -s nocasematch
+ local hw_version=$(cat /sys/devices/platform/mts-io/hw-version)
+ local firmware_model=$(tar -xO -f ${upgrade_file} model)
+ if [[ ! "${hw_version}" =~ ^${firmware_model}- ]]; then
+ echo "Wrong firmware for this hardware"
+ echo "hw version: ${hw_version}"
+ echo "firmware model: ${firmware_model}"
+ return
+ fi
+
+ echo "Checking MD5s"
+ # check md5sum
+ for (( i = 0; i < ${#files[@]}; i++ )); do
+ local file=${files[i]}
+ if tar -t -f ${upgrade_file} | grep -F -q "${file}"; then
+ if ! tar -x -f ${upgrade_file} ${file}.md5; then
+ echo "MD5 not found for ${file}"
+ return
+ fi
+ if ! tar -xO -f ${upgrade_file} ${file} | md5sum -c ${file}.md5; then
+ echo "MD5 check failed for ${file}"
+ return
+ fi
+ fi
+ done
+ fi
- # flash_root is not going to be umounted
- sed -i -e "\\|${flash_root}| d" /etc/mtab
+ echo ""
+ if [ -f "${upgrade_file}" ]; then
+ echo "Starting flash upgrade from ${upgrade_file}..."
+ elif [ -f "${kernel_solo_file}" ] || [ -f "${rootfs_solo_file}" ]; then
+ echo "Starting flash upgrade from ${flash_dir}..."
+ else
+ return
+ fi
- umount_all
+ blink_leds
- flash_erase -j ${rootfs_mtd} 0 0
- ${flash_dir}/nandwrite.static -p ${rootfs_mtd} ${rootfs_file}
+ cp ${reboot_cmd} ${flash_dir}/upgrade-reboot
+ cp ${nandwrite_cmd} ${flash_dir}/nandwrite.static
+ sync
+ sleep 2
+ mount -o remount,ro ${flash_root}
+
+ # flash_root is not going to be umounted
+ sed -i -e "\\|${flash_root}| d" /etc/mtab
+
+ umount_all
+
+ if [ -f "${upgrade_file}" ]; then
+ for (( i = 0; i < ${#files[@]}; i++ )); do
+ local file=${files[i]}
+ local dev=${devs[i]}
+ if tar -t -f ${upgrade_file} | grep -F -q "${file}"; then
+ if [ "${file}" == "${bootstrap_file}" ] || [ "${file}" == "${uboot_file}" ]; then
+ local file_size=$(tar -xO -f ${upgrade_file} ${file} | wc -c)
+ if dd if=${dev} bs=${file_size} count=1 | md5sum -c ${file}.md5; then
+ echo "Found ${file} in upgrade but it is the same as current. Continuing..."
+ continue
+ fi
+ fi
+ echo "Flashing ${dev} with ${file}..."
+
+ flash_erase -j ${dev} 0 0
+ tar -xO -f ${upgrade_file} ${file} | ${flash_dir}/nandwrite.static -p ${dev}
+ fi
+ done
+ else
+ if [ -f ${kernel_solo_file} ]; then
+ echo "Flashing ${kernel_mtd} (uImage) with ${kernel_solo_file}..."
+
+ flash_erase ${kernel_mtd} 0 0
+ ${flash_dir}/nandwrite.static -p ${kernel_mtd} ${kernel_solo_file}
+ else
+ echo "uImage file ${kernel_solo_file} not found"
+ fi
+
+ if [ -f ${rootfs_solo_file} ]; then
+ echo "Flashing ${rootfs_mtd} (rootfs) with ${rootfs_solo_file}..."
+
+ flash_erase -j ${rootfs_mtd} 0 0
+ ${flash_dir}/nandwrite.static -p ${rootfs_mtd} ${rootfs_solo_file}
+ else
+ echo "rootfs file ${rootfs_solo_file} not found"
+ fi
+ fi
- echo "Rebooting..."
+ echo "Rebooting..."
- ${flash_dir}/upgrade-reboot
+ ${flash_dir}/upgrade-reboot
- # Should not get here normally
- echo "upgrade-reboot failed"
- exit 1
- else
- echo "rootfs file ${rootfs_file} not found"
- fi
+ # Should not get here normally
+ echo "upgrade-reboot failed"
+ exit 1
}
# do flash on reboot if do_flash_upgrade exists
diff --git a/recipes-core/initscripts/initscripts_1.0.bbappend b/recipes-core/initscripts/initscripts_1.0.bbappend
index 54a7ed5..600060e 100644
--- a/recipes-core/initscripts/initscripts_1.0.bbappend
+++ b/recipes-core/initscripts/initscripts_1.0.bbappend
@@ -3,4 +3,4 @@ FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}-${PV}:"
# flash on reboot/umountfs needs regular umount (not busybox)
RDEPENDS_${PN} += "util-linux-umount util-linux-mount bash"
-PR .= ".1"
+PR .= ".2"