SDCARD-RAW-TOOLS: check requisite tools are available on the system

In addition, to script adaptation following shellcheck

Signed-off-by: Christophe Priouzeau <christophe.priouzeau@st.com>
Change-Id: I49d9f9a3ebfe7be2d1b8e77c8bf6a71751dbf228
This commit is contained in:
Christophe Priouzeau 2020-10-27 12:19:10 +01:00 committed by Bernard PUEL
parent 8d352d76f3
commit faedbbe552
1 changed files with 132 additions and 110 deletions

View File

@ -14,10 +14,12 @@
# CREATED: 11/22/2017 15:03 # CREATED: 11/22/2017 15:03
# REVISION: --- # REVISION: ---
#=============================================================================== #===============================================================================
#TODO: Pre-requisite tools
# sgdisk PRE_REQUISITE_TOOLS=" \
# du sgdisk \
# dd du \
dd \
"
unset FLASHLAYOUT_data unset FLASHLAYOUT_data
unset FLASHLAYOUT_filename unset FLASHLAYOUT_filename
@ -70,24 +72,36 @@ usage() {
} }
debug() { debug() {
if [ $DEBUG ]; if [ "$DEBUG" ];
then then
echo "" echo ""
echo "[DEBUG]: $@" echo "[DEBUG]: $*"
fi fi
} }
function exec_print() { function exec_print() {
if [ $DEBUG ]; if [ "$DEBUG" ];
then then
echo "" echo ""
echo "[DEBUG]: $@" echo "[DEBUG EXEC]: $*"
$@ eval "$@"
else else
$@ 2> /dev/null > /dev/null eval "$@" 2> /dev/null > /dev/null
fi fi
} }
tools_check() {
for tools in ${PRE_REQUISITE_TOOLS}; do
if [ "$(command -v "$tools" | wc -l )" -eq 0 ]; then
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
echo "[ERROR]: $tools cannot be found on your system."
echo " Please check corresponding package is installed or your PATH variable is set correctly."
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
exit 1
fi
done
}
# Read Flash Layout file and put information on array: FLASHLAYOUT_data # Read Flash Layout file and put information on array: FLASHLAYOUT_data
function read_flash_layout() { function read_flash_layout() {
local i=0 local i=0
@ -115,7 +129,7 @@ function read_flash_layout() {
#Bin2boot #Bin2boot
FLASHLAYOUT_data[$i,$COL_BIN2BOOT]=${flashlayout_data[7]} FLASHLAYOUT_data[$i,$COL_BIN2BOOT]=${flashlayout_data[7]}
i=$(($i+1)) i=$((i+1))
debug "READ: ${flashlayout_data[0]} ${flashlayout_data[1]} ${flashlayout_data[2]} ${flashlayout_data[3]} ..." debug "READ: ${flashlayout_data[0]} ${flashlayout_data[1]} ${flashlayout_data[2]} ${flashlayout_data[3]} ..."
fi fi
@ -158,17 +172,17 @@ function get_last_image_path() {
;; ;;
esac esac
fi fi
i=$(($i+1)) i=$((i+1))
done done
if [ -n $last_image ]; if [ -n "$last_image" ];
then then
if [ -f $FLASHLAYOUT_filename_path/$last_image ]; if [ -f "$FLASHLAYOUT_filename_path/$last_image" ];
then then
FLASHLAYOUT_prefix_image_path="$FLASHLAYOUT_filename_path" FLASHLAYOUT_prefix_image_path="$FLASHLAYOUT_filename_path"
elif [ -f $FLASHLAYOUT_filename_path/../$last_image ]; elif [ -f "$FLASHLAYOUT_filename_path/../$last_image" ];
then then
FLASHLAYOUT_prefix_image_path="$FLASHLAYOUT_filename_path/.." FLASHLAYOUT_prefix_image_path="$FLASHLAYOUT_filename_path/.."
elif [ -f $FLASHLAYOUT_filename_path/../../$last_image ]; elif [ -f "$FLASHLAYOUT_filename_path/../../$last_image" ];
then then
FLASHLAYOUT_prefix_image_path="$FLASHLAYOUT_filename_path/../.." FLASHLAYOUT_prefix_image_path="$FLASHLAYOUT_filename_path/../.."
else else
@ -194,7 +208,7 @@ function calculate_number_of_partition() {
then then
if [ "$selected" == "P" ] || [ "$selected" == "E" ] || [ "$selected" == "PD" ] || [ "$selected" == "DP" ]; if [ "$selected" == "P" ] || [ "$selected" == "E" ] || [ "$selected" == "PD" ] || [ "$selected" == "DP" ];
then then
num=$(($num+1)) num=$((num+1))
fi fi
fi fi
done done
@ -207,9 +221,9 @@ function calculate_number_of_partition() {
function move_partition_offset() { function move_partition_offset() {
ind=$1 ind=$1
new_offset=$2 new_offset=$2
offset_hexa=$(printf "%x\n" $new_offset) offset_hexa=$(printf "%x\n" "$new_offset")
for ((k=$ind;k<FLASHLAYOUT_number_of_line;k++)) for ((k=ind;k<FLASHLAYOUT_number_of_line;k++))
do do
selected=${FLASHLAYOUT_data[$k,$COL_SELECTED_OPT]} selected=${FLASHLAYOUT_data[$k,$COL_SELECTED_OPT]}
ip=${FLASHLAYOUT_data[$k,$COL_IP]} ip=${FLASHLAYOUT_data[$k,$COL_IP]}
@ -221,19 +235,19 @@ function move_partition_offset() {
#calculate actual size of partition (before update) #calculate actual size of partition (before update)
# in case of last partition, we doesn't take care of tmp_next_offset # in case of last partition, we doesn't take care of tmp_next_offset
# because there is no other partition to move. # because there is no other partition to move.
tmp_next_offset=${FLASHLAYOUT_data[$(($k+1)),$COL_OFFSET]} tmp_next_offset=${FLASHLAYOUT_data[$((k+1)),$COL_OFFSET]}
tmp_cur_offset=${FLASHLAYOUT_data[$k,$COL_OFFSET]} tmp_cur_offset=${FLASHLAYOUT_data[$k,$COL_OFFSET]}
tmp_partition_size=$(($tmp_next_offset - $tmp_cur_offset)) tmp_partition_size=$((tmp_next_offset - tmp_cur_offset))
#set new offset #set new offset
offset_hexa=$(printf "0x%x\n" $new_offset) offset_hexa=$(printf "0x%x\n" "$new_offset")
debug "${FLASHLAYOUT_data[$k,$COL_PARTNAME]}: Change Offset from ${FLASHLAYOUT_data[$k,$COL_OFFSET]}" \ debug "${FLASHLAYOUT_data[$k,$COL_PARTNAME]}: Change Offset from ${FLASHLAYOUT_data[$k,$COL_OFFSET]}" \
" to $offset_hexa" " to $offset_hexa"
FLASHLAYOUT_data[$k,$COL_OFFSET]=$offset_hexa FLASHLAYOUT_data[$k,$COL_OFFSET]=$offset_hexa
#calculate offset of next partition #calculate offset of next partition
new_offset=$(($new_offset + $tmp_partition_size)) new_offset=$((new_offset + tmp_partition_size))
fi fi
fi fi
done done
@ -288,9 +302,9 @@ function generate_gpt_partition_table_from_flash_layout() {
# get size of image to put on partition # get size of image to put on partition
if [ -n "$bin2flash" ]; if [ -n "$bin2flash" ];
then then
if [ -e $FLASHLAYOUT_prefix_image_path/$bin2flash ]; if [ -e "$FLASHLAYOUT_prefix_image_path/$bin2flash" ];
then then
image_size=$(du -Lb $FLASHLAYOUT_prefix_image_path/$bin2flash | tr '\t' ' ' | cut -d ' ' -f1) image_size=$(du -Lb "$FLASHLAYOUT_prefix_image_path/$bin2flash" | tr '\t' ' ' | cut -d ' ' -f1)
image_size_in_mb=$((image_size/1024/1024)) image_size_in_mb=$((image_size/1024/1024))
else else
image_size=0 image_size=0
@ -302,30 +316,31 @@ function generate_gpt_partition_table_from_flash_layout() {
fi fi
# get offset # get offset
offset=$(echo $offset | sed -e "s/0x//") #offset=$(echo $offset | sed -e "s/0x//")
offset_b=$(echo $((16#$offset)) ) offset=${offset//0x/}
offset_b=$((16#$offset))
offset=$((2 * $offset_b / 1024)) offset=$((2 * offset_b / 1024))
if [ $p -ne $(($number_of_partition -1)) ]; if [ $p -ne $((number_of_partition -1)) ];
then then
# get the begin offset of next partition # get the begin offset of next partition
next_offset=${FLASHLAYOUT_data[$(($i+1)),$COL_OFFSET]} next_offset=${FLASHLAYOUT_data[$((i+1)),$COL_OFFSET]}
next_offset=$(echo $next_offset | sed -e "s/0x//") next_offset=${next_offset//0x/}
next_offset_b=$(echo $((16#$next_offset))) next_offset_b=$((16#$next_offset))
if [ "$partName" == "rootfs" ]; if [ "$partName" == "rootfs" ];
then then
#force the size of rootfs parition to 768MB #force the size of rootfs parition to 768MB
new_next_partition_offset_b=$(($offset_b + 1024*$DEFAULT_ROOTFS_PARTITION_SIZE)) new_next_partition_offset_b=$((offset_b + 1024*DEFAULT_ROOTFS_PARTITION_SIZE))
next_offset_b=$new_next_partition_offset_b next_offset_b=$new_next_partition_offset_b
move_partition_offset $(($i+1)) $new_next_partition_offset_b move_partition_offset $((i+1)) $new_next_partition_offset_b
index_of_rootfs=$i index_of_rootfs=$i
fi fi
if [ $i -gt $index_of_rootfs ]; if [ $i -gt $index_of_rootfs ];
then then
if [ $(($next_offset_b + $image_size)) -gt $(($DEFAULT_RAW_SIZE * 1024*1024)) ] if [ $((next_offset_b + image_size)) -gt $((DEFAULT_RAW_SIZE * 1024*1024)) ]
then then
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
echo "[ERROR]: The rootfs and/or other partitions doesn't enter on a SDCARD size of $DEFAULT_RAW_SIZE MB" echo "[ERROR]: The rootfs and/or other partitions doesn't enter on a SDCARD size of $DEFAULT_RAW_SIZE MB"
@ -333,8 +348,8 @@ function generate_gpt_partition_table_from_flash_layout() {
exit 1 exit 1
fi fi
fi fi
next_offset=$((2 * $next_offset_b / 1024)) next_offset=$((2 * next_offset_b / 1024))
next_offset=$(($next_offset -1)) next_offset=$((next_offset -1))
if [ $next_offset -eq -1 ]; if [ $next_offset -eq -1 ];
then then
next_offset=" " next_offset=" "
@ -346,15 +361,15 @@ function generate_gpt_partition_table_from_flash_layout() {
fi fi
# calculate the size of partition # calculate the size of partition
partition_size=$(($next_offset_b - $offset_b)) partition_size=$((next_offset_b - offset_b))
if [ $partition_size -lt 0 ]; if [ $partition_size -lt 0 ];
then then
partition_size=0 partition_size=0
fi fi
if [ $i -ne $(($FLASHLAYOUT_number_of_line -1)) ]; if [ $i -ne $((FLASHLAYOUT_number_of_line -1)) ];
then then
free_size=$(($partition_size - $image_size)) free_size=$((partition_size - image_size))
else else
free_size=0 free_size=0
partition_size=0 partition_size=0
@ -382,11 +397,11 @@ function generate_gpt_partition_table_from_flash_layout() {
echo "[WARNING]: try to move last partition" echo "[WARNING]: try to move last partition"
# rootfs are too big for the partition, we increase the size of # rootfs are too big for the partition, we increase the size of
# partition of real rootfs image size + DEFAULT_PADDING_SIZE # partition of real rootfs image size + DEFAULT_PADDING_SIZE
new_next_partition_offset_b=$(($offset_b + $image_size + $DEFAULT_PADDING_SIZE)) new_next_partition_offset_b=$((offset_b + image_size + DEFAULT_PADDING_SIZE))
move_partition_offset $(($i+1)) $new_next_partition_offset_b move_partition_offset $((i+1)) $new_next_partition_offset_b
if [ $new_next_partition_offset_b -gt $(($DEFAULT_RAW_SIZE * 1024*1024)) ] if [ $new_next_partition_offset_b -gt $((DEFAULT_RAW_SIZE * 1024*1024)) ]
then then
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
echo "[ERROR]: IMAGE TOO BIG [$partName:$bin2flash $image_size_in_mb MB [requested $partition_size B]" echo "[ERROR]: IMAGE TOO BIG [$partName:$bin2flash $image_size_in_mb MB [requested $partition_size B]"
@ -394,8 +409,8 @@ function generate_gpt_partition_table_from_flash_layout() {
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
exit 1 exit 1
fi fi
next_offset=$((2 * $new_next_partition_offset_b / 1024)) next_offset=$((2 * new_next_partition_offset_b / 1024))
next_offset=$(($next_offset -1)) next_offset=$((next_offset -1))
else else
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
echo "[ERROR]: IMAGE TOO BIG [$partName:$bin2flash $image_size_in_mb MB [requested $partition_size B]" echo "[ERROR]: IMAGE TOO BIG [$partName:$bin2flash $image_size_in_mb MB [requested $partition_size B]"
@ -404,11 +419,11 @@ function generate_gpt_partition_table_from_flash_layout() {
fi fi
fi fi
if [ $p -eq $(($number_of_partition -1)) ]; if [ $p -eq $((number_of_partition -1)) ];
then then
temp_end_offset_b=$(($offset_b + $image_size)) temp_end_offset_b=$((offset_b + image_size))
if [ $temp_end_offset_b -gt $(($DEFAULT_RAW_SIZE * 1024*1024)) ]; if [ $temp_end_offset_b -gt $((DEFAULT_RAW_SIZE * 1024*1024)) ];
then then
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
echo "[ERROR]: IMAGE TOO BIG [$partName:$bin2flash $image_size_in_mb MB]" echo "[ERROR]: IMAGE TOO BIG [$partName:$bin2flash $image_size_in_mb MB]"
@ -428,19 +443,19 @@ function generate_gpt_partition_table_from_flash_layout() {
printf "part %d: %8s ..." $j "$partName" printf "part %d: %8s ..." $j "$partName"
exec_print "sgdisk -a 1 -n $j:$offset:$next_offset -c $j:$partName -t $j:$gpt_code $extrafs_param $FLASHLAYOUT_rawname" exec_print "sgdisk -a 1 -n $j:$offset:$next_offset -c $j:$partName -t $j:$gpt_code $extrafs_param $FLASHLAYOUT_rawname"
partition_size=$(sgdisk -p $FLASHLAYOUT_rawname | grep $partName | awk '{ print $4}') partition_size=$(sgdisk -p "$FLASHLAYOUT_rawname" | grep $partName | awk '{ print $4}')
partition_size_type=$(sgdisk -p $FLASHLAYOUT_rawname | grep $partName | awk '{ print $5}') partition_size_type=$(sgdisk -p "$FLASHLAYOUT_rawname" | grep $partName | awk '{ print $5}')
printf "\r[CREATED] part %d: %8s [partition size %s %s]\n" $j "$partName" "$partition_size" "$partition_size_type" printf "\r[CREATED] part %d: %8s [partition size %s %s]\n" $j "$partName" "$partition_size" "$partition_size_type"
j=$(($j+1)) j=$((j+1))
fi fi
p=$(($p+1)) p=$((p+1))
fi fi
done done
echo "" echo ""
echo "Partition table from $FLASHLAYOUT_rawname" echo "Partition table from $FLASHLAYOUT_rawname"
sgdisk -p $FLASHLAYOUT_rawname exec_print "sgdisk -p $FLASHLAYOUT_rawname"
echo "" echo ""
} }
@ -466,8 +481,8 @@ function populate_gpt_partition_table_from_flash_layout() {
offset=${FLASHLAYOUT_data[$i,$COL_OFFSET]} offset=${FLASHLAYOUT_data[$i,$COL_OFFSET]}
bin2flash=${FLASHLAYOUT_data[$i,$COL_BIN2FLASH]} bin2flash=${FLASHLAYOUT_data[$i,$COL_BIN2FLASH]}
offset=$(echo $offset | sed -e "s/0x//") offset=${offset//0x/}
offset=$(echo $((16#$offset))) offset=$((16#$offset))
debug " DUMP $selected $partId $partName $partType" debug " DUMP $selected $partId $partName $partType"
if [ "$ip" == "$SDCARD_TOKEN" ]; if [ "$ip" == "$SDCARD_TOKEN" ];
@ -482,7 +497,7 @@ function populate_gpt_partition_table_from_flash_layout() {
if [ "$selected" == "P" ] || [ "$selected" == "PD" ] || [ "$selected" == "DP" ]; if [ "$selected" == "P" ] || [ "$selected" == "PD" ] || [ "$selected" == "DP" ];
then then
# Populate only the partition in "P" # Populate only the partition in "P"
if [ -e $FLASHLAYOUT_prefix_image_path/$bin2flash ]; if [ -e "$FLASHLAYOUT_prefix_image_path/$bin2flash" ];
then then
printf "part %d: %8s, image: %s ..." $j "$partName" "$bin2flash" printf "part %d: %8s, image: %s ..." $j "$partName" "$bin2flash"
exec_print "dd if=$FLASHLAYOUT_prefix_image_path/$bin2flash of=$FLASHLAYOUT_rawname conv=fdatasync,notrunc seek=1 bs=$offset" exec_print "dd if=$FLASHLAYOUT_prefix_image_path/$bin2flash of=$FLASHLAYOUT_rawname conv=fdatasync,notrunc seek=1 bs=$offset"
@ -493,12 +508,12 @@ function populate_gpt_partition_table_from_flash_layout() {
echo " [WARNING]: THE PARTITION $partName ARE NOT FILL." echo " [WARNING]: THE PARTITION $partName ARE NOT FILL."
WARNING_TEXT+="[WARNING]: THE PARTITION $partName ARE NOT FILL (file $FLASHLAYOUT_prefix_image_path/$bin2flash are not present) #" WARNING_TEXT+="[WARNING]: THE PARTITION $partName ARE NOT FILL (file $FLASHLAYOUT_prefix_image_path/$bin2flash are not present) #"
fi fi
j=$(($j+1)) j=$((j+1))
else else
if [ "$selected" == "E" ]; if [ "$selected" == "E" ];
then then
printf "\r[UNFILLED] part %d: %8s, \n" $j "$partName" printf "\r[UNFILLED] part %d: %8s, \n" $j "$partName"
j=$(($j+1)) j=$((j+1))
fi fi
fi fi
@ -521,11 +536,11 @@ function print_shema_on_infofile() {
then then
if [ "$selected" == "P" ] || [ "$selected" == "E" ] || [ "$selected" == "PD" ] || [ "$selected" == "DP" ]; if [ "$selected" == "P" ] || [ "$selected" == "E" ] || [ "$selected" == "PD" ] || [ "$selected" == "DP" ];
then then
echo -n "=============" >> $FLASHLAYOUT_infoname echo -n "=============" >> "$FLASHLAYOUT_infoname"
fi fi
fi fi
done done
echo "=" >> $FLASHLAYOUT_infoname echo "=" >> "$FLASHLAYOUT_infoname"
#empty line #empty line
for ((i=0;i<FLASHLAYOUT_number_of_line;i++)) for ((i=0;i<FLASHLAYOUT_number_of_line;i++))
@ -536,11 +551,11 @@ function print_shema_on_infofile() {
then then
if [ "$selected" == "P" ] || [ "$selected" == "E" ] || [ "$selected" == "PD" ] || [ "$selected" == "DP" ]; if [ "$selected" == "P" ] || [ "$selected" == "E" ] || [ "$selected" == "PD" ] || [ "$selected" == "DP" ];
then then
echo -n "= " >> $FLASHLAYOUT_infoname echo -n "= " >> "$FLASHLAYOUT_infoname"
fi fi
fi fi
done done
echo "=" >> $FLASHLAYOUT_infoname echo "=" >> "$FLASHLAYOUT_infoname"
# part name # part name
for ((i=0;i<FLASHLAYOUT_number_of_line;i++)) for ((i=0;i<FLASHLAYOUT_number_of_line;i++))
do do
@ -551,11 +566,11 @@ function print_shema_on_infofile() {
then then
if [ "$selected" == "P" ] || [ "$selected" == "E" ] || [ "$selected" == "PD" ] || [ "$selected" == "DP" ]; if [ "$selected" == "P" ] || [ "$selected" == "E" ] || [ "$selected" == "PD" ] || [ "$selected" == "DP" ];
then then
printf "= %08s " "$partName" >> $FLASHLAYOUT_infoname printf "= %08s " "$partName" >> "$FLASHLAYOUT_infoname"
fi fi
fi fi
done done
echo "=" >> $FLASHLAYOUT_infoname echo "=" >> "$FLASHLAYOUT_infoname"
#empty #empty
for ((i=0;i<FLASHLAYOUT_number_of_line;i++)) for ((i=0;i<FLASHLAYOUT_number_of_line;i++))
do do
@ -565,11 +580,11 @@ function print_shema_on_infofile() {
then then
if [ "$selected" == "P" ] || [ "$selected" == "E" ] || [ "$selected" == "PD" ] || [ "$selected" == "DP" ]; if [ "$selected" == "P" ] || [ "$selected" == "E" ] || [ "$selected" == "PD" ] || [ "$selected" == "DP" ];
then then
echo -n "= " >> $FLASHLAYOUT_infoname echo -n "= " >> "$FLASHLAYOUT_infoname"
fi fi
fi fi
done done
echo "=" >> $FLASHLAYOUT_infoname echo "=" >> "$FLASHLAYOUT_infoname"
# partition number # partition number
for ((i=0;i<FLASHLAYOUT_number_of_line;i++)) for ((i=0;i<FLASHLAYOUT_number_of_line;i++))
do do
@ -579,12 +594,12 @@ function print_shema_on_infofile() {
then then
if [ "$selected" == "P" ] || [ "$selected" == "E" ] || [ "$selected" == "PD" ] || [ "$selected" == "DP" ]; if [ "$selected" == "P" ] || [ "$selected" == "E" ] || [ "$selected" == "PD" ] || [ "$selected" == "DP" ];
then then
printf "= %08s%-2d " "mmcblk0p" $j>> $FLASHLAYOUT_infoname printf "= %08s%-2d " "mmcblk0p" $j>> "$FLASHLAYOUT_infoname"
j=$(($j+1)) j=$((j+1))
fi fi
fi fi
done done
echo "=" >> $FLASHLAYOUT_infoname echo "=" >> "$FLASHLAYOUT_infoname"
j=1 j=1
for ((i=0;i<FLASHLAYOUT_number_of_line;i++)) for ((i=0;i<FLASHLAYOUT_number_of_line;i++))
do do
@ -594,12 +609,12 @@ function print_shema_on_infofile() {
then then
if [ "$selected" == "P" ] || [ "$selected" == "E" ] || [ "$selected" == "PD" ] || [ "$selected" == "DP" ]; if [ "$selected" == "P" ] || [ "$selected" == "E" ] || [ "$selected" == "PD" ] || [ "$selected" == "DP" ];
then then
printf "= (%-2d) " $j>> $FLASHLAYOUT_infoname printf "= (%-2d) " $j>> "$FLASHLAYOUT_infoname"
j=$(($j+1)) j=$((j+1))
fi fi
fi fi
done done
echo "=" >> $FLASHLAYOUT_infoname echo "=" >> "$FLASHLAYOUT_infoname"
for ((i=0;i<FLASHLAYOUT_number_of_line;i++)) for ((i=0;i<FLASHLAYOUT_number_of_line;i++))
do do
selected=${FLASHLAYOUT_data[$i,$COL_SELECTED_OPT]} selected=${FLASHLAYOUT_data[$i,$COL_SELECTED_OPT]}
@ -608,11 +623,11 @@ function print_shema_on_infofile() {
then then
if [ "$selected" == "P" ] || [ "$selected" == "E" ] || [ "$selected" == "PD" ] || [ "$selected" == "DP" ]; if [ "$selected" == "P" ] || [ "$selected" == "E" ] || [ "$selected" == "PD" ] || [ "$selected" == "DP" ];
then then
echo -n "= " >> $FLASHLAYOUT_infoname echo -n "= " >> "$FLASHLAYOUT_infoname"
fi fi
fi fi
done done
echo "=" >> $FLASHLAYOUT_infoname echo "=" >> "$FLASHLAYOUT_infoname"
for ((i=0;i<FLASHLAYOUT_number_of_line;i++)) for ((i=0;i<FLASHLAYOUT_number_of_line;i++))
do do
selected=${FLASHLAYOUT_data[$i,$COL_SELECTED_OPT]} selected=${FLASHLAYOUT_data[$i,$COL_SELECTED_OPT]}
@ -621,11 +636,11 @@ function print_shema_on_infofile() {
then then
if [ "$selected" == "P" ] || [ "$selected" == "E" ] || [ "$selected" == "PD" ] || [ "$selected" == "DP" ]; if [ "$selected" == "P" ] || [ "$selected" == "E" ] || [ "$selected" == "PD" ] || [ "$selected" == "DP" ];
then then
echo -n "=============" >> $FLASHLAYOUT_infoname echo -n "=============" >> "$FLASHLAYOUT_infoname"
fi fi
fi fi
done done
echo "=" >> $FLASHLAYOUT_infoname echo "=" >> "$FLASHLAYOUT_infoname"
# print legend of partition # print legend of partition
j=1 j=1
for ((i=0;i<FLASHLAYOUT_number_of_line;i++)) for ((i=0;i<FLASHLAYOUT_number_of_line;i++))
@ -638,16 +653,18 @@ function print_shema_on_infofile() {
then then
if [ "$selected" == "P" ] || [ "$selected" == "E" ] || [ "$selected" == "PD" ] || [ "$selected" == "DP" ]; if [ "$selected" == "P" ] || [ "$selected" == "E" ] || [ "$selected" == "PD" ] || [ "$selected" == "DP" ];
then then
echo "($j):" >> $FLASHLAYOUT_infoname {
echo " Device: /dev/mmcblk0p$j" >> $FLASHLAYOUT_infoname echo "($j):"
echo " Label: $partName" >> $FLASHLAYOUT_infoname echo " Device: /dev/mmcblk0p$j"
if [ -n "$bin2flash" ]; echo " Label: $partName"
then if [ -n "$bin2flash" ];
echo " Image: $bin2flash" >> $FLASHLAYOUT_infoname then
else echo " Image: $bin2flash"
echo " Image:" >> $FLASHLAYOUT_infoname else
fi echo " Image:"
j=$(($j+1)) fi
} >> "$FLASHLAYOUT_infoname"
j=$((j+1))
fi fi
fi fi
done done
@ -667,19 +684,19 @@ function print_populate_on_infofile() {
then then
if [ "$selected" == "E" ]; if [ "$selected" == "E" ];
then then
echo "- Populate partition $partName (/dev/mmcblk0p$j)" >> $FLASHLAYOUT_infoname echo "- Populate partition $partName (/dev/mmcblk0p$j)" >> "$FLASHLAYOUT_infoname"
if [ -n "$bin2flash" ]; if [ -n "$bin2flash" ];
then then
echo " dd if=$bin2flash of=/dev/mmcblk0p$j bs=1M conv=fdatasync status=progress" >> $FLASHLAYOUT_infoname echo " dd if=$bin2flash of=/dev/mmcblk0p$j bs=1M conv=fdatasync status=progress" >> "$FLASHLAYOUT_infoname"
else else
echo " dd if=<raw image of $partName> of=/dev/mmcblk0p$j bs=1M conv=fdatasync status=progress" >> $FLASHLAYOUT_infoname echo " dd if=<raw image of $partName> of=/dev/mmcblk0p$j bs=1M conv=fdatasync status=progress" >> "$FLASHLAYOUT_infoname"
fi fi
else else
echo "- Populate partition $partName (/dev/mmcblk0p$j)" >> $FLASHLAYOUT_infoname echo "- Populate partition $partName (/dev/mmcblk0p$j)" >> "$FLASHLAYOUT_infoname"
echo " dd if=$bin2flash of=/dev/mmcblk0p$j bs=1M conv=fdatasync status=progress" >> $FLASHLAYOUT_infoname echo " dd if=$bin2flash of=/dev/mmcblk0p$j bs=1M conv=fdatasync status=progress" >> "$FLASHLAYOUT_infoname"
fi fi
echo "" >> $FLASHLAYOUT_infoname echo "" >> "$FLASHLAYOUT_infoname"
j=$(($j+1)) j=$((j+1))
fi fi
fi fi
done done
@ -687,7 +704,7 @@ function print_populate_on_infofile() {
function create_info() { function create_info() {
cat > $FLASHLAYOUT_infoname << EOF cat > "$FLASHLAYOUT_infoname" << EOF
This file describe How to update manually the partition of SDCARD: This file describe How to update manually the partition of SDCARD:
1. SDCARD schema of partition 1. SDCARD schema of partition
2. How to populate each partition 2. How to populate each partition
@ -699,7 +716,7 @@ This file describe How to update manually the partition of SDCARD:
EOF EOF
print_shema_on_infofile print_shema_on_infofile
cat >> $FLASHLAYOUT_infoname << EOF cat >> "$FLASHLAYOUT_infoname" << EOF
2. How to populate each partition 2. How to populate each partition
--------------------------------- ---------------------------------
@ -707,7 +724,7 @@ EOF
print_populate_on_infofile print_populate_on_infofile
cat >> $FLASHLAYOUT_infoname << EOF cat >> "$FLASHLAYOUT_infoname" << EOF
3. How to update the kernel/devicetree 3. How to update the kernel/devicetree
-------------------------------------- --------------------------------------
@ -758,10 +775,13 @@ function print_warning() {
echo "" echo ""
echo "???????????????????????????????????????????????????????????????????????????" echo "???????????????????????????????????????????????????????????????????????????"
echo "???????????????????????????????????????????????????????????????????????????" echo "???????????????????????????????????????????????????????????????????????????"
for t in "`echo $WARNING_TEXT | tr '#' '\n'`"; OLD_IFS=$IFS
IFS=$'\n'
for t in $(echo "$WARNING_TEXT" | tr '#' '\n');
do do
echo "$t" echo "$t"
done done
IFS=$OLD_IFS
echo "[WARNING]: IT'S POSSIBLE, THE BOARD DOES NOT BOOT CORRECTLY DUE TO " echo "[WARNING]: IT'S POSSIBLE, THE BOARD DOES NOT BOOT CORRECTLY DUE TO "
echo " FILE(s) NOT PRESENT." echo " FILE(s) NOT PRESENT."
echo "???????????????????????????????????????????????????????????????????????????" echo "???????????????????????????????????????????????????????????????????????????"
@ -786,10 +806,12 @@ then
echo "" echo ""
usage usage
else else
tools_check
FLASHLAYOUT_filename=$1 FLASHLAYOUT_filename=$1
FLASHLAYOUT_filename_path=$(dirname $FLASHLAYOUT_filename) FLASHLAYOUT_filename_path=$(dirname "$FLASHLAYOUT_filename")
FLASHLAYOUT_filename_name=$(basename $FLASHLAYOUT_filename) FLASHLAYOUT_filename_name=$(basename "$FLASHLAYOUT_filename")
FLASHLAYOUT_dirname=$(basename $FLASHLAYOUT_filename_path) FLASHLAYOUT_dirname=$(basename "$FLASHLAYOUT_filename_path")
_extension="${FLASHLAYOUT_filename##*.}" _extension="${FLASHLAYOUT_filename##*.}"
if [ ! "$_extension" == "tsv" ]; if [ ! "$_extension" == "tsv" ];
@ -801,19 +823,19 @@ else
fi fi
# File have a correct extension # File have a correct extension
# #
if echo $FLASHLAYOUT_dirname | grep -q flashlayout if echo "$FLASHLAYOUT_dirname" | grep -q flashlayout
then then
# add directory name as prefix for raw image # add directory name as prefix for raw image
new_filename=$(echo "$FLASHLAYOUT_dirname/$FLASHLAYOUT_filename_name" | sed -e "s|/|_|g") new_filename=$(echo "$FLASHLAYOUT_dirname/$FLASHLAYOUT_filename_name" | sed -e "s|/|_|g")
filename_for_raw_to_use="$FLASHLAYOUT_filename_path/$new_filename" filename_for_raw_to_use="$FLASHLAYOUT_filename_path/$new_filename"
else else
filename_for_raw_to_use=$FLASHLAYOUT_filename filename_for_raw_to_use="$FLASHLAYOUT_filename"
fi fi
FLASHLAYOUT_rawname=$(basename $filename_for_raw_to_use | sed -e "s/tsv/raw/") FLASHLAYOUT_rawname=$(basename "$filename_for_raw_to_use" | sed -e "s/tsv/raw/")
FLASHLAYOUT_infoname=$(basename $filename_for_raw_to_use | sed -e "s/tsv/how_to_update.txt/") FLASHLAYOUT_infoname=$(basename "$filename_for_raw_to_use" | sed -e "s/tsv/how_to_update.txt/")
# check if flashlayout have sdcard name # check if flashlayout have sdcard name
if [ $(grep -i $SDCARD_TOKEN $FLASHLAYOUT_filename| wc -l) -eq 0 ]; if [ "$(grep -ic "$SDCARD_TOKEN" "$FLASHLAYOUT_filename")" -eq 0 ];
then then
echo "" echo ""
echo "[WARNING]: THE FLASHLAYOUT NAME DOES NOT CONTAINS SDCARD REFERENCE." echo "[WARNING]: THE FLASHLAYOUT NAME DOES NOT CONTAINS SDCARD REFERENCE."
@ -832,15 +854,15 @@ else
FLASHLAYOUT_infoname=$FLASHLAYOUT_prefix_image_path/$FLASHLAYOUT_infoname FLASHLAYOUT_infoname=$FLASHLAYOUT_prefix_image_path/$FLASHLAYOUT_infoname
# erase previous raw image # erase previous raw image
if [ -f $FLASHLAYOUT_rawname ]; if [ -f "$FLASHLAYOUT_rawname" ];
then then
echo "" echo ""
echo "[WARNING]: A previous raw image are present on this directory" echo "[WARNING]: A previous raw image are present on this directory"
echo "[WARNING]: $FLASHLAYOUT_rawname" echo "[WARNING]: $FLASHLAYOUT_rawname"
echo "[WARNING]: would you like to erase it: [Y/n]" echo "[WARNING]: would you like to erase it: [Y/n]"
read answer read -r answer
if [[ "$answer" =~ ^[Yy]+[ESes]* ]]; then if [[ "$answer" =~ ^[Yy]+[ESes]* ]]; then
rm -f $FLASHLAYOUT_rawname $FLASHLAYOUT_infoname rm -f "$FLASHLAYOUT_rawname" "$FLASHLAYOUT_infoname"
fi fi
fi fi
@ -851,8 +873,8 @@ else
fi fi
generate_empty_raw_image generate_empty_raw_image
generate_gpt_partition_table_from_flash_layout generate_gpt_partition_table_from_flash_layout ""
populate_gpt_partition_table_from_flash_layout populate_gpt_partition_table_from_flash_layout ""
create_info create_info
print_info print_info