#!/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
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
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 () {
}
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
function print_logo () {
echo ""
- echo "For VisionFive2 , version 1.0.1"
+ echo "For VisionFive2 and QEMU, version 1.1.0"
echo ""
}
shift
case $option in
- --f | --format)
+ -c | --create)
+ CREATE="1"
+ set -- -f "${@}"
+ binary_option=0
+ ;;
+ -f | --format)
FORMAT="1"
binary_option=0
;;
binary_option=1
shift
;;
+ -s)
+ LOOP_SIZE=$1
+ binary_option=0
+ shift
+ ;;
*)
if [ $binary_option == 1 ];then
add_fusing_binary $option