summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--meta-boot2qt-distro/conf/distro/include/toradex.inc4
-rw-r--r--meta-toradex-extras/classes/image_type_tezi_thud.bbclass250
2 files changed, 254 insertions, 0 deletions
diff --git a/meta-boot2qt-distro/conf/distro/include/toradex.inc b/meta-boot2qt-distro/conf/distro/include/toradex.inc
index 12a1999..95a52ee 100644
--- a/meta-boot2qt-distro/conf/distro/include/toradex.inc
+++ b/meta-boot2qt-distro/conf/distro/include/toradex.inc
@@ -55,3 +55,7 @@ IMAGE_BOOT_FILES += " \
55# use 1.14.0 that matches the imx version of gstreamer 55# use 1.14.0 that matches the imx version of gstreamer
56PREFERRED_VERSION_gstreamer1.0-plugins-ugly = "1.14.0" 56PREFERRED_VERSION_gstreamer1.0-plugins-ugly = "1.14.0"
57PREFERRED_VERSION_gstreamer1.0-libav = "1.14.0" 57PREFERRED_VERSION_gstreamer1.0-libav = "1.14.0"
58
59# override tezi bbclass
60IMAGE_CLASSES_remove = " image_type_tezi"
61IMAGE_CLASSES_append = " image_type_tezi_thud"
diff --git a/meta-toradex-extras/classes/image_type_tezi_thud.bbclass b/meta-toradex-extras/classes/image_type_tezi_thud.bbclass
new file mode 100644
index 0000000..22af071
--- /dev/null
+++ b/meta-toradex-extras/classes/image_type_tezi_thud.bbclass
@@ -0,0 +1,250 @@
1inherit image_types
2
3do_image_teziimg[depends] += "tezi-metadata:do_deploy virtual/bootloader:do_deploy"
4
5TEZI_ROOT_FSTYPE ??= "ext4"
6UBOOT_BINARY ??= "u-boot.${UBOOT_SUFFIX}"
7UBOOT_BINARY_TEZI = "${UBOOT_BINARY}"
8UBOOT_BINARY_TEZI_apalis-t30 = "apalis_t30.img"
9UBOOT_BINARY_TEZI_apalis-tk1 = "apalis-tk1.img"
10UBOOT_BINARY_TEZI_apalis-tk1-mainline = "apalis-tk1.img"
11UBOOT_ENV_TEZI = "uEnv.txt"
12
13def rootfs_get_size(d):
14 import subprocess
15
16 # Calculate size of rootfs in kilobytes...
17 output = subprocess.check_output(['du', '-ks',
18 d.getVar('IMAGE_ROOTFS', True)])
19 return int(output.split()[0])
20
21def rootfs_tezi_emmc(d):
22 import subprocess
23 from collections import OrderedDict
24 deploydir = d.getVar('DEPLOY_DIR_IMAGE', True)
25 kernel = d.getVar('KERNEL_IMAGETYPE', True)
26 offset_bootrom = d.getVar('OFFSET_BOOTROM_PAYLOAD', True)
27 offset_spl = d.getVar('OFFSET_SPL_PAYLOAD', True)
28 imagename = d.getVar('IMAGE_NAME', True)
29 imagename_suffix = d.getVar('IMAGE_NAME_SUFFIX', True)
30
31 # Calculate size of bootfs...
32 bootfiles = [ os.path.join(deploydir, kernel) ]
33 has_devicetree = d.getVar('KERNEL_DEVICETREE', True)
34 if has_devicetree:
35 for dtb in d.getVar('KERNEL_DEVICETREE', True).split():
36 bootfiles.append(os.path.join(deploydir, dtb))
37
38 args = ['du', '-kLc']
39 args.extend(bootfiles)
40 output = subprocess.check_output(args)
41 bootfssize_kb = int(output.splitlines()[-1].split()[0])
42
43 bootpart_rawfiles = []
44
45 has_spl = d.getVar('SPL_BINARY', True)
46 if has_spl:
47 bootpart_rawfiles.append(
48 {
49 "filename": d.getVar('SPL_BINARY', True),
50 "dd_options": "seek=" + offset_bootrom
51 })
52 bootpart_rawfiles.append(
53 {
54 "filename": d.getVar('UBOOT_BINARY_TEZI', True),
55 "dd_options": "seek=" + (offset_spl if has_spl else offset_bootrom)
56 })
57
58 return [
59 OrderedDict({
60 "name": "mmcblk0",
61 "partitions": [
62 {
63 "partition_size_nominal": 16,
64 "want_maximised": False,
65 "content": {
66 "label": "BOOT",
67 "filesystem_type": "FAT",
68 "mkfs_options": "",
69 "filename": imagename + ".bootfs.tar.xz",
70 "uncompressed_size": bootfssize_kb / 1024
71 }
72 },
73 {
74 "partition_size_nominal": 512,
75 "want_maximised": True,
76 "content": {
77 "label": "RFS",
78 "filesystem_type": d.getVar('TEZI_ROOT_FSTYPE', True),
79 "mkfs_options": "-E nodiscard",
80 "filename": imagename + imagename_suffix + ".tar.xz",
81 "uncompressed_size": rootfs_get_size(d) / 1024
82 }
83 }
84 ]
85 }),
86 OrderedDict({
87 "name": "mmcblk0boot0",
88 "content": {
89 "filesystem_type": "raw",
90 "rawfiles": bootpart_rawfiles
91 }
92 })]
93
94
95def rootfs_tezi_rawnand(d):
96 from collections import OrderedDict
97 imagename = d.getVar('IMAGE_NAME', True)
98 imagename_suffix = d.getVar('IMAGE_NAME_SUFFIX', True)
99
100 # Use device tree mapping to create product id <-> device tree relationship
101 dtmapping = d.getVarFlags('TORADEX_PRODUCT_IDS')
102 dtfiles = []
103 for f, v in dtmapping.items():
104 dtfiles.append({ "filename": v, "product_ids": f })
105
106 return [
107 OrderedDict({
108 "name": "u-boot1",
109 "content": {
110 "rawfile": {
111 "filename": d.getVar('UBOOT_BINARY_TEZI', True),
112 "size": 1
113 }
114 },
115 }),
116 OrderedDict({
117 "name": "u-boot2",
118 "content": {
119 "rawfile": {
120 "filename": d.getVar('UBOOT_BINARY_TEZI', True),
121 "size": 1
122 }
123 }
124 }),
125 OrderedDict({
126 "name": "ubi",
127 "ubivolumes": [
128 {
129 "name": "kernel",
130 "size_kib": 8192,
131 "type": "static",
132 "content": {
133 "rawfile": {
134 "filename": d.getVar('KERNEL_IMAGETYPE', True),
135 "size": 5
136 }
137 }
138 },
139 {
140 "name": "dtb",
141 "content": {
142 "rawfiles": dtfiles
143 },
144 "size_kib": 128,
145 "type": "static"
146 },
147 {
148 "name": "m4firmware",
149 "size_kib": 896,
150 "type": "static"
151 },
152 {
153 "name": "rootfs",
154 "content": {
155 "filesystem_type": "ubifs",
156 "filename": imagename + imagename_suffix + ".tar.xz",
157 "uncompressed_size": rootfs_get_size(d) / 1024
158 }
159 }
160 ]
161 })]
162
163python rootfs_tezi_json() {
164 import json
165 from collections import OrderedDict
166 from datetime import datetime
167
168 deploydir = d.getVar('DEPLOY_DIR_IMAGE', True)
169 # patched in IMAGE_CMD_teziimg() below
170 release_date = "%release_date%"
171
172 data = OrderedDict({ "config_format": 2, "autoinstall": False })
173
174 # Use image recipes SUMMARY/DESCRIPTION/PV...
175 data["name"] = d.getVar('SUMMARY', True)
176 data["description"] = d.getVar('DESCRIPTION', True)
177 data["version"] = d.getVar('PV', True)
178 data["release_date"] = release_date
179 data["u_boot_env"] = d.getVar('UBOOT_ENV_TEZI', True)
180 if os.path.exists(os.path.join(deploydir, "prepare.sh")):
181 data["prepare_script"] = "prepare.sh"
182 if os.path.exists(os.path.join(deploydir, "wrapup.sh")):
183 data["wrapup_script"] = "wrapup.sh"
184 if os.path.exists(os.path.join(deploydir, "marketing.tar")):
185 data["marketing"] = "marketing.tar"
186 if os.path.exists(os.path.join(deploydir, "toradexlinux.png")):
187 data["icon"] = "toradexlinux.png"
188
189 product_ids = d.getVar('TORADEX_PRODUCT_IDS', True)
190 if product_ids is None:
191 bb.fatal("Supported Toradex product ids missing, assign TORADEX_PRODUCT_IDS with a list of product ids.")
192
193 data["supported_product_ids"] = d.getVar('TORADEX_PRODUCT_IDS', True).split()
194
195 if bb.utils.contains("TORADEX_FLASH_TYPE", "rawnand", True, False, d):
196 data["mtddevs"] = rootfs_tezi_rawnand(d)
197 else:
198 data["blockdevs"] = rootfs_tezi_emmc(d)
199
200 deploy_dir = d.getVar('DEPLOY_DIR_IMAGE', True)
201 with open(os.path.join(deploy_dir, 'image.json'), 'w') as outfile:
202 json.dump(data, outfile, indent=4)
203 bb.note("Toradex Easy Installer metadata file image.json written.")
204}
205
206do_image_teziimg[prefuncs] += "rootfs_tezi_json"
207
208IMAGE_CMD_teziimg () {
209 bbnote "Create bootfs tarball"
210
211 # Fixup release_date in image.json, convert ${DATE} to isoformat
212 # This works around the non fatal ERRORS: "the basehash value changed" when DATE is referenced
213 # in a python prefunction to do_image
214 ISODATE=`echo ${DATE} | sed 's/\(....\)\(..\)\(..\)/\1-\2-\3/'`
215 sed -i "s/%release_date%/$ISODATE/" ${DEPLOY_DIR_IMAGE}/image.json
216
217 # Create list of device tree files
218 if test -n "${KERNEL_DEVICETREE}"; then
219 for DTS_FILE in ${KERNEL_DEVICETREE}; do
220 DTS_BASE_NAME=`basename ${DTS_FILE} .dtb`
221 if [ -e "${DEPLOY_DIR_IMAGE}/${DTS_BASE_NAME}.dtb" ]; then
222 KERNEL_DEVICETREE_FILES="${KERNEL_DEVICETREE_FILES} ${DTS_BASE_NAME}.dtb"
223 else
224 bbfatal "${DTS_FILE} does not exist."
225 fi
226 done
227 fi
228
229 cd ${DEPLOY_DIR_IMAGE}
230
231 case "${TORADEX_FLASH_TYPE}" in
232 rawnand)
233 # The first transform strips all folders from the files to tar, the
234 # second transform "moves" them in a subfolder ${IMAGE_NAME}_${PV}.
235 # The third transform removes zImage from the device tree.
236 ${IMAGE_CMD_TAR} --transform='s/.*\///' --transform 's,^,${IMAGE_NAME}-Tezi_${PV}/,' -chf ${IMGDEPLOYDIR}/${IMAGE_NAME}-Tezi_${PV}${TDX_VERDATE}.tar image.json toradexlinux.png marketing.tar prepare.sh wrapup.sh ${SPL_BINARY} ${UBOOT_BINARY_TEZI} ${UBOOT_ENV_TEZI} ${KERNEL_IMAGETYPE} ${KERNEL_DEVICETREE_FILES} ${IMGDEPLOYDIR}/${IMAGE_NAME}${IMAGE_NAME_SUFFIX}.tar.xz
237 ;;
238 *)
239 # Create bootfs...
240 ${IMAGE_CMD_TAR} --transform="flags=r;s|${KERNEL_IMAGETYPE}-||" -chf ${IMGDEPLOYDIR}/${IMAGE_NAME}.bootfs.tar -C ${DEPLOY_DIR_IMAGE} ${KERNEL_IMAGETYPE} ${KERNEL_DEVICETREE_FILES}
241 xz -f -k -c ${XZ_COMPRESSION_LEVEL} ${XZ_THREADS} --check=${XZ_INTEGRITY_CHECK} ${IMGDEPLOYDIR}/${IMAGE_NAME}.bootfs.tar > ${IMGDEPLOYDIR}/${IMAGE_NAME}.bootfs.tar.xz
242
243 # The first transform strips all folders from the files to tar, the
244 # second transform "moves" them in a subfolder ${IMAGE_NAME}-Tezi_${PV}.
245 ${IMAGE_CMD_TAR} --transform='s/.*\///' --transform 's,^,${IMAGE_NAME}-Tezi_${PV}/,' -chf ${IMGDEPLOYDIR}/${IMAGE_NAME}-Tezi_${PV}${TDX_VERDATE}.tar image.json toradexlinux.png marketing.tar prepare.sh wrapup.sh ${SPL_BINARY} ${UBOOT_BINARY_TEZI} ${UBOOT_ENV_TEZI} ${IMGDEPLOYDIR}/${IMAGE_NAME}.bootfs.tar.xz ${IMGDEPLOYDIR}/${IMAGE_NAME}${IMAGE_NAME_SUFFIX}.tar.xz
246 ;;
247 esac
248}
249
250IMAGE_TYPEDEP_teziimg += "tar.xz"