diff --git a/classes/omnect_initramfs.bbclass b/classes/omnect_initramfs.bbclass index 3bf205666..b7a0c8b78 100644 --- a/classes/omnect_initramfs.bbclass +++ b/classes/omnect_initramfs.bbclass @@ -11,15 +11,3 @@ IMAGE_FEATURES = "" IMAGE_LINGUAS = "" KERNELDEPMODDEPEND = "" IMAGE_NAME_SUFFIX = "" - -# don't use rootfs module initramfs-framework-base -BAD_RECOMMENDATIONS += "initramfs-module-rootfs" - -# check consistency of script ordering -ROOTFS_POSTPROCESS_COMMAND:append = " omnect_initramfs_check;" -omnect_initramfs_check() { - file_numbers=$(ls -1 ${IMAGE_ROOTFS}/init.d/ | sed 's/^\([0-9]\+\)-.*$/\1/g') - if [ "$(echo ${file_numbers})" != "$(echo ${file_numbers} | sort -u)" ]; then - bbfatal "wrong script ordering in ${IMAGE_ROOTFS}/init.d/" - fi -} diff --git a/conf/machine/include/phytec-imx8mm.inc b/conf/machine/include/phytec-imx8mm.inc index 5346008c8..e4fda0960 100644 --- a/conf/machine/include/phytec-imx8mm.inc +++ b/conf/machine/include/phytec-imx8mm.inc @@ -112,4 +112,4 @@ OMNECT_BOOTLOADER_RECIPE_PATH = "${LAYERDIR_phytec}/recipes-bsp/u-boot/u-boot-ph # OMNECT_BOOTLOADER_CHECKSUM_EXPTECTED:pn-bootloader-versioned - build will fail, if the # computed checksum is different to this; set to when # OMNECT_BOOTLOADER_CHECKSUM_COMPATIBLE:pn-bootloader-versioned is set -OMNECT_BOOTLOADER_CHECKSUM_EXPECTED:pn-bootloader-versioned = "5165f005922e91b9513e4316db9316097f421109e2e678f6aed21f3a5cfbff51" +OMNECT_BOOTLOADER_CHECKSUM_EXPECTED:pn-bootloader-versioned = "73d490ae9bf6014a6c18c34d002a4cd07d00587afb4a3b84cae957466df3fbad" diff --git a/recipes-bsp/grub/grub-efi/omnect.inc.in b/recipes-bsp/grub/grub-efi/omnect.inc.in index 0001a1101..95769f0d4 100644 --- a/recipes-bsp/grub/grub-efi/omnect.inc.in +++ b/recipes-bsp/grub/grub-efi/omnect.inc.in @@ -32,17 +32,13 @@ else save_env omnect_validate_update_failed fi -if [ "x${omnect_rootblk}" != "x" ]; then - set kernel_param_rootblk=rootblk=${omnect_rootblk} - export kernel_param_rootblk -fi - if [ "${default}" != "Certificate Provision" ]; then set default="omnect-os" fi menuentry 'omnect-os' --unrestricted { set root=(hd0,gpt${omnect_os_bootpart}) - linux /boot/bzImage rootpart=${omnect_os_bootpart} ${kernel_param_rootblk} ${omnect_extra_bootargs} @@OMNECT_APPEND_1ST_BOOT@@ + probe --set=bootpart_fsuuid --fs-uuid ${root} + linux /boot/bzImage rootpart=${omnect_os_bootpart} bootpart_fsuuid=${bootpart_fsuuid} ${kernel_param_rootblk} ${omnect_extra_bootargs} @@OMNECT_APPEND_1ST_BOOT@@ initrd /boot/initramfs.cpio.gz } diff --git a/recipes-bsp/grub/grub-efi_%.bbappend b/recipes-bsp/grub/grub-efi_%.bbappend index 71d28ded1..1a1020c83 100644 --- a/recipes-bsp/grub/grub-efi_%.bbappend +++ b/recipes-bsp/grub/grub-efi_%.bbappend @@ -25,4 +25,4 @@ do_install:append:class-target() { install -m 0644 ${WORKDIR}/grubenv ${D}${EFI_BOOT_PATH}/grubenv } -GRUB_BUILDIN:append = " echo sleep" +GRUB_BUILDIN:append = " echo sleep probe" diff --git a/recipes-bsp/u-boot/u-boot/omnect_env.h b/recipes-bsp/u-boot/u-boot/omnect_env.h index f4249c0aa..d1dc3744d 100644 --- a/recipes-bsp/u-boot/u-boot/omnect_env.h +++ b/recipes-bsp/u-boot/u-boot/omnect_env.h @@ -6,6 +6,10 @@ /* Attention: if vars are already part of CONFIG_EXTRA_ENV_SETTINGS * this doesnt work; these vars are shown correctly via userland fw_printenv, * but u-boot takes the default env value + * + * Every variable the OS writes at runtime belongs in this list. An unlisted + * variable is not guaranteed to survive a u-boot saveenv, which + * omnect_update_flow performs on the update paths. */ #define OMNECT_REQUIRED_WRITEABLE_ENV_FLAGS_EXTRA #define OMNECT_REQUIRED_WRITEABLE_ENV_FLAGS \ @@ -15,6 +19,13 @@ "flash-mode-devpath:sw," \ "omnect_bootloader_updated:bw," \ "omnect_extra_bootargs:sw," \ + "omnect_factory_reset_last_error:sw," \ + "omnect_first_boot_done:bw," \ + "omnect_fsck_boot:sw," \ + "omnect_fsck_cert:sw," \ + "omnect_fsck_data:sw," \ + "omnect_fsck_etc:sw," \ + "omnect_fsck_factory:sw," \ "omnect_os_bootpart:dw," \ "omnect_validate_extra_bootargs:sw," \ "omnect_validate_update:bw," \ diff --git a/recipes-omnect/images/omnect-os-initramfs.bb b/recipes-omnect/images/omnect-os-initramfs.bb index bf8287811..d9f93c663 100644 --- a/recipes-omnect/images/omnect-os-initramfs.bb +++ b/recipes-omnect/images/omnect-os-initramfs.bb @@ -13,51 +13,35 @@ inherit omnect_initramfs IMAGE_NAME = "${OMNECT_INITRAMFS_IMAGE_NAME}" -FLASH_MODE_X_PACKAGES = " \ - bmaptool \ - dhcpcd \ - xz \ -" - GRUB_SUPPORT_PACKAGES = " \ grub-editenv \ grub-env \ " +UBOOT_SUPPORT_PACKAGES = " \ + libubootenv \ + libubootenv-bin \ +" RESIZE_DATA_PACKAGES = "\ e2fsprogs-resize2fs \ gptfdisk \ parted \ " -UBOOT_SUPPORT_PACKAGES = " \ - libubootenv \ - libubootenv-bin \ -" - PACKAGE_INSTALL = "\ - base-passwd \ + bash \ coreutils \ - dosfstools \ - e2fsprogs \ + e2fsprogs-e2fsck \ e2fsprogs-mke2fs \ - e2fsprogs-tune2fs \ - initramfs-framework-base \ - initramfs-module-debug \ - jq \ - kmod \ - omnect-os-initramfs-scripts \ + e2fsprogs-tune2fs \ + omnect-os-init \ os-release \ + util-linux-blkid \ util-linux-fsck \ util-linux-sfdisk \ - util-linux-uuidgen \ ${ROOTFS_BOOTSTRAP_INSTALL} \ ${VIRTUAL-RUNTIME_base-utils} \ - ${@bb.utils.contains('DISTRO_FEATURES', 'flash-mode-2', '${FLASH_MODE_X_PACKAGES} dropbear', '', d)} \ - ${@bb.utils.contains('DISTRO_FEATURES', 'flash-mode-3', '${FLASH_MODE_X_PACKAGES} curl', '', d)} \ ${@bb.utils.contains('DISTRO_FEATURES', 'resize-data', '${RESIZE_DATA_PACKAGES}', '', d)} \ - ${@bb.utils.contains('MACHINE_FEATURES', 'efi', 'efibootmgr', '', d)} \ - ${@bb.utils.contains('OMNECT_RELEASE_IMAGE', '1', '', 'initramfs-module-debug', d)} \ " PACKAGE_INSTALL:append:omnect_grub = " ${GRUB_SUPPORT_PACKAGES}" @@ -77,4 +61,4 @@ add_fsck_vfat_support() { inherit ${@bb.utils.contains('DISTRO_FEATURES', 'flash-mode-2', 'omnect_user', '', d)} inherit ${@bb.utils.contains('DISTRO_FEATURES', 'efi-secure-boot', 'user-key-store', '', d)} -inherit omnect-initramfs-sign \ No newline at end of file +inherit omnect-initramfs-sign diff --git a/recipes-omnect/initrdscripts/omnect-os-initramfs-scripts.bb b/recipes-omnect/initrdscripts/omnect-os-initramfs-scripts.bb deleted file mode 100644 index c90787e28..000000000 --- a/recipes-omnect/initrdscripts/omnect-os-initramfs-scripts.bb +++ /dev/null @@ -1,94 +0,0 @@ -FILESEXTRAPATHS:prepend := "${THISDIR}/omnect-os-initramfs:" - -LICENSE = "MIT | Apache-2.0" - -LIC_FILES_CHKSUM = "\ - file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302 \ - file://${COMMON_LICENSE_DIR}/Apache-2.0;md5=89aea4e17d99a7cacdbeed46a0096b10 \ -" -SRC_URI = "\ - file://rootblk-dev \ - file://common-sh \ - file://factory-reset \ - file://flash-mode-1 \ - file://fs-link \ - file://fs-mount \ - file://omnect-device-service-setup \ -" -SRC_URI:append = "${@bb.utils.contains('DISTRO_FEATURES', 'flash-mode-2', ' file://flash-mode-2', '', d)}" -SRC_URI:append = "${@bb.utils.contains('DISTRO_FEATURES', 'flash-mode-3', ' file://flash-mode-3', '', d)}" -SRC_URI:append = "${@bb.utils.contains('DISTRO_FEATURES', 'resize-data', ' file://resize-data', '', d)}" -SRC_URI:append = "${@bb.utils.contains('DISTRO_FEATURES', 'persistent-var-log', ' file://persistent-var-log', '', d)}" -SRC_URI:append:mx8mm-nxp-bsp = " file://imx-sdma" -SRC_URI:append:omnect_grub = " file://grub-sh" -SRC_URI:append:omnect_uboot = " file://uboot-sh" - -DEPENDS = "bc-native" -RDEPENDS:${PN} = "bash" - -do_install() { - install -m 0755 -D ${WORKDIR}/common-sh ${D}/init.d/05-common_sh - install -m 0755 -D ${WORKDIR}/rootblk-dev ${D}/init.d/10-rootblk_dev - - install -m 0755 -D ${WORKDIR}/factory-reset ${D}/init.d/86-factory_reset - - install -m 0755 -D ${WORKDIR}/flash-mode-1 ${D}/init.d/87-flash_mode_1 - # set variables templates - sed -i -e 's|^\(UBOOT_ENV1_START\)="UNDEFINED"|\1="${OMNECT_PART_OFFSET_UBOOT_ENV1}"|' \ - -e 's|^\(UBOOT_ENV2_START\)="UNDEFINED"|\1="${OMNECT_PART_OFFSET_UBOOT_ENV2}"|' \ - -e 's|^\(UBOOT_ENV_SIZE\)="UNDEFINED"|\1="${OMNECT_PART_SIZE_UBOOT_ENV}"|' \ - -e 's|^\(DATA_SIZE\)="UNDEFINED"|\1="${OMNECT_PART_SIZE_DATA}"|' \ - ${D}/init.d/87-flash_mode_1 - if [ -n "${BOOTLOADER_SEEK}" ]; then - sed -i -e 's|^\(BOOTLOADER_START\)="UNDEFINED"|\1="${BOOTLOADER_SEEK}"|' ${D}/init.d/87-flash_mode_1 - fi - - if ${@bb.utils.contains('DISTRO_FEATURES', 'flash-mode-2', 'true', 'false', d)}; then - install -m 0755 -D ${WORKDIR}/flash-mode-2 ${D}/init.d/87-flash_mode_2 - # bitbake doesn't parse bash arithmetic expression, so we use bc - dd_zero_size=$(echo "${OMNECT_PART_OFFSET_BOOT} + ${OMNECT_PART_SIZE_BOOT}" | bc) - sed -i -e "s/@@DD_ZERO_SIZE@@/${dd_zero_size}/g" \ - -e "s/@@DIRECT_FLASHING@@/${@oe.utils.conditional('OMNECT_FLASH_MODE_2_DIRECT_FLASHING', '1', 'true', 'false', d)}/g" \ - ${D}/init.d/87-flash_mode_2 - fi - if ${@bb.utils.contains('DISTRO_FEATURES', 'flash-mode-3', 'true', 'false', d)}; then - install -m 0755 -D ${WORKDIR}/flash-mode-3 ${D}/init.d/87-flash_mode_3 - fi - if ${@bb.utils.contains('DISTRO_FEATURES', 'resize-data', 'true', 'false', d)}; then - install -m 0755 -D ${WORKDIR}/resize-data ${D}/init.d/88-resize_data - fi - install -m 0755 -D ${WORKDIR}/fs-mount ${D}/init.d/89-fs_mount - if ${@bb.utils.contains('DISTRO_FEATURES', 'persistent-var-log', 'true', 'false', d)}; then - install -m 0755 -D ${WORKDIR}/persistent-var-log ${D}/init.d/90-persistent_var_log - fi - install -m 0755 -D ${WORKDIR}/omnect-device-service-setup ${D}/init.d/95-omnect_device_service_setup - install -m 0755 -D ${WORKDIR}/fs-link ${D}/init.d/96-fs_link -} - -do_install:append:mx8mm-nxp-bsp () { - install -m 0755 -D ${WORKDIR}/imx-sdma ${D}/init.d/90-imx_sdma -} - -do_install:append:omnect_grub () { - install -m 0755 -D ${WORKDIR}/grub-sh ${D}/init.d/09-bootloader_sh -} - -do_install:append:omnect_uboot () { - install -m 0755 -D ${WORKDIR}/uboot-sh ${D}/init.d/09-bootloader_sh -} - -FILES:${PN} = "\ - /init.d/05-common_sh \ - /init.d/09-bootloader_sh \ - /init.d/10-rootblk_dev \ - /init.d/86-factory_reset \ - /init.d/87-flash_mode_1 \ - /init.d/89-fs_mount \ - /init.d/95-omnect_device_service_setup \ - /init.d/96-fs_link \ -" -FILES:${PN}:append = "${@bb.utils.contains('DISTRO_FEATURES', 'flash-mode-2', ' /init.d/87-flash_mode_2', '', d)}" -FILES:${PN}:append = "${@bb.utils.contains('DISTRO_FEATURES', 'flash-mode-3', ' /init.d/87-flash_mode_3', '', d)}" -FILES:${PN}:append = "${@bb.utils.contains('DISTRO_FEATURES', 'resize-data', ' /init.d/88-resize_data', '', d)}" -FILES:${PN}:append = "${@bb.utils.contains('DISTRO_FEATURES', 'persistent-var-log', ' /init.d/90-persistent_var_log', '', d)}" -FILES:${PN}:append:mx8mm-nxp-bsp = " /init.d/90-imx_sdma" diff --git a/recipes-omnect/initrdscripts/omnect-os-initramfs/common-sh b/recipes-omnect/initrdscripts/omnect-os-initramfs/common-sh deleted file mode 100644 index 06682bee2..000000000 --- a/recipes-omnect/initrdscripts/omnect-os-initramfs/common-sh +++ /dev/null @@ -1,392 +0,0 @@ -# -# common helper functions -# - -common_sh_enabled() -{ - return 1 # there is no entry point in this library -} - -# - overwrites msg from initramfs-framework -# - we write to kmsg, so we can respect the kernel cmdline "quiet" argument -# and we're able to find the initramfs output in the journal -msg() { - echo "<6>omnect-os-initramfs: ${@}" > /dev/kmsg -} - -msg_fatal() { - echo "<2>omnect-os-initramfs: FATAL ERROR: ${@}" > /dev/kmsg -} - -msg_error() { - echo "<3>omnect-os-initramfs: ERROR: ${@}" > /dev/kmsg -} - -msg_warning() { - echo "<4>omnect-os-initramfs: WARNING: ${@}" > /dev/kmsg -} - -stderr_error() { - echo "ERROR: $@" >&2 -} - -stderr_fatal() { - echo "FATAL ERROR: $@" >&2 -} - -run_cmd() { - msg "$@" - # avoid errors with directly redirecting too long output to /dev/kmsg - out=$(eval "$@" 2>&1) - local result=$? - while read l; do echo -n "$l" > /dev/kmsg; done <<<"$out" - if [ ${result} -ne 0 ]; then msg_error "command \"$@\" failed: ${result}"; return ${result}; fi - return 0 -} - -run_cmd_stdout() { - echo "$@" - eval "$@" - local result=$? - if [ ${result} -ne 0 ]; then stderr_error "command \"$@\" failed: ${result}"; return ${result}; fi - return 0 -} - -# check filesystem -# re-format partition in the case of uncorrectable fsck errors or enforced flag -check_fs() -{ - local label=$1 # label - local fsck_res=0 - local kmsg_ratelimit=$(cat /proc/sys/kernel/printk_devkmsg) - - msg "check_fs /dev/omnect/${label}" - echo "on" > /proc/sys/kernel/printk_devkmsg - - # in case of EFI the boot partition gets checked multiple times - if [ -f /tmp/fsck_out.${label} ]; then - msg "already run fsck for \"${label}\"" - return 0 - fi - - fsck -y /dev/omnect/${label} &> /tmp/fsck_out.${label} - fsck_res=$? - msg "fsck result for \"${label}\" is ${fsck_res}" - msg "$( /proc/sys/kernel/printk_devkmsg - return 0 -} - -reformat_ext4_fs() { - local path="${1}" # filesystem - local label="${2}" - - # -- mkfs enforced OR uncorrectable fsck errors -- - msg "reformatting ${path} ..." - run_cmd mkfs.ext4 -F -q ${path} || return 1 - - # set ext4 label; disable enforced fsck - run_cmd tune2fs ${path} -c -1 -i 0 -L ${label} || return 1 - run_cmd sync -} - -# mount filesystem of partition -mount_partition() -{ - local fs_type="$1" # filesystem type - local blk_dev="$2" # block device name - local mnt_dir="$3" # mount point - local mnt_opts="$4" # mount options - - if [ -z "${blk_dev}" ] || [ ! -b "${blk_dev}" ]; then - msg_fatal "\"${blk_dev}\" not a valid block device" - return 1 - fi - - run_cmd mount -t "${fs_type}" -o "${mnt_opts}" "${blk_dev} " "${mnt_dir}" - return $? -} - -# mount overlay filesystem -mount_overlayfs() -{ - local lowerdir="$1" - local upperdir="$2" - local workdir="$3" - local mnt_opts="$4" # mount options - local mnt_dir="$5" # mount point - - run_cmd mount -t overlay \ - -o ${mnt_opts},lowerdir=${lowerdir},upperdir=${upperdir},workdir=${workdir} \ - overlay ${mnt_dir} -} - -# if etc partition is empty, copy the etc dir from factory partition -setup_etc_from_factory() -{ - local rootfs_dir="$1" - - if [ ! -d "${rootfs_dir}/mnt/etc/upper" ]; then - msg "first boot detected" - run_cmd mkdir -p "${rootfs_dir}/mnt/etc/upper" - run_cmd mkdir -p "${rootfs_dir}/mnt/etc/work" - if [ -d "${rootfs_dir}/mnt/factory/etc" ]; then - msg "setup etc from factory partition" - run_cmd cp -av "${rootfs_dir}/mnt/factory/etc/." "${rootfs_dir}/mnt/etc/upper" - fi - - # below has nothing to do with etc setup, but we only want to do this after flash-mode-1 - if [[ -f /run/factory-reset ]]; then - # unlikely case that the env changes during factory-reset, since we don't reset environment - # Note: if we would handle this case, we would have to reboot after factory-reset is done and thus - # lose the omnect-os-initramfs.json result - return 0 - fi - - local mounted=0 - if ! mountpoint -q ${ROOTFS_DIR}/boot; then - mkdir -p ${ROOTFS_DIR}/boot - check_fs "boot" - # Dangerous: This function gets potentially called when /dev/omnect/* doesn't exist yet (caused by the init script system) - # Currently it is safe - mount -t vfat /dev/omnect/boot ${ROOTFS_DIR}/boot && msg "mounted ${ROOTFS_DIR}/boot" || return 1 - mounted=1 - fi - local current_bootargs="$(get_bootloader_env_var "omnect_extra_bootargs")" - local new_bootargs="$(< ${ROOTFS_DIR}/boot/omnect_extra_bootargs_omnect)" - [ -r "${ROOTFS_DIR}/boot/omnect_extra_bootargs_custom" ] \ - && new_bootargs="${new_bootargs} $(< ${ROOTFS_DIR}/boot/omnect_extra_bootargs_custom)" - new_bootargs="$(echo ${new_bootargs} | awk '{$1=$1};1')" # remove possibly trailing space - msg "current_bootargs=${current_bootargs} new_bootargs=${new_bootargs}" - if [[ "${current_bootargs}" != "${new_bootargs}" ]]; then - set_bootloader_env_var "omnect_extra_bootargs" "${new_bootargs}" - msg "reboot by omnect_extra_bootargs handling on first boot" - sync - umount ${ROOTFS_DIR}/mnt/cert - umount ${ROOTFS_DIR}/mnt/etc - run_cmd reboot -f - fi - [[ ${mounted} -eq 1 ]] && umount ${ROOTFS_DIR}/boot - fi -} - -umount_rootfs_partition() -{ - local rootfs_dir="$1" - run_cmd umount "${rootfs_dir}" -} - -setup_etc_partition() -{ - local rootfs_dir="$1" - local mnt_opts="$2" - - msg "setup etc partition" - - # check etc partition to handle unclean (not unmounted) state - check_fs etc - - # mount etc partition - mount_partition "ext4" /dev/omnect/etc "${rootfs_dir}/mnt/etc" "${mnt_opts}" - - setup_etc_from_factory "${rootfs_dir}" - - # mount etc overlay - mount_overlayfs "${rootfs_dir}/etc" "${rootfs_dir}/mnt/etc/upper" "${rootfs_dir}/mnt/etc/work" \ - "${mnt_opts}",index=off "${rootfs_dir}/etc" -} - -umount_etc_partition() -{ - local rootfs_dir="$1" - - run_cmd umount "${rootfs_dir}/etc" - run_cmd umount "${rootfs_dir}/mnt/etc" -} - -setup_data_partition() -{ - local rootfs_dir="$1" - local mnt_opts="$2" - - msg "setup data partition" - - # check data partition to handle unclean (not unmounted) state - check_fs data - - # mount data partition - mount_partition "ext4" "/dev/omnect/data" "${rootfs_dir}/mnt/data" "${mnt_opts}" - - # mount home overlay - run_cmd mkdir -p "${rootfs_dir}/mnt/data/home/work" - run_cmd mkdir -p "${rootfs_dir}/mnt/data/home/upper" - run_cmd mkdir -p "${rootfs_dir}/mnt/data/var/lib" - run_cmd mkdir -p "${rootfs_dir}/mnt/data/local" - mount_overlayfs "${rootfs_dir}/home" "${rootfs_dir}/mnt/data/home/upper" "${rootfs_dir}/mnt/data/home/work" \ - "${mnt_opts}",index=off "${rootfs_dir}/home" - - # bind mount /var/lib - run_cmd mkdir -p "${rootfs_dir}/mnt/data/var/lib" - run_cmd mount -o bind "${rootfs_dir}/mnt/data/var/lib" "${rootfs_dir}/var/lib" - - # bind mount /usr/local - run_cmd mkdir -p "${rootfs_dir}/mnt/data/local" - run_cmd mount -o bind "${rootfs_dir}/mnt/data/local" "${rootfs_dir}/usr/local" -} - -umount_data_partition() -{ - local rootfs_dir="$1" - - run_cmd umount "${rootfs_dir}/usr/local" - run_cmd umount "${rootfs_dir}/var/lib" - run_cmd umount "${rootfs_dir}/home" - run_cmd umount "${rootfs_dir}/mnt/data" -} - -setup_persistent_var_log() -{ - local rootfs_dir="$1" - - if grep ^DISTRO_FEATURES ${rootfs_dir}/etc/os-release | grep -q '[" ]persistent-var-log[ "]'; then - msg "setup persistent var log" - run_cmd mkdir -p ${rootfs_dir}/mnt/data/log || return 1 - run_cmd mount -o bind ${rootfs_dir}/mnt/data/log ${rootfs_dir}/var/log || return 1 - fi - return $? -} - -umount_persistent_var_log() -{ - local rootfs_dir="$1" - - if grep ^DISTRO_FEATURES ${rootfs_dir}/etc/os-release | grep -q '[" ]persistent-var-log[ "]'; then - run_cmd umount ${rootfs_dir}/var/log - fi -} - -get_partition_type() -{ - local value=$(sfdisk -l /dev/omnect/rootblk 2>&1 | grep "^Disklabel type:" | awk '{print $NF}') - debug "get_partition_type: ${value}" - echo ${value} -} - -on_exit_debug_image() -{ - if [ "${return}" != "0" ]; then - echo "clear" >> /tmp/debug_init - echo "echo \"initramfs failed: ${1}\"" >> /tmp/debug_init - /bin/bash --init-file /tmp/debug_init - fi -} - -on_exit_release_image() -{ - # todo: as soon we have failure handling in the boot process, we should reboot here. - # for now, it would probably result in a reboot loop. so we don't. - if [ "${return}" != "0" ]; then - while true; do - msg_fatal "iniramfs failed: ${1}" - sleep 60 - done - fi -} - -on_exit() -{ - local release=$(grep ^OMNECT_RELEASE_IMAGE= /etc/os-release | awk -F'"' '{print $2}') - if [ "${release}" = "1" ]; then - on_exit_release_image ${2} - else - on_exit_debug_image ${2} - fi -} - -flash_mode_efi_handling() -{ - local dest_dev=${1} - local p=${2} - local machine_features=$(grep ^MACHINE_FEATURES= /etc/os-release | awk -F'"' '{print $2}') - local boot_dev="/dev/omnect/boot" - local ret=0 - - if [ -n "${dest_dev}" ]; then - boot_dev="${dest_dev}${p}1" - else - dest_dev="/dev/omnect/rootblk" - fi - - if [[ " ${machine_features} " =~ " efi " ]]; then - echo "Configuring efi" - # delete all efi entries - local efi_entries=$(efibootmgr | grep ^Boot[0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]\* | awk '{print $1}') - for i in ${efi_entries}; do - i=${i#Boot} - i=${i%\*} - run_cmd_stdout efibootmgr --bootnum ${i} --delete-bootnum || return 1 - done - - run_cmd_stdout mkdir -p /tmp/boot - run_cmd_stdout mount ${boot_dev} /tmp/boot - run_cmd_stdout efibootmgr --create --disk ${dest_dev} --part 1 --label "omnect_os" --loader \\\\EFI\\\\BOOT\\\\bootx64.efi - # same entry with another label ... for debug purposes, when booting after flash-mode-{1,2} fails - run_cmd_stdout efibootmgr --create --disk ${dest_dev} --part 1 --label "omnect_os " --loader \\\\EFI\\\\BOOT\\\\bootx64.efi - efibootmgr -v > /tmp/boot/EFI/BOOT/efibootmgr_entry - run_cmd_stdout umount /tmp/boot - fi - return $ret -} - -flash_mode_setup_network() { - local if_name="$1" - local ip_addr="" - - # get network interface up - while true; do - ifconfig ${if_name} up >/dev/null 2>&1 - if [ $? -eq 0 ]; then break; fi - msg "Waiting for ${if_name} ..." - sleep 1 - done - - # start dhcp client; it is backgrounding in the case the IP address was assigned or timeout - run_cmd mkdir -p /tmp || return 1 - run_cmd dhcpcd ${if_name} || return 1 - - # wait for IPv4 address - while true; do - msg "Waiting for IP address... on ${if_name}" - ip_addr=$(ip addr show dev ${if_name} | grep "inet " | awk '{print $2}') - if [ -n "${ip_addr}" ]; then break; fi - sleep 1 - done - FLASH_MODE_IP_ADDR="${ip_addr%/*}" - - # setup PTY - run_cmd mkdir -p /dev/pts || return 1 - run_cmd mount -t devpts devpts /dev/pts || return 1 - - # start SSH server; generate host key on the fly - mkdir -p /etc/dropbear - run_cmd dropbear -R || return 1 -} - -# get ID field from group file -get_id() { - local name="$1" - local file="$2" - - grep -E "^${name}:" "${file}" | awk -F: '{print $3}' -} diff --git a/recipes-omnect/initrdscripts/omnect-os-initramfs/factory-reset b/recipes-omnect/initrdscripts/omnect-os-initramfs/factory-reset deleted file mode 100644 index e6cf37b08..000000000 --- a/recipes-omnect/initrdscripts/omnect-os-initramfs/factory-reset +++ /dev/null @@ -1,337 +0,0 @@ -#!/bin/sh - -# -# handle triggered factory reset -# -# + The factory reset has to be performed before mounting the logical filesystem tree, -# because it re-formats the filesystems part of the partitions etc and data. - -factory_reset_backup_dir="/tmp/factory_reset/backup" -factory_reset="" -warnings="" -mount=0 - -# called by generic INITRAMFS -factory_reset_enabled() { - ret=0 - factory_reset=$(get_bootloader_env_var "factory-reset") - echo "null" > /tmp/factory-reset.json - if [ -z "${factory_reset}" ]; then - ret=1 # no factory reset triggered; normal boot - else - set_bootloader_env_var "factory-reset" "" - touch /run/factory-reset - fi - - # we already mounted /dev/omnect/boot when we're using grub. so we unmount so we don't disturb the restore mount/umount handling - if [ -f /usr/bin/grub-editenv ]; then - sync - run_cmd umount ${ROOTFS_DIR}/boot - fi - - return ${ret} -} - -# wipe a partition using dd command -# in the case of wear leveling, it does not guarantee strict privacy -wipe_partition_dd() { - local part="$1" - local seek_bytes=$((1024+1024)) # alignment + superblock - - if [ -z "${part}" ]; then return 1; fi - - # skip superblock, to keep label in the case of interruption; may take a longer time - run_cmd dd bs=1M if=/dev/urandom iflag=fullblock oflag=direct oflag=seek_bytes seek=${seek_bytes} of=${part} status=progress - sync - return 0 -} - -# wipe based on commands rm and fstrim -# assumption: the disk supports the ATA TRIM command -# in the case of wear leveling, it does not guarantee strict privacy -wipe_partition_fstrim() { - local part="$1" - local mnt_point="/tmp/mnt" - - if [ -z "${part}" ]; then return 1; fi - - run_cmd mkdir -p ${mnt_point} - run_cmd mount ${part} ${mnt_point} || return 0 # abort in case of failed mount - cd ${mnt_point} || return 1 - # 1st: remove all - run_cmd /bin/rm -rf * - cd - >/dev/null - # 2nd: tell the disk the removed blocks - run_cmd fstrim -v ${mnt_point} - run_cmd umount ${mnt_point} - return 0 -} - -factory_reset_wipe_dd() { - local ret=0 - - msg "wipe method 1" - wipe_partition_dd /dev/omnect/etc || ret=$? - wipe_partition_dd /dev/omnect/data || ret=$? - return ${ret} -} - -factory_reset_wipe_fstrim() { - local ret=0 - - msg "wipe method 2" - wipe_partition_fstrim /dev/omnect/etc || ret=$? - wipe_partition_fstrim /dev/omnect/data || ret=$? - return ${ret} -} - -factory_reset_wipe_custom() { - local custom_wipe="/opt/factory_reset/custom-wipe" - - if [ ! -x ${custom_wipe} ]; then - msg "ERROR: custom wipe \"${custom_wipe}\" not found or executable; abort..." - return 2 - fi - msg "Running custom wipe ${custom_wipe}..." - run_cmd ${custom_wipe} - if [ $? -ne 0 ]; then - msg "ERROR: custom wipe \"${custom_wipe}\" failed; abort..." - return 1 - fi - return 0 -} - -# backup file or directory -factory_reset_backup() { - local path_name="$1" # file or directory - local ret=0 - - msg "backup: ${path_name}" - - if [ ! -e "${ROOTFS_DIR}/${path_name}" ]; then - msg "->does not exist; ignore..." - return 0 - fi - - # do backup, keep permissions and ownership - run_cmd cp --parents -av "${ROOTFS_DIR}/${path_name}" "${factory_reset_backup_dir}" - ret=$? - - sync - return ${ret} -} - -factory_reset_restore() { - local path_name="$1" # file or directory - local ret=0 - local destpath=$(dirname ${ROOTFS_DIR}${path_name}) - local nested_mount="" - - msg "restore: ${path_name}" - - if [ ! -e "${factory_reset_backup_dir}/${ROOTFS_DIR}/${path_name}" ]; then - msg "->does not exist; ignore..." - return 0 - fi - - while [[ "${destpath}" != "${ROOTFS_DIR}" ]]; do - mountpoint -q ${destpath} && nested_mount=${destpath/${ROOTFS_DIR}} && break - destpath=$(dirname ${destpath}) - done - - # do restore, keep permissions and ownership - if [ -n "${nested_mount}" ]; then - msg "nested mount: ${factory_reset_backup_dir}/${ROOTFS_DIR}${nested_mount}" - cd ${factory_reset_backup_dir}/${ROOTFS_DIR}${nested_mount} - path_name=${path_name#${nested_mount}\/} - run_cmd cp --parents -av "${path_name}" "${ROOTFS_DIR}${nested_mount}" - ret=$? - cd - &>/dev/null - else - msg_error "restore: no mountpoint found in destination path: ${destpath}" - ret=66 - fi - - - sync - return ${ret} -} - -iterate_restore_list() { - local do_backup="${1}" - local restore_list=( "${@:2}" ) - - local ret=0 - local status=0 - local context="" - - for i in ${restore_list[@]}; do - if [ ${do_backup} -eq 1 ]; then - factory_reset_backup "${i}"; ret=$? - [[ ${ret} -ne 0 ]] && { handle_status "2" "${ret}" "${i}:backup" "${restore_list[@]}"; return ${ret}; } - else - factory_reset_restore "${i}"; ret=$? - if [ ${ret} -ne 0 ]; then - status=2; - context+="${i};" - fi # continue restoring next paths; deliver failure - fi - done - - if [ 2 -eq ${status} ]; then - context="${context%?}:restore" - handle_status "${status}" "${ret}" "${context}" "${restore_list[@]}" - return ${ret} - fi - - # ToDO reflect possible wiper error in status? - [[ 0 -eq ${do_backup} ]] && handle_status "0" "0" "" "${restore_list[@]}" - sync - return 0 -} - -factory_reset_mount() { - mount=1 - mount_partition "ext4" "/dev/omnect/rootCurrent" "${ROOTFS_DIR}" "defaults,ro" - mount_partition "ext4" "/dev/omnect/factory" "${ROOTFS_DIR}/mnt/factory" "defaults,ro" - setup_etc_partition "${ROOTFS_DIR}" "defaults,rw" - setup_data_partition "${ROOTFS_DIR}" "defaults,rw" - setup_persistent_var_log "${ROOTFS_DIR}" -} - -factory_reset_umount() { - mount=0 - umount_persistent_var_log "${ROOTFS_DIR}" - umount_data_partition "${ROOTFS_DIR}" - umount_etc_partition "${ROOTFS_DIR}" - run_cmd umount "${ROOTFS_DIR}/mnt/factory" - umount_rootfs_partition "${ROOTFS_DIR}" - msg "mount: " - run_cmd mount -} - -handle_status() { - local status=${1} - local error=${2} - local context=${3} - local preserve_paths=( "${@:4}" ) - - msg "status: status=${status}, error=${error}, context=${context}, preserve_path=${preserve_paths[@]}" - if [ -n "${warnings}" ]; then - [[ -n "${context}" ]] && context+=";" - context+="${warnings}" - fi - - if [ -n "${context}" ]; then - echo "{}" | jq -e \ - --argjson status "${status}" \ - --arg error "${error}" \ - --arg context "${context}" \ - '.status=$status | .error=$error | .context=$context | .paths=$ARGS.positional' --args ${preserve_paths[@]} > \ - /tmp/factory-reset.json - else - echo "{}" | jq -e \ - --argjson status "${status}" \ - --arg error "${error}" \ - '.status=$status | .error=$error | .paths=$ARGS.positional' --args ${preserve_paths[@]} > \ - /tmp/factory-reset.json - fi -} - -factory_reset_post () { - [[ ${mount} -eq 1 ]] && factory_reset_umount -} - -# main entry point -factory_reset_run() { - local mode="" - local preserve="" - - add_module_post_hook factory_reset_post - - if [ -z "${ROOTFS_DIR}" ]; then - fatal "no ROOTFS_DIR" - return 1 - fi - mode=$(echo "${factory_reset}" | jq -e -r '.mode') || { handle_status "1" "-" "mode not set" ""; return; } - preserve=$(echo "${factory_reset}" | jq -e -r '.preserve') || { handle_status "3" "-" "preserve object not set" ""; return; } - if [ "[]" != "${preserve}" ]; then - preserve=($(echo "${factory_reset}" | jq -e -r '.preserve | .[]')) || { handle_status "3" "-" "could_not_parse_preserve_array" ""; return; } - else - preserve=() - fi - - msg "Running factory-reset [mode=${mode}, preserve=${preserve[@]}]..." - factory_reset_mount - - # create preserve_list - declare -a preserve_list - preserve_list+=("/etc/omnect/factory-reset.d/") - if [[ " ${preserve[@]} " =~ " applications " ]]; then - preserve=( ${preserve[@]/applications} ) - local preserve_path=""; - for i in $(find ${ROOTFS_DIR}/etc/omnect/factory-reset.d/ -iname *.json); do - preserve_path=$(jq -r -e '.paths' ${i}) || \ - { handle_status "3" "-" "${i/${ROOTFS_DIR}}: no path object" "${preserve_list[@]}"; return; } - if [ "[]" != "${preserve_path}" ]; then - preserve_list+=( $(jq -r -e '.paths[]' ${i}) ) || \ - { handle_status "3" "${?}" "${i/${ROOTFS_DIR}}: couldn't parse paths array" "${preserve_list[@]}"; return; } - fi - done - fi - - for key in "${preserve[@]}"; do - preserve_path=$(jq -r -e --arg key "${key}" .$key ${ROOTFS_DIR}/etc/omnect/factory-reset.json) || \ - { handle_status "3" "-" "${i/${ROOTFS_DIR}}: no ${key} object" "${preserve_list[@]}"; return; } - if [ "[]" != "${preserve_path}" ]; then - preserve_list+=( $(jq -r -e --arg key "${key}" .$key[] ${ROOTFS_DIR}/etc/omnect/factory-reset.json) ) || \ - { handle_status "3" "${?}" "${ROOTFS_DIR}/etc/omnect/factory-reset.json:${key}" "${preserve_list[@]}"; return; } - fi - done - - msg "factor-reset preserve_list=${preserve_list[@]}" - - # do the backup - run_cmd mkdir -p ${factory_reset_backup_dir} - iterate_restore_list 1 "${preserve_list[@]}" || return; - factory_reset_umount - - # possibly wipe - wipe_ret=0 - case ${mode} in - 1) wipe_ret=0 # no wipe - ;; - 2) factory_reset_wipe_dd - wipe_ret=$? - ;; - 3) factory_reset_wipe_fstrim - wipe_ret=$? - ;; - 4) factory_reset_wipe_custom - wipe_ret=$? - ;; - *) msg "ERROR: factory reset mode \"${mode}\" not supported; abort..." - handle_status "1" "-" "" "${preserve_list[@]}" - return 0 - ;; - esac - - # if we had a wipe error, we will try to continue anyway - if [ 0 -ne ${wipe_ret} ]; then - warning_wipe="warning: wipe failed with \"${wipe_ret}\"" - [[ -n "${warnings}" ]] && warnings+=";" - warnings+="${warning_wipe}" - msg_warning "${warning_wipe/"warning: "}" - fi - - # enforce mkfs - reformat_ext4_fs "/dev/omnect/data" "data" - reformat_ext4_fs "/dev/omnect/etc" "etc" - - # restore - factory_reset_mount # logical filesystem tree - iterate_restore_list 0 "${preserve_list[@]}" - factory_reset_umount - rm -f /run/factory-reset - msg "factory-reset done" -} diff --git a/recipes-omnect/initrdscripts/omnect-os-initramfs/flash-mode-1 b/recipes-omnect/initrdscripts/omnect-os-initramfs/flash-mode-1 deleted file mode 100644 index acb5053d7..000000000 --- a/recipes-omnect/initrdscripts/omnect-os-initramfs/flash-mode-1 +++ /dev/null @@ -1,256 +0,0 @@ -#!/bin/bash - -# -# optionally provide flashing whole disk image in INITRAMFS context -# - -# Flash Mode -# 1 clone disk image from active block device to other one -# -FLASH_MODE="" - -FLASH_MODE_VAR="flash-mode" -FLASH_MODE_DEVPATH_VAR="flash-mode-devpath" - -# variable templates, which are replaced at build time -BOOTLOADER_START="UNDEFINED" # optionally, start of bootloader area -UBOOT_ENV1_START="UNDEFINED" # start of first u-boot environment -UBOOT_ENV2_START="UNDEFINED" # start of second u-boot environment -UBOOT_ENV_SIZE="UNDEFINED" # size of u-boot environment -DATA_SIZE="UNDEFINED" # initial size of data partition (in KB) - -# called by generic INITRAMFS -flash_mode_1_enabled() { - debug "flash mode 1: ${FLASH_MODE} - ${FLASH_MODE_VAR}" - - # flash mode triggered at runtime - FLASH_MODE=$(get_bootloader_env_var ${FLASH_MODE_VAR}) - if [ "${FLASH_MODE}" == "1" ] && [ -n "${FLASH_MODE_VAR}" ]; then - return 0 # enable flash mode; call main entry point - fi - - return 1 # disable flash mode; normal boot; main entry point _NOT_ called -} - -get_start_sector() -{ - local part_dev="$(readlink -f $1)" - - sfdisk -d $(readlink -f /dev/omnect/rootblk) | \ - sed -n "s|^${part_dev}.*start=[[:space:]]\+\([[:digit:]]\+\),.*$|\1|p" -} - -# clone active disk image to other block device -run_flash_mode_1() { - local blk_dev_dst="" - local blk_dev_src="" - local data_partition="" - local data_partition_size="" - local data_partition_start="" - local efi_entries="" - local extended_partition="" - local extended_partition_size="" - local extended_partition_start="" - local last_lba="" - local machine_features=$(grep ^MACHINE_FEATURES= /etc/os-release | awk -F'"' '{print $2}') - local p="" - local part_type="" - - echo "Entering omnect flashing mode 1 ..." - - # detect destination block device from environment variable - blk_dev_dst=$(get_bootloader_env_var ${FLASH_MODE_DEVPATH_VAR} | cut -d= -f2) - blk_dev_dst=$(readlink -f ${blk_dev_dst}) - - # disable flash mode for subsequent restarts - set_bootloader_env_var ${FLASH_MODE_VAR} - set_bootloader_env_var ${FLASH_MODE_DEVPATH_VAR} - - # we already mounted /dev/omnect/boot when we're using grub. so we unmount before copying boot. - if [ -f /usr/bin/grub-editenv ]; then - sync - run_cmd umount ${ROOTFS_DIR}/boot - fi - - # check for (mandatory) substitutions of variable templates - if [[ ! " ${machine_features} " =~ " grub " ]]; then - if [ "${UBOOT_ENV1_START}" == "UNDEFINED" ]; then stderr_fatal "missing definition UBOOT_ENV1_START"; return 1; fi - if [ "${UBOOT_ENV2_START}" == "UNDEFINED" ]; then stderr_fatal "missing definition UBOOT_ENV2_START"; return 1; fi - if [ "${UBOOT_ENV_SIZE}" == "UNDEFINED" ]; then stderr_fatal "missing definition UBOOT_ENV_SIZE"; return 1; fi - fi - - if [ "${DATA_SIZE}" == "UNDEFINED" ]; then stderr_fatal "missing definition DATA_SIZE"; return 1; fi - - if [ -z "${blk_dev_dst}" ]; then - stderr_fatal "bootloader environment variable \"${FLASH_MODE_DEVPATH_VAR}\" not set" - return 1 - fi - for i in $(seq 1 30); do - if [ -b "${blk_dev_dst}" ]; then break; fi - echo "WAITING FOR destination block device \"${blk_dev_dst}\"..." - sleep 1 - done - if [ ${i} -eq 30 ]; then - stderr_fatal "cannot find destination block device \"${blk_dev_dst}\"" - return 1 - fi - - # detect source block device - blk_dev_src=$(readlink -f /dev/omnect/rootblk) - - if [ ! -b "${blk_dev_src}" ]; then stderr_fatal "${blk_dev_src} does not exist or not a block device"; return 1; fi - - if [ "${blk_dev_dst}" == "${blk_dev_src}" ]; then - stderr_fatal "identical source and destination: \"${blk_dev_dst}\"" - return 1 - fi - - data_partition=$(readlink -f /dev/omnect/data) - if [ -z "${data_partition}" ]; then - stderr_fatal "cannot detect data partition" - return 1 - fi - # adapt size of data partition to initial value, before (optional) resize of data partition - data_partition_size=$((DATA_SIZE * 2)) # 1024 (yocto) -> 512 (sfdisk) - - # check for partition type - part_type=$(get_partition_type) - if [ "${part_type}" = "gpt" ]; then - echo "DUMP gpt / partition table..." - data_partition_start=$(get_start_sector ${data_partition}) - last_lba=$((data_partition_start+data_partition_size-1)) - sfdisk --dump "${blk_dev_src}" | \ - sed "s|^last-lba: \(.*\)$|last-lba: ${last_lba}|g" | \ - sed "s|\(^${data_partition}.*size=[[:space:]]\+\)\([[:digit:]]\+,\)\(.*\)$|\1 ${data_partition_size}, \3|g" >/tmp/sfdisk.txt - elif [ "${part_type}" = "dos" ]; then - echo "DUMP mbr / partition table..." - extended_partition=$(readlink -f /dev/omnect/extended) - if [ -z "${extended_partition}" ]; then - stderr_fatal "cannot detect extended partition" - return 1 - fi - # calculate size of extended partition, not affected by (optional) resize of data partition - extended_partition_start=$(get_start_sector $(readlink -f extended)) - data_partition_start=$(get_start_sector ${data_partition}) - extended_partition_size=$((data_partition_start - extended_partition_start + data_partition_size)) - if [ -z "${extended_partition_size}" ]; then - stderr_fatal "cannot detect extended partition size" - return 1 - fi - - sfdisk --dump "${blk_dev_src}" | \ - sed "s|\(^${data_partition}.*size=[[:space:]]\+\)\([[:digit:]]\+,\)\(.*\)$|\1 ${data_partition_size}, \3|g" | \ - sed "s|\(^${extended_partition}.*size=[[:space:]]\+\)\([[:digit:]]\+,\)\(.*\)$|\1 ${extended_partition_size}, \3|g" >/tmp/sfdisk.txt - else - stderr_fatal "unhandled partition type: \"${part_type}\"" - return 1 - fi - - echo "######## cloning disk: ${blk_dev_src} -> ${blk_dev_dst} ########" - cat /tmp/sfdisk.txt - run_cmd_stdout "sfdisk ${blk_dev_dst} rootblk=/dev/sda vs root=/dev/mmcblk1p2 -> rootblk=/dev/mmcblk1 - if [ ! -b "${blk_dev_dst}1" ]; then - p="p" - fi - - echo "CHECK for new partition scheme.." - if [ ! -b "${blk_dev_dst}${p}1" ]; then stderr_fatal "\"${blk_dev_dst}${p}1\" is not a block device"; return 1; fi - if [ ! -b "${blk_dev_dst}${p}2" ]; then stderr_fatal "\"${blk_dev_dst}${p}2\" is not a block device"; return 1; fi - if [ ! -b "${blk_dev_dst}${p}3" ]; then stderr_fatal "\"${blk_dev_dst}${p}3\" is not a block device"; return 1; fi - if [ ! -b "${blk_dev_dst}${p}4" ]; then stderr_fatal "\"${blk_dev_dst}${p}4\" is not a block device"; return 1; fi - if [ ! -b "${blk_dev_dst}${p}5" ]; then stderr_fatal "\"${blk_dev_dst}${p}5\" is not a block device"; return 1; fi - if [ ! -b "${blk_dev_dst}${p}6" ]; then stderr_fatal "\"${blk_dev_dst}${p}6\" is not a block device"; return 1; fi - if [ ! -b "${blk_dev_dst}${p}7" ]; then stderr_fatal "\"${blk_dev_dst}${p}7\" is not a block device"; return 1; fi - if [ "${part_type}" = "dos" ]; then - if [ ! -b "${blk_dev_dst}${p}8" ]; then stderr_fatal "\"${blk_dev_dst}${p}8\" is not a block device"; return 1; fi - fi - - # handle u-boot not stored inside the boot partition - # e.g. not UNDEFINED if BOOTLOADER_SEEK is set (phytec boards) - if [ "${BOOTLOADER_START}" != "UNDEFINED" ]; then - echo "COPY u-boot..." - run_cmd_stdout dd if=${blk_dev_src} iflag=skip_bytes skip=$((BOOTLOADER_START*1024)) \ - of=${blk_dev_dst} oflag=seek_bytes seek=$((BOOTLOADER_START*1024)) \ - bs=1024 count=$((UBOOT_ENV1_START - BOOTLOADER_START)) || return 1 - fi - - # enforce first boot condition - echo "MKFS etc and data..." - - if [ "${part_type}" = "gpt" ]; then - reformat_ext4_fs "${blk_dev_dst}${p}6" "etc" - reformat_ext4_fs "${blk_dev_dst}${p}7" "data" - elif [ "${part_type}" = "dos" ]; then - reformat_ext4_fs "${blk_dev_dst}${p}7" "etc" - reformat_ext4_fs "${blk_dev_dst}${p}8" "data" - else - echo "unhandled partition type: ${part_type}" - fi - - echo "COPY boot, factory and cert..." - run_cmd_stdout dd if=/dev/omnect/boot of="$(readlink -f ${blk_dev_dst}${p}1)" bs=10M || return 1 - if [ "${part_type}" = "gpt" ]; then - run_cmd_stdout dd if=/dev/omnect/factory of="$(readlink -f ${blk_dev_dst}${p}4)" bs=10M || return 1 - run_cmd_stdout dd if=/dev/omnect/cert of="$(readlink -f ${blk_dev_dst}${p}5)" bs=10M || return 1 - elif [ "${part_type}" = "dos" ]; then - run_cmd_stdout dd if=/dev/omnect/factory of="$(readlink -f ${blk_dev_dst}${p}5)" bs=10M || return 1 - run_cmd_stdout dd if=/dev/omnect/cert of="$(readlink -f ${blk_dev_dst}${p}6)" bs=10M || return 1 - fi - - orig_uuid=$(sfdisk --part-uuid ${blk_dev_dst} 1) - new_uuid=$(uuidgen) - echo "Make partition UUID of copied boot partition unique (${orig_uuid} -> ${new_uuid})" - run_cmd_stdout sfdisk --part-uuid ${blk_dev_dst} 1 ${new_uuid} || return 1 - - echo "COPY current rootfs to rootfsA..." - run_cmd_stdout e2image -ra -p "/dev/omnect/rootCurrent" "$(readlink -f ${blk_dev_dst}${p}2)" || return 1 - - orig_uuid=$(sfdisk --part-uuid ${blk_dev_dst} 2) - new_uuid=$(uuidgen) - echo "Make partition UUID of copied rootfs partition unique (${orig_uuid} -> ${new_uuid})" - run_cmd_stdout sfdisk --part-uuid ${blk_dev_dst} 2 ${new_uuid} || return 1 - - if [[ " ${machine_features} " =~ " grub " ]]; then - echo "Configuring grub" - run_cmd_stdout mkdir -p /tmp/boot - run_cmd_stdout mount ${blk_dev_dst}${p}1 /tmp/boot - cp /etc/omnect/grubenv.in /tmp/boot/EFI/BOOT/grubenv - run_cmd_stdout umount /tmp/boot - else - echo "ENFORCE default bootloader environment..." - # Warning: we enforce here that there is a redundant uboot env available, even if the initial wic did'nt have one - run_cmd_stdout dd if=/etc/omnect/uboot-env.bin of="${blk_dev_dst}" oflag=seek_bytes seek=$((UBOOT_ENV1_START*1024)) || return 1 - run_cmd_stdout dd if=/etc/omnect/uboot-env.bin of="${blk_dev_dst}" oflag=seek_bytes seek=$((UBOOT_ENV2_START*1024)) || return 1 - fi - - flash_mode_efi_handling ${blk_dev_dst} ${p} - - echo "flash mode 1 successfully finished" - run_cmd_stdout sync - return 0 -} - -# main entry point -flash_mode_1_run() { - add_module_post_hook on_exit - set -o pipefail - local blk_dev_data="" - - run_flash_mode_1 2>&1 | tee /tmp/flash-mode-1.log >/dev/console 2>&1; - return=${?} - blk_dev_data=$(readlink -f /dev/omnect/data) - if [ -b "${blk_dev_data}" ]; then - # store log file - mkdir -p /tmp/mnt_data - check_fs "data" - mount_partition "ext4" "${blk_dev_data}" "/tmp/mnt_data" "defaults,rw" - run_cmd cp /tmp/flash-mode-1.log "/tmp/mnt_data" - run_cmd sync - run_cmd umount "/tmp/mnt_data" - fi - if [ ${return} -eq 0 ]; then poweroff -f; fi -} diff --git a/recipes-omnect/initrdscripts/omnect-os-initramfs/flash-mode-2 b/recipes-omnect/initrdscripts/omnect-os-initramfs/flash-mode-2 deleted file mode 100644 index 0c0521ba3..000000000 --- a/recipes-omnect/initrdscripts/omnect-os-initramfs/flash-mode-2 +++ /dev/null @@ -1,125 +0,0 @@ -#!/bin/bash - -# -# optionally provide flashing whole disk image in INITRAMFS context -# - -# Flash Mode -# 2 flash disk image from network to active block device -# -FLASH_MODE="" -FLAG_FILE="/etc/enforce_flash_mode" -DIRECT_FLASHING=@@DIRECT_FLASHING@@ - -# called by generic INITRAMFS -flash_mode_2_enabled() { - debug "flash mode 2: ${FLASH_MODE}" - - # flag file (part of "omnect-os-initramfs-test") - if [ -f ${FLAG_FILE} ]; then - msg "enable flash mode: by ${FLAG_FILE}" - FLASH_MODE=2 - return 0 # enable flash mode; call main entry point - fi - - # flash mode triggered at runtime - FLASH_MODE=$(get_bootloader_env_var flash-mode) - if [ "${FLASH_MODE}" == "2" ]; then - return 0 # enable flash mode; call main entry point - fi - - return 1 # disable flash mode; normal boot; main entry point _NOT_ called -} - -run_bmap_tool() { - local umount_dev="" - local bmap_ret="" - - # umount, if necessary - mkdir -p /tmp - cp /proc/mounts /tmp/all_mounts # make snapshot - while read umount_dev ignore; do - if [[ ${umount_dev} =~ /${blkdev##*/} ]]; then - echo "umount ${umount_dev}" - umount ${umount_dev} 2>/dev/null - fi - done omnect@${FLASH_MODE_IP_ADDR}:wic.bmap" - while true; do - if [ -f /home/omnect/wic.bmap ]; then break; fi - sleep 1 - done - - msg "please run scp omnect@${FLASH_MODE_IP_ADDR}:wic.xz" - export PATH - if ! ${DIRECT_FLASHING}; then - # wait until scp is complete, resp. uncompress+verify wic image before writing - msg "verifying input wic.xz ..." - run_cmd_stdout bmaptool copy --bmap /home/omnect/wic.bmap \ - /home/omnect/wic.xz /home/omnect/wic || return 1 - msg "successfully verified input wic.xz" - fi - non_bmap_dd_handling - msg "start flashing ..." - if ! ${DIRECT_FLASHING}; then - run_cmd_stdout bmaptool copy --bmap /home/omnect/wic.bmap \ - /home/omnect/wic /dev/omnect/rootblk || return 1 - else - run_cmd_stdout bmaptool copy --bmap /home/omnect/wic.bmap \ - /home/omnect/wic.xz /dev/omnect/rootblk || return 1 - fi - msg "successfully flashed input wic.xz" -} - -non_bmap_dd_handling() -{ - # grub: - # we encountered situations where the device could not boot after - # flash-mode-2 and could boot if flash-mode-2 did run again. - # it also could be fixed by manually copying the to be flashed - # grub binary bootx64.efi again. (in the error case checksums - # of bootx64.efi on the device and in the wic image differed.) - - # u-boot: - # we encountered situations where the boot partition has errors - # after flash-mode-2 with bmaptool. - - dd if=/dev/zero of=/dev/omnect/rootblk bs=@@DD_ZERO_SIZE@@K count=1 -} - -# deploy WIC image via network to (same) active block device -run_flash_mode_2() { - msg "Entering omnect flashing mode 2 ..." - - # disable flash mode for subsequent restarts - set_bootloader_env_var flash-mode - - # we already mounted /dev/omnect/boot when we're using grub. so we unmount before copying boot. - if [ -f /usr/bin/grub-editenv ]; then - sync - run_cmd umount ${ROOTFS_DIR}/boot - fi - - flash_mode_setup_network eth0 || return 1 - run_bmap_tool || return 1 - flash_mode_efi_handling - - msg "Rebooting system..." - sync - run_cmd reboot -f - # -- never reached -- -} - -# main entry point -flash_mode_2_run() { - add_module_post_hook on_exit - run_flash_mode_2 - return=${?} - echo flash_mode_2_run return=${return} - return ${return} -} diff --git a/recipes-omnect/initrdscripts/omnect-os-initramfs/flash-mode-3 b/recipes-omnect/initrdscripts/omnect-os-initramfs/flash-mode-3 deleted file mode 100644 index 1aaaf1c99..000000000 --- a/recipes-omnect/initrdscripts/omnect-os-initramfs/flash-mode-3 +++ /dev/null @@ -1,110 +0,0 @@ -#!/bin/bash - -# -# optionally provide flashing whole disk image in INITRAMFS context -# - -# Flash Mode -# 3 flash disk image from network to active block device -# -FLASH_MODE="" - -# called by generic INITRAMFS -flash_mode_3_enabled() { - debug "flash mode 3: ${FLASH_MODE}" - - # flash mode triggered at runtime - FLASH_MODE=$(get_bootloader_env_var flash-mode) - if [ "${FLASH_MODE}" == "3" ]; then - return 0 # enable flash mode; call main entry point - fi - - return 1 # disable flash mode; normal boot; main entry point _NOT_ called -} - -run_bmap_tool() { - local url="${1}" - local url_sha256="${2}" - local umount_dev="" - local bmap_ret="" - - # umount, if necessary - mkdir -p /tmp - cp /proc/mounts /tmp/all_mounts # make snapshot - while read umount_dev ignore; do - if [[ ${umount_dev} =~ /${blkdev##*/} ]]; then - echo "umount ${umount_dev}" - umount ${umount_dev} 2>/dev/null - fi - done /dev/null) || return 1 - fi - echo -n "${return}" -} - - -rootblk_dev_generate_dev_omnect() { - # we assume there is only one internal harddrive device - # we assume /dev/sdb is usb when sata device is /dev/sda (no verification though) - # we assume /dev/sda is usb when nvme device exists (no verification though) - local search_rootblk=("/dev/sdb" "/dev/sda" "/dev/nvme0n1p") - local rootblk="" - local rootpart=${bootparam_rootpart} - local part="" - - [ -z "${bootparam_rootpart}" ] && msg "no rootpart set" && return 1 - - mkdir -p /dev/omnect - cd /dev/omnect - - # get rootblk via kernel param ... if not set, we search - rootblk=${bootparam_rootblk} - msg "env rootblk=${bootparam_rootblk}" - if [ -z "${rootblk}" ]; then - for i in "${search_rootblk[@]}" - do - msg "probing \"${i}${rootpart}\"" - # we wait for max 2sec - make it configurable? - local sleep_cnt=0 - while [ ! -b "${i}${rootpart}" ] && [ ${sleep_cnt} -le 20 ]; do - debug "waiting for \"${i}${rootpart}\"" - sleep 0.1 - sleep_cnt=$((${sleep_cnt}+1)) - done - - if [ -b "${i}${rootpart}" ]; then - rootblk="${i}" - msg "found \"${rootblk}\"" - break; - fi - done - else - while [ ! -b "${rootblk}1" ]; do - debug "waiting for rootblk=${rootblk}" - sleep 0.1 - done - fi - - if [ ! -b ${rootblk} ]; then - part="p" - rootblk=${rootblk%p*} - if [ ! -b ${rootblk} ]; then - msg_fatal "failed to detect root blk device" && return 1 - fi - fi - - debug part=${part} - debug rootblk=${rootblk} - - ln -sf ${rootblk} rootblk - ln -sf ${rootblk}${part}1 boot - ln -sf ${rootblk}${part}2 rootA - ln -sf ${rootblk}${part}3 rootB - ln -sf ${rootblk}${part}${rootpart} rootCurrent - ln -sf ${rootblk}${part}4 factory - ln -sf ${rootblk}${part}5 cert - ln -sf ${rootblk}${part}6 etc - ln -sf ${rootblk}${part}7 data - - # save so next boot has bootparam_rootblk and we can skip search - if [ -z "${bootparam_rootblk}" ]; then - set_bootloader_env_var "omnect_rootblk" "${rootblk}${part}" - fi -} diff --git a/recipes-omnect/initrdscripts/omnect-os-initramfs/imx-sdma b/recipes-omnect/initrdscripts/omnect-os-initramfs/imx-sdma deleted file mode 100644 index 207bb3e2d..000000000 --- a/recipes-omnect/initrdscripts/omnect-os-initramfs/imx-sdma +++ /dev/null @@ -1,20 +0,0 @@ -#!/bin/sh - -imx_sdma_enabled() { - return 0 -} - -imx_sdma_run() { - # explictly no exit hook handling here - - # load imx_sdma as early as possible with firmware available - mkdir -p /lib/firmware - mkdir -p /lib/modules - mount -o bind /rootfs/lib/modules /lib/modules - mount -o bind /rootfs/lib/firmware /lib/firmware - modprobe imx_sdma - # umount deactivated on purpose: umount: can't unmount /lib/firmware: Device or resource busy - # it isn't mounted in omnect-os anyway - #umount /lib/firmware - #umount /lib/modules -} diff --git a/recipes-omnect/initrdscripts/omnect-os-initramfs/omnect-device-service-setup b/recipes-omnect/initrdscripts/omnect-os-initramfs/omnect-device-service-setup deleted file mode 100644 index f93156b92..000000000 --- a/recipes-omnect/initrdscripts/omnect-os-initramfs/omnect-device-service-setup +++ /dev/null @@ -1,108 +0,0 @@ -#!/bin/sh - -# -# Setup files used to trigger factory reset and reboot -# - -omnect_device_service_group="not set yet" -omnect_device_service_user="not set yet" -omnect_run_dir="${ROOTFS_DIR}/run/omnect-device-service" -omnect_os_initramfs_json="${omnect_run_dir}/omnect-os-initramfs.json" - -omnect_device_service_setup_enabled() { - return 0 -} - -fsck_handling() { - local labels=("boot" "cert" "data" "etc") - - echo "{}" > /tmp/fsck.json - for i in ${labels[@]}; do - local content=$(get_fsck_status ${i}) - if [ -n "${content}" ]; then - jq --arg i "${i}" --arg content "${content}" '. += {($i): ($content)}' /tmp/fsck.json > /tmp/fsck.json.tmp || { msg "omnect_fsck_${i} json handling error"; return 1; } - mv /tmp/fsck.json.tmp /tmp/fsck.json - set_bootloader_env_var omnect_fsck_${i} "" - else - msg "no omnect_fsck_${i} available" - fi - done - - cat ${omnect_os_initramfs_json} | jq --argjson fsck "$(cat /tmp/fsck.json)" '.fsck=$fsck' > /tmp/omnect-os-initramfs.json - [ 0 -ne $? ] && msg "fsck_handling set json failed" - mv /tmp/omnect-os-initramfs.json ${omnect_os_initramfs_json} - rm /tmp/fsck.json -} - -factory_reset_status_handling() { - cat ${omnect_os_initramfs_json} | jq --argjson factory_reset "$(cat /tmp/factory-reset.json)" '."factory-reset"=$factory_reset' > /tmp/omnect-os-initramfs.json - [ 0 -ne $? ] && msg "factory_reset_status_handling set json failed" - mv /tmp/omnect-os-initramfs.json ${omnect_os_initramfs_json} - rm /tmp/factory-reset.json -} - -# setup conditional temp files for omnect-device-service, e.g. for the update workflow handling; -# (static temp files for omnect-device-service are created via systemd-tmpfiles.d) -run_omnect_device_service_setup () { - local omnect_validate_update_failed_file="${omnect_run_dir}/omnect_validate_update_failed" - local omnect_validate_update_failed_flag="$(get_bootloader_env_var omnect_validate_update_failed)" - local omnect_validate_update_file="${omnect_run_dir}/omnect_validate_update" - local omnect_validate_update_flag="$(get_bootloader_env_var omnect_validate_update)" - local omnect_bootloader_updated_file="${omnect_run_dir}/omnect_bootloader_updated" - local omnect_bootloader_updated_flag="$(get_bootloader_env_var omnect_bootloader_updated)" - - omnect_device_service_group="$(get_id omnect_device_service ${ROOTFS_DIR}/etc/group)" - omnect_device_service_user="$(get_id omnect_device_service ${ROOTFS_DIR}/etc/passwd)" - - [ -z "${omnect_device_service_user}" ] && msg "ERROR: user omnect_device_service not found in rootfs" && return 1 - [ -z "${omnect_device_service_group}" ] && msg "ERROR: group omnect_device_service not found in rootfs" && return 1 - - run_cmd mkdir -p ${omnect_run_dir} \ - && run_cmd chown ${omnect_device_service_user}:${omnect_device_service_group} ${omnect_run_dir} \ - && run_cmd chmod 775 ${omnect_run_dir} - - if [ -n "${omnect_validate_update_flag}" ] && [ -n "${omnect_validate_update_failed_flag}" ]; then - msg_fatal "both flags are set \"omnect_validate_update\" and \"omnect_validate_update_failed\"" - return 1 - fi - - # omnect update workflow handling - if [ -n "${omnect_validate_update_flag}" ]; then - run_cmd touch ${omnect_validate_update_file} \ - && run_cmd chown ${omnect_device_service_user}:${omnect_device_service_group} ${omnect_validate_update_file} \ - && run_cmd chmod 644 ${omnect_validate_update_file} - fi - if [ -n "${omnect_validate_update_failed_flag}" ]; then - run_cmd touch ${omnect_validate_update_failed_file} \ - && run_cmd chown ${omnect_device_service_user}:${omnect_device_service_group} ${omnect_validate_update_failed_file} \ - && run_cmd chmod 644 ${omnect_validate_update_failed_file} \ - && set_bootloader_env_var omnect_validate_update_failed "" - # ToDo: discuss if we want to unset `omnect_validate_update_failed` - # here or reset it via omnect-device-service; - # a possible reason to not do it here could be that we never - # reach aziot-identityd-precondition - fi - if [ -n "${omnect_bootloader_updated_flag}" ]; then - run_cmd touch ${omnect_bootloader_updated_file} \ - && run_cmd chown ${omnect_device_service_user}:${omnect_device_service_group} ${omnect_bootloader_updated_file} \ - && run_cmd chmod 600 ${omnect_bootloader_updated_file} \ - && set_bootloader_env_var omnect_bootloader_updated "" - fi - - run_cmd "echo \"{}\" > ${omnect_os_initramfs_json}" - - fsck_handling || return 1 - factory_reset_status_handling || return 1 - - run_cmd chown ${omnect_device_service_user}:${omnect_device_service_group} ${omnect_os_initramfs_json} \ - && run_cmd chmod 600 ${omnect_os_initramfs_json} - - return 0 -} - -omnect_device_service_setup_run() { - add_module_post_hook on_exit - msg omnect_device_service_setup - run_omnect_device_service_setup - return=${?} -} diff --git a/recipes-omnect/initrdscripts/omnect-os-initramfs/persistent-var-log b/recipes-omnect/initrdscripts/omnect-os-initramfs/persistent-var-log deleted file mode 100644 index 8da90ccb1..000000000 --- a/recipes-omnect/initrdscripts/omnect-os-initramfs/persistent-var-log +++ /dev/null @@ -1,15 +0,0 @@ -#!/bin/sh - -persistent_var_log_enabled() { - return 0 -} - -persistent_var_log_run() { - add_module_post_hook on_exit - if [ -z "${ROOTFS_DIR}" ]; then - fatal "no ROOTFS_DIR" - return 1 - fi - setup_persistent_var_log "${ROOTFS_DIR}" - return=${?} -} diff --git a/recipes-omnect/initrdscripts/omnect-os-initramfs/resize-data b/recipes-omnect/initrdscripts/omnect-os-initramfs/resize-data deleted file mode 100644 index f125b2ce4..000000000 --- a/recipes-omnect/initrdscripts/omnect-os-initramfs/resize-data +++ /dev/null @@ -1,69 +0,0 @@ -#!/bin/sh - -resize_data_enabled() { - return 0 -} - -# true if the data partition already fills the disk (no resize needed) -data_already_resized() { - local root_disk="$1" - local free_sectors=$(sfdisk -F ${root_disk} 2>/dev/null | sed -n 's/^Unpartitioned space[^,]*, [0-9]* bytes, \([0-9][0-9]*\) sectors$/\1/p') - # can't read free space: assume not resized and let the (idempotent) grow - # path run rather than risk leaving the partition small - [ -z "${free_sectors}" ] && return 1 - debug "data_already_resized: ${free_sectors} free sectors" - # tolerate alignment / GPT-tail slack; genuine unallocated space is GB-scale - [ "${free_sectors}" -le 4096 ] -} - -run_resize_data() { - local resized_data=$(get_bootloader_env_var "resized-data") - - [ -n "${resized_data}" ] && return 0 - - data_part=$(readlink -f /dev/omnect/data) - [[ $(cat /proc/mounts | grep ${data_part} | wc -l) -ne 0 ]] && msg "error: resize_data: \"${data_part}\" is mounted." && return - - root_disk=$(readlink -f /dev/omnect/rootblk) - data_part_nr=${data_part:0-1} - - # the flag is gone but the partition was already grown on an earlier boot - # (e.g. a bootloader update wiped the env): just restore the flag - if data_already_resized ${root_disk}; then - msg "omnect-os data partition already resized" - set_bootloader_env_var resized-data 1 - return 0 - fi - - local ptype=$(get_partition_type) - msg "omnect-os resize data partition: ${root_disk} partition ${data_part_nr}" - - if [ "${ptype}" = "gpt" ]; then - run_cmd sgdisk ${root_disk} -e - elif [ "${ptype}" = "dos" ]; then - [[ $(parted -s ${root_disk} print | grep extended | wc -l) -ne 1 ]] && msg_error "resize_data: couldn't determine extended partion" && return 1 - extended_part_nr=$(parted -s ${root_disk} print | grep extended | awk '{print $1}') - run_cmd parted -s ${root_disk} resizepart ${extended_part_nr} 100% || return 1 - else - msg_fatal "unhandled partition type: \"${ptype}\"" && return 1 - fi - - run_cmd parted -s ${root_disk} resizepart ${data_part_nr} 100% || return 1 - - run_cmd ln -sf /proc/self/mounts /etc/mtab || return 1 - # e2fsck exit 1 means it corrected errors, which is not a failure here - run_cmd e2fsck -y ${data_part} - [ $? -gt 1 ] && return 1 - run_cmd resize2fs -f ${data_part} || return 1 - run_cmd sync - - set_bootloader_env_var resized-data 1 - - return 0 -} - -resize_data_run() { - add_module_post_hook on_exit - run_resize_data - return=${?} -} diff --git a/recipes-omnect/initrdscripts/omnect-os-initramfs/rootblk-dev b/recipes-omnect/initrdscripts/omnect-os-initramfs/rootblk-dev deleted file mode 100644 index cd97d5b92..000000000 --- a/recipes-omnect/initrdscripts/omnect-os-initramfs/rootblk-dev +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/sh - -rootblk_dev_enabled() { - return 0 -} - -rootblk_dev_run() { - add_module_post_hook on_exit - msg "$(grep ^PRETTY_NAME= /etc/os-release | cut -d= -f2) initramfs" - rootblk_dev_generate_dev_omnect - return=${?} -} diff --git a/recipes-omnect/initrdscripts/omnect-os-initramfs/uboot-sh b/recipes-omnect/initrdscripts/omnect-os-initramfs/uboot-sh deleted file mode 100644 index b48cb96db..000000000 --- a/recipes-omnect/initrdscripts/omnect-os-initramfs/uboot-sh +++ /dev/null @@ -1,96 +0,0 @@ -bootloader_sh_enabled() -{ - return 1 # there is no entry point in this library -} - -# get value of bootloader environment variable -get_bootloader_env_var() -{ - local var_name="$1" - local value="$(fw_printenv -n "${var_name}")" - debug "get_bootloader_env_var ${var_name}=${value}" - echo "${value}" -} - -# set/delete bootloader environment variable -set_bootloader_env_var() -{ - local var_name="$1" - local var_value="$2" # empty string to delete variable - debug "set_bootloader_env_var" "${var_name}" "${var_value}" - - if [ -n "${var_value}" ];then - fw_setenv "${var_name}" "${var_value}" || return 1 - else - fw_setenv "${var_name}" || return 1 - fi -} - -save_fsck_status() -{ - local part_name="${1}" - local source_file="${2}" - local fsck_res="${3}" #ignored here - set_bootloader_env_var omnect_fsck_${part_name} $(gzip -9c ${source_file} | base64 -w0 -) -} - -get_fsck_status() -{ - local part_name="${1}" - echo -n "$(fw_printenv -n omnect_fsck_${part_name} | base64 -d - | zcat - 2>/dev/null)" -} - -rootblk_dev_generate_dev_omnect() { - [ -z "${bootparam_root}" ] && msg "no root device set" && return 1 - - # waiting for root device to show up, e.g. needed by welotec boot from usb - while [ ! -b "${bootparam_root}" ]; do - debug "waiting for root=${bootparam_root}" - sleep 0.1 - done - - mkdir -p /dev/omnect - cd /dev/omnect - - rootblk=${bootparam_root} - rootblk=${rootblk##*/} - rootblk=${rootblk%[0-9]*} - - # do we need partition handling? - # eg root=/dev/sda2 -> rootblk=/dev/sda vs root=/dev/mmcblk1p2 -> rootblk=/dev/mmcblk1 - part="" - if [ ! -b /dev/${rootblk} ]; then - part="p" - rootblk=${rootblk%p*} - if [ ! -b /dev/${rootblk} ]; then - msg_fatal "failed to detect root blk device" && return 1 - fi - fi - - debug part=${part} - debug rootblk=${rootblk} - - ln -sf /dev/${rootblk} rootblk - ln -sf /dev/${rootblk}${part}1 boot - ln -sf /dev/${rootblk}${part}2 rootA - ln -sf /dev/${rootblk}${part}3 rootB - ln -sf ${bootparam_root} rootCurrent - - #gpt vs mbr - local ptype=$(get_partition_type) - if [ "${ptype}" = "gpt" ]; then - ln -sf /dev/${rootblk}${part}4 factory - ln -sf /dev/${rootblk}${part}5 cert - ln -sf /dev/${rootblk}${part}6 etc - ln -sf /dev/${rootblk}${part}7 data - elif [ "${ptype}" = "dos" ]; then - ln -sf /dev/${rootblk}${part}4 extended - ln -sf /dev/${rootblk}${part}5 factory - ln -sf /dev/${rootblk}${part}6 cert - ln -sf /dev/${rootblk}${part}7 etc - ln -sf /dev/${rootblk}${part}8 data - else - msg_fatal "unhandled partition type: \"${ptype}\"" && return 1 - fi - return 0 -} diff --git a/recipes-omnect/omnect-base-files/omnect-base-files.bb b/recipes-omnect/omnect-base-files/omnect-base-files.bb index d63f9136c..1821d90e7 100644 --- a/recipes-omnect/omnect-base-files/omnect-base-files.bb +++ b/recipes-omnect/omnect-base-files/omnect-base-files.bb @@ -34,6 +34,7 @@ FILES:${PN} = "\ /mnt/etc \ /mnt/factory \ /mnt/rootCurrent \ + /mnt/rootCurrentPrivate \ /usr/bin/omnect_extra_bootargs.sh \ /usr/bin/omnect_get_deviceid.sh \ /usr/bin/omnect_get_dps_tpm_enrollment.sh \ @@ -61,6 +62,7 @@ do_install() { install -d -D ${D}/mnt/etc \ install -d -D ${D}/mnt/factory \ install -d -D ${D}/mnt/rootCurrent \ + install -d -D ${D}/mnt/rootCurrentPrivate \ install -d -D ${D}/var/lib \ install -d -D ${D}${exec_prefix}/local diff --git a/recipes-omnect/omnect-os-init/omnect-os-init.inc b/recipes-omnect/omnect-os-init/omnect-os-init.inc new file mode 100644 index 000000000..12ba70194 --- /dev/null +++ b/recipes-omnect/omnect-os-init/omnect-os-init.inc @@ -0,0 +1,26 @@ +LICENSE = "MIT | Apache-2.0" + +LIC_FILES_CHKSUM = "\ + file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302 \ + file://${COMMON_LICENSE_DIR}/Apache-2.0;md5=89aea4e17d99a7cacdbeed46a0096b10 \ +" +INSANE_SKIP:${PN} += "already-stripped" + +CARGO_FEATURES:append = "${@'grub' if 'efi' in d.getVar('MACHINE_FEATURES') else 'uboot'}" +CARGO_FEATURES:append = "${@bb.utils.contains('DISTRO_FEATURES', 'resize-data', ',resize-data', '', d)}" +CARGO_FEATURES:append = ",factory-reset" +# All current omnect-os targets use GPT partition tables (see wic/*.wks.in) +CARGO_FEATURES:append = ",gpt" +CARGO_FEATURES:append = "${@bb.utils.contains('OMNECT_RELEASE_IMAGE', '1', ',release-image', '', d)}" +CARGO_FEATURES:append = "${@bb.utils.contains('DISTRO_FEATURES', 'persistent-var-log', ',persistent-var-log', '', d)}" +CARGO_BUILD_FLAGS += "--features ${CARGO_FEATURES}" + +do_compile:prepend() { + export LIBCLANG_PATH="${STAGING_LIBDIR_NATIVE}/llvm-rust/lib" +} + +do_install:append() { + mv ${D}/usr/bin/omnect-os-init ${D}/init + rmdir ${D}/usr/bin +} +FILES:${PN} += "init" diff --git a/recipes-omnect/omnect-os-init/omnect-os-init_0.1.0.bb b/recipes-omnect/omnect-os-init/omnect-os-init_0.1.0.bb new file mode 100644 index 000000000..5eced0a37 --- /dev/null +++ b/recipes-omnect/omnect-os-init/omnect-os-init_0.1.0.bb @@ -0,0 +1,89 @@ +# Auto-Generated by cargo-bitbake 0.3.16-alpha.0 +# +inherit cargo + +# If this is git based prefer versioned ones if they exist +# DEFAULT_PREFERENCE = "-1" + +# how to get omnect-os-init could be as easy as but default to a git checkout: +# SRC_URI += "crate://crates.io/omnect-os-init/0.1.0" +SRC_URI += "git://git@github.com/JoergZeidler/omnect-os-init.git;protocol=ssh;nobranch=1;branch=smoke-test-fixes" +SRCREV = "fef79e5151bce8cd1c5a61157593cc60cdee0392" +S = "${WORKDIR}/git" +CARGO_SRC_DIR = "" +PV:append = ".AUTOINC+fef79e5151" + +# please note if you have entries that do not begin with crate:// +# you must change them to how that package can be fetched +SRC_URI += " \ + crate://crates.io/bitflags/2.10.0 \ + crate://crates.io/cfg-if/1.0.4 \ + crate://crates.io/cfg_aliases/0.2.1 \ + crate://crates.io/errno/0.3.14 \ + crate://crates.io/fastrand/2.3.0 \ + crate://crates.io/itoa/1.0.17 \ + crate://crates.io/libc/0.2.180 \ + crate://crates.io/linux-raw-sys/0.11.0 \ + crate://crates.io/log/0.4.29 \ + crate://crates.io/memchr/2.7.6 \ + crate://crates.io/nix/0.29.0 \ + crate://crates.io/once_cell/1.21.3 \ + crate://crates.io/proc-macro2/1.0.105 \ + crate://crates.io/quote/1.0.43 \ + crate://crates.io/rustix/1.1.3 \ + crate://crates.io/serde/1.0.228 \ + crate://crates.io/serde_core/1.0.228 \ + crate://crates.io/serde_derive/1.0.228 \ + crate://crates.io/serde_json/1.0.149 \ + crate://crates.io/syn/2.0.114 \ + crate://crates.io/tempfile/3.24.0 \ + crate://crates.io/thiserror-impl/2.0.18 \ + crate://crates.io/thiserror/2.0.18 \ + crate://crates.io/unicode-ident/1.0.22 \ + crate://crates.io/windows-link/0.2.1 \ + crate://crates.io/windows-sys/0.61.2 \ + crate://crates.io/zmij/1.0.16 \ +" + +SRC_URI[bitflags-2.10.0.sha256sum] = "812e12b5285cc515a9c72a5c1d3b6d46a19dac5acfef5265968c166106e31dd3" +SRC_URI[cfg-if-1.0.4.sha256sum] = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801" +SRC_URI[cfg_aliases-0.2.1.sha256sum] = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724" +SRC_URI[errno-0.3.14.sha256sum] = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb" +SRC_URI[fastrand-2.3.0.sha256sum] = "37909eebbb50d72f9059c3b6d82c0463f2ff062c9e95845c43a6c9c0355411be" +SRC_URI[itoa-1.0.17.sha256sum] = "92ecc6618181def0457392ccd0ee51198e065e016d1d527a7ac1b6dc7c1f09d2" +SRC_URI[libc-0.2.180.sha256sum] = "bcc35a38544a891a5f7c865aca548a982ccb3b8650a5b06d0fd33a10283c56fc" +SRC_URI[linux-raw-sys-0.11.0.sha256sum] = "df1d3c3b53da64cf5760482273a98e575c651a67eec7f77df96b5b642de8f039" +SRC_URI[log-0.4.29.sha256sum] = "5e5032e24019045c762d3c0f28f5b6b8bbf38563a65908389bf7978758920897" +SRC_URI[memchr-2.7.6.sha256sum] = "f52b00d39961fc5b2736ea853c9cc86238e165017a493d1d5c8eac6bdc4cc273" +SRC_URI[nix-0.29.0.sha256sum] = "71e2746dc3a24dd78b3cfcb7be93368c6de9963d30f43a6a73998a9cf4b17b46" +SRC_URI[once_cell-1.21.3.sha256sum] = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d" +SRC_URI[proc-macro2-1.0.105.sha256sum] = "535d180e0ecab6268a3e718bb9fd44db66bbbc256257165fc699dadf70d16fe7" +SRC_URI[quote-1.0.43.sha256sum] = "dc74d9a594b72ae6656596548f56f667211f8a97b3d4c3d467150794690dc40a" +SRC_URI[rustix-1.1.3.sha256sum] = "146c9e247ccc180c1f61615433868c99f3de3ae256a30a43b49f67c2d9171f34" +SRC_URI[serde-1.0.228.sha256sum] = "9a8e94ea7f378bd32cbbd37198a4a91436180c5bb472411e48b5ec2e2124ae9e" +SRC_URI[serde_core-1.0.228.sha256sum] = "41d385c7d4ca58e59fc732af25c3983b67ac852c1a25000afe1175de458b67ad" +SRC_URI[serde_derive-1.0.228.sha256sum] = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79" +SRC_URI[serde_json-1.0.149.sha256sum] = "83fc039473c5595ace860d8c4fafa220ff474b3fc6bfdb4293327f1a37e94d86" +SRC_URI[syn-2.0.114.sha256sum] = "d4d107df263a3013ef9b1879b0df87d706ff80f65a86ea879bd9c31f9b307c2a" +SRC_URI[tempfile-3.24.0.sha256sum] = "655da9c7eb6305c55742045d5a8d2037996d61d8de95806335c7c86ce0f82e9c" +SRC_URI[thiserror-2.0.18.sha256sum] = "4288b5bcbc7920c07a1149a35cf9590a2aa808e0bc1eafaade0b80947865fbc4" +SRC_URI[thiserror-impl-2.0.18.sha256sum] = "ebc4ee7f67670e9b64d05fa4253e753e016c6c95ff35b89b7941d6b856dec1d5" +SRC_URI[unicode-ident-1.0.22.sha256sum] = "9312f7c4f6ff9069b165498234ce8be658059c6728633667c526e27dc2cf1df5" +SRC_URI[windows-link-0.2.1.sha256sum] = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5" +SRC_URI[windows-sys-0.61.2.sha256sum] = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc" +SRC_URI[zmij-1.0.16.sha256sum] = "dfcd145825aace48cff44a8844de64bf75feec3080e0aa5cdbde72961ae51a65" + +# FIXME: update generateme with the real MD5 of the license file +LIC_FILES_CHKSUM = " \ + file://MIT OR Apache-2.0;md5=generateme \ +" + +SUMMARY = "Rust-based init process for omnect-os initramfs" +HOMEPAGE = "https://github.com/omnect/omnect-os-init" +LICENSE = "MIT OR Apache-2.0" + +# includes this file if it exists but does not fail +# this is useful for anything you may want to override from +# what cargo-bitbake generates. +include omnect-os-init-${PV}.inc +include omnect-os-init.inc