From: Raymond Mao Date: Thu, 25 Jul 2024 13:57:51 +0000 (-0700) Subject: tools: Add script to update git subtree projects X-Git-Url: http://git.dujemihanovic.xyz/html/static/%7B%7B%20.Permalink%20%7D%7D?a=commitdiff_plain;h=c502d7ada25ab21cc04e1df62fd22af5c8360275;p=u-boot.git tools: Add script to update git subtree projects Recently we are introducing multiple git subtree projects and it is the right time to have a universal script to update various subtrees and replace the dts/update-dts-subtree.sh. update-subtree.sh is a wrapper of git subtree commands. Usage: From U-Boot top directory, run $ ./tools/update-subtree.sh pull for pulling a tag from the upstream. Or run $ ./tools/update-subtree.sh pick for cherry-pick a commit from the upstream. Currently supports dts, mbedtls and lwip. Signed-off-by: Raymond Mao --- diff --git a/doc/develop/devicetree/control.rst b/doc/develop/devicetree/control.rst index ca4fb0b5b1..211f7e4909 100644 --- a/doc/develop/devicetree/control.rst +++ b/doc/develop/devicetree/control.rst @@ -96,12 +96,12 @@ sync the `dts/upstream/` subtree from the devicetree-rebasing repo whenever the next branch opens (refer: :doc:`../release_cycle`) with the latest mainline Linux kernel release. To sync the `dts/upstream/` subtree, run:: - ./dts/update-dts-subtree.sh pull + ./tools/update-subtree.sh pull dts If required it is also possible to cherry-pick fixes from the devicetree-rebasing repository prior to next sync, usage:: - ./dts/update-dts-subtree.sh pick + ./tools/update-subtree.sh pick dts Configuration @@ -116,8 +116,8 @@ However, if `dts/upstream/` hasn't yet received devicetree source file for your newly added board support then one option is that you can add the corresponding devicetree source file as `arch//dts/.dts`. To select that add `# CONFIG_OF_UPSTREAM is not set` and set `DEFAULT_DEVICE_TREE=` when -prompted by Kconfig. Another option is that you can use use the "pick" option of -`dts/update-dts-subtree.sh` mentioned above to bring in the commits that you +prompted by Kconfig. Another option is that you can use the "pick" option of +`tools/update-subtree.sh` mentioned above to bring in the commits that you need. This should include your CPU or SoC's devicetree file. On top of that any U-Boot diff --git a/dts/update-dts-subtree.sh b/dts/update-dts-subtree.sh deleted file mode 100755 index a57b78a41d..0000000000 --- a/dts/update-dts-subtree.sh +++ /dev/null @@ -1,48 +0,0 @@ -#!/bin/sh -# SPDX-License-Identifier: GPL-2.0+ -# -# Copyright 2024 Linaro Ltd. -# -# Usage: from the top level U-Boot source tree, run: -# $ ./dts/update-dts-subtree.sh pull -# $ ./dts/update-dts-subtree.sh pick -# -# The script will pull changes from devicetree-rebasing repo into U-Boot -# as a subtree located as /dts/upstream sub-directory. It will -# automatically create a squash/merge commit listing the commits imported. - -set -e - -merge_commit_msg=$(cat << EOF -Subtree merge tag '$2' of devicetree-rebasing repo [1] into dts/upstream - -[1] https://git.kernel.org/pub/scm/linux/kernel/git/devicetree/devicetree-rebasing.git/ -EOF -) - -remote_add_and_fetch() { - if ! git remote get-url devicetree-rebasing 2>/dev/null - then - echo "Warning: Script automatically adds new git remote via:" - echo " git remote add devicetree-rebasing \\" - echo " https://git.kernel.org/pub/scm/linux/kernel/git/devicetree/devicetree-rebasing.git" - git remote add devicetree-rebasing \ - https://git.kernel.org/pub/scm/linux/kernel/git/devicetree/devicetree-rebasing.git - fi - git fetch devicetree-rebasing master -} - -if [ "$1" = "pull" ] -then - remote_add_and_fetch - git subtree pull --prefix dts/upstream devicetree-rebasing \ - "$2" --squash -m "${merge_commit_msg}" -elif [ "$1" = "pick" ] -then - remote_add_and_fetch - git cherry-pick -x --strategy=subtree -Xsubtree=dts/upstream/ "$2" -else - echo "usage: $0 " - echo " pull or pick" - echo " release tag [pull] or commit id [pick]" -fi diff --git a/tools/update-subtree.sh b/tools/update-subtree.sh new file mode 100755 index 0000000000..536b331857 --- /dev/null +++ b/tools/update-subtree.sh @@ -0,0 +1,85 @@ +#!/bin/sh +# SPDX-License-Identifier: GPL-2.0+ +# +# Copyright (c) 2024 Linaro Limited +# +# Usage: from the top level U-Boot source tree, run: +# $ ./tools/update-subtree.sh pull +# Or: +# $ ./tools/update-subtree.sh pick +# +# The script will pull changes from subtree repo into U-Boot. +# It will automatically create a squash/merge commit listing the commits +# imported. + +set -e + +print_usage() { + echo "usage: $0 " + echo " pull or pick" + echo " mbedtls or dts or lwip" + echo " release tag [pull] or commit id [pick]" +} + +if [ $# -ne 3 ]; then + print_usage + exit 1 +fi + +op=$1 +subtree_name=$2 +ref=$3 + +set_params() { + case "$subtree_name" in + mbedtls) + path=lib/mbedtls/external/mbedtls + repo_url=https://github.com/Mbed-TLS/mbedtls.git + remote_name="mbedtls_upstream" + ;; + dts) + path=dts/upstream + repo_url=https://git.kernel.org/pub/scm/linux/kernel/git/devicetree/devicetree-rebasing.git + remote_name="devicetree-rebasing" + ;; + lwip) + path=lib/lwip/lwip + repo_url=https://git.savannah.gnu.org/git/lwip.git + remote_name="lwip_upstream" + ;; + *) + echo "Invalid subtree name: $subtree_name" + print_usage + exit 1 + esac +} + +set_params + +merge_commit_msg=$(cat << EOF +Subtree merge tag '$ref' of $subtree_name repo [1] into $path + +[1] $repo_url +EOF +) + +remote_add_and_fetch() { + if [ -z "$(git remote get-url $remote_name 2>/dev/null)" ]; then + echo "Warning: Script automatically adds new git remote via:" + echo " git remote add $remote_name \\" + echo " $repo_url" + git remote add $remote_name $repo_url + fi + git fetch $remote_name master +} + +if [ "$op" = "pull" ]; then + remote_add_and_fetch + git subtree pull --prefix $path $remote_name "$ref" --squash -m "$merge_commit_msg" +elif [ "$op" = "pick" ]; then + remote_add_and_fetch + git cherry-pick -x --strategy=subtree -Xsubtree=$path/ "$ref" +else + print_usage + exit 1 +fi