Skip to content

Commit

Permalink
scripts: librefactor: implement download functions
Browse files Browse the repository at this point in the history
test version


Signed-off-by: YuLong Yao <[email protected]>
  • Loading branch information
feilongfl committed Aug 7, 2022
1 parent 425716b commit eec38d3
Show file tree
Hide file tree
Showing 11 changed files with 95 additions and 44 deletions.
2 changes: 2 additions & 0 deletions scripts/lib_refactor/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
tmp
dest
24 changes: 24 additions & 0 deletions scripts/lib_refactor/build.sh
Original file line number Diff line number Diff line change
@@ -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}
44 changes: 0 additions & 44 deletions scripts/lib_refactor/make_new_hal.sh

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 6 additions & 0 deletions scripts/lib_refactor/resources/gd32e10x.conf
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions scripts/lib_refactor/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash

find ./resources -name "*.conf" | xargs -n1 ./build.sh
60 changes: 60 additions & 0 deletions scripts/lib_refactor/utils.sh
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit eec38d3

Please sign in to comment.