diff --git a/lib/functions/compilation/uboot-git.sh b/lib/functions/compilation/uboot-git.sh new file mode 100644 index 000000000..ea6f1fe71 --- /dev/null +++ b/lib/functions/compilation/uboot-git.sh @@ -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 + fi + return 0 +} diff --git a/lib/functions/compilation/uboot.sh b/lib/functions/compilation/uboot.sh index 60cc5265b..84018f68b 100644 --- a/lib/functions/compilation/uboot.sh +++ b/lib/functions/compilation/uboot.sh @@ -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 - 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 diff --git a/lib/functions/host/mountpoints.sh b/lib/functions/host/mountpoints.sh index b374dbca6..d4002a954 100644 --- a/lib/functions/host/mountpoints.sh +++ b/lib/functions/host/mountpoints.sh @@ -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" ) } diff --git a/lib/functions/main/config-prepare.sh b/lib/functions/main/config-prepare.sh index 10f481bf6..075cb5285 100644 --- a/lib/functions/main/config-prepare.sh +++ b/lib/functions/main/config-prepare.sh @@ -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}" diff --git a/lib/functions/main/default-build.sh b/lib/functions/main/default-build.sh index 5138c3599..1df843a5c 100644 --- a/lib/functions/main/default-build.sh +++ b/lib/functions/main/default-build.sh @@ -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 diff --git a/lib/library-functions.sh b/lib/library-functions.sh index 82ac927ba..0d67bb58e 100644 --- a/lib/library-functions.sh +++ b/lib/library-functions.sh @@ -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