scripts: Add support for cereating images for use with QEMU.
authorŁukasz Stelmach <l.stelmach@samsung.com>
Thu, 24 Aug 2023 10:05:04 +0000 (12:05 +0200)
committerJaehoon Chung <jh80.chung@samsung.com>
Tue, 17 Oct 2023 11:02:46 +0000 (20:02 +0900)
Using the loopback driver the script can create, partition and record
Tizen onto a disk image (a regular file) that can be used to run Tizen
in QEMU.

Change-Id: I819f10899c0e4c4532fe7c65e9e00b43b69a4a04
Signed-off-by: Łukasz Stelmach <l.stelmach@samsung.com>
scripts/tizen/sd_fusing_vf2.sh

index d8c9e06..5b7cc9b 100755 (executable)
@@ -1,7 +1,10 @@
 #!/bin/bash
 
-declare FORMAT=""
+declare CREATE=""
 declare DEVICE=""
+declare FILE=""
+declare FORMAT=""
+declare LOOP_SIZE="8192"
 declare -i OLD_DD=0
 
 # Binaires array for fusing
@@ -30,6 +33,9 @@ declare -a PART_TABLE=(
 declare -r -i PART_TABLE_COL=5
 declare -r -i PART_TABLE_ROW=${#PART_TABLE[*]}/${PART_TABLE_COL}
 
+# tear down loopback device on exit
+trap 'test -n "$FILE" && losetup -d "$DEVICE"' EXIT
+
 # partition table support
 function get_index_use_name () {
        local -r binary_name=$1
@@ -298,9 +304,11 @@ function mkpart_3 () {
 
 function show_usage () {
        echo "- Usage:"
-       echo "  sudo ./sd_fusing*.sh -d <device> [-b <path> <path> ..] [--format]"
-       echo "  -d  : device ndoe "
-       echo "  -b  : binary "
+       echo "  sudo ./sd_fusing*.sh -d <device> [-b <path> <path> ..] [--format] [--create]"
+       echo "  --create : create the backing file and format the loopback device"
+       echo "  -d       : device node or loopback backing file"
+       echo "  -b       : binary"
+       echo "  -s       : size of the loopback device to create in MiB"
 }
 
 function check_partition_format () {
@@ -355,6 +363,22 @@ function check_args () {
 }
 
 function check_device () {
+       if [ ! -e "$DEVICE" -a "$CREATE" == "1" ]; then
+               dd if=/dev/zero of="$DEVICE" conv=sparse bs=1M count=$LOOP_SIZE
+               if [ "$?" != "0" ]; then
+                       echo "Failed to create the backing file"
+                       exit -1
+               fi
+       fi
+       if [ -f "$DEVICE" ]; then
+               FILE="$DEVICE"
+               DEVICE=$(losetup --partscan --show --find $FILE)
+               if [ "$?" != "0" ]; then
+                       echo "Failed to set up the loopback device"
+                       exit -1
+               fi
+       fi
+
        if [ ! -b "$DEVICE" ]; then
                echo "No such device: $DEVICE"
                exit 0
@@ -382,7 +406,7 @@ function check_device () {
 
 function print_logo () {
        echo ""
-       echo "For VisionFive2 , version 1.0.1"
+       echo "For VisionFive2 and QEMU, version 1.1.0"
        echo ""
 }
 
@@ -410,7 +434,12 @@ while test $# -ne 0; do
        shift
 
        case $option in
-       --f | --format)
+       -c | --create)
+               CREATE="1"
+               set -- -f "${@}"
+               binary_option=0
+               ;;
+       -f | --format)
                FORMAT="1"
                binary_option=0
                ;;
@@ -424,6 +453,11 @@ while test $# -ne 0; do
                binary_option=1
                shift
                ;;
+       -s)
+               LOOP_SIZE=$1
+               binary_option=0
+               shift
+               ;;
        *)
                if [ $binary_option == 1 ];then
                        add_fusing_binary $option