armbian-next: u-boot: use git worktree for u-boot; full mainline clone for bare

- share a single `.git` for all u-boots
- all fetches are done against it, maximizing cache hit ratio drastically
- also reduces the size of each working copy by more than 70%
- split uboot's git stuff into uboot-git.sh
- split `uboot_prepare_git()` from `compile_uboot()`
This commit is contained in:
Ricardo Pardini 2022-11-30 16:34:48 +01:00
parent 84c0bf0f7d
commit 074857ede3
No known key found for this signature in database
GPG Key ID: 3D38CA12A66C5D02
6 changed files with 55 additions and 5 deletions

View File

@ -0,0 +1,40 @@
function uboot_prepare_bare_repo() {
uboot_git_bare_tree="${SRC}/cache/git-bare/u-boot" # sets the outer scope variable
declare uboot_git_bare_tree_done_marker="${uboot_git_bare_tree}/.git/armbian-bare-tree-done"
if [[ ! -d "${uboot_git_bare_tree}" || ! -f "${uboot_git_bare_tree_done_marker}" ]]; then
if [[ -d "${uboot_git_bare_tree}" ]]; then
display_alert "Removing old u-boot bare tree" "${uboot_git_bare_tree}" "info"
rm -rf "${uboot_git_bare_tree}"
fi
# get the mainline u-boot repo completely; use clone, not fetch.
display_alert "Cloning u-boot from mainline into bare tree" "this might take a somewhat-long time" "info"
declare -a verbose_params=() && if_user_on_terminal_and_not_logging_add verbose_params "--verbose" "--progress"
run_host_command_logged git clone "${verbose_params[@]}" --tags --no-checkout \
"${MAINLINE_UBOOT_SOURCE}" "${uboot_git_bare_tree}"
# write the marker file
touch "${uboot_git_bare_tree_done_marker}"
fi
return 0
}
function uboot_prepare_git() {
display_alert "Preparing git for u-boot" "BOOTSOURCE: ${BOOTSOURCE}" "debug"
if [[ -n $BOOTSOURCE ]] && [[ "${BOOTSOURCE}" != "none" ]]; then
# Prepare the git bare repo for u-boot.
declare uboot_git_bare_tree
uboot_prepare_bare_repo # this sets uboot_git_bare_tree
display_alert "Downloading sources" "u-boot; BOOTSOURCEDIR=${BOOTSOURCEDIR}" "git"
GIT_FIXED_WORKDIR="${BOOTSOURCEDIR}" \
GIT_BARE_REPO_FOR_WORKTREE="${uboot_git_bare_tree}" \
GIT_BARE_REPO_INITIAL_BRANCH="master" \
GIT_SKIP_SUBMODULES="${UBOOT_GIT_SKIP_SUBMODULES}" \
fetch_from_repo "$BOOTSOURCE" "$BOOTDIR" "$BOOTBRANCH" "yes" # fetch_from_repo <url> <dir> <ref> <subdir_flag>
fi
return 0
}

View File

@ -240,14 +240,11 @@ function deploy_built_uboot_bins_for_one_target_to_packaging_area() {
function compile_uboot() {
display_alert "Compiling u-boot" "BOOTSOURCE: ${BOOTSOURCE}" "debug"
if [[ -n $BOOTSOURCE ]] && [[ "${BOOTSOURCE}" != "none" ]]; then
display_alert "Downloading sources" "u-boot" "git"
GIT_SKIP_SUBMODULES="${UBOOT_GIT_SKIP_SUBMODULES}" fetch_from_repo "$BOOTSOURCE" "$BOOTDIR" "$BOOTBRANCH" "yes" # fetch_from_repo <url> <dir> <ref> <subdir_flag>
display_alert "Extensions: fetch custom uboot" "fetch_custom_uboot" "debug"
call_extension_method "fetch_custom_uboot" <<- 'FETCH_CUSTOM_UBOOT'
*allow extensions to fetch extra uboot sources*
For downstream uboot et al.
This is done after `GIT_SKIP_SUBMODULES="${UBOOT_GIT_SKIP_SUBMODULES}" fetch_from_repo "$BOOTSOURCE" "$BOOTDIR" "$BOOTBRANCH" "yes"`
This is done after `fetch_from_repo`, but before actually compiling u-boot.
FETCH_CUSTOM_UBOOT
fi

View File

@ -14,6 +14,7 @@ function prepare_armbian_mountpoints_description_dict() {
"cache/initrd"
"cache/sources"
"cache/sources/linux-kernel-worktree"
"cache/sources/u-boot-worktree"
"cache/ccache"
)
@ -32,6 +33,7 @@ function prepare_armbian_mountpoints_description_dict() {
["cache/initrd"]="docker_kind_linux=bind docker_kind_darwin=namedvolume" # initrd.img cache, can be bind-mounted or a volume. On Darwin it's too slow to bind-mount, so it's a volume by default. On Linux, it's a bind-mount by default.
["cache/sources"]="docker_kind_linux=bind docker_kind_darwin=namedvolume" # operating directory. many things are cloned in here, and some are even built inside. needs to be local to the container, so it's a volume by default. On Linux, it's a bind-mount by default.
["cache/sources/linux-kernel-worktree"]="docker_kind_linux=bind docker_kind_darwin=namedvolume" # working tree for kernel builds. huge. contains both sources and the built object files. needs to be local to the container, so it's a volume by default. On Linux, it's a bind-mount by default.
["cache/sources/u-boot-worktree"]="docker_kind_linux=bind docker_kind_darwin=namedvolume" # working tree for u-boot. large. contains both sources and the built object files. needs to be local to the container, so it's a volume by default. On Linux, it's a bind-mount by default.
["cache/ccache"]="docker_kind_linux=bind docker_kind_darwin=namedvolume" # ccache object store. limited to 5gb by default. needs to be local to the container, so it's a volume by default. On Linux, it's a bind-mount by default.
)
@ -41,6 +43,7 @@ function prepare_armbian_mountpoints_description_dict() {
"cache/gitballs"
"cache/sources/kernel"
"cache/sources/linux-kernel"
"cache/sources/u-boot"
)
}

View File

@ -114,7 +114,7 @@ function prepare_and_config_main_build_single() {
IMAGE_TYPE=user-built
fi
export BOOTSOURCEDIR="${BOOTDIR}/$(branch2dir "${BOOTBRANCH}")"
export BOOTSOURCEDIR="u-boot-worktree/${BOOTDIR}/$(branch2dir "${BOOTBRANCH}")"
[[ -n $ATFSOURCE ]] && export ATFSOURCEDIR="${ATFDIR}/$(branch2dir "${ATFBRANCH}")"
export BSP_CLI_PACKAGE_NAME="armbian-bsp-cli-${BOARD}${EXTRA_BSP_NAME}"

View File

@ -92,6 +92,7 @@ function main_default_build_single() {
fi
# @TODO: refactor this construct. we use it too many times.
if [[ "${REPOSITORY_INSTALL}" != *u-boot* ]]; then
LOG_SECTION="uboot_prepare_git" do_with_logging_unless_user_terminal uboot_prepare_git
LOG_SECTION="compile_uboot" do_with_logging compile_uboot
fi
fi

View File

@ -235,6 +235,15 @@ set -o errexit ## set -e : exit the script if any statement returns a non-true
# shellcheck source=lib/functions/compilation/patch/patching.sh
source "${SRC}"/lib/functions/compilation/patch/patching.sh
# no errors tolerated. invoked before each sourced file to make sure.
#set -o pipefail # trace ERR through pipes - will be enabled "soon"
#set -o nounset ## set -u : exit the script if you try to use an uninitialised variable - one day will be enabled
set -o errtrace # trace ERR through - enabled
set -o errexit ## set -e : exit the script if any statement returns a non-true return value - enabled
### lib/functions/compilation/uboot-git.sh
# shellcheck source=lib/functions/compilation/uboot-git.sh
source "${SRC}"/lib/functions/compilation/uboot-git.sh
# no errors tolerated. invoked before each sourced file to make sure.
#set -o pipefail # trace ERR through pipes - will be enabled "soon"
#set -o nounset ## set -u : exit the script if you try to use an uninitialised variable - one day will be enabled