diff options
| -rw-r--r-- | classes/sota.bbclass | 11 | ||||
| -rw-r--r-- | recipes-sota/ota-u-boot-script/files/uEnv-fileenv.txt | 1 | ||||
| -rw-r--r-- | recipes-sota/ota-u-boot-script/files/uEnv-fit.txt | 1 | ||||
| -rw-r--r-- | recipes-sota/ota-u-boot-script/files/uEnv-rollback.txt | 8 | ||||
| -rw-r--r-- | recipes-sota/ota-u-boot-script/files/uEnv.txt | 33 | ||||
| -rw-r--r-- | recipes-sota/ota-u-boot-script/ota-u-boot-script.bb | 50 |
6 files changed, 104 insertions, 0 deletions
diff --git a/classes/sota.bbclass b/classes/sota.bbclass index 92b4c43..12f8148 100644 --- a/classes/sota.bbclass +++ b/classes/sota.bbclass | |||
| @@ -38,6 +38,15 @@ GARAGE_TARGET_NAME ?= "${OSTREE_BRANCHNAME}" | |||
| 38 | GARAGE_TARGET_VERSION ?= "" | 38 | GARAGE_TARGET_VERSION ?= "" |
| 39 | GARAGE_TARGET_URL ?= "https://example.com/" | 39 | GARAGE_TARGET_URL ?= "https://example.com/" |
| 40 | 40 | ||
| 41 | SOTA_BOOTLOADER_EXTRA_PARAMS ??= "" | ||
| 42 | SOTA_BOOTLOADER_BOOTCOMMAND ??= "bootm" | ||
| 43 | SOTA_BOOTLOADER_KERNEL_ADDR ??= "\$\{ramdisk_addr_r\}" | ||
| 44 | SOTA_BOOTLOADER_RAMDISK_ADDR ??= "-" | ||
| 45 | SOTA_BOOTLOADER_FDT_ADDR ??= "-" | ||
| 46 | SOTA_BOOTLOADER_BOOT_PART ??= "mmc 0:1" | ||
| 47 | SOTA_BOOTLOADER_MAIN_PART ??= "mmc 0:2" | ||
| 48 | SOTA_BOOTLOADER_ROOT_DEVICE ??= "/dev/mmcblk0p2" | ||
| 49 | |||
| 41 | SOTA_MACHINE ??="none" | 50 | SOTA_MACHINE ??="none" |
| 42 | SOTA_MACHINE_rpi ?= "raspberrypi" | 51 | SOTA_MACHINE_rpi ?= "raspberrypi" |
| 43 | SOTA_MACHINE_porter ?= "porter" | 52 | SOTA_MACHINE_porter ?= "porter" |
| @@ -49,4 +58,6 @@ SOTA_MACHINE_am335x-evm ?= "am335x-evm-wifi" | |||
| 49 | SOTA_OVERRIDES_BLACKLIST = "ostree ota" | 58 | SOTA_OVERRIDES_BLACKLIST = "ostree ota" |
| 50 | SOTA_REQUIRED_VARIABLES = "OSTREE_REPO OSTREE_BRANCHNAME OSTREE_OSNAME OSTREE_BOOTLOADER OSTREE_BOOT_PARTITION GARAGE_SIGN_REPO GARAGE_TARGET_NAME" | 59 | SOTA_REQUIRED_VARIABLES = "OSTREE_REPO OSTREE_BRANCHNAME OSTREE_OSNAME OSTREE_BOOTLOADER OSTREE_BOOT_PARTITION GARAGE_SIGN_REPO GARAGE_TARGET_NAME" |
| 51 | 60 | ||
| 61 | do_image_wic[depends] += " ota-u-boot-script:do_deploy " | ||
| 62 | |||
| 52 | inherit sota_sanity sota_${SOTA_MACHINE} image_repo_manifest | 63 | inherit sota_sanity sota_${SOTA_MACHINE} image_repo_manifest |
diff --git a/recipes-sota/ota-u-boot-script/files/uEnv-fileenv.txt b/recipes-sota/ota-u-boot-script/files/uEnv-fileenv.txt new file mode 100644 index 0000000..3646416 --- /dev/null +++ b/recipes-sota/ota-u-boot-script/files/uEnv-fileenv.txt | |||
| @@ -0,0 +1 @@ | |||
| bootcmd_create_envfile=if test ! -e ${updater_boot_part} uboot.env; then saveenv; fi; | |||
diff --git a/recipes-sota/ota-u-boot-script/files/uEnv-fit.txt b/recipes-sota/ota-u-boot-script/files/uEnv-fit.txt new file mode 100644 index 0000000..64e34b0 --- /dev/null +++ b/recipes-sota/ota-u-boot-script/files/uEnv-fit.txt | |||
| @@ -0,0 +1 @@ | |||
| bootcmd_fitconf=run bootcmd_getroot; if test -e ${sota_main_part} "${ostree_root}/usr/lib/fit_conf"; then load ${sota_main_part} $loadaddr "${ostree_root}/usr/lib/fit_conf"; env import -t $loadaddr $filesize; fi; setenv sota_kernel_addr ${sota_kernel_addr}${fit_conf} | |||
diff --git a/recipes-sota/ota-u-boot-script/files/uEnv-rollback.txt b/recipes-sota/ota-u-boot-script/files/uEnv-rollback.txt new file mode 100644 index 0000000..07b6b22 --- /dev/null +++ b/recipes-sota/ota-u-boot-script/files/uEnv-rollback.txt | |||
| @@ -0,0 +1,8 @@ | |||
| 1 | bootcmd_rollbackenv=setenv kernel_image ${kernel_image2}; setenv ramdisk_image ${ramdisk_image2}; setenv fdt_file ${fdt_file2}; setenv bootargs ${bootargs2} | ||
| 2 | |||
| 3 | bootlimit=3 | ||
| 4 | |||
| 5 | bootcmd_set_rollback=if test ! "${rollback}" = "1"; then setenv rollback 1; setenv upgrade_available 0; saveenv; fi | ||
| 6 | altbootcmd=run bootcmd_create_envfile; run bootcmd_otenv; run bootcmd_set_rollback; if test -n "${kernel_image2}"; then run bootcmd_rollbackenv; fi; run bootcmd_args; run bootcmd_fitconf; run bootcmd_load; run bootcmd_run; reset | ||
| 7 | |||
| 8 | |||
diff --git a/recipes-sota/ota-u-boot-script/files/uEnv.txt b/recipes-sota/ota-u-boot-script/files/uEnv.txt new file mode 100644 index 0000000..0cd97b7 --- /dev/null +++ b/recipes-sota/ota-u-boot-script/files/uEnv.txt | |||
| @@ -0,0 +1,33 @@ | |||
| 1 | bootcmd_fitconf= | ||
| 2 | bootcmd_create_envfile= | ||
| 3 | |||
| 4 | sota_bootcommand=bootm | ||
| 5 | sota_kernel_addr=${ramdisk_addr_r} | ||
| 6 | sota_ramdisk_addr=- | ||
| 7 | sota_fdt_addr=- | ||
| 8 | sota_boot_part=mmc 0:1 | ||
| 9 | sota_main_part=mmc 0:2 | ||
| 10 | sota_root_device=/dev/mmcblk0p2 | ||
| 11 | |||
| 12 | %%INITFINISHED%% | ||
| 13 | |||
| 14 | bootcmd_resetvars=setenv kernel_image; setenv bootargs; setenv kernel_image2; setenv bootargs2 | ||
| 15 | bootcmd_otenv=run bootcmd_resetvars; load ${updater_main_part} $loadaddr /boot/loader/uEnv.txt; env import -t $loadaddr $filesize | ||
| 16 | |||
| 17 | bootcmd_args=setenv bootargs "$bootargs $bootargs_fdt ostree_root=${updater_root_device} root=/dev/ram0 rw rootwait rootdelay=2 ramdisk_size=8192 panic=1 %%SOTA_EXTRA_BOOTCMD%%" | ||
| 18 | |||
| 19 | bootcmd_getroot=setexpr ostree_root gsub "^.*ostree=([^ ]*).*$" "\\\\1" "${bootargs}"; | ||
| 20 | |||
| 21 | bootcmd_load_kernel=load ${updater_main_part} ${sota_kernel_addr} "/boot"$kernel_image | ||
| 22 | |||
| 23 | bootcmd_load_ramdisk=if ! "${sota_ramdisk_addr}" = "-"; then load ${updater_main_part} ${sota_ramdisk_addr} "/boot"$ramdisk_image; fi | ||
| 24 | |||
| 25 | bootcmd_load_fdt=if ! "${sota_fdt_addr}" = "-"; then load ${updater_main_part} ${sota_fdt_addr} "/boot"$fdt_file; fi | ||
| 26 | |||
| 27 | bootcmd_load=run bootcmd_load_kernel; run bootcmd_load_ramdisk; run bootcmd_load_fdt; | ||
| 28 | |||
| 29 | bootcmd_run=${sota_bootcommand} ${sota_kernel_addr} ${sota_ramdisk_addr} ${sota_fdt_addr} | ||
| 30 | |||
| 31 | bootcmd=if test "${rollback}" = "1"; then run altbootcmd; else run bootcmd_create_envfile; run bootcmd_otenv; run bootcmd_args; run bootcmd_fitconf; run bootcmd_load; run bootcmd_run; if ! "${upgrade_available}" = "1"; then setenv upgrade_available 1; saveenv; fi; reset; fi | ||
| 32 | |||
| 33 | |||
diff --git a/recipes-sota/ota-u-boot-script/ota-u-boot-script.bb b/recipes-sota/ota-u-boot-script/ota-u-boot-script.bb new file mode 100644 index 0000000..5c7ed57 --- /dev/null +++ b/recipes-sota/ota-u-boot-script/ota-u-boot-script.bb | |||
| @@ -0,0 +1,50 @@ | |||
| 1 | DESCRIPTION = "Boot script template for OTA-enabled image" | ||
| 2 | LICENSE = "MIT" | ||
| 3 | LIC_FILES_CHKSUM = "file://${COREBASE}/meta/COPYING.MIT;md5=3da9cfbcb788c80a0384361b4de20420" | ||
| 4 | |||
| 5 | inherit deploy | ||
| 6 | |||
| 7 | SRC_URI = "file://uEnv-fileenv.txt \ | ||
| 8 | file://uEnv-fit.txt \ | ||
| 9 | file://uEnv-rollback.txt \ | ||
| 10 | file://uEnv.txt" | ||
| 11 | |||
| 12 | do_deploy() { | ||
| 13 | |||
| 14 | UENV_TEMPLATE=$(mktemp) | ||
| 15 | # Initialization portion | ||
| 16 | sed -n '0,/%%INITFINISHED%%/p' < ${WORKDIR}/uEnv.txt | head -n -1 > $UENV_TEMPLATE | ||
| 17 | |||
| 18 | # Support for FIT images | ||
| 19 | if [ "${KERNEL_IMAGETYPE_SOTA}" = "fitImage"]; then | ||
| 20 | cat ${WORKDIR}/uEnv-fit.txt >> $UENV_TEMPLATE | ||
| 21 | fi | ||
| 22 | |||
| 23 | # Rollback support | ||
| 24 | if [ -n "${SOTA_ROLLBACK_MECHANISM}" ]; then | ||
| 25 | cat ${WORKDIR}/uEnv-rollback.txt >> $UENV_TEMPLATE | ||
| 26 | |||
| 27 | if [ "${SOTA_ROLLBACK_MECHANISM}" = "file-env" ]; | ||
| 28 | cat ${WORKDIR}/uEnv-fileenv.txt >> $UENV_TEMPLATE | ||
| 29 | fi | ||
| 30 | fi | ||
| 31 | |||
| 32 | # The rest of the base template | ||
| 33 | sed -n '/%%INITFINISHED%%/,$p' < ${WORKDIR}/uEnv.txt | sed -n '2,$p' >> $UENV_TEMPLATE | ||
| 34 | |||
| 35 | # Substitute the variables | ||
| 36 | sed -e 's/@@SOTA_BOOTLOADER_EXTRA_PARAMS@@/${SOTA_BOOTLOADER_EXTRA_PARAMS}' \ | ||
| 37 | -e 's/@@SOTA_BOOTLOADER_BOOTCOMMAND@@/${SOTA_BOOTLOADER_BOOTCOMMAND}' \ | ||
| 38 | -e 's/@@SOTA_BOOTLOADER_KERNEL_ADDR@@/${SOTA_BOOTLOADER_KERNEL_ADDR}' \ | ||
| 39 | -e 's/@@SOTA_BOOTLOADER_RAMDISK_ADDR@@/${SOTA_BOOTLOADER_RAMDISK_ADDR}' \ | ||
| 40 | -e 's/@@SOTA_BOOTLOADER_FDT_ADDR@@/${SOTA_BOOTLOADER_FDT_ADDR}' \ | ||
| 41 | -e 's/@@SOTA_BOOTLOADER_BOOT_PART@@/${SOTA_BOOTLOADER_BOOT_PART}' \ | ||
| 42 | -e 's/@@SOTA_BOOTLOADER_MAIN_PART@@/${SOTA_BOOTLOADER_KERNEL_MAIN_PART}' \ | ||
| 43 | -e 's/@@SOTA_BOOTLOADER_ROOT_DEVICE@@/${SOTA_BOOTLOADER_ROOT_DEVICE}' \ | ||
| 44 | "$UENV_TEMPLATE" > ${DEPLOY_DIR_IMAGE}/uEnv.txt | ||
| 45 | |||
| 46 | |||
| 47 | if [ -n ""] | ||
| 48 | } | ||
| 49 | |||
| 50 | addtask deploy before do_package | ||
