From 06d92ee94ba7fa805b83491f7e408ad5b1b46ad4 Mon Sep 17 00:00:00 2001 From: Brian Woods Date: Tue, 22 Oct 2019 18:38:57 -0700 Subject: Add command line arguments for uboot-script-gen Add some simple command line arguments and some dependency checking that makes running this outside of a container much easier. The environment variable LOAD_CMD has been removed and all the config options are done via command line arguemtnt for consistency. Signed-off-by: Brian Woods Signed-off-by: Stefano Stabellini Reviewed-by: Stefano Stabellini --- README.md | 13 +++++--- scripts/imagebuilder_sd | 3 +- scripts/imagebuilder_tftp | 3 +- scripts/uboot-script-gen | 78 +++++++++++++++++++++++++++++++++++++++++++++-- 4 files changed, 85 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index f26ff54..5eb4a49 100644 --- a/README.md +++ b/README.md @@ -71,13 +71,16 @@ Where: Then you can invoke uboot-script-gen as follows: ``` -$ export LOAD_CMD="tftpb" -$ bash ./scripts/uboot-script-gen /path/to/config-file +$ bash ./scripts/uboot-script-gen -c /path/to/config-file -d . -t tftp ``` -Where LOAD_CMD specifies the u-boot command to load the binaries. -For tftp, use LOAD_CMD="tftpb". -For SCSI, use LOAD_CMD="load scsi 0:1". +Where: +-c specifies the path to the config file to use +-d specifies the working directory (path in the config file are relative + to it) +-t specifies the u-boot command to load the binaries. "tftp" and "sd" + are shorthands for "tftpb" and "load scsi 0:1", but actually any + arbitrary command can be used, for instance -t "fatload" is valid. ## Container Usage diff --git a/scripts/imagebuilder_sd b/scripts/imagebuilder_sd index fc00716..460746e 100644 --- a/scripts/imagebuilder_sd +++ b/scripts/imagebuilder_sd @@ -5,6 +5,5 @@ mkdir /tmp/output cp config /tmp/output cp -r /home/builder/output/* /tmp/output cd /tmp/output -export LOAD_CMD="load scsi 0:1" -bash /uboot-script-gen ./config +bash /uboot-script-gen -c ./config -d ./ -t sd bash /disk_image diff --git a/scripts/imagebuilder_tftp b/scripts/imagebuilder_tftp index 1dd2e3f..70b5379 100644 --- a/scripts/imagebuilder_tftp +++ b/scripts/imagebuilder_tftp @@ -5,5 +5,4 @@ mkdir /tmp/output cp config /tmp/output cp -r /home/builder/output/* /tmp/output cd /tmp/output -export LOAD_CMD="tftpb" -bash /uboot-script-gen ./config +bash /uboot-script-gen -c ./config -d ./ -t tftp diff --git a/scripts/uboot-script-gen b/scripts/uboot-script-gen index 5b60737..a7d1a2f 100644 --- a/scripts/uboot-script-gen +++ b/scripts/uboot-script-gen @@ -2,6 +2,7 @@ offset=$((2*1024*1024)) filesize=0 +prog_req=(mkimage file) function add_device_tree_kernel() { @@ -130,12 +131,83 @@ function check_compressed_file_type() check_file_type $filename "$type" } -if test $# -lt 1 +function check_depends() +{ + for ((i=0; i<${#prog_req[@]}; i++)) + do + if ! command -v ${prog_req[i]} > /dev/null + then + echo "Please install the needed program: ${prog_req[i]}." + exit 1 + fi + done +} + +function print_help +{ + echo "usage:" + echo " $0 -c CONFIG_FILE -t UBOOT_TYPE -d DIRECTORY" + echo " $0 -h" + echo "where:" + echo " CONFIG_FILE - configuration file" + echo " UBOOT_TYPE can be:" + echo " sd - alias for \"scsi load 0:1\" for uboot load commands" + echo " tftp - alias for \"tftpb\" for uboot load cammnds" + echo " < > - used for uboot load commands" + echo " DIRECTORY - root directory of where the files of CONFIG_FILE" + echo " -h - prints out the help message and exits " + echo "Defaults:" + echo " CONFIG_FILE=$cfg_file, UBOOT_TYPE=\"LOAD_CMD\" env var, DIRECTORY=$uboot_dir" + echo "Example:" + echo " $0 -c ../config -d ./build42 -t \"scsi load 1:1\"" +} + +while getopts ":c:t:d:h" opt; do + case ${opt} in + t ) + case $OPTARG in + sd ) + LOAD_CMD="load scsi 0:1" + ;; + tftp ) + LOAD_CMD="tftpb" + ;; + * ) + LOAD_CMD="$OPTARG" + ;; + esac + ;; + c ) + cfg_file=$OPTARG + ;; + d ) + uboot_dir=$OPTARG + ;; + h ) + print_help + exit 0 + ;; + * ) + echo "Unknown option, see \"$0 -h\"" + exit 1 + ;; + esac +done +shift $((OPTIND -1)) + +if [ -z "$LOAD_CMD" ] || [ -z "$cfg_file" ] || [ -z "$uboot_dir" ] then - echo "Usage $0 " + echo "Undefined arguments, see \"$0 -h\"" exit 1 fi -source $1 + +check_depends + +source "$cfg_file" + +# the cd is needed so that the relative paths will match once we use +# tftp or move the files to a partition +cd "$uboot_dir" rm -f $UBOOT_SOURCE $UBOOT_SCRIPT memaddr=$(( $MEMORY_START + $offset )) -- cgit v1.2.3