Enhance card write/part scripts

* Check for partion table: If the desired is not found, write it
* Split resize commands so that an error can be identified better.
* Replay sync by dd's oflag=nocache

Signed-off-by: Andreas Müller <schnitzeltony@gmail.com>
This commit is contained in:
Andreas Müller
2018-10-06 15:54:56 +02:00
parent 1662dbec7e
commit a85c9745c6
4 changed files with 63 additions and 13 deletions

View File

@@ -267,6 +267,49 @@ RunUserStartRoot() {
fi
}
# CheckPartitionTable: Checks if device has a partition table. If not write one.
# The following parameters are expected:
# 1. Device: e.g /dev/sdc
# 2. Partition table type: This parameter is optional and default value is msdos
CheckPartitionTable() {
# This function is supposed to be called fist before data is written
# so do same safety checks (although it might be redundant)
if [ -z "$1" ]; then
ErrorOut "CheckPartitionTable: no parameter"
fi
if [ ! -b "$1" ]; then
ErrorOut "CheckPartitionTable: parameter $1 does not point to a block device"
fi
dev=`basename $1`
if [ ! `cat /sys/block/$dev/removable` = '1' ]; then
ErrorOut "CheckPartitionTable: parameter $1 does not point to a removable device"
fi
# checks passed here
parttype="$2"
if [ -z "$parttype" ]; then
parttype="msdos"
fi
# check for partition table
partresult=`parted -s $1 -- print 2> /dev/null`
PartTableReq=0
if ! echo -e $partresult | grep -q "$parttype"; then
PartTableReq=1
fi
# do we need to write part table?
if [ $PartTableReq -eq 1 ]; then
EvalExAuto "parted -s $1 -- mklabel $parttype" "\nWrite partition table $parttype..."
# During tests I found that my card writer failed writing parttion-
# table. So for others have similiar - check if partition table arrived.
# Funny side note: Now my box with sdcard marked as 'broken' is empty again :)
partresult=`parted -s $1 -- print 2> /dev/null`
if ! echo -e $partresult | grep -q "$parttype"; then
ErrorOut "Partition table '$parttype' was not written. Check your sdcard or another card-adapter!"
fi
fi
unset retVal parttype partresult retVal PartTableReq
}
StartCardWrite() {
# If not set on call - get defaults from machine.inc
if [ -z "$Machine" ]; then

View File

@@ -16,17 +16,19 @@ DEFAULT_FIND_KERNEL="-name ${DEFAULT_KERNEL_IMAGE_TYPE}-abiversion-* -type l"
RootCardWriteCallback() {
# rootfs write/resize to card fit
time(
# evt. write partition table
CheckPartitionTable "$DevicePath"
# write
StartMessage="\nWrite $DeployedFile to $DevicePath..."
if echo $DeployedFile | grep -q '.wic.gz'; then
EvalExAuto "gunzip -c $DeployedFile | dd of=$DevicePath bs=1024K" "$StartMessage"
EvalExAuto "gunzip -c $DeployedFile | dd of=$DevicePath oflag=nocache bs=1024K" "$StartMessage"
else
EvalExAuto "dd of=$DevicePath if=$DeployedFile bs=1024K" "$StartMessage"
EvalExAuto "dd of=$DevicePath oflag=nocache if=$DeployedFile bs=1024K" "$StartMessage"
fi
# sync
EvalExAuto "sync" "\nSync..."
# resize
EvalExAuto "parted -s $DevicePath -- resizepart 2 -0 && resize2fs ${DevicePath}2" "\nResize ${DevicePath}2..."
# resize I
EvalExAuto "parted -s $DevicePath -- resizepart 2 -0" "\nResize I ${DevicePath}2..."
# resize II
EvalExAuto "resize2fs ${DevicePath}2" "\nResize II ${DevicePath}2..."
)
}

View File

@@ -16,12 +16,14 @@ DEFAULT_FIND_KERNEL="-name ${DEFAULT_KERNEL_IMAGE_TYPE}-abiversion-* -type l"
RootCardWriteCallback() {
# rootfs write/resize to card fit
time(
# evt. write partition table
CheckPartitionTable "$DevicePath"
# write
EvalExAuto "dd of=$DevicePath if=$DeployedFile bs=1024K" "\nWrite $DeployedFile to $DevicePath..."
# sync
EvalExAuto "sync" "\nSync..."
# resize
EvalExAuto "parted -s $DevicePath -- resizepart 2 -0 && resize2fs ${DevicePath}2" "\nResize ${DevicePath}2..."
EvalExAuto "dd of=$DevicePath oflag=nocache if=$DeployedFile bs=1024K" "\nWrite $DeployedFile to $DevicePath..."
# resize I
EvalExAuto "parted -s $DevicePath -- resizepart 2 -0" "\nResize I ${DevicePath}2..."
# resize II
EvalExAuto "resize2fs ${DevicePath}2" "\nResize II ${DevicePath}2..."
)
}

View File

@@ -20,8 +20,11 @@ SelectInOut() {
# implement here - not im machine-ti-old-omap.inc
RootCardWriteCallback() {
# kill u-boot environment
EvalExAuto "dd if=/dev/zero of=$DevicePath bs=1024 count=1024" "\nKill u-boot environment..."
# evt. write partition table
CheckPartitionTable "$DevicePath"
# kill u-boot environment
EvalExAuto "dd if=/dev/zero of=$DevicePath ti-old-omap-card-part.sh bs=1024 count=1024" "\nKill u-boot environment..."
# Create the FAT partition of 64MB and make it bootable
EvalExAuto "parted -s $DevicePath mklabel msdos && parted -s $DevicePath mkpart primary fat32 63s 64MB && parted -s $DevicePath toggle 1 boot" "\nCreate boot partition..."