diff options
Diffstat (limited to 'classes/sdcard_image-rpi-ota.bbclass')
-rw-r--r-- | classes/sdcard_image-rpi-ota.bbclass | 190 |
1 files changed, 0 insertions, 190 deletions
diff --git a/classes/sdcard_image-rpi-ota.bbclass b/classes/sdcard_image-rpi-ota.bbclass deleted file mode 100644 index 9c859fe..0000000 --- a/classes/sdcard_image-rpi-ota.bbclass +++ /dev/null | |||
@@ -1,190 +0,0 @@ | |||
1 | inherit image_types | ||
2 | inherit linux-raspberrypi-base | ||
3 | |||
4 | # | ||
5 | # Create an image that can by written onto a SD card using dd. | ||
6 | # | ||
7 | # The disk layout used is: | ||
8 | # | ||
9 | # 0 -> IMAGE_ROOTFS_ALIGNMENT - reserved for other data | ||
10 | # IMAGE_ROOTFS_ALIGNMENT -> BOOT_SPACE - bootloader and kernel | ||
11 | # BOOT_SPACE -> SDIMG_OTA_SIZE - rootfs | ||
12 | # | ||
13 | |||
14 | # Default Free space = 1.3x | ||
15 | # Use IMAGE_OVERHEAD_FACTOR to add more space | ||
16 | # <---------> | ||
17 | # 4MiB 40MiB SDIMG_OTA_ROOTFS | ||
18 | # <-----------------------> <----------> <----------------------> | ||
19 | # ------------------------ ------------ ------------------------ | ||
20 | # | IMAGE_ROOTFS_ALIGNMENT | BOOT_SPACE | OTAROOT_SIZE | | ||
21 | # ------------------------ ------------ ------------------------ | ||
22 | # ^ ^ ^ ^ | ||
23 | # | | | | | ||
24 | # 0 4MiB 4MiB + 40MiB 4MiB + 40Mib + SDIMG_OTA_ROOTFS | ||
25 | |||
26 | # This image depends on the rootfs image | ||
27 | IMAGE_TYPEDEP_rpi-sdimg-ota = "${SDIMG_OTA_ROOTFS_TYPE}" | ||
28 | |||
29 | # Set kernel and boot loader | ||
30 | IMAGE_BOOTLOADER ?= "bcm2835-bootfiles" | ||
31 | |||
32 | # Set initramfs extension | ||
33 | KERNEL_INITRAMFS ?= "" | ||
34 | |||
35 | # Kernel image name | ||
36 | SDIMG_OTA_KERNELIMAGE_raspberrypi ?= "kernel.img" | ||
37 | SDIMG_OTA_KERNELIMAGE_raspberrypi2 ?= "kernel7.img" | ||
38 | SDIMG_OTA_KERNELIMAGE_raspberrypi3 ?= "kernel7.img" | ||
39 | |||
40 | # Boot partition volume id | ||
41 | BOOTDD_VOLUME_ID ?= "${MACHINE}" | ||
42 | |||
43 | # Boot partition size [in KiB] (will be rounded up to IMAGE_ROOTFS_ALIGNMENT) | ||
44 | BOOT_SPACE ?= "40960" | ||
45 | |||
46 | # Set alignment to 4MB [in KiB] | ||
47 | IMAGE_ROOTFS_ALIGNMENT = "4096" | ||
48 | |||
49 | # Use an uncompressed ext3 by default as rootfs | ||
50 | SDIMG_OTA_ROOTFS_TYPE ?= "otaimg" | ||
51 | SDIMG_OTA_ROOTFS = "${DEPLOY_DIR_IMAGE}/${IMAGE_LINK_NAME}.${SDIMG_OTA_ROOTFS_TYPE}" | ||
52 | |||
53 | IMAGE_DEPENDS_rpi-sdimg-ota = " \ | ||
54 | parted-native \ | ||
55 | mtools-native \ | ||
56 | dosfstools-native \ | ||
57 | virtual/kernel:do_deploy \ | ||
58 | ${IMAGE_BOOTLOADER} \ | ||
59 | u-boot \ | ||
60 | " | ||
61 | IMAGE_TYPEDEP_rpi-sdimg-ota = "otaimg" | ||
62 | |||
63 | # SD card image name | ||
64 | SDIMG_OTA = "${IMGDEPLOYDIR}/${IMAGE_NAME}.rootfs.rpi-sdimg-ota" | ||
65 | |||
66 | # Compression method to apply to SDIMG_OTA after it has been created. Supported | ||
67 | # compression formats are "gzip", "bzip2" or "xz". The original .rpi-sdimg-ota file | ||
68 | # is kept and a new compressed file is created if one of these compression | ||
69 | # formats is chosen. If SDIMG_OTA_COMPRESSION is set to any other value it is | ||
70 | # silently ignored. | ||
71 | #SDIMG_OTA_COMPRESSION ?= "" | ||
72 | |||
73 | # Additional files and/or directories to be copied into the vfat partition from the IMAGE_ROOTFS. | ||
74 | FATPAYLOAD ?= "" | ||
75 | |||
76 | IMAGE_CMD_rpi-sdimg-ota () { | ||
77 | |||
78 | # Align partitions | ||
79 | OTAROOT_SIZE=`du -Lb ${SDIMG_OTA_ROOTFS} | cut -f1` | ||
80 | OTAROOT_SIZE=$(expr ${OTAROOT_SIZE} / 1024 + 1) | ||
81 | BOOT_SPACE_ALIGNED=$(expr ${BOOT_SPACE} + ${IMAGE_ROOTFS_ALIGNMENT} - 1) | ||
82 | BOOT_SPACE_ALIGNED=$(expr ${BOOT_SPACE_ALIGNED} - ${BOOT_SPACE_ALIGNED} % ${IMAGE_ROOTFS_ALIGNMENT}) | ||
83 | SDIMG_OTA_SIZE=$(expr ${IMAGE_ROOTFS_ALIGNMENT} + ${BOOT_SPACE_ALIGNED} + $OTAROOT_SIZE) | ||
84 | |||
85 | echo "Creating filesystem with Boot partition ${BOOT_SPACE_ALIGNED} KiB and RootFS $OTAROOT_SIZE KiB" | ||
86 | |||
87 | # Check if we are building with device tree support | ||
88 | DTS="${@get_dts(d, None)}" | ||
89 | |||
90 | # Initialize sdcard image file | ||
91 | dd if=/dev/zero of=${SDIMG_OTA} bs=1024 count=0 seek=${SDIMG_OTA_SIZE} | ||
92 | |||
93 | # Create partition table | ||
94 | parted -s ${SDIMG_OTA} mklabel msdos | ||
95 | # Create boot partition and mark it as bootable | ||
96 | parted -s ${SDIMG_OTA} unit KiB mkpart primary fat32 ${IMAGE_ROOTFS_ALIGNMENT} $(expr ${BOOT_SPACE_ALIGNED} \+ ${IMAGE_ROOTFS_ALIGNMENT}) | ||
97 | parted -s ${SDIMG_OTA} set 1 boot on | ||
98 | # Create rootfs partition to the end of disk | ||
99 | parted -s ${SDIMG_OTA} -- unit KiB mkpart primary ext2 $(expr ${BOOT_SPACE_ALIGNED} \+ ${IMAGE_ROOTFS_ALIGNMENT}) -1s | ||
100 | parted ${SDIMG_OTA} print | ||
101 | |||
102 | # Create a vfat image with boot files | ||
103 | BOOT_BLOCKS=$(LC_ALL=C parted -s ${SDIMG_OTA} unit b print | awk '/ 1 / { print substr($4, 1, length($4 -1)) / 512 /2 }') | ||
104 | rm -f ${WORKDIR}/boot.img | ||
105 | mkfs.vfat -n "${BOOTDD_VOLUME_ID}" -S 512 -C ${WORKDIR}/boot.img $BOOT_BLOCKS | ||
106 | sync | ||
107 | |||
108 | mcopy -i ${WORKDIR}/boot.img -s ${DEPLOY_DIR_IMAGE}/bcm2835-bootfiles/* ::/ | ||
109 | |||
110 | if test -n "${DTS}"; then | ||
111 | # Device Tree Overlays are assumed to be suffixed by '-overlay.dtb' string and will be put in a dedicated folder | ||
112 | DT_OVERLAYS="${@split_overlays(d, 0)}" | ||
113 | DT_ROOT="${@split_overlays(d, 1)}" | ||
114 | |||
115 | # Copy board device trees to root folder | ||
116 | for DTB in ${DT_ROOT}; do | ||
117 | DTB_BASE_NAME=`basename ${DTB} .dtb` | ||
118 | |||
119 | mcopy -i ${WORKDIR}/boot.img -s ${DEPLOY_DIR_IMAGE}/${KERNEL_IMAGETYPE}-${DTB_BASE_NAME}.dtb ::${DTB_BASE_NAME}.dtb | ||
120 | done | ||
121 | |||
122 | # Copy device tree overlays to dedicated folder | ||
123 | mmd -i ${WORKDIR}/boot.img overlays | ||
124 | for DTB in ${DT_OVERLAYS}; do | ||
125 | DTB_EXT=${DTB##*.} | ||
126 | DTB_BASE_NAME=`basename ${DTB} ."${DTB_EXT}"` | ||
127 | |||
128 | mcopy -i ${WORKDIR}/boot.img -s ${DEPLOY_DIR_IMAGE}/${KERNEL_IMAGETYPE}-${DTB_BASE_NAME}.${DTB_EXT} ::overlays/${DTB_BASE_NAME}.${DTB_EXT} | ||
129 | done | ||
130 | fi | ||
131 | |||
132 | case "${KERNEL_IMAGETYPE}" in | ||
133 | "uImage") | ||
134 | mcopy -i ${WORKDIR}/boot.img -s ${DEPLOY_DIR_IMAGE}/u-boot.bin ::${SDIMG_OTA_KERNELIMAGE} | ||
135 | ;; | ||
136 | *) | ||
137 | bbfatal "Kernel uImage is required for OTA image. Please set KERNEL_IMAGETYPE to \"uImage\"" | ||
138 | ;; | ||
139 | esac | ||
140 | |||
141 | if [ -n ${FATPAYLOAD} ] ; then | ||
142 | echo "Copying payload into VFAT" | ||
143 | for entry in ${FATPAYLOAD} ; do | ||
144 | # add the || true to stop aborting on vfat issues like not supporting .~lock files | ||
145 | mcopy -i ${WORKDIR}/boot.img -s -v ${IMAGE_ROOTFS}$entry :: || true | ||
146 | done | ||
147 | fi | ||
148 | |||
149 | # Add stamp file | ||
150 | echo "${IMAGE_NAME}" > ${WORKDIR}/image-version-info | ||
151 | mcopy -i ${WORKDIR}/boot.img -v ${WORKDIR}//image-version-info :: | ||
152 | |||
153 | # Burn Partitions | ||
154 | sync | ||
155 | dd if=${WORKDIR}/boot.img of=${SDIMG_OTA} conv=notrunc seek=1 bs=$(expr ${IMAGE_ROOTFS_ALIGNMENT} \* 1024) && sync && sync | ||
156 | # If SDIMG_OTA_ROOTFS_TYPE is a .xz file use xzcat | ||
157 | if echo "${SDIMG_OTA_ROOTFS_TYPE}" | egrep -q "*\.xz" | ||
158 | then | ||
159 | xzcat ${SDIMG_OTA_ROOTFS} | dd of=${SDIMG_OTA} conv=notrunc seek=1 bs=$(expr 1024 \* ${BOOT_SPACE_ALIGNED} + ${IMAGE_ROOTFS_ALIGNMENT} \* 1024) && sync && sync | ||
160 | else | ||
161 | dd if=${SDIMG_OTA_ROOTFS} of=${SDIMG_OTA} conv=notrunc seek=1 bs=$(expr 1024 \* ${BOOT_SPACE_ALIGNED} + ${IMAGE_ROOTFS_ALIGNMENT} \* 1024) && sync && sync | ||
162 | fi | ||
163 | |||
164 | # Optionally apply compression | ||
165 | case "${SDIMG_OTA_COMPRESSION}" in | ||
166 | "gzip") | ||
167 | gzip -k9 "${SDIMG_OTA}" | ||
168 | ;; | ||
169 | "bzip2") | ||
170 | bzip2 -k9 "${SDIMG_OTA}" | ||
171 | ;; | ||
172 | "xz") | ||
173 | xz -k "${SDIMG_OTA}" | ||
174 | ;; | ||
175 | esac | ||
176 | } | ||
177 | |||
178 | ROOTFS_POSTPROCESS_COMMAND += " rpi_generate_sysctl_config ; " | ||
179 | |||
180 | rpi_generate_sysctl_config() { | ||
181 | # systemd sysctl config | ||
182 | test -d ${IMAGE_ROOTFS}${sysconfdir}/sysctl.d && \ | ||
183 | echo "vm.min_free_kbytes = 8192" > ${IMAGE_ROOTFS}${sysconfdir}/sysctl.d/rpi-vm.conf | ||
184 | |||
185 | # sysv sysctl config | ||
186 | IMAGE_SYSCTL_CONF="${IMAGE_ROOTFS}${sysconfdir}/sysctl.conf" | ||
187 | test -e ${IMAGE_ROOTFS}${sysconfdir}/sysctl.conf && \ | ||
188 | sed -e "/vm.min_free_kbytes/d" -i ${IMAGE_SYSCTL_CONF} | ||
189 | echo "" >> ${IMAGE_SYSCTL_CONF} && echo "vm.min_free_kbytes = 8192" >> ${IMAGE_SYSCTL_CONF} | ||
190 | } | ||