Milton D. Miller II | 270cbb8 | 2016-01-20 15:36:27 -0600 | [diff] [blame] | 1 | IMAGE_BASETYPE ?= "squashfs-xz" |
Andrew Jeffery | 9fa0129 | 2016-02-23 23:46:58 +1030 | [diff] [blame] | 2 | OVERLAY_BASETYPE ?= "jffs2" |
Milton D. Miller II | 270cbb8 | 2016-01-20 15:36:27 -0600 | [diff] [blame] | 3 | |
Brad Bishop | c536147 | 2016-02-29 10:21:51 -0500 | [diff] [blame] | 4 | IMAGE_TYPES += "overlay" |
Milton D. Miller II | 270cbb8 | 2016-01-20 15:36:27 -0600 | [diff] [blame] | 5 | |
Brad Bishop | c536147 | 2016-02-29 10:21:51 -0500 | [diff] [blame] | 6 | IMAGE_TYPEDEP_overlay = "${IMAGE_BASETYPE}" |
Milton D. Miller II | 270cbb8 | 2016-01-20 15:36:27 -0600 | [diff] [blame] | 7 | IMAGE_TYPES_MASKED += "overlay" |
| 8 | |
Rick Altherr | 0e7e709 | 2017-01-04 17:25:18 -0800 | [diff] [blame] | 9 | FLASH_IMAGE_NAME ?= "flash-${MACHINE}-${DATETIME}" |
| 10 | FLASH_IMAGE_NAME[vardepsexclude] = "DATETIME" |
| 11 | FLASH_IMAGE_LINK ?= "flash-${MACHINE}" |
| 12 | |
Rick Altherr | c919f53 | 2017-01-11 17:33:47 -0800 | [diff] [blame] | 13 | FLASH_KERNEL_IMAGE ?= "fitImage-${INITRAMFS_IMAGE}-${MACHINE}.bin" |
Rick Altherr | 0e7e709 | 2017-01-04 17:25:18 -0800 | [diff] [blame] | 14 | |
| 15 | FLASH_UBOOT_OFFSET ?= "0" |
| 16 | FLASH_KERNEL_OFFSET ?= "512" |
Rick Altherr | 0e7e709 | 2017-01-04 17:25:18 -0800 | [diff] [blame] | 17 | FLASH_ROFS_OFFSET ?= "4864" |
| 18 | FLASH_RWFS_OFFSET ?= "28672" |
| 19 | RWFS_SIZE ?= "4096" |
| 20 | |
| 21 | # Allow rwfs mkfs configuration through OVERLAY_MKFS_OPTS and OVERRIDES. However, |
| 22 | # avoid setting 'ext4' or 'jffs2' in OVERRIDES as such raw filesystem types are |
| 23 | # reserved for the primary image (and setting them currently breaks the build). |
| 24 | # Instead, prefix the overlay override value with 'rwfs-' to avoid collisions. |
| 25 | DISTROOVERRIDES .= ":rwfs-${OVERLAY_BASETYPE}" |
| 26 | |
| 27 | OVERLAY_MKFS_OPTS_rwfs-ext4 = "-b 4096 -F -O^huge_file" |
| 28 | |
| 29 | # $(( ${FLASH_SIZE} - ${FLASH_RWFS_OFFSET} )) |
| 30 | |
| 31 | mk_nor_image() { |
Brad Bishop | 30304a5 | 2017-07-22 14:20:20 -0400 | [diff] [blame] | 32 | image_dst="$1" |
| 33 | image_size_kb=$2 |
| 34 | dd if=/dev/zero bs=1k count=$image_size_kb \ |
| 35 | | tr '\000' '\377' > $image_dst |
Rick Altherr | 0e7e709 | 2017-01-04 17:25:18 -0800 | [diff] [blame] | 36 | } |
| 37 | |
| 38 | do_generate_flash() { |
Brad Bishop | 30304a5 | 2017-07-22 14:20:20 -0400 | [diff] [blame] | 39 | ddir="${DEPLOY_DIR_IMAGE}" |
| 40 | kernel="${FLASH_KERNEL_IMAGE}" |
| 41 | uboot="u-boot.${UBOOT_SUFFIX}" |
| 42 | rootfs="${IMAGE_LINK_NAME}.${IMAGE_BASETYPE}" |
| 43 | rwfs="rwfs.${OVERLAY_BASETYPE}" |
Rick Altherr | 0e7e709 | 2017-01-04 17:25:18 -0800 | [diff] [blame] | 44 | |
Brad Bishop | 30304a5 | 2017-07-22 14:20:20 -0400 | [diff] [blame] | 45 | if [ ! -f $ddir/$kernel ]; then |
| 46 | bbfatal "Kernel file $ddir/$kernel does not exist" |
| 47 | fi |
| 48 | if [ ! -f $ddir/$uboot ]; then |
| 49 | bbfatal "U-boot file $ddir/$uboot does not exist" |
| 50 | fi |
| 51 | if [ ! -f $ddir/$rootfs ]; then |
| 52 | bbfatal "Rootfs file $ddir/$rootfs does not exist" |
| 53 | fi |
Rick Altherr | 0e7e709 | 2017-01-04 17:25:18 -0800 | [diff] [blame] | 54 | |
Brad Bishop | 30304a5 | 2017-07-22 14:20:20 -0400 | [diff] [blame] | 55 | mk_nor_image $ddir/$rwfs ${RWFS_SIZE} |
| 56 | if [ "${OVERLAY_BASETYPE}" != jffs2 ]; then |
| 57 | mkfs.${OVERLAY_BASETYPE} ${OVERLAY_MKFS_OPTS} $ddir/$rwfs || \ |
| 58 | bbfatal "mkfs rwfs" |
| 59 | fi |
Rick Altherr | 0e7e709 | 2017-01-04 17:25:18 -0800 | [diff] [blame] | 60 | |
Brad Bishop | 30304a5 | 2017-07-22 14:20:20 -0400 | [diff] [blame] | 61 | dst="$ddir/${FLASH_IMAGE_NAME}" |
| 62 | rm -rf $dst |
| 63 | mk_nor_image $dst ${FLASH_SIZE} |
| 64 | dd if=$ddir/$uboot of=$dst bs=1k conv=notrunc seek=${FLASH_UBOOT_OFFSET} |
| 65 | dd if=$ddir/$kernel of=$dst bs=1k conv=notrunc seek=${FLASH_KERNEL_OFFSET} |
| 66 | dd if=$ddir/$rootfs of=$dst bs=1k conv=notrunc seek=${FLASH_ROFS_OFFSET} |
| 67 | dd if=$ddir/$rwfs of=$dst bs=1k conv=notrunc seek=${FLASH_RWFS_OFFSET} |
| 68 | dstlink="$ddir/${FLASH_IMAGE_LINK}" |
| 69 | rm -rf $dstlink |
| 70 | ln -sf ${FLASH_IMAGE_NAME} $dstlink |
Rick Altherr | 0e7e709 | 2017-01-04 17:25:18 -0800 | [diff] [blame] | 71 | |
Brad Bishop | 30304a5 | 2017-07-22 14:20:20 -0400 | [diff] [blame] | 72 | ln -sf ${FLASH_IMAGE_NAME} $ddir/image-bmc |
| 73 | ln -sf $uboot $ddir/image-u-boot |
| 74 | ln -sf $kernel $ddir/image-kernel |
| 75 | ln -sf $rootfs $ddir/image-rofs |
| 76 | ln -sf $rwfs $ddir/image-rwfs |
Rick Altherr | 0e7e709 | 2017-01-04 17:25:18 -0800 | [diff] [blame] | 77 | |
Brad Bishop | 30304a5 | 2017-07-22 14:20:20 -0400 | [diff] [blame] | 78 | tar -h -cvf $ddir/${MACHINE}-${DATETIME}.all.tar -C $ddir image-bmc |
| 79 | tar -h -cvf $ddir/${MACHINE}-${DATETIME}.tar -C $ddir image-u-boot image-kernel image-rofs image-rwfs |
Rick Altherr | 0e7e709 | 2017-01-04 17:25:18 -0800 | [diff] [blame] | 80 | } |
| 81 | do_generate_flash[vardepsexclude] = "DATETIME" |
| 82 | |
Patrick Williams | 7c780e5 | 2016-06-21 14:00:16 -0500 | [diff] [blame] | 83 | do_generate_flash[depends] += "${PN}:do_image_complete" |
Rick Altherr | 0e7e709 | 2017-01-04 17:25:18 -0800 | [diff] [blame] | 84 | do_generate_flash[depends] += "u-boot:do_populate_sysroot" |
Milton D. Miller II | 270cbb8 | 2016-01-20 15:36:27 -0600 | [diff] [blame] | 85 | |
Brad Bishop | c536147 | 2016-02-29 10:21:51 -0500 | [diff] [blame] | 86 | addtask generate_flash before do_build |