Skip to content

Commit 8eac1eb

Browse files
committed
framework: split armbian-bsp-cli into bsp-cli and bsp-generic. WIP.
1 parent 063c641 commit 8eac1eb

7 files changed

Lines changed: 293 additions & 21 deletions

File tree

Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
#!/usr/bin/env bash
2+
#
3+
# SPDX-License-Identifier: GPL-2.0
4+
#
5+
# Copyright (c) 2013-2023 Igor Pecovnik, igor@armbian.com
6+
#
7+
# This file is a part of the Armbian Build Framework
8+
# https://github.com/armbian/build/
9+
10+
function artifact_armbian-bsp-generic_config_dump() {
11+
artifact_input_variables[RELEASE]="${RELEASE}"
12+
artifact_input_variables[BRANCH]="${BRANCH}"
13+
}
14+
15+
function artifact_armbian-bsp-generic_prepare_version() {
16+
: "${BRANCH:?BRANCH is not set}"
17+
18+
artifact_version="undetermined" # outer scope
19+
artifact_version_reason="undetermined" # outer scope
20+
21+
declare short_hash_size=4
22+
23+
declare fake_unchanging_base_version="1"
24+
25+
# Generic package has no board/family hooks
26+
declare hash_hooks_short="0000"
27+
28+
# get the bootscript info...
29+
declare -A bootscript_info=()
30+
get_bootscript_info # fills in bootscript_info array
31+
32+
# Hash variables/bootscripts that affect the contents of bsp-generic package.
33+
# Those contain /armbian a lot, so don't normalize them.
34+
#FIXME: what's a bootscript for bsp-generic?
35+
declare -a vars_to_hash_no_normalize=(
36+
"bootscript_file_contents: ${bootscript_info[bootscript_file_contents]}"
37+
"bootenv_file_contents: ${bootscript_info[bootenv_file_contents]}"
38+
)
39+
declare hash_variables="undetermined" # will be set by calculate_hash_for_variables(), but without normalization
40+
do_normalize_src_path="no" calculate_hash_for_variables "${vars_to_hash_no_normalize[@]}" # don't normalize
41+
declare hash_vars_no_normalize="${hash_variables}"
42+
43+
declare -a vars_to_hash=(
44+
"KEEP_ORIGINAL_OS_RELEASE: ${KEEP_ORIGINAL_OS_RELEASE:-"no"}" # /etc/os-release
45+
"IMAGE_TYPE: ${IMAGE_TYPE}" # /etc/armbian-release
46+
"hash_vars_no_normalize: ${hash_vars_no_normalize}" # The non-normalized part, above
47+
)
48+
declare hash_variables="undetermined" # will be set by calculate_hash_for_variables(), which normalizes the input
49+
calculate_hash_for_variables "${vars_to_hash[@]}"
50+
declare vars_config_hash="${hash_variables}"
51+
declare var_config_hash_short="${vars_config_hash:0:${short_hash_size}}"
52+
53+
declare -a dirs_to_hash=(
54+
"${SRC}/packages/bsp/common" # common stuff
55+
)
56+
declare hash_files="undetermined"
57+
calculate_hash_for_all_files_in_dirs "${dirs_to_hash[@]}"
58+
packages_config_hash="${hash_files}"
59+
declare packages_config_hash_short="${packages_config_hash:0:${short_hash_size}}"
60+
61+
# get the hashes of the lib/ bash sources involved...
62+
declare hash_files="undetermined"
63+
#FIXME: do we need to fork bsp/armbian-bsp-cli-deb.sh ?
64+
calculate_hash_for_bash_deb_artifact "bsp/armbian-bsp-cli-deb.sh" "bsp/utils-bsp.sh"
65+
declare bash_hash="${hash_files}"
66+
declare bash_hash_short="${bash_hash:0:${short_hash_size}}"
67+
68+
# outer scope
69+
artifact_version="${fake_unchanging_base_version}-PC${packages_config_hash_short}-V${var_config_hash_short}-H${hash_hooks_short}-B${bash_hash_short}"
70+
71+
declare -a reasons=(
72+
"Armbian package armbian-bsp-generic"
73+
"BRANCH \"${BRANCH}\""
74+
"EXTRA_BSP_NAME \"${EXTRA_BSP_NAME}\""
75+
"Packages and config files hash \"${packages_config_hash}\""
76+
"Hooks hash \"${hash_hooks}\""
77+
"Variables/bootscripts hash \"${vars_config_hash}\""
78+
"framework bash hash \"${bash_hash}\""
79+
)
80+
81+
artifact_version_reason="${reasons[*]}" # outer scope
82+
83+
artifact_deb_repo="global" # "global" meaning: release-independent repo. could be '${RELEASE}' for a release-specific package.
84+
artifact_deb_arch="all" # arch-specific package, or 'all' for arch-independent package.
85+
#FIXME: BRANCH for sure, RELEASE maybe?
86+
artifact_name="armbian-bsp-generic-${BRANCH}"
87+
artifact_type="deb-tar"
88+
89+
artifact_map_packages=(["armbian-bsp-generic"]="${artifact_name}")
90+
91+
# Register the function used to re-version the _contents_ of the bsp-cli deb file (non-transitional)
92+
# FIXME: can we live without this?
93+
#artifact_debs_reversion_functions+=("reversion_armbian-bsp-generic_deb_contents")
94+
95+
# there is no transitional package, this is just boilerplate
96+
#if artifact_armbian-bsp-generic_needs_transitional_package; then
97+
# artifact_map_packages+=(["armbian-bsp-generic-transitional"]="armbian-bsp-generic-${BOARD}${EXTRA_BSP_NAME}")
98+
# # Register the function used to re-version the _contents_ of the bsp-cli deb file (transitional)
99+
# artifact_debs_reversion_functions+=("reversion_armbian-bsp-generic-transitional_deb_contents")
100+
#fi
101+
102+
return 0
103+
}
104+
105+
function artifact_armbian-bsp-generic_build_from_sources() {
106+
LOG_SECTION="compile_armbian-bsp-generic" do_with_logging compile_armbian-bsp-generic
107+
108+
# Generate transitional package when needed.
109+
if artifact_armbian-bsp-generic_needs_transitional_package; then
110+
: # we don't have this hook, it's just boilerplate
111+
#LOG_SECTION="compile_armbian-bsp-generic" do_with_logging compile_armbian-bsp-generic-transitional
112+
fi
113+
}
114+
115+
function artifact_armbian-bsp-generic_cli_adapter_pre_run() {
116+
declare -g ARMBIAN_COMMAND_REQUIRE_BASIC_DEPS="yes" # Require prepare_host_basic to run before the command.
117+
118+
# "gimme root on a Linux machine"
119+
cli_standard_relaunch_docker_or_sudo
120+
}
121+
122+
function artifact_armbian-bsp-generic_cli_adapter_config_prep() {
123+
# there is no need for aggregation here.
124+
use_board="no" allow_no_family="no" skip_kernel="no" prep_conf_main_minimal_ni < /dev/null # no stdin for this, so it bombs if tries to be interactive.
125+
}
126+
127+
function artifact_armbian-bsp-generic_get_default_oci_target() {
128+
artifact_oci_target_base="${GHCR_SOURCE}/armbian/os/"
129+
}
130+
131+
function artifact_armbian-bsp-generic_is_available_in_local_cache() {
132+
is_artifact_available_in_local_cache
133+
}
134+
135+
function artifact_armbian-bsp-generic_is_available_in_remote_cache() {
136+
is_artifact_available_in_remote_cache
137+
}
138+
139+
function artifact_armbian-bsp-generic_obtain_from_remote_cache() {
140+
obtain_artifact_from_remote_cache
141+
}
142+
143+
function artifact_armbian-bsp-generic_deploy_to_remote_cache() {
144+
upload_artifact_to_oci
145+
}
146+
147+
function artifact_armbian-bsp-generic_needs_transitional_package() {
148+
return 1 # we're too new to need a transitional package. Note that this follows the C/bash errno convention where 0 is true
149+
# see equivalent for artifact_armbian-bsp-cli
150+
}

lib/functions/artifacts/artifacts-obtain.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ function initialize_artifact() {
6161
[[ "${chosen_artifact}" == *","* ]] && exit_with_error "Artifact name cannot contain commas"
6262

6363
armbian_register_artifacts
64-
declare -g chosen_artifact_impl="${ARMBIAN_ARTIFACTS_TO_HANDLERS_DICT["${chosen_artifact}"]}"
64+
declare -g chosen_artifact_impl="${ARMBIAN_ARTIFACTS_TO_HANDLERS_DICT["${chosen_artifact}"]}" #"
6565
[[ "x${chosen_artifact_impl}x" == "xx" ]] && exit_with_error "Unknown artifact '${chosen_artifact}'"
6666
display_alert "artifact" "${chosen_artifact} :: ${chosen_artifact_impl}()" "info"
6767
create_artifact_functions

lib/functions/artifacts/artifacts-registry.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ function armbian_register_artifacts() {
2323
["armbian-plymouth-theme"]="armbian-plymouth-theme"
2424
["armbian-base-files"]="armbian-base-files"
2525
["armbian-bsp-cli"]="armbian-bsp-cli"
26+
["armbian-bsp-generic"]="armbian-bsp-generic"
2627
["armbian-bsp-desktop"]="armbian-bsp-desktop"
2728
["armbian-desktop"]="armbian-desktop"
2829

lib/functions/bsp/armbian-bsp-cli-deb.sh

Lines changed: 128 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,20 @@ function reversion_armbian-bsp-cli-transitional_deb_contents() {
5454

5555
}
5656

57+
function reversion_armbian-bsp-generic-transitional_deb_contents() {
58+
if [[ "${1}" != "armbian-bsp-generic-transitional" ]]; then
59+
return 0 # Not our deb, nothing to do.
60+
fi
61+
display_alert "Reversion" "reversion_armbian-bsp-generic-transitional_deb_contents: '$*'" "debug"
62+
63+
# Depends on the new package
64+
cat <<- EOF >> "${control_file_new}"
65+
Depends: ${artifact_name} (= ${REVISION})
66+
EOF
67+
68+
}
69+
70+
5771
function compile_armbian-bsp-cli() {
5872
: "${artifact_version:?artifact_version is not set}"
5973
: "${artifact_name:?artifact_name is not set}"
@@ -121,12 +135,6 @@ function compile_armbian-bsp-cli() {
121135
# in practice: packages/bsp-cli and variations of config/optional/...
122136
copy_all_packages_files_for "bsp-cli"
123137

124-
# copy common files from a premade directory structure
125-
# @TODO this includes systemd config, assumes things about serial console, etc, that need dynamism or just to not exist with modern systemd
126-
display_alert "Copying common bsp files" "packages/bsp/common" "info"
127-
run_host_command_logged rsync -av "${SRC}"/packages/bsp/common/* "${destination}"
128-
wait_for_disk_sync "after rsync'ing package/bsp/common for bsp-cli"
129-
130138
mkdir -p "${destination}"/usr/share/armbian/
131139

132140
# get bootscript information.
@@ -179,24 +187,24 @@ function compile_armbian-bsp-cli() {
179187
# TODO: Add proper handling for updated conffiles
180188
# We are runing this script each time apt runs. If this package is removed, file is removed and error is triggered.
181189
# Keeping armbian-apt-updates as a configuration, solve the problem
182-
cat <<- EOF > "${destination}"/DEBIAN/conffiles
183-
/usr/lib/armbian/armbian-apt-updates
184-
/etc/X11/xorg.conf.d/01-armbian-defaults.conf
185-
EOF
190+
#cat <<- EOF > "${destination}"/DEBIAN/conffiles
191+
# /usr/lib/armbian/armbian-apt-updates
192+
# /etc/X11/xorg.conf.d/01-armbian-defaults.conf
193+
#EOF
186194

187195
# trigger uInitrd creation after installation, to apply
188196
# /etc/initramfs/post-update.d/99-uboot
189-
cat <<- EOF > "${destination}"/DEBIAN/triggers
190-
activate update-initramfs
191-
EOF
197+
#cat <<- EOF > "${destination}"/DEBIAN/triggers
198+
# activate update-initramfs
199+
#EOF
192200

193201
# copy distribution support and upgrade status
194202
# this information is used in motd to show status and within armbian-config to perform upgrades
195-
declare -a releases=()
196-
mapfile -t releases < <(for relorder in "${SRC}"/config/distributions/*/order; do echo "${relorder} $(xargs echo < "${relorder}")"; done | sort -nk2 | sed "s/\/order.*//g")
197-
for i in "${releases[@]}"; do
198-
echo "$(echo "$i" | sed 's/.*\///')=$(cat "$i"/support)$(echo ";upgrade" | sed 's/.*\///')=$(cat "$i"/upgrade)" >> "${destination}"/etc/armbian-distribution-status
199-
done
203+
#declare -a releases=()
204+
#mapfile -t releases < <(for relorder in "${SRC}"/config/distributions/*/order; do echo "${relorder} $(xargs echo < "${relorder}")"; done | sort -nk2 | sed "s/\/order.*//g")
205+
#for i in "${releases[@]}"; do
206+
# echo "$(echo "$i" | sed 's/.*\///')=$(cat "$i"/support)$(echo ";upgrade" | sed 's/.*\///')=$(cat "$i"/upgrade)" >> "${destination}"/etc/armbian-distribution-status
207+
#done
200208

201209
# execute $LINUXFAMILY-specific tweaks
202210
if [[ $(type -t family_tweaks_bsp) == function ]]; then
@@ -205,6 +213,13 @@ function compile_armbian-bsp-cli() {
205213
display_alert "Done with family_tweaks_bsp" "${LINUXFAMILY} - ${BOARDFAMILY}" "debug"
206214
fi
207215

216+
#FIXME: this is just the dir structure from packages/bsp/common. Likely that many of these directories are unneeded.
217+
# we add them because of the below hook that may want to add contents.
218+
#FIXME: it may be better to make those hooks add the directories instead.
219+
mkdir -p "${destination}/lib/systemd/system" "${destination}/lib/udev"
220+
mkdir -p "${destination}"/etc/{NetworkManager/conf.d,X11/xorg.conf.d,apt/apt.conf.d,apt/preferences.d}
221+
mkdir -p "${destination}"/etc/{cron.d,cron.daily,default,initramfs/post-update.d}
222+
mkdir -p "${destination}"/etc/kernel/{postinst.d,postrm.d} "${destination}"/etc/{modprobe.d,profile.d,systemd/system,udev/rules.d,update-motd.d,skel}
208223
call_extension_method "post_family_tweaks_bsp" <<- 'POST_FAMILY_TWEAKS_BSP'
209224
*family_tweaks_bsp overrrides what is in the config, so give it a chance to override the family tweaks*
210225
This should be implemented by the config to tweak the BSP, after the board or family has had the chance to.
@@ -265,6 +280,100 @@ function compile_armbian-bsp-cli() {
265280
display_alert "Done building BSP CLI package" "${destination}" "debug"
266281
}
267282

283+
function compile_armbian-bsp-generic() {
284+
: "${artifact_version:?artifact_version is not set}"
285+
: "${artifact_name:?artifact_name is not set}"
286+
: "${BRANCH:?BRANCH is not set}"
287+
288+
display_alert "Creating bsp-generic on branch '${BRANCH}'" "${artifact_name} :: ${artifact_version}" "info"
289+
290+
# "destination" is used a lot in hooks already. keep this name, even if only for compatibility.
291+
declare cleanup_id="" destination=""
292+
prepare_temp_dir_in_workdir_and_schedule_cleanup "deb-bsp-generic" cleanup_id destination # namerefs
293+
294+
mkdir -p "${destination}"/DEBIAN
295+
cd "${destination}" || exit_with_error "Failed to cd to ${destination}"
296+
297+
# array of code to be included in preinst, postinst, prerm and postrm scripts (more than default code)
298+
declare -a preinst_functions=()
299+
declare -a postinst_functions=()
300+
declare -a postrm_functions=()
301+
302+
declare -a extra_description=()
303+
[[ "${EXTRA_BSP_NAME}" != "" ]] && extra_description+=("(variant '${EXTRA_BSP_NAME}')")
304+
305+
# armbianmonitor needs curl, but if it's not there it will install it.
306+
# armbian-resize-filesystem needs parted and fdisk
307+
cat <<- EOF > "${destination}"/DEBIAN/control
308+
Package: ${artifact_name}
309+
Version: ${artifact_version}
310+
Architecture: all
311+
Maintainer: Armbian
312+
Section: kernel
313+
Priority: optional
314+
Depends: bash, linux-base, parted, fdisk, bc, u-boot-tools, initramfs-tools, lsb-release, fping
315+
Recommends: bsdutils, util-linux, toilet, curl
316+
Provides: armbian-ramlog, armbian-resize-filesystem, armbian-zram-config, armbian-allwinner-battery, armbian-firstrun, armbian-hardware-monitor, armbian-hardware-optimization, armbian-led-state
317+
Description: Armbian Generic BSP for branch '${BRANCH}' ${extra_description[@]}
318+
EOF
319+
320+
# armhwinfo, firstrun, armbianmonitor, etc. config file; also sourced in postinst
321+
mkdir -p "${destination}"/etc
322+
323+
# copy general overlay from packages/bsp-cli
324+
# in practice: packages/bsp-cli and variations of config/optional/...
325+
copy_all_packages_files_for "bsp-generic"
326+
327+
# copy common files from a premade directory structure
328+
# @TODO this includes systemd config, assumes things about serial console, etc, that need dynamism or just to not exist with modern systemd
329+
display_alert "Copying common bsp files" "packages/bsp/common" "info"
330+
run_host_command_logged rsync -av "${SRC}"/packages/bsp/common/* "${destination}"
331+
wait_for_disk_sync "after rsync'ing package/bsp/common for bsp-cli"
332+
333+
mkdir -p "${destination}"/usr/share/armbian/
334+
335+
# get bootscript information.
336+
#declare -A bootscript_info=()
337+
#get_bootscript_info
338+
339+
# won't recreate files if they were removed by user
340+
# TODO: Add proper handling for updated conffiles
341+
# We are runing this script each time apt runs. If this package is removed, file is removed and error is triggered.
342+
# Keeping armbian-apt-updates as a configuration, solve the problem
343+
cat <<- EOF > "${destination}"/DEBIAN/conffiles
344+
/usr/lib/armbian/armbian-apt-updates
345+
/etc/X11/xorg.conf.d/01-armbian-defaults.conf
346+
EOF
347+
348+
# Render the postinst/postrm/etc
349+
# set up pre install script; use inline functions
350+
# This is never run in build context; instead, it's source code is dumped inside a file that is packaged.
351+
# It is done this way so we get shellcheck and formatting instead of a huge heredoc.
352+
### preinst
353+
#FIXME: this mentions boards, is this relevant to bsp-generic? see below for postrm & postinst too
354+
artifact_package_hook_helper_board_side_functions "preinst" board_side_bsp_cli_preinst "${preinst_functions[@]}"
355+
unset board_side_bsp_cli_preinst
356+
357+
### postrm
358+
artifact_package_hook_helper_board_side_functions "postrm" board_side_bsp_cli_postrm "${postrm_functions[@]}"
359+
unset board_side_bsp_cli_postrm
360+
361+
### postinst -- a bit more complex, extendable via postinst_functions which can be customized in hook above
362+
artifact_package_hook_helper_board_side_functions "postinst" board_side_bsp_cli_postinst_base "${postinst_functions[@]}" board_side_bsp_cli_postinst_finish
363+
unset board_side_bsp_cli_postinst_base board_side_bsp_cli_postinst_update_uboot_bootscript board_side_bsp_cli_postinst_finish
364+
365+
# fixing permissions (basic), reference: dh_fixperms
366+
find "${destination}" -print0 2> /dev/null | xargs -0r chown --no-dereference 0:0
367+
find "${destination}" ! -type l -print0 2> /dev/null | xargs -0r chmod 'go=rX,u+rw,a-s'
368+
369+
# Build / close the package. This will run shellcheck / show the generated files if debugging
370+
dpkg_deb_build "${destination}" "armbian-bsp-generic"
371+
372+
done_with_temp_dir "${cleanup_id}" # changes cwd to "${SRC}" and fires the cleanup function early
373+
374+
display_alert "Done building BSP Generic package" "${destination}" "debug"
375+
}
376+
268377
# Reversion function is called with the following parameters:
269378
# ${1} == deb_id
270379
function reversion_armbian-bsp-cli_deb_contents() {
@@ -282,7 +391,7 @@ function reversion_armbian-bsp-cli_deb_contents() {
282391
depends_base_files=""
283392
fi
284393
cat <<- EOF >> "${control_file_new}"
285-
Depends: bash, linux-base, u-boot-tools, initramfs-tools, lsb-release, fping, device-tree-compiler${depends_base_files}
394+
Depends: armbian-bsp-generic, bash, linux-base, u-boot-tools, initramfs-tools, lsb-release, fping, device-tree-compiler${depends_base_files}
286395
Replaces: zram-config, armbian-bsp-cli-${BOARD}${EXTRA_BSP_NAME} (<< ${REVISION})
287396
Breaks: armbian-bsp-cli-${BOARD}${EXTRA_BSP_NAME} (<< ${REVISION})
288397
Provides: armbian-bsp-cli

lib/functions/main/build-packages.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ function determine_artifacts_to_build_for_image() {
5050
artifacts_to_build+=("armbian-desktop")
5151
artifacts_to_build+=("armbian-bsp-desktop")
5252
fi
53+
artifacts_to_build+=("armbian-bsp-generic")
5354
fi
5455

5556
# If we're only dumping the config, include the rootfs artifact.

lib/functions/rootfs/distro-agnostic.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ function install_distribution_agnostic() {
220220
DEFAULT_OVERLAYS_ARR=("${DEFAULT_OVERLAYS_ARR[@]/%/".dtbo"}")
221221
DEFAULT_OVERLAYS_ARR=("${DEFAULT_OVERLAYS_ARR[@]/#/"${bootpart_prefix}dtb/${BOOT_FDT_FILE%%/*}/overlay/${OVERLAY_PREFIX}-"}")
222222

223-
display_alert "Adding to extlinux.conf" "fdtoverlays=${DEFAULT_OVERLAYS_ARR[*]}" "debug"
223+
display_alert "Adding to extlinux.conf" "fdtoverlays=${DEFAULT_OVERLAYS_ARR[*]}" "debug" #"
224224
echo " fdtoverlays ${DEFAULT_OVERLAYS_ARR[*]}" >> "$SDCARD/boot/extlinux/extlinux.conf"
225225
fi
226226

@@ -403,6 +403,8 @@ function install_distribution_agnostic() {
403403
fi
404404
fi
405405

406+
#FIXME: this belongs in rootfs not image
407+
install_artifact_deb_chroot "armbian-bsp-generic"
406408
# install board support packages
407409
install_artifact_deb_chroot "armbian-bsp-cli"
408410

0 commit comments

Comments
 (0)