From d0dcab2864d14c31d14a673571dc366af11740a3 Mon Sep 17 00:00:00 2001 From: Bohdan Buinich Date: Tue, 9 Jan 2024 01:40:08 +0200 Subject: [PATCH] Moved post-build and post-images on top level (not fully tested) --- .../board/ovos/ova/post-build.sh | 57 --------- .../board/ovos/ova/post-image.sh | 34 ----- .../board/ovos/pc/post-build.sh | 32 ----- .../board/ovos/pc/post-image.sh | 27 ---- .../board/ovos/raspberrypi/post-build.sh | 88 ------------- .../board/ovos/raspberrypi/post-image.sh | 64 ---------- .../board/ovos/raspberrypi/rpi3/post-build.sh | 1 - .../board/ovos/raspberrypi/rpi3/post-image.sh | 1 - .../board/ovos/raspberrypi/rpi4/post-build.sh | 1 - .../board/ovos/raspberrypi/rpi4/post-image.sh | 1 - buildroot-external/configs/ova_64_defconfig | 6 +- buildroot-external/configs/rpi3_64_defconfig | 6 +- buildroot-external/configs/rpi4_64_defconfig | 6 +- .../configs/x86_64-base_defconfig | 6 +- .../ovos-containers/fetch-container-image.sh | 2 +- buildroot-external/scripts/post-build.sh | 119 ++++++++++++++++++ buildroot-external/scripts/post-image.sh | 68 ++++++++++ 17 files changed, 200 insertions(+), 319 deletions(-) delete mode 100755 buildroot-external/board/ovos/ova/post-build.sh delete mode 100755 buildroot-external/board/ovos/ova/post-image.sh delete mode 100755 buildroot-external/board/ovos/pc/post-build.sh delete mode 100755 buildroot-external/board/ovos/pc/post-image.sh delete mode 100755 buildroot-external/board/ovos/raspberrypi/post-build.sh delete mode 100755 buildroot-external/board/ovos/raspberrypi/post-image.sh delete mode 120000 buildroot-external/board/ovos/raspberrypi/rpi3/post-build.sh delete mode 120000 buildroot-external/board/ovos/raspberrypi/rpi3/post-image.sh delete mode 120000 buildroot-external/board/ovos/raspberrypi/rpi4/post-build.sh delete mode 120000 buildroot-external/board/ovos/raspberrypi/rpi4/post-image.sh create mode 100755 buildroot-external/scripts/post-build.sh create mode 100755 buildroot-external/scripts/post-image.sh diff --git a/buildroot-external/board/ovos/ova/post-build.sh b/buildroot-external/board/ovos/ova/post-build.sh deleted file mode 100755 index f6c73e13..00000000 --- a/buildroot-external/board/ovos/ova/post-build.sh +++ /dev/null @@ -1,57 +0,0 @@ -#!/bin/sh - -set -u -set -e - -BOARD_DIR="$(dirname $0)" - -. "${BR2_EXTERNAL_OPENVOICEOS_PATH}/meta" -. "${BOARD_DIR}/meta" - -# Write os-release -{ - echo "NAME=\"${OVOS_NAME}\"" - echo "VERSION=\"${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_BUILD} ${BOARD_NAME}\"" - echo "ID=${OVOS_ID}" - echo "VERSION_ID=${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_BUILD}" - echo "PRETTY_NAME=\"${OVOS_NAME} ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_BUILD} ${BOARD_NAME}\"" - echo "CPE_NAME=cpe:2.3:o:openvoiceos:${OVOS_ID}:${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_BUILD}:*:${DEPLOYMENT}:*:*:*:${BOARD_ID}:*" - echo "HOME_URL=https://github.com/OpenVoiceOS/OpenVoiceOS" - echo "DOCUMENTATION_URL=https://github.com/OpenVoiceOS/OpenVoiceOS/tree/develop/documentation" - echo "SUPPORT_URL=https://github.com/OpenVoiceOS/OpenVoiceOS/issues" - echo "VARIANT=\"${OVOS_NAME} - Buildroot Edition\"" - echo "VARIANT_ID=${OVOS_ID}-${BOARD_ID}-buildroot" -} > "${TARGET_DIR}/usr/lib/os-release" - -# Write machine-info -{ - echo "CHASSIS=${CHASSIS}" - echo "DEPLOYMENT=${DEPLOYMENT}" -} > "${TARGET_DIR}/etc/machine-info" - -cp -f ../buildroot-external/board/ovos/ova/grub-efi.cfg ${BINARIES_DIR}/efi-part/EFI/BOOT/grub.cfg -cp -f ../buildroot-external/board/ovos/ova/cmdline.txt ${BINARIES_DIR} -cp -f ../buildroot-external/board/ovos/ova/sw-description ${BINARIES_DIR} - -grub-editenv "${BINARIES_DIR}/efi-part/EFI/BOOT/grubenv" create - -echo "Check for compressed kernel in ${TARGET_DIR}" -if [ -f "${TARGET_DIR}/boot/bzImage" ]; then - echo "Found bzImage, renaming to kernel" - mv ${TARGET_DIR}/boot/bzImage ${TARGET_DIR}/boot/kernel -fi - -# Prepare home data -rm -f ${BINARIES_DIR}/homefs.ext4 -truncate --size="6890M" ${BINARIES_DIR}/homefs.ext4 -mkfs.ext4 -L "homefs" -E lazy_itable_init=0,lazy_journal_init=0 ${BINARIES_DIR}/homefs.ext4 - -# Mount home image -mkdir -p ${BINARIES_DIR}/home -sudo mount -o loop,discard ${BINARIES_DIR}/homefs.ext4 ${BINARIES_DIR}/home - -# sync home folder -sudo rsync -ah --progress ${TARGET_DIR}/home/* ${BINARIES_DIR}/home/ - -# Unmount home image -sudo umount ${BINARIES_DIR}/homefs.ext4 diff --git a/buildroot-external/board/ovos/ova/post-image.sh b/buildroot-external/board/ovos/ova/post-image.sh deleted file mode 100755 index 0a93ef16..00000000 --- a/buildroot-external/board/ovos/ova/post-image.sh +++ /dev/null @@ -1,34 +0,0 @@ -#!/bin/bash - -set -e - -BOARD_DIR="$(dirname $0)" -BOARD_NAME="$(basename ${BOARD_DIR})" -GENIMAGE_CFG="${BOARD_DIR}/genimage-${BOARD_NAME}.cfg" -GENIMAGE_TMP="${BUILD_DIR}/genimage.tmp" -SWUPDATE_FILES="sw-description rootfs.squashfs" - -# Pass an empty rootpath. genimage makes a full copy of the given rootpath to -# ${GENIMAGE_TMP}/root so passing TARGET_DIR would be a waste of time and disk -# space. We don't rely on genimage to build the rootfs image, just to insert a -# pre-built one in the disk image. - -trap 'rm -rf "${ROOTPATH_TMP}"' EXIT -ROOTPATH_TMP="$(mktemp -d)" - -rm -rf "${GENIMAGE_TMP}" - -genimage \ - --rootpath "${ROOTPATH_TMP}" \ - --tmppath "${GENIMAGE_TMP}" \ - --inputpath "${BINARIES_DIR}" \ - --outputpath "${BINARIES_DIR}" \ - --config "${GENIMAGE_CFG}" - -pushd ${BINARIES_DIR} -for f in ${SWUPDATE_FILES} ; do - echo ${f} -done | cpio -ov -H crc > rootfs.swu -popd - -exit $? diff --git a/buildroot-external/board/ovos/pc/post-build.sh b/buildroot-external/board/ovos/pc/post-build.sh deleted file mode 100755 index 13ecb32f..00000000 --- a/buildroot-external/board/ovos/pc/post-build.sh +++ /dev/null @@ -1,32 +0,0 @@ -#!/bin/sh - -set -u -set -e - -BOARD_DIR="$(dirname $0)" - -. "${BR2_EXTERNAL_OPENVOICEOS_PATH}/meta" -. "${BOARD_DIR}/meta" - -# Write os-release -{ - echo "NAME=\"${OVOS_NAME}\"" - echo "VERSION=\"${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_BUILD} ${BOARD_NAME}\"" - echo "ID=${OVOS_ID}" - echo "VERSION_ID=${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_BUILD}" - echo "PRETTY_NAME=\"${OVOS_NAME} ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_BUILD} ${BOARD_NAME}\"" - echo "CPE_NAME=cpe:2.3:o:openvoiceos:${OVOS_ID}:${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_BUILD}:*:${DEPLOYMENT}:*:*:*:${BOARD_ID}:*" - echo "HOME_URL=https://github.com/OpenVoiceOS/OpenVoiceOS" - echo "DOCUMENTATION_URL=https://github.com/OpenVoiceOS/OpenVoiceOS/tree/develop/documentation" - echo "SUPPORT_URL=https://github.com/OpenVoiceOS/OpenVoiceOS/issues" - echo "VARIANT=\"${OVOS_NAME} - Buildroot Edition\"" - echo "VARIANT_ID=${OVOS_ID}-${BOARD_ID}-buildroot" -} > "${TARGET_DIR}/usr/lib/os-release" - -# Write machine-info -{ - echo "CHASSIS=${CHASSIS}" - echo "DEPLOYMENT=${DEPLOYMENT}" -} > "${TARGET_DIR}/etc/machine-info" - -cp -f ../buildroot-external/board/ovos/ova/grub-efi.cfg ${BINARIES_DIR}/efi-part/EFI/BOOT/grub.cfg diff --git a/buildroot-external/board/ovos/pc/post-image.sh b/buildroot-external/board/ovos/pc/post-image.sh deleted file mode 100755 index 6cad20fb..00000000 --- a/buildroot-external/board/ovos/pc/post-image.sh +++ /dev/null @@ -1,27 +0,0 @@ -#!/bin/bash - -set -e - -BOARD_DIR="$(dirname $0)" -BOARD_NAME="$(basename ${BOARD_DIR})" -GENIMAGE_CFG="${BOARD_DIR}/genimage-${BOARD_NAME}.cfg" -GENIMAGE_TMP="${BUILD_DIR}/genimage.tmp" - -# Pass an empty rootpath. genimage makes a full copy of the given rootpath to -# ${GENIMAGE_TMP}/root so passing TARGET_DIR would be a waste of time and disk -# space. We don't rely on genimage to build the rootfs image, just to insert a -# pre-built one in the disk image. - -trap 'rm -rf "${ROOTPATH_TMP}"' EXIT -ROOTPATH_TMP="$(mktemp -d)" - -rm -rf "${GENIMAGE_TMP}" - -genimage \ - --rootpath "${ROOTPATH_TMP}" \ - --tmppath "${GENIMAGE_TMP}" \ - --inputpath "${BINARIES_DIR}" \ - --outputpath "${BINARIES_DIR}" \ - --config "${GENIMAGE_CFG}" - -exit $? diff --git a/buildroot-external/board/ovos/raspberrypi/post-build.sh b/buildroot-external/board/ovos/raspberrypi/post-build.sh deleted file mode 100755 index c14d528b..00000000 --- a/buildroot-external/board/ovos/raspberrypi/post-build.sh +++ /dev/null @@ -1,88 +0,0 @@ -#!/bin/sh -set -eu - -# Set board directory and include meta files -BOARD_DIR="$(dirname $0)" -. "${BR2_EXTERNAL_OPENVOICEOS_PATH}/meta" -. "${BOARD_DIR}/meta" - -# Function to create and write os-release file -write_os_release() { - local os_release_file="${TARGET_DIR}/usr/lib/os-release" - echo "Creating os-release at ${os_release_file}" - { - echo "NAME=\"${OVOS_NAME}\"" - echo "VERSION=\"${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_BUILD} ${BOARD_NAME}\"" - echo "ID=${OVOS_ID}" - echo "VERSION_ID=${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_BUILD}" - echo "PRETTY_NAME=\"${OVOS_NAME} ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_BUILD} ${BOARD_NAME}\"" - echo "CPE_NAME=cpe:2.3:o:openvoiceos:${OVOS_ID}:${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_BUILD}:*:${DEPLOYMENT}:*:*:*:${BOARD_ID}:*" - echo "HOME_URL=https://github.com/OpenVoiceOS/OpenVoiceOS" - echo "DOCUMENTATION_URL=https://github.com/OpenVoiceOS/OpenVoiceOS/tree/develop/documentation" - echo "SUPPORT_URL=https://github.com/OpenVoiceOS/OpenVoiceOS/issues" - echo "VARIANT=\"${OVOS_NAME} - Buildroot Edition\"" - echo "VARIANT_ID=${OVOS_ID}-${BOARD_ID}-buildroot" - } > "${os_release_file}" -} - -# Function to create and write machine-info file -write_machine_info() { - local machine_info_file="${TARGET_DIR}/etc/machine-info" - echo "Creating machine-info at ${machine_info_file}" - { - echo "CHASSIS=${CHASSIS}" - echo "DEPLOYMENT=${DEPLOYMENT}" - } > "${machine_info_file}" -} - -# Function to handle Raspberry Pi specific files -handle_raspberry_pi() { - local pi_version=$1 - echo "Handling Raspberry Pi ${pi_version} specific files" - cp -f "../buildroot-external/board/ovos/raspberrypi/${pi_version}/config.txt" "${BINARIES_DIR}/rpi-firmware/config.txt" - cp -f "../buildroot-external/board/ovos/raspberrypi/${pi_version}/RPI_EFI.fd" "${BINARIES_DIR}/rpi-firmware/RPI_EFI.fd" - cp -f "../buildroot-external/board/ovos/raspberrypi/grub-efi.cfg" "${BINARIES_DIR}/efi-part/EFI/BOOT/grub.cfg" - cp -f "../buildroot-external/board/ovos/raspberrypi/${pi_version}/sw-description" "${BINARIES_DIR}" -} - -# Main function to execute script logic -main() { - write_os_release - write_machine_info - - echo "Copying cmdline.txt to ${BINARIES_DIR}/rpi-firmware/" - cp -f ../buildroot-external/board/ovos/raspberrypi/cmdline.txt "${BINARIES_DIR}/rpi-firmware/cmdline.txt" - - echo "Creating grubenv" - grub-editenv "${BINARIES_DIR}/efi-part/EFI/BOOT/grubenv" create - - echo "Checking for kernel in ${TARGET_DIR}" - if [ -f "${TARGET_DIR}/boot/Image" ]; then - echo "Found Image, renaming to kernel" - mv "${TARGET_DIR}/boot/Image" "${TARGET_DIR}/boot/kernel" - fi - - # Process command line arguments - for arg in "$@"; do - case "${arg}" in - --rpi3) handle_raspberry_pi "rpi3" ;; - --rpi4) handle_raspberry_pi "rpi4" ;; - # --rpi5) handle_raspberry_pi "rpi5" ;; - esac - done - - # Prepare and sync home data - local home_img="${BINARIES_DIR}/homefs.ext4" - echo "Preparing home data at ${home_img}" - rm -f "${home_img}" - truncate --size="6890M" "${home_img}" - mkfs.ext4 -L "homefs" -E lazy_itable_init=0,lazy_journal_init=0 "${home_img}" - - local home_mount_point="${BINARIES_DIR}/home" - mkdir -p "${home_mount_point}" - sudo mount -o loop,discard "${home_img}" "${home_mount_point}" - sudo rsync -ah --progress "${TARGET_DIR}/home/"* "${home_mount_point}/" - sudo umount "${home_img}" -} - -main "$@" diff --git a/buildroot-external/board/ovos/raspberrypi/post-image.sh b/buildroot-external/board/ovos/raspberrypi/post-image.sh deleted file mode 100755 index 0d73c9ed..00000000 --- a/buildroot-external/board/ovos/raspberrypi/post-image.sh +++ /dev/null @@ -1,64 +0,0 @@ -#!/bin/bash - -set -e - -# Define board directory and related variables -BOARD_DIR="$(dirname "$0")" -BOARD_NAME="$(basename "${BOARD_DIR}")" -GENIMAGE_CFG="${BOARD_DIR}/genimage-${BOARD_NAME}.cfg" -GENIMAGE_TMP="${BUILD_DIR}/genimage.tmp" - -# Define files for SWUPDATE -SWUPDATE_FILES=("sw-description" "rootfs.squashfs") - -# Check if necessary files and directories exist -if [ ! -d "${BUILD_DIR}" ] || [ ! -f "${GENIMAGE_CFG}" ]; then - echo "Required directories or config files are missing." - exit 1 -fi - -# Function to create SWU file -create_swu_file() { - local binaries_dir=$1 - shift - local files=("$@") - - pushd "${binaries_dir}" > /dev/null - printf '%s\n' "${files[@]}" | cpio -ov -H crc > rootfs.swu - if [ $? -ne 0 ]; then - echo "Error creating SWU file." - exit 1 - fi - popd > /dev/null -} - -# Clean up function for EXIT trap -cleanup() { - echo "Cleaning up temporary files." - rm -rf "${ROOTPATH_TMP}" - rm -rf "${GENIMAGE_TMP}" -} - -# Setting up trap for cleanup on script exit -trap cleanup EXIT - -# Create temporary root path -ROOTPATH_TMP="$(mktemp -d)" - -# Generate image using genimage -echo "Generating image with genimage..." -genimage \ - --rootpath "${ROOTPATH_TMP}" \ - --tmppath "${GENIMAGE_TMP}" \ - --inputpath "${BINARIES_DIR}" \ - --outputpath "${BINARIES_DIR}" \ - --config "${GENIMAGE_CFG}" - -if [ $? -ne 0 ]; then - echo "Error during image generation." - exit 1 -fi - -# Create SWU file -echo "Creating SWU file..." -create_swu_file "${BINARIES_DIR}" "${SWUPDATE_FILES[@]}" diff --git a/buildroot-external/board/ovos/raspberrypi/rpi3/post-build.sh b/buildroot-external/board/ovos/raspberrypi/rpi3/post-build.sh deleted file mode 120000 index cd7f1164..00000000 --- a/buildroot-external/board/ovos/raspberrypi/rpi3/post-build.sh +++ /dev/null @@ -1 +0,0 @@ -../post-build.sh \ No newline at end of file diff --git a/buildroot-external/board/ovos/raspberrypi/rpi3/post-image.sh b/buildroot-external/board/ovos/raspberrypi/rpi3/post-image.sh deleted file mode 120000 index ae6294fa..00000000 --- a/buildroot-external/board/ovos/raspberrypi/rpi3/post-image.sh +++ /dev/null @@ -1 +0,0 @@ -../post-image.sh \ No newline at end of file diff --git a/buildroot-external/board/ovos/raspberrypi/rpi4/post-build.sh b/buildroot-external/board/ovos/raspberrypi/rpi4/post-build.sh deleted file mode 120000 index cd7f1164..00000000 --- a/buildroot-external/board/ovos/raspberrypi/rpi4/post-build.sh +++ /dev/null @@ -1 +0,0 @@ -../post-build.sh \ No newline at end of file diff --git a/buildroot-external/board/ovos/raspberrypi/rpi4/post-image.sh b/buildroot-external/board/ovos/raspberrypi/rpi4/post-image.sh deleted file mode 120000 index ae6294fa..00000000 --- a/buildroot-external/board/ovos/raspberrypi/rpi4/post-image.sh +++ /dev/null @@ -1 +0,0 @@ -../post-image.sh \ No newline at end of file diff --git a/buildroot-external/configs/ova_64_defconfig b/buildroot-external/configs/ova_64_defconfig index 47b6ef0d..2d41ebb6 100644 --- a/buildroot-external/configs/ova_64_defconfig +++ b/buildroot-external/configs/ova_64_defconfig @@ -24,9 +24,9 @@ BR2_GENERATE_LOCALE="en_US.UTF-8" BR2_SYSTEM_ENABLE_NLS=y BR2_ROOTFS_USERS_TABLES="$(BR2_EXTERNAL)/user_table.txt" BR2_ROOTFS_OVERLAY="$(BR2_EXTERNAL)/rootfs-overlay $(BR2_EXTERNAL)/board/ovos/ova/rootfs-overlay" -BR2_ROOTFS_POST_BUILD_SCRIPT="$(BR2_EXTERNAL)/board/ovos/ova/post-build.sh" -BR2_ROOTFS_POST_IMAGE_SCRIPT="$(BR2_EXTERNAL)/board/ovos/ova/post-image.sh" -BR2_ROOTFS_POST_SCRIPT_ARGS="--ova" +BR2_ROOTFS_POST_BUILD_SCRIPT="$(BR2_EXTERNAL)/scripts/post-build.sh" +BR2_ROOTFS_POST_IMAGE_SCRIPT="$(BR2_EXTERNAL)/scripts/post-image.sh" +BR2_ROOTFS_POST_SCRIPT_ARGS="$(BR2_EXTERNAL)/board/ovos/ova" BR2_LINUX_KERNEL=y BR2_LINUX_KERNEL_CUSTOM_VERSION=y BR2_LINUX_KERNEL_CUSTOM_VERSION_VALUE="6.1.69" diff --git a/buildroot-external/configs/rpi3_64_defconfig b/buildroot-external/configs/rpi3_64_defconfig index 8c2d18a1..777956b0 100644 --- a/buildroot-external/configs/rpi3_64_defconfig +++ b/buildroot-external/configs/rpi3_64_defconfig @@ -24,9 +24,9 @@ BR2_GENERATE_LOCALE="en_US.UTF-8" BR2_SYSTEM_ENABLE_NLS=y BR2_ROOTFS_USERS_TABLES="$(BR2_EXTERNAL)/user_table.txt" BR2_ROOTFS_OVERLAY="$(BR2_EXTERNAL)/rootfs-overlay $(BR2_EXTERNAL)/board/ovos/raspberrypi/rootfs-overlay $(BR2_EXTERNAL)/board/ovos/raspberrypi/rpi3/rootfs-overlay" -BR2_ROOTFS_POST_BUILD_SCRIPT="$(BR2_EXTERNAL)/board/ovos/raspberrypi/rpi3/post-build.sh" -BR2_ROOTFS_POST_IMAGE_SCRIPT="$(BR2_EXTERNAL)/board/ovos/raspberrypi/rpi3/post-image.sh" -BR2_ROOTFS_POST_SCRIPT_ARGS="--rpi3" +BR2_ROOTFS_POST_BUILD_SCRIPT="$(BR2_EXTERNAL)/scripts/post-build.sh" +BR2_ROOTFS_POST_IMAGE_SCRIPT="$(BR2_EXTERNAL)/scripts/post-image.sh" +BR2_ROOTFS_POST_SCRIPT_ARGS="$(BR2_EXTERNAL)/board/ovos/raspberrypi/rpi3" BR2_LINUX_KERNEL=y BR2_LINUX_KERNEL_CUSTOM_TARBALL=y BR2_LINUX_KERNEL_CUSTOM_TARBALL_LOCATION="$(call github,raspberrypi,linux,342c7ee49e862edc30c893f141f55b9211b7a43b)/linux-342c7ee49e862edc30c893f141f55b9211b7a43b.tar.gz" diff --git a/buildroot-external/configs/rpi4_64_defconfig b/buildroot-external/configs/rpi4_64_defconfig index 3bc24cf2..c95bc6c2 100644 --- a/buildroot-external/configs/rpi4_64_defconfig +++ b/buildroot-external/configs/rpi4_64_defconfig @@ -25,9 +25,9 @@ BR2_GENERATE_LOCALE="en_US.UTF-8" BR2_SYSTEM_ENABLE_NLS=y BR2_ROOTFS_USERS_TABLES="$(BR2_EXTERNAL)/user_table.txt" BR2_ROOTFS_OVERLAY="$(BR2_EXTERNAL)/rootfs-overlay $(BR2_EXTERNAL)/board/ovos/raspberrypi/rootfs-overlay $(BR2_EXTERNAL)/board/ovos/raspberrypi/rpi4/rootfs-overlay" -BR2_ROOTFS_POST_BUILD_SCRIPT="$(BR2_EXTERNAL)/board/ovos/raspberrypi/rpi4/post-build.sh" -BR2_ROOTFS_POST_IMAGE_SCRIPT="$(BR2_EXTERNAL)/board/ovos/raspberrypi/rpi4/post-image.sh" -BR2_ROOTFS_POST_SCRIPT_ARGS="--rpi4" +BR2_ROOTFS_POST_BUILD_SCRIPT="$(BR2_EXTERNAL)/scripts/post-build.sh" +BR2_ROOTFS_POST_IMAGE_SCRIPT="$(BR2_EXTERNAL)/scripts/post-image.sh" +BR2_ROOTFS_POST_SCRIPT_ARGS="$(BR2_EXTERNAL)/board/ovos/raspberrypi/rpi4" BR2_LINUX_KERNEL=y BR2_LINUX_KERNEL_CUSTOM_TARBALL=y BR2_LINUX_KERNEL_CUSTOM_TARBALL_LOCATION="$(call github,raspberrypi,linux,342c7ee49e862edc30c893f141f55b9211b7a43b)/linux-342c7ee49e862edc30c893f141f55b9211b7a43b.tar.gz" diff --git a/buildroot-external/configs/x86_64-base_defconfig b/buildroot-external/configs/x86_64-base_defconfig index 1f44341e..3c492c43 100644 --- a/buildroot-external/configs/x86_64-base_defconfig +++ b/buildroot-external/configs/x86_64-base_defconfig @@ -26,9 +26,9 @@ BR2_GENERATE_LOCALE="en_US.UTF-8" BR2_SYSTEM_ENABLE_NLS=y BR2_ROOTFS_USERS_TABLES="$(BR2_EXTERNAL)/user_table.txt" BR2_ROOTFS_OVERLAY="$(BR2_EXTERNAL)/rootfs-overlay/base $(BR2_EXTERNAL)/board/ovos/pc/rootfs-overlay/base" -BR2_ROOTFS_POST_BUILD_SCRIPT="$(BR2_EXTERNAL)/board/ovos/pc/post-build.sh" -BR2_ROOTFS_POST_IMAGE_SCRIPT="$(BR2_EXTERNAL)/board/ovos/pc/post-image.sh" -BR2_ROOTFS_POST_SCRIPT_ARGS="--x86" +BR2_ROOTFS_POST_BUILD_SCRIPT="$(BR2_EXTERNAL)/scripts/post-build.sh" +BR2_ROOTFS_POST_IMAGE_SCRIPT="$(BR2_EXTERNAL)/scripts/post-image.sh" +BR2_ROOTFS_POST_SCRIPT_ARGS="$(BR2_EXTERNAL)/board/ovos/pc" BR2_LINUX_KERNEL=y BR2_LINUX_KERNEL_CUSTOM_VERSION=y BR2_LINUX_KERNEL_CUSTOM_VERSION_VALUE="6.1.25" diff --git a/buildroot-external/package/ovos-containers/fetch-container-image.sh b/buildroot-external/package/ovos-containers/fetch-container-image.sh index 1fffcab1..624edcb6 100755 --- a/buildroot-external/package/ovos-containers/fetch-container-image.sh +++ b/buildroot-external/package/ovos-containers/fetch-container-image.sh @@ -2,7 +2,7 @@ # Original script from Home Assistant -set -euo pipefail +set -eu # Variables arch="$1" diff --git a/buildroot-external/scripts/post-build.sh b/buildroot-external/scripts/post-build.sh new file mode 100755 index 00000000..00ee0f77 --- /dev/null +++ b/buildroot-external/scripts/post-build.sh @@ -0,0 +1,119 @@ +#!/bin/sh + +set -eu + +# Define board directory and related variables +BOARD_DIR=$2 +BOARD_TYPE=$(basename "${BOARD_DIR}") + +# Source external metadata +. "${BR2_EXTERNAL_OPENVOICEOS_PATH}/meta" +. "${BOARD_DIR}/meta" + +# Function to create and write os-release file +write_os_release() { + local os_release_file="${TARGET_DIR}/usr/lib/os-release" + echo "Creating os-release at ${os_release_file}" + { + echo "NAME=\"${OVOS_NAME}\"" + echo "VERSION=\"${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_BUILD} ${BOARD_NAME}\"" + echo "ID=${OVOS_ID}" + echo "VERSION_ID=${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_BUILD}" + echo "PRETTY_NAME=\"${OVOS_NAME} ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_BUILD} ${BOARD_NAME}\"" + echo "CPE_NAME=cpe:2.3:o:openvoiceos:${OVOS_ID}:${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_BUILD}:*:${DEPLOYMENT}:*:*:*:${BOARD_ID}:*" + echo "HOME_URL=https://github.com/OpenVoiceOS/OpenVoiceOS" + echo "DOCUMENTATION_URL=https://github.com/OpenVoiceOS/OpenVoiceOS/tree/develop/documentation" + echo "SUPPORT_URL=https://github.com/OpenVoiceOS/OpenVoiceOS/issues" + echo "VARIANT=\"${OVOS_NAME} - Buildroot Edition\"" + echo "VARIANT_ID=${OVOS_ID}-${BOARD_ID}-buildroot" + } > "${os_release_file}" +} + +# Function to create and write machine-info file +write_machine_info() { + local machine_info_file="${TARGET_DIR}/etc/machine-info" + echo "Creating machine-info at ${machine_info_file}" + { + echo "CHASSIS=${CHASSIS}" + echo "DEPLOYMENT=${DEPLOYMENT}" + } > "${machine_info_file}" +} + +# Function to copy files based on board type +copy_board_specific_files() { + echo "Copying files for board type: ${BOARD_TYPE}" + + case "${BOARD_TYPE}" in + "rpi3"|"rpi4"|"rpi5") + cp -f "${BOARD_DIR}/../cmdline.txt" "${BINARIES_DIR}/rpi-firmware/cmdline.txt" + cp -f "${BOARD_DIR}/config.txt" "${BINARIES_DIR}/rpi-firmware/config.txt" + cp -f "${BOARD_DIR}/RPI_EFI.fd" "${BINARIES_DIR}/rpi-firmware/RPI_EFI.fd" + cp -f "${BOARD_DIR}/../grub-efi.cfg" "${BINARIES_DIR}/efi-part/EFI/BOOT/grub.cfg" + cp -f "${BOARD_DIR}/sw-description" "${BINARIES_DIR}" + ;; + "ova") + cp -f "${BOARD_DIR}/grub-efi.cfg" "${BINARIES_DIR}/efi-part/EFI/BOOT/grub.cfg" + cp -f "${BOARD_DIR}/cmdline.txt" "${BINARIES_DIR}" + cp -f "${BOARD_DIR}/sw-description" "${BINARIES_DIR}" + ;; + "pc") + cp -f "${BOARD_DIR}/grub-efi.cfg" "${BINARIES_DIR}/efi-part/EFI/BOOT/grub.cfg" + ;; + *) + echo "No specific files to copy for board type: ${BOARD_TYPE}" + ;; + esac +} + +# Function to handle kernel renaming based on board type +handle_kernel_renaming() { + case "${BOARD_TYPE}" in + "rpi3"|"rpi4"|"rpi5") + grub-editenv "${BINARIES_DIR}/efi-part/EFI/BOOT/grubenv" create + if [ -f "${TARGET_DIR}/boot/Image" ]; then + echo "Found Image, renaming to kernel" + mv "${TARGET_DIR}/boot/Image" "${TARGET_DIR}/boot/kernel" + fi + ;; + "ova") + grub-editenv "${BINARIES_DIR}/efi-part/EFI/BOOT/grubenv" create + if [ -f "${TARGET_DIR}/boot/bzImage" ]; then + echo "Found bzImage, renaming to kernel" + mv "${TARGET_DIR}/boot/bzImage" "${TARGET_DIR}/boot/kernel" + fi + ;; + "x86_64") + # No kernel renaming logic needed for x86_64 + ;; + esac +} + +# Main function to execute script logic +main() { + write_os_release + write_machine_info + copy_board_specific_files + handle_kernel_renaming + + # Prepare and sync home data + local home_img="${BINARIES_DIR}/homefs.ext4" + echo "Preparing home data at ${home_img}" + rm -f "${home_img}" + truncate --size="6890M" "${home_img}" + mkfs.ext4 -L "homefs" -E lazy_itable_init=0,lazy_journal_init=0 "${home_img}" + + local home_mount_point="${BINARIES_DIR}/home" + mkdir -p "${home_mount_point}" + sudo mount -o loop,discard "${home_img}" "${home_mount_point}" + sudo rsync -ah --progress "${TARGET_DIR}/home/"* "${home_mount_point}/" + sudo umount "${home_img}" +} + +# Ensure the script is called with the correct number of arguments +if [ "$#" -ne 2 ]; then + echo "Usage: $0 " + exit 1 +fi + +# Call the main function +main \ No newline at end of file diff --git a/buildroot-external/scripts/post-image.sh b/buildroot-external/scripts/post-image.sh new file mode 100755 index 00000000..3078092a --- /dev/null +++ b/buildroot-external/scripts/post-image.sh @@ -0,0 +1,68 @@ +#!/bin/bash + +set -eu + +# Define board directory and related variables +BOARD_DIR=$2 +BOARD_TYPE="$(basename "${BOARD_DIR}")" +GENIMAGE_CFG="${BOARD_DIR}/genimage-${BOARD_TYPE}.cfg" +GENIMAGE_TMP="${BUILD_DIR}/genimage.tmp" + +# Define files for SWUPDATE +SWUPDATE_FILES=("sw-description" "rootfs.squashfs") + +# Function to create SWU file +create_swu_file() { + local binaries_dir=$1 + local files=("${@:2}") + + pushd "${binaries_dir}" > /dev/null + printf '%s\n' "${files[@]}" | cpio -ov -H crc > rootfs.swu + popd > /dev/null +} + +# Clean up function for EXIT trap +cleanup() { + echo "Cleaning up temporary files." + rm -rf "${ROOTPATH_TMP}" "${GENIMAGE_TMP}" +} + +# Main function to execute script logic +main() { + # Check if necessary files and directories exist + if [ ! -d "${BUILD_DIR}" ] || [ ! -f "${GENIMAGE_CFG}" ]; then + echo "Required directories or config files are missing." + exit 1 + fi + + # Generate image using genimage + echo "Generating image with genimage..." + if ! genimage \ + --rootpath "${ROOTPATH_TMP}" \ + --tmppath "${GENIMAGE_TMP}" \ + --inputpath "${BINARIES_DIR}" \ + --outputpath "${BINARIES_DIR}" \ + --config "${GENIMAGE_CFG}"; then + echo "Error during image generation." + exit 1 + fi + + # Create SWU file + echo "Creating SWU file..." + create_swu_file "${BINARIES_DIR}" "${SWUPDATE_FILES[@]}" +} + +# Setting up trap for cleanup on script exit +trap cleanup EXIT + +# Check for correct number of arguments +if [ "$#" -ne 2 ]; then + echo "Usage: $0 " + exit 1 +fi + +# Create temporary root path +ROOTPATH_TMP="$(mktemp -d)" + +# Call the main function +main