From eec38d3083d66d6267f1fd052b6f084710b432f3 Mon Sep 17 00:00:00 2001 From: YuLong Yao Date: Mon, 8 Aug 2022 05:40:17 +0800 Subject: [PATCH] scripts: librefactor: implement download functions test version Signed-off-by: YuLong Yao --- scripts/lib_refactor/.gitignore | 2 + scripts/lib_refactor/build.sh | 24 ++++++++ scripts/lib_refactor/make_new_hal.sh | 44 -------------- scripts/lib_refactor/{ => patches}/can.cocci | 0 scripts/lib_refactor/{ => patches}/i2c.cocci | 0 scripts/lib_refactor/{ => patches}/nvic.cocci | 0 .../{ => patches}/redfine_marco.cocci | 0 .../lib_refactor/{ => patches}/timer.cocci | 0 scripts/lib_refactor/resources/gd32e10x.conf | 6 ++ scripts/lib_refactor/run.sh | 3 + scripts/lib_refactor/utils.sh | 60 +++++++++++++++++++ 11 files changed, 95 insertions(+), 44 deletions(-) create mode 100644 scripts/lib_refactor/.gitignore create mode 100755 scripts/lib_refactor/build.sh delete mode 100755 scripts/lib_refactor/make_new_hal.sh rename scripts/lib_refactor/{ => patches}/can.cocci (100%) rename scripts/lib_refactor/{ => patches}/i2c.cocci (100%) rename scripts/lib_refactor/{ => patches}/nvic.cocci (100%) rename scripts/lib_refactor/{ => patches}/redfine_marco.cocci (100%) rename scripts/lib_refactor/{ => patches}/timer.cocci (100%) create mode 100644 scripts/lib_refactor/resources/gd32e10x.conf create mode 100755 scripts/lib_refactor/run.sh create mode 100644 scripts/lib_refactor/utils.sh diff --git a/scripts/lib_refactor/.gitignore b/scripts/lib_refactor/.gitignore new file mode 100644 index 0000000..dad0edb --- /dev/null +++ b/scripts/lib_refactor/.gitignore @@ -0,0 +1,2 @@ +tmp +dest diff --git a/scripts/lib_refactor/build.sh b/scripts/lib_refactor/build.sh new file mode 100755 index 0000000..990d2b1 --- /dev/null +++ b/scripts/lib_refactor/build.sh @@ -0,0 +1,24 @@ +#!/usr/bin/env bash + +# prepare env var +source utils.sh +source $1 + +TMPDIR=tmp +DESTDIR=dest/${NAME} + +echo Processing ${NAME} + +# make workspace folder +mkdir -p ${TMPDIR} +mkdir -p ${DESTDIR} + +# download files +getfile ${TMPDIR}/${FILENAME} ${URL} ${HASH} +# todo: abort if hash not match + +uncompress ${TMPDIR}/${FILENAME} ${DESTDIR} + +drop_unnessary_files ${DESTDIR} +change_file_format ${DESTDIR} +patch_cocci ${DESTDIR} diff --git a/scripts/lib_refactor/make_new_hal.sh b/scripts/lib_refactor/make_new_hal.sh deleted file mode 100755 index 4ca6830..0000000 --- a/scripts/lib_refactor/make_new_hal.sh +++ /dev/null @@ -1,44 +0,0 @@ -#!/usr/bin/env bash - -if [ $# -ne 1 ] - then - echo "number of arguments must be 1" - exit -fi - -script_dir=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) -echo $script_dir -# set top (realpath $script_dir/../..) -top=$(realpath $script_dir/../..) -echo $top -target=$(realpath $top/$1) -echo work at $top , target: $target - -# check lib folder file is correct -if [ ! -d $target/Firmware/CMSIS ]; then - echo "file in folder is not correct!" - exit -fi - -# mkdirs -libbak=$target.bak -mv $target $libbak -mkdir -p $target - -# copy files and drop unnessary files -cp -rv $libbak/Firmware/CMSIS $target/cmsis -rm $target/cmsis/*.h -rm -r $target/cmsis/GD/*/Source/ARM -rm -r $target/cmsis/GD/*/Source/IAR -cp -rv $libbak/Firmware/*_standard_peripheral $target/standard_peripheral -cp $libbak/Template/*_libopt.h $target/standard_peripheral/Include/ - -# change file to unix format -find $target type f -print0 | xargs -0 dos2unix -k - -# patch the files -pushd $script_dir -for cocci in *.cocci; do - find $target -name "*.h" -or -name "*.c" | xargs -P0 -n1 $script_dir/eval_patch.sh $cocci -done -popd diff --git a/scripts/lib_refactor/can.cocci b/scripts/lib_refactor/patches/can.cocci similarity index 100% rename from scripts/lib_refactor/can.cocci rename to scripts/lib_refactor/patches/can.cocci diff --git a/scripts/lib_refactor/i2c.cocci b/scripts/lib_refactor/patches/i2c.cocci similarity index 100% rename from scripts/lib_refactor/i2c.cocci rename to scripts/lib_refactor/patches/i2c.cocci diff --git a/scripts/lib_refactor/nvic.cocci b/scripts/lib_refactor/patches/nvic.cocci similarity index 100% rename from scripts/lib_refactor/nvic.cocci rename to scripts/lib_refactor/patches/nvic.cocci diff --git a/scripts/lib_refactor/redfine_marco.cocci b/scripts/lib_refactor/patches/redfine_marco.cocci similarity index 100% rename from scripts/lib_refactor/redfine_marco.cocci rename to scripts/lib_refactor/patches/redfine_marco.cocci diff --git a/scripts/lib_refactor/timer.cocci b/scripts/lib_refactor/patches/timer.cocci similarity index 100% rename from scripts/lib_refactor/timer.cocci rename to scripts/lib_refactor/patches/timer.cocci diff --git a/scripts/lib_refactor/resources/gd32e10x.conf b/scripts/lib_refactor/resources/gd32e10x.conf new file mode 100644 index 0000000..5dd0305 --- /dev/null +++ b/scripts/lib_refactor/resources/gd32e10x.conf @@ -0,0 +1,6 @@ +NAME=GD32E10x +VER=1.3.0 + +URL=https://gd32mcu.com/download/down/document_id/230/path_type/1 +FILENAME=GD32E10x.rar +HASH=9d080dee5960c8ab56aabb40341fbfaa diff --git a/scripts/lib_refactor/run.sh b/scripts/lib_refactor/run.sh new file mode 100755 index 0000000..11d29f3 --- /dev/null +++ b/scripts/lib_refactor/run.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash + +find ./resources -name "*.conf" | xargs -n1 ./build.sh diff --git a/scripts/lib_refactor/utils.sh b/scripts/lib_refactor/utils.sh new file mode 100644 index 0000000..b9c3917 --- /dev/null +++ b/scripts/lib_refactor/utils.sh @@ -0,0 +1,60 @@ +#!/usr/bin/env bash + +function download() { + wget -O $1 $2 +} + +function getfile() { + # todo: check file exist and hash match + + # download if not exist or hash not match + download $1 $2 +} + +function uncompress_rar() { + unrar x $1 $2 + find $2/*/ -maxdepth 1 -exec mv {} $2 \; + find $2/ -maxdepth 1 -name "*Firmware_Library*" -exec rm -rv {} \; +} + +function uncompress() { + rm -rvf $2 + mkdir -p $2 + + ftpye=$(file "$1") + case "$ftpye" in + "$1: RAR archive"*) + uncompress_rar $1 $2 + ;; + *) + echo unsupport file format: $ftpye + ;; + esac +} + +function drop_unnessary_files() { + libbak=$1.bak + mv $1 $libbak + mkdir -p $1 + + cp -rv $1/Firmware/CMSIS $1/cmsis + rm $1/cmsis/*.h + rm -r $1/cmsis/GD/*/Source/ARM + rm -r $1/cmsis/GD/*/Source/IAR + cp -rv $libbak/Firmware/*_standard_peripheral $1/standard_peripheral + cp $1/Template/*_libopt.h $1/standard_peripheral/Include/ + rm -rv $libbak +} + +function change_file_format() { + find $1 type f -print0 | xargs -0 dos2unix -k +} + +function patch_cocci() { + script_dir=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) + # pushd $script_dir + for cocci in $script_dir/patches/*.cocci; do + find $1 -name "*.h" -or -name "*.c" | xargs -P0 -n1 echo $script_dir/eval_patch.sh $cocci + done + # popd +}