summaryrefslogtreecommitdiffstats
path: root/recipes-sota/ota-u-boot-script/ota-u-boot-script.bb
blob: de0014833250c24324281826ad0ec0198312805f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
DESCRIPTION = "Boot script template for OTA-enabled image"
LICENSE = "MIT"
LIC_FILES_CHKSUM = "file://${COREBASE}/meta/COPYING.MIT;md5=3da9cfbcb788c80a0384361b4de20420"

inherit deploy

SRC_URI = "file://uEnv-fileenv.txt \
           file://uEnv-fit.txt \
           file://uEnv-rollback.txt \
           file://uEnv.txt"

python () {
  d.setVar('SOTA_BOOTLOADER_EXTRA_PARAMS', d.getVar('SOTA_BOOTLOADER_EXTRA_PARAMS').replace('/', '\/'))
  d.setVar('SOTA_BOOTLOADER_BOOTCOMMAND', d.getVar('SOTA_BOOTLOADER_BOOTCOMMAND').replace('/', '\/'))
  d.setVar('SOTA_BOOTLOADER_KERNEL_ADDR', d.getVar('SOTA_BOOTLOADER_KERNEL_ADDR').replace('/', '\/'))
  d.setVar('SOTA_BOOTLOADER_RAMDISK_ADDR', d.getVar('SOTA_BOOTLOADER_RAMDISK_ADDR').replace('/', '\/'))
  d.setVar('SOTA_BOOTLOADER_FDT_ADDR', d.getVar('SOTA_BOOTLOADER_FDT_ADDR').replace('/', '\/'))
  d.setVar('SOTA_BOOTLOADER_BOOT_PART', d.getVar('SOTA_BOOTLOADER_BOOT_PART').replace('/', '\/'))
  d.setVar('SOTA_BOOTLOADER_MAIN_PART', d.getVar('SOTA_BOOTLOADER_MAIN_PART').replace('/', '\/'))
  d.setVar('SOTA_BOOTLOADER_ROOT_DEVICE', d.getVar('SOTA_BOOTLOADER_ROOT_DEVICE').replace('/', '\/'))
}

do_compile() {

  UENV_TEMPLATE="${WORKDIR}/uEnv.template"
  # Initialization portion
  sed -n '0,/@@INITFINISHED@@/p' < ${WORKDIR}/uEnv.txt | head -n -1 > $UENV_TEMPLATE

  # Support for FIT images
  if [ "${KERNEL_IMAGETYPE}" = "fitImage" ]; then
    cat ${WORKDIR}/uEnv-fit.txt >> $UENV_TEMPLATE
  fi

  # Rollback support
  if [ -n "${SOTA_ROLLBACK_MECHANISM}" ]; then
    cat ${WORKDIR}/uEnv-rollback.txt >> $UENV_TEMPLATE

    if [ "${SOTA_ROLLBACK_MECHANISM}" = "file-env" ]; then
      cat ${WORKDIR}/uEnv-fileenv.txt >> $UENV_TEMPLATE
    fi
  fi

  # The rest of the base template
  sed -n '/@@INITFINISHED@@/,$p' < ${WORKDIR}/uEnv.txt | sed -n '2,$p' >> $UENV_TEMPLATE

  # Substitute the variables
  sed -e 's/@@SOTA_BOOTLOADER_EXTRA_PARAMS@@/${SOTA_BOOTLOADER_EXTRA_PARAMS}/' \
      -e 's/@@SOTA_BOOTLOADER_BOOTCOMMAND@@/${SOTA_BOOTLOADER_BOOTCOMMAND}/' \
      -e 's/@@SOTA_BOOTLOADER_KERNEL_ADDR@@/${SOTA_BOOTLOADER_KERNEL_ADDR}/' \
      -e 's/@@SOTA_BOOTLOADER_RAMDISK_ADDR@@/${SOTA_BOOTLOADER_RAMDISK_ADDR}/' \
      -e 's/@@SOTA_BOOTLOADER_FDT_ADDR@@/${SOTA_BOOTLOADER_FDT_ADDR}/' \
      -e 's/@@SOTA_BOOTLOADER_BOOT_PART@@/${SOTA_BOOTLOADER_BOOT_PART}/' \
      -e 's/@@SOTA_BOOTLOADER_MAIN_PART@@/${SOTA_BOOTLOADER_MAIN_PART}/' \
      -e 's/@@SOTA_BOOTLOADER_ROOT_DEVICE@@/${SOTA_BOOTLOADER_ROOT_DEVICE}/' \
    "$UENV_TEMPLATE" > ${WORKDIR}/uEnv-final.txt
}

do_deploy() {
    install -d ${DEPLOYDIR}
    install -m 0644 ${WORKDIR}/uEnv-final.txt ${DEPLOYDIR}/uEnv.txt
}

addtask deploy after do_compile before do_build