From 367814e94c29b4a3a2e344343f1d35fb89993052 Mon Sep 17 00:00:00 2001 From: Samuel Dolt Date: Wed, 22 Feb 2023 13:59:22 +0100 Subject: [PATCH] feat(coreos-emmc-flasher): beaglebone support This introduce a new coreos-emmc-flasher-beaglebone recipe that create a SWU file that can be used to create the partition in the internal emmc of a beaglebone and flash both u-boot and efibootguard. Support for create efibootguard configuration partition and flashing kernel and rootfs is not included. --- .../conf/machine/beaglebone.conf | 2 + .../include/coreos-generic-features/emmc.inc | 7 +++ .../coreos-emmc-flasher-beaglebone.bb | 6 +++ .../sw-description | 48 ++++++++++++++++++ .../coreos-emmc-flasher-uboot.inc | 10 ++++ .../coreos-emmc-flasher.inc | 31 ++++++++++++ ...dd-support-to-create-FAT16-partition.patch | 50 +++++++++++++++++++ .../swupdate/swupdate/defconfig | 4 ++ .../swupdate/sw-collections-config.sh | 3 ++ ...e_%.bbappend => swupdate_2022.12.bbappend} | 20 +++++--- 10 files changed, 175 insertions(+), 6 deletions(-) create mode 100644 layers/meta-belden-coreos-bsp/conf/machine/include/coreos-generic-features/emmc.inc create mode 100644 layers/meta-belden-coreos-bsp/recipes-bsp/coreos-emmc-flasher/coreos-emmc-flasher-beaglebone.bb create mode 100644 layers/meta-belden-coreos-bsp/recipes-bsp/coreos-emmc-flasher/coreos-emmc-flasher-beaglebone/sw-description create mode 100644 layers/meta-belden-coreos-bsp/recipes-bsp/coreos-emmc-flasher/coreos-emmc-flasher-uboot.inc create mode 100644 layers/meta-belden-coreos-bsp/recipes-bsp/coreos-emmc-flasher/coreos-emmc-flasher.inc create mode 100644 layers/meta-belden-coreos/recipes-support/swupdate/swupdate/0001-fs-add-support-to-create-FAT16-partition.patch rename layers/meta-belden-coreos/recipes-support/swupdate/{swupdate_%.bbappend => swupdate_2022.12.bbappend} (69%) diff --git a/layers/meta-belden-coreos-bsp/conf/machine/beaglebone.conf b/layers/meta-belden-coreos-bsp/conf/machine/beaglebone.conf index 8ada8b7..a7e1f4c 100644 --- a/layers/meta-belden-coreos-bsp/conf/machine/beaglebone.conf +++ b/layers/meta-belden-coreos-bsp/conf/machine/beaglebone.conf @@ -5,6 +5,7 @@ MACHINE_EXTRA_RRECOMMENDS = "kernel-modules kernel-devicetree" EXTRA_IMAGEDEPENDS += "virtual/bootloader" + DEFAULTTUNE ?= "cortexa8hf-neon" include conf/machine/include/arm/armv7a/tune-cortexa8.inc @@ -66,3 +67,4 @@ COREOS_PLATFORM1_ROOT ?= "/dev/mmcblk0p4" require conf/machine/include/coreos-generic-features/efi.inc require conf/machine/include/coreos-generic-features/legacy-mbr-disk.inc +require conf/machine/include/coreos-generic-features/emmc.inc diff --git a/layers/meta-belden-coreos-bsp/conf/machine/include/coreos-generic-features/emmc.inc b/layers/meta-belden-coreos-bsp/conf/machine/include/coreos-generic-features/emmc.inc new file mode 100644 index 0000000..87e64f5 --- /dev/null +++ b/layers/meta-belden-coreos-bsp/conf/machine/include/coreos-generic-features/emmc.inc @@ -0,0 +1,7 @@ +# This configuration file should be included for all hardware that has an +# integrated emmc + +MACHINE_FEATURES += "emmc" + +# Generate a SWU image to flash the emmc +do_image[depends] += "coreos-emmc-flasher-${MACHINE}:do_swuimage" diff --git a/layers/meta-belden-coreos-bsp/recipes-bsp/coreos-emmc-flasher/coreos-emmc-flasher-beaglebone.bb b/layers/meta-belden-coreos-bsp/recipes-bsp/coreos-emmc-flasher/coreos-emmc-flasher-beaglebone.bb new file mode 100644 index 0000000..f3d2678 --- /dev/null +++ b/layers/meta-belden-coreos-bsp/recipes-bsp/coreos-emmc-flasher/coreos-emmc-flasher-beaglebone.bb @@ -0,0 +1,6 @@ +COMPATIBLE_MACHINE = "beaglebone" + +require coreos-emmc-flasher.inc +require coreos-emmc-flasher-uboot.inc + +SWUPDATE_IMAGES += "MLO" diff --git a/layers/meta-belden-coreos-bsp/recipes-bsp/coreos-emmc-flasher/coreos-emmc-flasher-beaglebone/sw-description b/layers/meta-belden-coreos-bsp/recipes-bsp/coreos-emmc-flasher/coreos-emmc-flasher-beaglebone/sw-description new file mode 100644 index 0000000..a2b6359 --- /dev/null +++ b/layers/meta-belden-coreos-bsp/recipes-bsp/coreos-emmc-flasher/coreos-emmc-flasher-beaglebone/sw-description @@ -0,0 +1,48 @@ +software = +{ + version = "@@DISTRO_VERSION@@"; + @@MACHINE@@ = { + hardware-compatibility: ["1.0"]; + factory = { + emmc = { + partitions: ( + { + type = "diskpart"; + device = "/dev/mmcblk1"; + properties: { + labeltype = "dos"; + partition-1 = [ "size=32M", "start=133120", "name=efi", "type=0xef", "fstype=fat16"]; + }; + } + ); + images: ( + { + filename = "MLO"; + device = "/dev/mmcblk1"; + offset = "128K"; + sha256 = "$swupdate_get_sha256(MLO)"; + }, + { + filename = "u-boot-beaglebone.img"; + device = "/dev/mmcblk1"; + offset = "384K"; + sha256 = "$swupdate_get_sha256(u-boot-beaglebone.img)"; + + } + ); + files: ( + { + filename = "efibootguardarm.efi"; + path = "/EFI/BOOT/bootarm.efi"; + device = "/dev/mmcblk1p1"; + filesystem = "vfat"; + sha256 = "$swupdate_get_sha256(efibootguardarm.efi)"; + properties: { + create-destination = "true"; + } + } + ); + } + } + } +} diff --git a/layers/meta-belden-coreos-bsp/recipes-bsp/coreos-emmc-flasher/coreos-emmc-flasher-uboot.inc b/layers/meta-belden-coreos-bsp/recipes-bsp/coreos-emmc-flasher/coreos-emmc-flasher-uboot.inc new file mode 100644 index 0000000..f096e38 --- /dev/null +++ b/layers/meta-belden-coreos-bsp/recipes-bsp/coreos-emmc-flasher/coreos-emmc-flasher-uboot.inc @@ -0,0 +1,10 @@ +# Machine that use u-boot can include this file after +# coreo-swupdate-flasher.inc + +# Add support to flash u-boot +IMAGE_DEPENDS += "virtual/bootloader" + +UBOOT_SUFFIX ??= "img" +SWUPDATE_IMAGES += "u-boot" +SWUPDATE_IMAGES_FSTYPES[u-boot] = ".${UBOOT_SUFFIX}" + diff --git a/layers/meta-belden-coreos-bsp/recipes-bsp/coreos-emmc-flasher/coreos-emmc-flasher.inc b/layers/meta-belden-coreos-bsp/recipes-bsp/coreos-emmc-flasher/coreos-emmc-flasher.inc new file mode 100644 index 0000000..fdf4049 --- /dev/null +++ b/layers/meta-belden-coreos-bsp/recipes-bsp/coreos-emmc-flasher/coreos-emmc-flasher.inc @@ -0,0 +1,31 @@ + +DESCRIPTION = "SWU Image generation to flash the internal emmc" +SECTION = "bootloaders" +LICENSE = "CLOSED" +PR = "r1" + +SRC_URI = " \ + file://sw-description \ + " + +# efibootguard +# ============================================================================== +# efibootguard support is not machine depends so it can be done here + +require conf/image-uefi.conf + +# The efibootguard binary has to be embedded into the image. swupdate will check +# that the binary exist +IMAGE_DEPENDS += "efibootguard" +SWUPDATE_IMAGES += "efibootguard${EFI_ARCH}" + +# Override or variable are not supported in var[flag] statement, but having more +# flags than necessary doesn't do any arm +SWUPDATE_IMAGES_FSTYPES[efibootguardx64] = ".efi" +SWUPDATE_IMAGES_FSTYPES[efibootguardaa64] = ".efi" +SWUPDATE_IMAGES_FSTYPES[efibootguardarm] = ".efi" + +# Image generated should be named coreos-swupdater-flasher-${MACHINE} +# and not the default coreos-swupdate-flasher-${MACHINE}-${MACHINE} +IMAGE_BASENAME ?= "coreos-emmc-flasher" +inherit swupdate diff --git a/layers/meta-belden-coreos/recipes-support/swupdate/swupdate/0001-fs-add-support-to-create-FAT16-partition.patch b/layers/meta-belden-coreos/recipes-support/swupdate/swupdate/0001-fs-add-support-to-create-FAT16-partition.patch new file mode 100644 index 0000000..8ee78f1 --- /dev/null +++ b/layers/meta-belden-coreos/recipes-support/swupdate/swupdate/0001-fs-add-support-to-create-FAT16-partition.patch @@ -0,0 +1,50 @@ +From 323c7fdda60758506dea9da6c477e42a0dbe86ca Mon Sep 17 00:00:00 2001 +From: Samuel Dolt +Date: Wed, 22 Feb 2023 13:22:27 +0100 +Subject: [PATCH] fs: add support to create FAT16 partition + +Currently swupdate can create vfat partition using an embedded +copy of the fat_fs library. The partition created by fat_fs is +can be any FAT format (12/16/32) based on the partition size. + +As the partition created by fat_fs was not readable by U-Boot, +this commit add a new "fat16" filesystem type that use the +external binary mkfs.fat to always create FAT16 partition. +--- + fs/diskformat.c | 16 ++++++++++++++++ + 1 file changed, 16 insertions(+) + +diff --git a/fs/diskformat.c b/fs/diskformat.c +index 8d58fc3..f98c9d7 100644 +--- a/fs/diskformat.c ++++ b/fs/diskformat.c +@@ -19,6 +19,21 @@ static inline int ext_mkfs_short(const char *device_name, const char *fstype) + } + #endif + ++int fat_mkfs_extern(const char *device_name, const char *fstype) ++{ ++ char cmd[100] = "mkfs.fat -F "; ++ if(strcmp(fstype, "fat16") == 0){ ++ strcat(cmd, "16 "); ++ } else { ++ ERROR("fat_mkfs_extern: unsupported fstype %s", fstype); ++ return -1; ++ } ++ strncat(cmd, device_name, sizeof(cmd) - strlen(cmd) - 1); ++ ++ TRACE("fat_mkfs_extern: running %s", cmd); ++ return system(cmd); ++} ++ + struct supported_filesystems { + const char *fstype; + int (*mkfs)(const char *device_name, const char *fstype); +@@ -28,6 +43,7 @@ static struct supported_filesystems fs[] = { + #if defined(CONFIG_FAT_FILESYSTEM) + {"vfat", fat_mkfs}, + #endif ++ {"fat16", fat_mkfs_extern}, + #if defined(CONFIG_EXT_FILESYSTEM) + {"ext2", ext_mkfs_short}, + {"ext3", ext_mkfs_short}, diff --git a/layers/meta-belden-coreos/recipes-support/swupdate/swupdate/defconfig b/layers/meta-belden-coreos/recipes-support/swupdate/swupdate/defconfig index e8c5086..d8a2a88 100644 --- a/layers/meta-belden-coreos/recipes-support/swupdate/swupdate/defconfig +++ b/layers/meta-belden-coreos/recipes-support/swupdate/swupdate/defconfig @@ -20,3 +20,7 @@ CONFIG_SYSTEMD=y CONFIG_UPDATE_STATE_CHOICE_BOOTLOADER=y CONFIG_UPDATE_STATE_BOOTLOADER="ustate" CONFIG_LIBCONFIG=y +CONFIG_DISKPART=y +CONFIG_DISKPART_FORMAT=y +CONFIG_FAT_FILESYSTEM=y +CONFIG_EXT_FILESYSTEM=y diff --git a/layers/meta-belden-coreos/recipes-support/swupdate/swupdate/sw-collections-config.sh b/layers/meta-belden-coreos/recipes-support/swupdate/swupdate/sw-collections-config.sh index 1238e9b..c9e4d43 100644 --- a/layers/meta-belden-coreos/recipes-support/swupdate/swupdate/sw-collections-config.sh +++ b/layers/meta-belden-coreos/recipes-support/swupdate/swupdate/sw-collections-config.sh @@ -37,3 +37,6 @@ case $ROOT_PARTLABEL in exit 1 ;; esac + +# Allow to use image that flash the emmc +SWUPDATE_ARGS="${SWUPDATE_ARGS} -e factory,emmc" diff --git a/layers/meta-belden-coreos/recipes-support/swupdate/swupdate_%.bbappend b/layers/meta-belden-coreos/recipes-support/swupdate/swupdate_2022.12.bbappend similarity index 69% rename from layers/meta-belden-coreos/recipes-support/swupdate/swupdate_%.bbappend rename to layers/meta-belden-coreos/recipes-support/swupdate/swupdate_2022.12.bbappend index f962dac..95d7c30 100644 --- a/layers/meta-belden-coreos/recipes-support/swupdate/swupdate_%.bbappend +++ b/layers/meta-belden-coreos/recipes-support/swupdate/swupdate_2022.12.bbappend @@ -3,20 +3,26 @@ FILESEXTRAPATHS:prepend := "${THISDIR}/swupdate:" RDEPENDS:${PN}:append = " efibootguard" -SRC_URI += " \ - file://webserver-config.sh \ - file://sw-collections-config.sh \ -" +SRC_URI += "file://webserver-config.sh \ + file://sw-collections-config.sh \ + file://0001-fs-add-support-to-create-FAT16-partition.patch \ + " + +# 0001-fs-add-support-to-create-FAT16-partition.patch depends on the +# mkfs.fat binary +RDEPENDS:${PN} += "dosfstools" + +# Don't use /www as the web root wwwdir = "/usr/share/swupdate-www" FILES:${PN} += " \ ${SWUPDATE_SW_VERSIONS_FILE} \ ${SWUPDATE_HW_COMPATIBILITY_FILE} \ + ${libdir}/swupdate/conf.d/sw-collections-config.sh \ " FILES:${PN}-www += " \ ${libdir}/swupdate/conf.d/webserver-config.sh \ - ${libdir}/swupdate/conf.d/sw-collections-config.sh \ " do_install:append() { @@ -25,4 +31,6 @@ do_install:append() { install -m 755 ${WORKDIR}/sw-collections-config.sh ${D}${libdir}/swupdate/conf.d/ echo "${MACHINE} 1.0" > ${D}${SWUPDATE_HW_COMPATIBILITY_FILE} -} \ No newline at end of file +} + +PR = "r1" \ No newline at end of file