Commit 8289d166 authored by Dorota Czaplejewicz's avatar Dorota Czaplejewicz
Browse files

Merge branch 'generate-boot-image' into 'master'

Generate additional boot image for eMMC boot hwpart

See merge request Librem5/image-builder!87
parents 86aa13d4 40c47a55
......@@ -4,6 +4,7 @@ node {
artifacts = "checksums,${params.board}.img.xz,tmp/*-report.log,files/meta.yml"
build_on_x86 = [ 'imx6', 'qemu-x86_64' ]
qcow2_builds = [ 'qemu-x86_64' ]
separate_boot_image = []
currentBuild.description = "${params.board} ${params.dist} ${build_type} image"
parameters {
......@@ -23,6 +24,10 @@ node {
artifacts += ",${params.board}.qcow2"
}
if (separate_boot_image.contains(params.board)) {
artifacts += ",${params.board}-boot.img.xz"
}
node (nodename) {
stage('Setup') {
git url: gitUrl, branch: branch
......
# SPDX-License-Identifier: GPL-3.0+
BOARD=imx6
TYPE=unstable
IMAGE=$(BOARD).img
COMPRESSED=$(IMAGE).xz
CHECKSUM=sha256sums
DIST=buster+ci
BOARD ?= imx6
TYPE ?= unstable
DIST ?= buster+ci
SHELL := /bin/bash
# Get a variable from the board config
# $1 : Variable name to get the value for
define get_board_var
$(shell pureos_board=$(BOARD); . conf/board; echo $$$1)
endef
STAMPFILE := tmp/$(BOARD).img.stamp
IMAGES := $(BOARD).img
ifeq ($(call get_board_var,want_boot_image),1)
IMAGES += $(BOARD)-boot.img
endif
COMPRESSED := $(addsuffix .xz,$(IMAGES))
CHECKSUM := sha256sums
DEPS=\
build-image \
root.sh \
......@@ -18,24 +31,28 @@ SHELLCHECK_SCRIPTS=\
build/build_kernel_deb.sh \
$(NULL)
.PHONY: all
all: $(COMPRESSED)
$(IMAGE): tmp/$(IMAGE).stamp
tmp/$(IMAGE).stamp: local.sh-link $(DEPS)
$(IMAGES): $(STAMPFILE)
# Use an order-only dependency to prevent rebuilding $(STAMPFILE) every time
# local.sh-link is out of date (it is always out of date because of .PHONY).
$(STAMPFILE): | local.sh-link
$(STAMPFILE): $(DEPS)
./build-image -b $(BOARD) -T $(TYPE) -d $(DIST)
touch tmp/$(IMAGE).stamp
touch $@
%.img.xz: %.img tmp/%.img.stamp
%.img.xz: %.img
xz -T0 --stdout $< > $@.tmp
mv $@.tmp $@
$(CHECKSUM):
$(CHECKSUM): $(COMPRESSED)
sha256sum $(COMPRESSED) > $@.tmp
mv $@.tmp $@
clean:
rm -rf files/ tmp/ $(IMAGE) $(COMPRESSED) $(CHECKSUM)*
rm -rf files/ tmp/ $(IMAGES) $(COMPRESSED) $(CHECKSUM) *.tmp
check:
shellcheck -x $(SHELLCHECK_SCRIPTS)
......
......@@ -84,6 +84,21 @@ image:
EOF
}
append_boot_image_meta() {
local out="$1"
local image="$2"
image_sha256sum=$(sha256sum "${image}" | sed 's/\([a-f0-9]\+\) .*/\1/')
image_size=$(stat --format='%s' "${image}")
echo "Image '${image} has sha256sum ${image_sha256sum}"
cat <<EOF >> "${out}"
boot-image:
size: ${image_size}
sha256sum: ${image_sha256sum}
EOF
}
cwd=$(pwd)
distro=${DIST:-buster+ci}
......@@ -94,6 +109,7 @@ NULL=
uboot_bin=
build_tarball=
want_qcow2=
want_boot_image=
apt_sources=
debootstrap_dist=
kernel_deb=
......@@ -132,7 +148,7 @@ done
[[ "${distro}" =~ \+ci ]] && ci_pkgs=1 || ci_pkgs=0
distro="${distro/+ci}"
bootimg="${pureos_board}.img"
mainimg="${pureos_board}.img"
. conf/board
. conf/packages
......@@ -140,7 +156,7 @@ bootimg="${pureos_board}.img"
. conf/dists/"${distro}"
[ -n "${debootstrap_dist}" ] || debootstrap_dist="${distro}"
echo "Building ${bootimg} (board_type: ${board_type}, arch: ${arch}, build_type: ${build_type}, ci_pkgs: ${ci_pkgs}, ${debootstrap_dist})"
echo "Building ${mainimg} (board_type: ${board_type}, arch: ${arch}, build_type: ${build_type}, ci_pkgs: ${ci_pkgs}, ${debootstrap_dist})"
echo "Installing extra packages ${packages}"
[ -z "${board_packages}" ] || echo "Installing extra board specific packages ${board_packages}"
......@@ -200,7 +216,7 @@ sudo pureos_board="${pureos_board}" \
FK_MACHINE="${fk_machine}" \
vmdebootstrap \
--enable-dhcp \
--verbose --image "${bootimg}" --log "tmp/${bootimg}.log" --size 3600M \
--verbose --image "${mainimg}" --log "tmp/${mainimg}.log" --size 3600M \
--mirror "${mirror}" \
--configure-apt \
--distribution "${debootstrap_dist}" \
......@@ -219,18 +235,27 @@ if [ "${arch}" == "arm64" ]; then
wget -Pfiles/uboot-${uboot_type}/ "${kernel_url}/uboot-${uboot_type}/m4.bin"
fi
loop=$(setup_loop "${bootimg}")
sudo dd if="files/uboot-${uboot_type}/${uboot_bin}" of="${loop}" bs=1024 seek=33
sudo dd if="files/uboot-${uboot_type}/m4.bin" of="${loop}" bs=1024 seek=2
sudo losetup -d "${loop}"
if [ "${want_boot_image}" == 1 ]; then
# Copy the boot image as a separate file
bootimg="${pureos_board}-boot.img"
cp "files/uboot-${uboot_type}/${pureos_board}-boot.img" "${bootimg}"
else
# Merge boot image inside the main image
loop=$(setup_loop "${mainimg}")
sudo dd if="files/uboot-${uboot_type}/${pureos_board}-boot.img" of="${loop}" bs=1024 seek=2
sudo losetup -d "${loop}"
fi
fi
[ -f "./tmp/${pureos_board}-report.log" ] || { echo "No install report found."; exit 1; }
write_meta "${meta_yml}" "${bootimg}"
write_meta "${meta_yml}" "${mainimg}"
if [ "${want_boot_image}" == 1 ]; then
append_boot_image_meta "${meta_yml}" "${bootimg}"
fi
if [ "${want_qcow2}" == 1 ]; then
qcow2="$(basename "${bootimg}" .img)".qcow2
qemu-img convert -f raw -O qcow2 "${bootimg}" "${qcow2}"
qcow2="$(basename "${mainimg}" .img)".qcow2
qemu-img convert -f raw -O qcow2 "${mainimg}" "${qcow2}"
qemu-img resize -f qcow2 "${qcow2}" +28G
fi
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment