From 0fce3d4b9e05d9ff225948cf9b28060d62e643ce Mon Sep 17 00:00:00 2001 From: Brian Woods Date: Thu, 16 Jan 2020 18:04:03 -0800 Subject: Add stricter checking of files in config The boot script files would still be generated even if the files used in the config don't exist. This checks to make sure the files exist and if they don't, it exits and errs out. Signed-off-by: Brian Woods Reviewed-by: Stefano Stabellini --- scripts/uboot-script-gen | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) (limited to 'scripts/uboot-script-gen') diff --git a/scripts/uboot-script-gen b/scripts/uboot-script-gen index f17d8ac..0382478 100644 --- a/scripts/uboot-script-gen +++ b/scripts/uboot-script-gen @@ -13,6 +13,13 @@ function remove_tmp_files() done } +function cleanup_and_return_err() +{ + rm -f $UBOOT_SOURCE $UBOOT_SCRIPT + remove_tmp_files + exit 1 +} + function add_device_tree_kernel() { local path=$1 @@ -118,6 +125,12 @@ function check_file_type() local filename=$1 local type="$2" + if [ ! -f $filename ] + then + echo "File $filename doesn't exist, exiting"; + cleanup_and_return_err + fi + # if file doesn't know what it is, it outputs data, so include that # since some executables aren't recongnized if [ "$type" = "executable" ] @@ -128,7 +141,8 @@ function check_file_type() file $filename | grep "$type" &> /dev/null if test $? != 0 then - echo Wrong file type "$filename". It should be "$type". + echo Wrong file type "$filename". It should be "$type", exiting. + clean_up_and_err_out fi } @@ -137,6 +151,12 @@ function check_compressed_file_type() local filename=$1 local type="$2" + if [ ! -f $filename ] + then + echo "File $filename doesn't exist, exiting"; + cleanup_and_return_err + fi + file $filename | grep "gzip compressed data" &> /dev/null if test $? == 0 then @@ -298,7 +318,7 @@ memaddr=$(( $MEMORY_END - $memaddr - $offset )) if test $memaddr -lt 0 then echo Error, not enough memory to load all binaries - exit 1 + cleanup_and_return_err fi echo "Generated uboot script $UBOOT_SCRIPT, to be loaded at address $uboot_addr:" -- cgit v1.2.3