From ce8ec733c41c0bf42f79fb3e9022823c018592ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Igor=20Pe=C4=8Dovnik?= Date: Mon, 7 Dec 2015 21:28:23 +0100 Subject: [PATCH] zador's work + my mods --- patching.sh | 156 ++++++++++++++++++++++++++-------------------------- 1 file changed, 77 insertions(+), 79 deletions(-) diff --git a/patching.sh b/patching.sh index 62ae6bf093..6313e01b07 100644 --- a/patching.sh +++ b/patching.sh @@ -13,48 +13,82 @@ # # - +# advanced_patch +# +# parameters: +# : u-boot, kernel +# : u-boot: u-boot, u-boot-neo; kernel: sun4i-default, sunxi-next, ... +# : cubieboard, cubieboard2, cubietruck, ... +# : additional description text +# +# priority: +# $SRC/userpatches/// +# $SRC/userpatches// +# $SRC/lib/patch/// +# $SRC/lib/patch// +# advanced_patch () { -#--------------------------------------------------------------------------------------------------------------------------------- -# Patching from certain subdirectory -#--------------------------------------------------------------------------------------------------------------------------------- - # count files - shopt -s nullglob dotglob # To include hidden files - local files=($1/*.patch) - if [ ${#files[@]} -gt 0 ]; then - display_alert "Patching $2" "$3" "info"; - fi - - # go through all patch files - for patch in $1*.patch; do - - # check if directory exits - if [[ ! -d $1 ]]; then - display_alert "... directory not exists" "$1" "wrn"; - break; - fi - - # check if files exits - test -f "$patch" || continue - - # detect and remove files which patch will create - LANGUAGE=english patch --batch --dry-run -p1 -N < $patch | grep create \ - | awk '{print $NF}' | sed -n 's/,//p' | xargs -I % sh -c 'rm %' - - # main patch command - echo "$patch" >> $DEST/debug/install.log - patch --batch --silent -p1 -N < $patch >> $DEST/debug/install.log 2>&1 - - if [ $? -ne 0 ]; then - # display warning if patching fails - display_alert "... "${patch#*$1} "failed" "wrn"; - else - # display patching information - display_alert "... "${patch#*$1} "succeeded" "info" - fi + local dest=$1 + local family=$2 + local device=$3 + local description=$4 + + local names=() + local dirs=("$SRC/userpatches/$dest/$family/$device" "$SRC/userpatches/$dest/$family" "$SRC/lib/patch/$dest/$family/$device" "$SRC/lib/patch/$dest/$family") + + # required for "for" command + shopt -s nullglob dotglob + + # get patch file names + for dir in "${dirs[@]}"; do + for patch in $dir/*.patch; do + names+=($(basename $patch)) + done done + # remove duplicates + names=$(echo "${names[@]}" | tr ' ' '\n' | sort -u | tr '\n' ' ') + + # apply patches + for name in "${names[@]}"; do + for dir in "${dirs[@]}"; do + if [ -f "$dir/$name" ] || [ -L "$dir/$name" ]; then + if [ -s "$dir/$name" ]; then + process_patch_file "$dir/$name" "$description" + else + display_alert "... ${description} ${name}" "skipped" "info" + fi + break # next name + fi + done + done +} + +# process_patch_file +# +# parameters: +# : path to patch file +# : additional description text +# +process_patch_file() { + + local patch=$1 + local description=$2 + + # detect and remove files which patch will create + LANGUAGE=english patch --batch --dry-run -p1 -N < $patch | grep create \ + | awk '{print $NF}' | sed -n 's/,//p' | xargs -I % sh -c 'rm %' + + # main patch command + echo "$patch" >> $DEST/debug/install.log + patch --batch --silent -p1 -N < $patch >> $DEST/debug/install.log 2>&1 + + if [ $? -ne 0 ]; then + display_alert "... $(basename $patch) $description" "failed" "wrn"; + else + display_alert "... $(basename $patch) $description" "succeeded" "info" + fi } @@ -89,11 +123,10 @@ patching_sources(){ LINUXFAMILY="banana"; fi - # system patches - advanced_patch "$SRC/lib/patch/kernel/$LINUXFAMILY-$BRANCH/" "kernel" "$LINUXFAMILY-$BRANCH $VER" - - # user patches - advanced_patch "$SRC/userpatches/kernel/" "kernel with user patches" "$LINUXFAMILY-$BRANCH $VER" + # this exception is needed since AW boards share single mainline kernel + [[ $LINUXFAMILY == sun*i && $BRANCH != "default" ]] && LINUXFAMILY="sunxi" + + advanced_patch "kernel" "$LINUXFAMILY-$BRANCH" "$BOARD" "$LINUXFAMILY-$BRANCH $VER" # it can be changed in this process grab_kernel_version @@ -112,41 +145,6 @@ patching_sources(){ git checkout $FORCE -q $UBOOTTAG; fi - # system patches - advanced_patch "$SRC/lib/patch/u-boot/$BOOTSOURCE/" "u-boot" "$UBOOTTAG" - - # user patches - advanced_patch "$SRC/userpatches/u-boot/" "u-boot with user patches" "$UBOOTTAG" - - -#--------------------------------------------------------------------------------------------------------------------------------- -# Patching others: FBTFT drivers, ... -#--------------------------------------------------------------------------------------------------------------------------------- - - cd $SOURCES/$MISC4_DIR - display_alert "Patching" "other sources $VER" "info" - - # add small TFT display support - if [[ "$FBTFT" = "yes" && $BRANCH != "next" ]]; then - IFS='.' read -a array <<< "$VER" - if (( "${array[0]}" == "3" )) && (( "${array[1]}" < "14" )); then - git checkout $FORCE -q 06f0bba152c036455ae76d26e612ff0e70a83a82 - else - git checkout $FORCE -q master - fi - - # DMA disable on FBTFT drivers - patch --batch -p1 -N -r - < $SRC/lib/patch/misc/bananafbtft.patch >> \ - $DEST/debug/install.log 2>&1 || check_error "fbtft" - - # mount bind fbtft sources to kernel sources - mkdir -p $SOURCES/$LINUXSOURCE/drivers/video/fbtft - mount --bind $SOURCES/$MISC4_DIR $SOURCES/$LINUXSOURCE/drivers/video/fbtft - - cd $SOURCES/$LINUXSOURCE - # patch / add fbtft drivers to kernel - patch --batch -p1 -N -r - < $SRC/lib/patch/kernel/small_lcd_drivers.patch >> \ - $DEST/debug/install.log 2>&1 || check_error "fbtft" - fi + advanced_patch "u-boot" "$BOOTSOURCE" "$BOARD" "$UBOOTTAG" } \ No newline at end of file