[PATCH v4 02/29] mbedtls: Add script to update MbedTLS subtree

Raymond Mao raymond.mao at linaro.org
Tue Jul 2 20:22:38 CEST 2024


lib/mbedtls/update-mbedtls-subtree.sh is a wrapper of git subtree
commands.
Usage from U-Boot top directory, run:

$ ./lib/mbedtls/update-mbedtls-subtree.sh pull <release-tag>
$ ./lib/mbedtls/update-mbedtls-subtree.sh pick <commit-id>

Signed-off-by: Raymond Mao <raymond.mao at linaro.org>
---
Changes in v2
- Initial patch.
Changes in v3
- None.
Changes in v4
- Minor fix and move the script into tools dir.

 tools/update-mbedtls-subtree.sh | 47 +++++++++++++++++++++++++++++++++
 1 file changed, 47 insertions(+)
 create mode 100755 tools/update-mbedtls-subtree.sh

diff --git a/tools/update-mbedtls-subtree.sh b/tools/update-mbedtls-subtree.sh
new file mode 100755
index 00000000000..0a98a4d6e82
--- /dev/null
+++ b/tools/update-mbedtls-subtree.sh
@@ -0,0 +1,47 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0+
+#
+# Copyright 2024 Linaro Ltd.
+#
+# Usage: from the top level U-Boot source tree, run:
+# $ ./tools/update-mbedtls-subtree.sh pull <release-tag>
+# $ ./tools/update-mbedtls-subtree.sh pick <commit-id>
+#
+# The script will pull changes from MbedTLS repo into U-Boot
+# as a subtree located as <U-Boot>/lib/mbedtls/external/mbedtls 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 MbedTLS repo [1] into lib/mbedtls/external/mbedtls
+
+[1] https://github.com/Mbed-TLS/mbedtls.git
+EOF
+)
+
+remote_add_and_fetch() {
+    if [ -z "$(git remote get-url mbedtls_upstream 2>/dev/null)" ]; then
+        echo "Warning: Script automatically adds new git remote via:"
+        echo "    git remote add mbedtls_upstream \\"
+        echo "        https://github.com/Mbed-TLS/mbedtls.git"
+        git remote add mbedtls_upstream \
+            https://github.com/Mbed-TLS/mbedtls.git
+    fi
+    git fetch mbedtls_upstream master
+}
+
+if [ "$1" = 'pull' ]; then
+    remote_add_and_fetch
+    git subtree pull --prefix lib/mbedtls/external/mbedtls mbedtls_upstream \
+        "$2" --squash -m "${merge_commit_msg}"
+elif [ "$1" = 'pick' ]; then
+    remote_add_and_fetch
+    git cherry-pick -x --strategy=subtree \
+        -Xsubtree=lib/mbedtls/external/mbedtls/ "$2"
+else
+    echo "usage: $0 <op> <ref>"
+    echo "  <op>     pull or pick"
+    echo "  <ref>    release tag [pull] or commit id [pick]"
+fi
-- 
2.25.1



More information about the U-Boot mailing list