Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
60ab82c
build: kernel: armbian: drop unneeded "dpkg-dev" package from kernel …
rpardini Jan 12, 2025
ad525bb
build: kernels: fix for kernel builds that produce DTBs
rpardini Jan 12, 2025
ba62642
build: hook lint as git pre-commit hook when ran
rpardini Jan 12, 2025
c4803fe
build: shellcheck: simplify code
rpardini Jan 18, 2025
85e1183
common: installing deps shouldn't generate a warning
rpardini Feb 12, 2025
b830b31
kernel: refreshing kernel-releases.json should not be a warning
rpardini Feb 12, 2025
7f3c92a
inventory: split default (built-from-source) and foreign (Armbian) in…
rpardini Mar 5, 2025
8d5f57e
common: bootable: introduce `add_bootable_id()`; add supporting `last…
rpardini Mar 5, 2025
5a2ac2e
bootable: inventory: basic structure for bootable media inventory
rpardini Mar 5, 2025
4080afb
bootable: base "bootable media" interfaces and CLI
rpardini Mar 5, 2025
1a6c491
bootable: gha-matrix JSON implementation for bootables
rpardini Mar 5, 2025
2477e90
bootable: introduce `create_image_fat32_root_from_dir()`
rpardini Mar 5, 2025
e62a394
bootable: add the `rpi` (RaspberryPi 3b/4b/5) bootable media implemen…
rpardini Mar 5, 2025
94fe5c5
bootable: add the `u-boot` (from Armbian) bootable media implementations
rpardini Mar 5, 2025
13903e0
common: add `pixz` dependency (apt/brew)
rpardini Jan 19, 2025
2fa30e5
common: add `pv` dependency (apt/brew)
rpardini Jan 19, 2025
e4ff46d
bootable: introduce output/write image methods
rpardini Mar 5, 2025
0e87225
kernel: extract method `kernel_obtain_output_id()`
rpardini Feb 24, 2025
f96b5ac
bootable: consume kernel_obtain_output_id() early
rpardini Feb 24, 2025
c6f02fa
bootable: implement outer shell of GRUB bootable for amd64/arm64
rpardini Feb 24, 2025
5285780
bootable: grub: bootable_id's for default kernels
rpardini Feb 24, 2025
0c0430a
bootable: grub: bootable_id's for latest-lts kernels
rpardini Feb 24, 2025
682678d
bootable: grub: bootable_id's for armbian-uefi foreign kernels
rpardini Feb 24, 2025
5781767
bootable: grub: implement grabbing GRUB bins from Linuxkit into EFI/BOOT
rpardini Feb 24, 2025
6105c60
bootable: grub: implement writing basic grub.cfg
rpardini Feb 24, 2025
2a10b06
common: introduce `log_tree()`, which logs and outputs a dir structure
rpardini Feb 24, 2025
e7622e3
bootable: use `log_tree()` instead of bare tree for debugging
rpardini Feb 24, 2025
4287f24
bootable: grub: enable serial console
rpardini Feb 24, 2025
aaed42f
bootable/common: include BOOTABLE_ID in bootable_info dict
rpardini Feb 24, 2025
cacc3b7
bootable: grub: use the bootable's id for each grub "board"
rpardini Feb 24, 2025
3c8723d
bootable: grub: inventory: set the default SERIAL_CONSOLE for each bo…
rpardini Feb 24, 2025
0e17fdb
bootable: grub: inventory: only Armbian UEFI arm64 includes DTBs
rpardini Feb 24, 2025
5d27ec4
bootable: fix: only add bootable-only host dependencies when building…
rpardini Mar 5, 2025
c33caa2
Merge branch 'main' into bootable-media
mergify[bot] Mar 31, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ hook*.*.yaml
!linuxkit-templates
out/
cache/
bootable/
!bash/bootable
*.swp
.idea
kernel/Dockerfile.autogen.*
Expand Down
102 changes: 102 additions & 0 deletions bash/bootable-media.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
function build_bootable_media() {
log info "would build build_bootable_media: '${*}'"

declare -r -g bootable_id="${1}" # read-only variable from here

declare -g -A bootable_info=()
get_bootable_info_dict "${bootable_id}"

# Dump the bootable_info dict
log info "bootable_info: $(declare -p bootable_info)"

# Get the kernel info from the bootable_info INVENTORY_ID
declare -g -A kernel_info=()
declare -g inventory_id="${bootable_info['INVENTORY_ID']}"
get_kernel_info_dict "${inventory_id}"
log info "kernel_info: $(declare -p kernel_info)"
set_kernel_vars_from_info_dict
kernel_obtain_output_id # sets OUTPUT_ID

# A few scenarios we want to support:
# A) UEFI bootable media; GPT + ESP, FAT32, GRUB, kernel/initrd, grub.conf + some kernel command line.
# B) RPi 3b/4/5 bootable media; GPT, non-ESP partition, FAT32, kernel/initrd, config.txt, cmdline.txt + some kernel command line.
# C) Rockchip bootable media; GPT, non-ESP partition, FAT32, extlinux.conf + some kernel command line; write u-boot bin on top of GPT via Armbian sh
# D) Amlogic bootable media; MBR, FAT32, extlinux.conf + some kernel command line; write u-boot bin on top of MBR via Armbian sh

# General process:
# Obtain extra variables from environment (BOARD/BRANCH for armbian); optional.
# Obtain the latest Armbian u-boot version from the OCI registry, using Skopeo.
# 1) (C/D) Obtain the u-boot artifact binaries using ORAS, given the version above; massage using Docker and extract the binaries.
# 1) (A) Obtain grub somehow; LinuxKit has them ready-to-go in a Docker image.
# 1) (B) Obtain the rpi firmware files (bootcode.bin, start.elf, fixup.dat) from the RaspberryPi Foundation
# 2) Prepare the FAT32 contents; kernel/initrd, grub.conf, config.txt, cmdline.txt, extlinux.conf depending on scenario
# 3) Create a GPT+ESP, GTP+non-ESP, or MBR partition table image with the contents of the FAT32 (use libguestfs)
# 4) For the scenarios with u-boot, write u-boot binaries to the correct offsets in the image.

# @TODO: possibly make sure the kernel and lk is built before delegating?

# Call the bootable build function
declare bootable_build_func="${bootable_info['BOOTABLE_BUILD_FUNC']}"
log info "Calling bootable build function: ${bootable_build_func}"
"${bootable_build_func}"

}

function get_bootable_info_dict() {
declare bootable="${1}"
declare bootable_data_str="${bootable_inventory_dict[${bootable}]}"
if [[ -z "${bootable_data_str}" ]]; then
log error "No bootable data found for '${bootable}'; valid ones are: ${bootable_inventory_ids[*]} "
exit 1
fi
log debug "Bootable data for '${bootable}': ${bootable_data_str}"
declare -g -A bootable_info
eval "bootable_info=(${bootable_data_str})"

# Post process; calculate bash function names given the handler
bootable_info['BOOTABLE_LIST_FUNC']="list_bootable_${bootable_info['HANDLER']}"
bootable_info['BOOTABLE_BUILD_FUNC']="build_bootable_${bootable_info['HANDLER']}"

# Ensure bootable_info a valid TAG
if [[ -z "${bootable_info['TAG']}" ]]; then
log error "No TAG found for bootable '${bootable}'"
exit 1
fi
}

function output_bootable_media() {
declare input_file="${1}"
declare output_fn="${2}"
declare full_output_fn="out/${output_fn}.xz"

# If CARD_DEVICE is set, write the image to the device; otherwise, compress it
if [[ -n "${CARD_DEVICE}" ]]; then
write_image_to_device "${input_file}" "${CARD_DEVICE}"
log info "Wrote image file ${input_file} to device ${CARD_DEVICE}; done."
return 0
fi

# Use pixz to compress the image; use all CPU cores, default compression level
log info "Compressing image file ${input_file} to ${full_output_fn} -- wait..."
pixz -i "${input_file}" -o "${full_output_fn}"
ls -lah "${full_output_fn}"
log info "Compressed image file ${input_file} to ${full_output_fn}"

return 0
}

function write_image_to_device() {
local image_file="${1}"
local device="${2}"
if [[ -b "${device}" && -f "${image_file}" ]]; then
log info "Writing image file ${image_file} to device ${device}"
pv -p -b -r -c -N "dd" "${image_file}" | dd "of=${device}" bs=1M iflag=fullblock oflag=direct status=none
log info "Waiting for fsync()..."
sync
else
if [[ -n ${device} ]]; then
log error "Device ${device} not found or image file ${image_file} not found"
exit 3
fi
fi
}
Loading
Loading