From 76f2e17f11b08a0c05bc1a19c7732cffa2500c11 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=C5=81ukasz=20Stelmach?= Date: Thu, 24 Aug 2023 12:05:04 +0200 Subject: [PATCH] scripts: Add support for cereating images for use with QEMU. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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 --- scripts/tizen/sd_fusing_vf2.sh | 46 ++++++++++++++++++++++++++++++++++++------ 1 file changed, 40 insertions(+), 6 deletions(-) diff --git a/scripts/tizen/sd_fusing_vf2.sh b/scripts/tizen/sd_fusing_vf2.sh index d8c9e06..5b7cc9b 100755 --- a/scripts/tizen/sd_fusing_vf2.sh +++ b/scripts/tizen/sd_fusing_vf2.sh @@ -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 [-b ..] [--format]" - echo " -d : device ndoe " - echo " -b : binary " + echo " sudo ./sd_fusing*.sh -d [-b ..] [--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 -- 2.7.4