SDCARD-RAW-TOOLS: extend script support

Change-Id: I0187e879bfcf1544d406c78a33dfbcee0070e0ca
This commit is contained in:
Romuald JEANNE 2020-06-17 16:42:12 +02:00
parent c9e37af629
commit 2fbe4ce39c
2 changed files with 58 additions and 43 deletions

View File

@ -17,6 +17,22 @@ inherit deploy
SCRIPT_DEPLOYDIR ?= "scripts" SCRIPT_DEPLOYDIR ?= "scripts"
do_configure() {
if [ -e ${WORKDIR}/create_sdcard_from_flashlayout.sh ]; then
bbnote "Update DEFAULT_ROOTFS_PARTITION_SIZE to ${ROOTFS_PARTITION_SIZE}"
sed 's/^DEFAULT_ROOTFS_PARTITION_SIZE=.*$/DEFAULT_ROOTFS_PARTITION_SIZE='"${ROOTFS_PARTITION_SIZE}"'/' -i ${WORKDIR}/create_sdcard_from_flashlayout.sh
if [ ${ROOTFS_PARTITION_SIZE} -gt 1572864 ]; then
# rootfs > 1.5GB then put sdcard raw size = ROOTFS_PARTITION_SIZE + 1.5GB
raw_size=$(expr ${ROOTFS_PARTITION_SIZE} / 1024 )
raw_size=$(expr $raw_size + 1536)
sed 's/^DEFAULT_RAW_SIZE=.*$/DEFAULT_RAW_SIZE='"$raw_size"'/' -i ${WORKDIR}/create_sdcard_from_flashlayout.sh
fi
bbnote "Update DEFAULT_SDCARD_PARTUUID to ${DEVICE_PARTUUID_ROOTFS_SDCARD}"
sed 's/^DEFAULT_SDCARD_PARTUUID=.*$/DEFAULT_SDCARD_PARTUUID='"${DEVICE_PARTUUID_ROOTFS_SDCARD}"'/' -i ${WORKDIR}/create_sdcard_from_flashlayout.sh
fi
}
do_install() { do_install() {
install -d ${D}/${bindir} install -d ${D}/${bindir}
install -m 0755 ${WORKDIR}/create_sdcard_from_flashlayout.sh ${D}/${bindir} install -m 0755 ${WORKDIR}/create_sdcard_from_flashlayout.sh ${D}/${bindir}

View File

@ -14,6 +14,10 @@
# CREATED: 11/22/2017 15:03 # CREATED: 11/22/2017 15:03
# REVISION: --- # REVISION: ---
#=============================================================================== #===============================================================================
#TODO: Pre-requisite tools
# sgdisk
# du
# dd
unset FLASHLAYOUT_data unset FLASHLAYOUT_data
unset FLASHLAYOUT_filename unset FLASHLAYOUT_filename
@ -40,6 +44,8 @@ DEFAULT_ROOTFS_PARTITION_SIZE=768432
# 32 MB of Padding on B # 32 MB of Padding on B
DEFAULT_PADDING_SIZE=33554432 DEFAULT_PADDING_SIZE=33554432
DEFAULT_SDCARD_PARTUUID=e91c4e10-16e6-4c0e-bd0e-77becf4a3582
# Columns name on FLASHLAYOUT_data # Columns name on FLASHLAYOUT_data
COL_SELECTED_OPT=0 COL_SELECTED_OPT=0
COL_PARTID=1 COL_PARTID=1
@ -90,7 +96,7 @@ function read_flash_layout() {
debug "Number of line: $FLASHLAYOUT_number_of_line" debug "Number of line: $FLASHLAYOUT_number_of_line"
while read -ra flashlayout_data; do while read -ra flashlayout_data; do
selected=${flashlayout_data[0]} selected=${flashlayout_data[0]}
if [ "$selected" == "P" ] || [ "$selected" == "E" ]; if [ "$selected" == "P" ] || [ "$selected" == "E" ] || [ "$selected" == "PD" ] || [ "$selected" == "DP" ];
then then
# Selected= # Selected=
FLASHLAYOUT_data[$i,$COL_SELECTED_OPT]=${flashlayout_data[0]} FLASHLAYOUT_data[$i,$COL_SELECTED_OPT]=${flashlayout_data[0]}
@ -142,7 +148,7 @@ function get_last_image_path() {
if [ "$ip" == "$SDCARD_TOKEN" ]; if [ "$ip" == "$SDCARD_TOKEN" ];
then then
case "$selected" in case "$selected" in
1|P) 1|P|D|PD|DP)
if [ "$partName" == 'rootfs' ]; if [ "$partName" == 'rootfs' ];
then then
last_image=$bin2flash last_image=$bin2flash
@ -186,7 +192,7 @@ function calculate_number_of_partition() {
ip=${FLASHLAYOUT_data[$i,$COL_IP]} ip=${FLASHLAYOUT_data[$i,$COL_IP]}
if [ "$ip" == "$SDCARD_TOKEN" ] if [ "$ip" == "$SDCARD_TOKEN" ]
then then
if [ "$selected" == "P" ] || [ "$selected" == "E" ]; if [ "$selected" == "P" ] || [ "$selected" == "E" ] || [ "$selected" == "PD" ] || [ "$selected" == "DP" ];
then then
num=$(($num+1)) num=$(($num+1))
fi fi
@ -210,7 +216,7 @@ function move_partition_offset() {
if [ "$ip" == "$SDCARD_TOKEN" ] if [ "$ip" == "$SDCARD_TOKEN" ]
then then
if [ "$selected" == "P" ] || [ "$selected" == "E" ] ; if [ "$selected" == "P" ] || [ "$selected" == "E" ] || [ "$selected" == "PD" ] || [ "$selected" == "DP" ];
then then
#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
@ -257,20 +263,27 @@ function generate_gpt_partition_table_from_flash_layout() {
debug "DUMP Process for $partName partition" debug "DUMP Process for $partName partition"
case "$selected" in case "$selected" in
P|E|1) P|E|1|PD|DP)
# partition are present and must be created # partition are present and must be created
;; ;;
*) *)
continue continue
;; ;;
esac esac
# add boot flags on gpt parition
if [ "$partName" == "bootfs" ]; case "$partName" in
then boot)
bootfs_param=" -A $j:set:2" # add boot flags on gpt parition
else extrafs_param=" -A $j:set:2"
bootfs_param="" ;;
fi rootfs)
# add rootfs PARTUUID flags
extrafs_param=" -u $j:${DEFAULT_SDCARD_PARTUUID}"
;;
*)
extrafs_param=""
;;
esac
# get size of image to put on partition # get size of image to put on partition
if [ -n "$bin2flash" ]; if [ -n "$bin2flash" ];
@ -359,7 +372,7 @@ function generate_gpt_partition_table_from_flash_layout() {
debug " DUMP image size $image_size" debug " DUMP image size $image_size"
debug " DUMP partition size $partition_size" debug " DUMP partition size $partition_size"
debug " DUMP free size $free_size " debug " DUMP free size $free_size "
if [ "$selected" == "P" ] || [ "$selected" == "E" ]; if [ "$selected" == "P" ] || [ "$selected" == "E" ] || [ "$selected" == "PD" ] || [ "$selected" == "DP" ];
then then
if [ $free_size -lt 0 ]; if [ $free_size -lt 0 ];
then then
@ -414,7 +427,7 @@ function generate_gpt_partition_table_from_flash_layout() {
fi fi
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 $bootfs_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"
@ -466,7 +479,7 @@ function populate_gpt_partition_table_from_flash_layout() {
#debug " DUMP ip $ip" #debug " DUMP ip $ip"
#debug " DUMP offset $offset " #debug " DUMP offset $offset "
#debug " DUMP bin2flash $bin2flash" #debug " DUMP bin2flash $bin2flash"
if [ "$selected" == "P" ]; 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 ];
@ -506,7 +519,7 @@ function print_shema_on_infofile() {
ip=${FLASHLAYOUT_data[$i,$COL_IP]} ip=${FLASHLAYOUT_data[$i,$COL_IP]}
if [ "$ip" == "$SDCARD_TOKEN" ]; if [ "$ip" == "$SDCARD_TOKEN" ];
then then
if [ "$selected" == "P" ] || [ "$selected" == "E" ]; if [ "$selected" == "P" ] || [ "$selected" == "E" ] || [ "$selected" == "PD" ] || [ "$selected" == "DP" ];
then then
echo -n "=============" >> $FLASHLAYOUT_infoname echo -n "=============" >> $FLASHLAYOUT_infoname
fi fi
@ -521,7 +534,7 @@ function print_shema_on_infofile() {
ip=${FLASHLAYOUT_data[$i,$COL_IP]} ip=${FLASHLAYOUT_data[$i,$COL_IP]}
if [ "$ip" == "$SDCARD_TOKEN" ]; if [ "$ip" == "$SDCARD_TOKEN" ];
then then
if [ "$selected" == "P" ] || [ "$selected" == "E" ]; if [ "$selected" == "P" ] || [ "$selected" == "E" ] || [ "$selected" == "PD" ] || [ "$selected" == "DP" ];
then then
echo -n "= " >> $FLASHLAYOUT_infoname echo -n "= " >> $FLASHLAYOUT_infoname
fi fi
@ -536,7 +549,7 @@ function print_shema_on_infofile() {
partName=${FLASHLAYOUT_data[$i,$COL_PARTNAME]} partName=${FLASHLAYOUT_data[$i,$COL_PARTNAME]}
if [ "$ip" == "$SDCARD_TOKEN" ]; if [ "$ip" == "$SDCARD_TOKEN" ];
then then
if [ "$selected" == "P" ] || [ "$selected" == "E" ]; if [ "$selected" == "P" ] || [ "$selected" == "E" ] || [ "$selected" == "PD" ] || [ "$selected" == "DP" ];
then then
printf "= %08s " "$partName" >> $FLASHLAYOUT_infoname printf "= %08s " "$partName" >> $FLASHLAYOUT_infoname
fi fi
@ -550,7 +563,7 @@ function print_shema_on_infofile() {
ip=${FLASHLAYOUT_data[$i,$COL_IP]} ip=${FLASHLAYOUT_data[$i,$COL_IP]}
if [ "$ip" == "$SDCARD_TOKEN" ]; if [ "$ip" == "$SDCARD_TOKEN" ];
then then
if [ "$selected" == "P" ] || [ "$selected" == "E" ]; if [ "$selected" == "P" ] || [ "$selected" == "E" ] || [ "$selected" == "PD" ] || [ "$selected" == "DP" ];
then then
echo -n "= " >> $FLASHLAYOUT_infoname echo -n "= " >> $FLASHLAYOUT_infoname
fi fi
@ -564,7 +577,7 @@ function print_shema_on_infofile() {
ip=${FLASHLAYOUT_data[$i,$COL_IP]} ip=${FLASHLAYOUT_data[$i,$COL_IP]}
if [ "$ip" == "$SDCARD_TOKEN" ]; if [ "$ip" == "$SDCARD_TOKEN" ];
then then
if [ "$selected" == "P" ] || [ "$selected" == "E" ]; 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))
@ -579,7 +592,7 @@ function print_shema_on_infofile() {
ip=${FLASHLAYOUT_data[$i,$COL_IP]} ip=${FLASHLAYOUT_data[$i,$COL_IP]}
if [ "$ip" == "$SDCARD_TOKEN" ]; if [ "$ip" == "$SDCARD_TOKEN" ];
then then
if [ "$selected" == "P" ] || [ "$selected" == "E" ]; 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))
@ -593,7 +606,7 @@ function print_shema_on_infofile() {
ip=${FLASHLAYOUT_data[$i,$COL_IP]} ip=${FLASHLAYOUT_data[$i,$COL_IP]}
if [ "$ip" == "$SDCARD_TOKEN" ]; if [ "$ip" == "$SDCARD_TOKEN" ];
then then
if [ "$selected" == "P" ] || [ "$selected" == "E" ]; if [ "$selected" == "P" ] || [ "$selected" == "E" ] || [ "$selected" == "PD" ] || [ "$selected" == "DP" ];
then then
echo -n "= " >> $FLASHLAYOUT_infoname echo -n "= " >> $FLASHLAYOUT_infoname
fi fi
@ -606,7 +619,7 @@ function print_shema_on_infofile() {
ip=${FLASHLAYOUT_data[$i,$COL_IP]} ip=${FLASHLAYOUT_data[$i,$COL_IP]}
if [ "$ip" == "$SDCARD_TOKEN" ]; if [ "$ip" == "$SDCARD_TOKEN" ];
then then
if [ "$selected" == "P" ] || [ "$selected" == "E" ]; if [ "$selected" == "P" ] || [ "$selected" == "E" ] || [ "$selected" == "PD" ] || [ "$selected" == "DP" ];
then then
echo -n "=============" >> $FLASHLAYOUT_infoname echo -n "=============" >> $FLASHLAYOUT_infoname
fi fi
@ -623,7 +636,7 @@ function print_shema_on_infofile() {
bin2flash=${FLASHLAYOUT_data[$i,$COL_BIN2FLASH]} bin2flash=${FLASHLAYOUT_data[$i,$COL_BIN2FLASH]}
if [ "$ip" == "$SDCARD_TOKEN" ]; if [ "$ip" == "$SDCARD_TOKEN" ];
then then
if [ "$selected" == "P" ] || [ "$selected" == "E" ]; if [ "$selected" == "P" ] || [ "$selected" == "E" ] || [ "$selected" == "PD" ] || [ "$selected" == "DP" ];
then then
echo "($j):" >> $FLASHLAYOUT_infoname echo "($j):" >> $FLASHLAYOUT_infoname
echo " Device: /dev/mmcblk0p$j" >> $FLASHLAYOUT_infoname echo " Device: /dev/mmcblk0p$j" >> $FLASHLAYOUT_infoname
@ -650,7 +663,7 @@ function print_populate_on_infofile() {
bin2flash=${FLASHLAYOUT_data[$i,$COL_BIN2FLASH]} bin2flash=${FLASHLAYOUT_data[$i,$COL_BIN2FLASH]}
if [ "$ip" == "$SDCARD_TOKEN" ]; if [ "$ip" == "$SDCARD_TOKEN" ];
then then
if [ "$selected" == "P" ] || [ "$selected" == "E" ]; if [ "$selected" == "P" ] || [ "$selected" == "E" ] || [ "$selected" == "PD" ] || [ "$selected" == "DP" ];
then then
if [ "$selected" == "E" ]; if [ "$selected" == "E" ];
then then
@ -698,15 +711,15 @@ cat >> $FLASHLAYOUT_infoname << EOF
3. How to update the kernel/devicetree 3. How to update the kernel/devicetree
-------------------------------------- --------------------------------------
The kernel and devicetree are present on "bootfs" partition. The kernel and devicetree are present on "boot" partition.
To change kernel and devicetree, you can copy the file on this partitions: To change kernel and devicetree, you can copy the file on this partitions:
- plug SDCARD on your PC - plug SDCARD on your PC
- copy kernel uImage on SDCARD - copy kernel uImage on SDCARD
sudo cp uImage /media/\$USER/bootfs/ sudo cp uImage /media/\$USER/boot/
- copy devicetree uImage on SDCARD - copy devicetree uImage on SDCARD
sudo cp stm32mp1*.dtb /media/\$USER/bootfs/ sudo cp stm32mp1*.dtb /media/\$USER/boot/
- umount partitions of SDCARD - umount partitions of SDCARD
sudo umount /media/\$USER/bootfs/ sudo umount /media/\$USER/boot/
(dont't forget to umount the other partitions of SDCARD: (dont't forget to umount the other partitions of SDCARD:
sudo umount \`lsblk --list | grep mmcblk0 | grep part | gawk '{ print \$7 }' | tr '\\n' ' '\` sudo umount \`lsblk --list | grep mmcblk0 | grep part | gawk '{ print \$7 }' | tr '\\n' ' '\`
) )
@ -756,11 +769,6 @@ function print_warning() {
fi fi
} }
function check_if_command_exists() {
command -v $1 >/dev/null 2>&1 \
|| { echo "Cannot continue. Please install $1 first."; exit 1; }
}
function usage() { function usage() {
echo "" echo ""
echo "Help:" echo "Help:"
@ -778,12 +786,6 @@ then
echo "" echo ""
usage usage
else else
# Pre-requisite tools
for i in sgdisk du dd;
do
check_if_command_exists $i
done
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)
@ -839,9 +841,6 @@ else
read answer read answer
if [[ "$answer" =~ ^[Yy]+[ESes]* ]]; then if [[ "$answer" =~ ^[Yy]+[ESes]* ]]; then
rm -f $FLASHLAYOUT_rawname $FLASHLAYOUT_infoname rm -f $FLASHLAYOUT_rawname $FLASHLAYOUT_infoname
else
echo "Cannot continue."
exit 1
fi fi
fi fi