.bash_aliases_linux
1 #!/bin/bash 2 # 3 # Copyright (c) 2023 Krzysztof Kozlowski 4 # Author: Krzysztof Kozlowski <k.kozlowski.k@gmail.com> 5 # <krzk@kernel.org> 6 # 7 # SPDX-License-Identifier: GPL-2.0 8 # 9 10 alias crosc="CROSS_COMPILE=\"ccache arm-linux-gnueabi-\" ARCH=arm KBUILD_OUTPUT=out/" 11 alias crosc64="CROSS_COMPILE=\"ccache aarch64-linux-gnu-\" ARCH=arm64 KBUILD_OUTPUT=out/" 12 alias crosc_riscv="CROSS_COMPILE=\"ccache riscv64-linux-gnu-\" ARCH=riscv KBUILD_OUTPUT=out/" 13 14 alias git_bisect_fixed="git bisect start --term-new fixed --term-old broken; echo \"Use terms fixed or broken\"" 15 16 # Faster tig 17 tigl() { 18 local head="${1:-HEAD}" 19 tig ${head}~1000..${head} 20 } 21 22 # Apply one patch 23 b4_am_patch() { 24 local msg_id="$1" 25 local am_options="$2" 26 27 test -n "$msg_id" || return 1 28 29 #b4 am --check-newer-revisions --apply-cover-trailers --outdir - --add-link --cherry-pick _ "${msg_id}" | git am $am_options 30 b4 shazam --apply-cover-trailers --add-link --cherry-pick _ $am_options "${msg_id}" 31 } 32 33 # Apply series 34 b4_am_series() { 35 local msg_id="$1" 36 local am_options="$2" 37 38 test -n "$msg_id" || return 1 39 40 #b4 am --check-newer-revisions --apply-cover-trailers --outdir - --add-link "${msg_id}" | git am $am_options 41 b4 shazam --apply-cover-trailers --add-link $am_options "${msg_id}" 42 } 43 44 # Download series 45 b4_get() { 46 local msg_id="$1" 47 local out_dir="${2:-$HOME/tmp/}" 48 49 test -n "$msg_id" || return 1 50 51 b4 mbox -f -o "$out_dir" "${msg_id}" 52 } 53 54 # Sync track/next and master branches with remotes 55 git_sync_mainline() { 56 local branch="$(git rev-parse --abbrev-ref HEAD)" 57 if [ "$branch" == "track/next" ]; then 58 echo "On next branch ($branch), use git reset --hard manually to update it" 59 else 60 local upstream="$(git rev-parse --abbrev-ref track/next@{upstream})" 61 if [ $? -ne 0 ]; then 62 echo "No upstream configured for track/next" 63 else 64 echo "Updating track/next to upstream: $upstream" 65 # For non-fast-forward: 66 git update-ref refs/heads/track/next refs/remotes/${upstream} 67 fi 68 fi 69 if [ "$branch" == "master" ]; then 70 echo "On master branch ($branch), use git pull manually to update it" 71 else 72 local upstream="$(git rev-parse --abbrev-ref master@{upstream})" 73 if [ $? -ne 0 ]; then 74 echo "No upstream configured for master" 75 else 76 echo "Updating master to upstream: $upstream" 77 # For fast-forward 78 git fetch ${upstream%%/*} ${upstream##*/}:master 79 fi 80 fi 81 } 82 83 # Get maintainers for git send-email 84 get_maint() { 85 local maintainers="$(scripts/get_maintainer.pl --s --no-multiline --interactive --separator=\'' --to '\' $*)" 86 echo "--to '$maintainers'" 87 } 88 89 # Improved git send-email to CC all maintainers/lists on all patches. 90 # git_send_email [--cc=ARG] files 91 git_send_email() { 92 local files 93 local cc="" 94 95 if [[ "$1" == --cc* ]] || [[ "$1" == --to* ]]; then 96 cc="$1" 97 shift 98 fi 99 100 files="$*" 101 test -n "$files" || return 1 102 103 # Do not use --to-cmd because it collects addresses per each email. 104 # Instead need to collect addressesonce and use them for entire set. 105 if [ "$cc" == "" ]; then 106 git send-email --to="$(scripts/get_maintainer.pl --no-multiline --separator=, --no-git --no-roles --no-rolestats --no-git-fallback $files)" \ 107 --cc linux-kernel@vger.kernel.org $files 108 else 109 git send-email "$cc" --to="$(scripts/get_maintainer.pl --no-multiline --separator=, --no-git --no-roles --no-rolestats --no-git-fallback $files)" \ 110 --cc linux-kernel@vger.kernel.org $files 111 fi 112 } 113 114 # cros_build cross_arch arch command 115 # e.g.: 116 # cross_build arm-linux-gnueabi arm 117 # cross_build aarch64-linux arm64 118 # Assuming cross compilers are /opt/CROSS_ARCH 119 cross_build() { 120 if [ -z "$1" ] || [ -z "$2" ]; then 121 echo "Usage: cross_build cross_arch arch ... " 122 echo " cross_build arm-linux-gnueabi arm" 123 return 1 124 fi 125 local cross="$1" 126 local arch="$2" 127 shift 2 128 ARCH="$arch" CROSS_COMPILE="ccache /opt/${cross}/bin/${cross}-" KBUILD_OUTPUT=out/ $* 129 } 130 131 # dt_check target schema 132 # e.g.: 133 # crosc dt_check dt_binding_check sound/samsung,aries-wm8994.yaml 134 # DT_CHECKER_FLAGS=-g crosc dt_check dt_binding_check sound/samsung,aries-wm8994.yam 135 # DT_CHECKER_FLAGS=-v crosc dt_check dt_binding_check sound/samsung,aries-wm8994.yam 136 dt_check() { 137 local target="$1" 138 local schema="$2" 139 shift 140 shift 141 142 if [ -z "$target" ] || [ -z "$schema" ]; then 143 echo "Usage: dt_check <target> <schema>" 144 return 1 145 fi 146 147 make -j$(nproc) $target DT_SCHEMA_FILES="${schema}" $* 148 } 149 150 crosc_dt_binding_check() { 151 crosc dt_check dt_binding_check $* 152 } 153 crosc_dtbs_all_check() { 154 crosc dt_check dtbs_check $* 155 } 156 crosc64_dt_binding_check() { 157 crosc64 dt_check dt_binding_check $* 158 } 159 crosc64_dtbs_all_check() { 160 crosc64 dt_check dtbs_check $* 161 } 162 163 # dtb_check <target> [schema] 164 dtb_check() { 165 local target="$1" 166 local schema="$2" 167 168 if [ -z "$target" ]; then 169 echo "Usage: dtbs_check <target> [schema]" 170 echo " target - DTB target (e.g. renesas/r9a07g043u11-smarc.dtb)" 171 return 1 172 fi 173 174 if [ -n "$schema" ]; then 175 make -j$(nproc) DT_SCHEMA_FILES="${schema}" CHECK_DTBS=y W=1 "$target" 176 else 177 make -j$(nproc) CHECK_DTBS=y W=1 "$target" 178 fi 179 }