-
Notifications
You must be signed in to change notification settings - Fork 1
/
fitimage.bbclass
195 lines (158 loc) · 5.55 KB
/
fitimage.bbclass
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
FITIMAGE_KERNELS ??= ""
FITIMAGE_KERNELS[type] = "list"
FITIMAGE_DTBS ??= ""
FITIMAGE_DTBS[type] = "list"
FITIMAGE_OVERLAYS ??= ""
FITIMAGE_OVERLAYS[type] = "list"
FITIMAGE_RAMDISKS ??= ""
FITIMAGE_RAMDISKS[type] = "list"
FITIMAGE_TEMPLATE ?= "fitimage.its"
FITIMAGE_ITSFILE ?= "fitimage-gen.its"
FITIMAGE_CFGNODE ??= ""
#FITIMAGE_CFGNODE[type] = "string"
FITIMAGE_CFG_OVERLAYS ??= "${FITIMAGE_OVERLAYS}"
FITIMAGE_CFG_OVERLAYS[type] = "list"
FITIMAGE_CFG_RAMDISKS ??= "${FITIMAGE_RAMDISKS}"
FITIMAGE_CFG_RAMDISKS[type] = "list"
FITIMAGE_SEARCH_PATH ?= "\
${DEPLOY_DIR_IMAGE} \
"
FITIMAGE_SEARCH_PATH[type] = "list"
FITIMAGE_COMPONENTS ?= "\
virtual/dtb:do_deploy \
virtual/kernel:do_deploy \
"
FITIMAGE_COMPONENTS[type] = "list"
FITIMAGE_BOOT_NAME ??= "${IMAGE_BASENAME}"
FITIMAGE_ATTR_ID ??= "device-id"
FITIMAGE_ATTR_DESC ??= "device-description"
DEPENDS += "dtc-native"
PACKAGE_ARCH = "${MACHINE_ARCH}"
## do not create -dev + -dbg packages; their deps on ${PN} break SDK build else
ALLOW_EMPTY:${PN}-dev = ""
ALLOW_EMPTY:${PN}-dbg = ""
inherit image_types deploy
## we do not want the '.rootfs' suffix
IMAGE_NAME_SUFFIX:forcevariable = ""
def fitimage_expand_filenames(d, varname):
res = []
raw = oe.data.typed_value(varname, d)
search_path = oe.data.typed_value("FITIMAGE_SEARCH_PATH",d)
for r in raw:
resolved = None
for p in search_path:
full_name = os.path.join(p, r)
if os.path.exists(full_name):
resolved = full_name
break
## when raw path is absolute, abort after the first
## search path item
if r.startswith('/'):
break
if resolved is None:
bb.fatal("file %s not found" % (r,))
else:
res += [resolved,]
return res
def fitimage_generate_fragment(d):
from elito.fitimage import FitImage
return FitImage.from_desc(kernels = fitimage_expand_filenames(d, 'FITIMAGE_KERNELS'),
dtbs = fitimage_expand_filenames(d, 'FITIMAGE_DTBS'),
overlays = fitimage_expand_filenames(d, 'FITIMAGE_OVERLAYS'),
ramdisks = fitimage_expand_filenames(d, 'FITIMAGE_RAMDISKS'),
cfgnode = d.getVar('FITIMAGE_CFGNODE', d),
cfg_overlays = oe.data.typed_value('FITIMAGE_CFG_OVERLAYS', d),
cfg_ramdisks = oe.data.typed_value('FITIMAGE_CFG_RAMDISKS', d),
id_attr = d.getVar('FITIMAGE_ATTR_ID'),
desc_attr = d.getVar('FITIMAGE_ATTR_DESC'))
def fitimage_generate_its(d, template, output):
(frag,cfg) = fitimage_generate_fragment(d)
## normalize paths; when relative us WORKDIR resp. B as parent directory
template = os.path.join(d.getVar("WORKDIR"), d.expand(template))
output = os.path.join(d.getVar("B"), d.expand(output))
with open(output, "w") as out_file:
with open(template, "r") as in_file:
out_file.write(d.expand(in_file.read()))
out_file.write('\n'.join(frag.finish().emit(d)))
out_file.write('\n')
if cfg:
out_file.write('\n'.join(cfg.finish().emit(d)))
out_file.write('\n')
do_fitimage_prepare_its[vardeps] += "FITIMAGE_KERNELS FITIMAGE_DTBS FITIMAGE_OVERLAYS FITIMAGE_RAMDISKS"
do_fitimage_prepare_its[vardeps] += "FITIMAGE_ATTR_ID FITIMAGE_ATTR_DESC"
do_fitimage_prepare_its[vardeps] += "FITIMAGE_SEARCH_PATH FITIMAGE_TEMPLATE FITIMAGE_ITSFILE"
do_fitimage_prepare_its[depends] += "${FITIMAGE_COMPONENTS}"
python do_fitimage_prepare_its() {
fitimage_generate_its(d, d.getVar('FITIMAGE_TEMPLATE'), d.getVar('FITIMAGE_ITSFILE'))
}
addtask do_fitimage_prepare_its after do_configure before do_image_fit
IMAGE_CMD:fit[vardepsexclude] = "DATETIME"
IMAGE_CMD:fit = "mkimage ${EXTRA_IMAGECMD} -f '${FITIMAGE_ITSFILE}' ${IMAGE_NAME}${IMAGE_NAME_SUFFIX}.fit"
## TODO: make gzip/xz-native depending on conversion
do_image_fit[depends] += "\
u-boot-tools-native:do_populate_sysroot \
${PN}:do_fitimage_prepare_its \
gzip-native:do_populate_sysroot \
xz-native:do_populate_sysroot \
"
do_image_fit[dirs] = "${B}"
fitimage_do_image_fit() {
# used by CONVERSION_CMD:xxx
type=fit
rm -f ${IMAGE_BASENAME}.fit* ${IMAGE_NAME}.fit
# first pass; generate the fit image
for t in ${IMAGE_TYPES}; do
case $t in
fit|fit.*)
${IMAGE_CMD:fit}
break
;;
esac
done
# second pass; apply conversions
for t in ${IMAGE_TYPES}; do
case $t in
fit.gz)
${CONVERSION_CMD:gz}
;;
fit.xz)
${CONVERSION_CMD:xz}
;;
esac
done
# third pass; rename to base name
for t in ${IMAGE_TYPES}; do
case $t in
fit|fit.*)
mv ${IMAGE_NAME}.$t ${IMAGE_BASENAME}.$t
;;
esac
done
}
addtask do_image_fit before do_deploy
do_install[dirs] = "${B}"
fitimage_do_install() {
for t in ${IMAGE_TYPES}; do
case $t in
fit|fit.*)
install -D -p -m 0644 ${IMAGE_BASENAME}.$t ${D}/boot/${FITIMAGE_BOOT_NAME}.$t
;;
esac
done
}
addtask do_install before do_build after do_image_fit
do_deploy[cleandirs] = "${DEPLOYDIR}"
do_deploy[dirs] = "${B}"
fitimage_do_deploy() {
for t in ${IMAGE_TYPES}; do
case $t in
fit|fit.*)
install -D -p -m 0644 '${IMAGE_BASENAME}'.$t '${DEPLOYDIR}/${IMAGE_NAME}'.$t
ln -s '${IMAGE_NAME}'.$t '${DEPLOYDIR}/${IMAGE_BASENAME}'.$t
ln -s '${IMAGE_NAME}'.$t '${DEPLOYDIR}/${IMAGE_BASENAME}-${MACHINE}'.$t
;;
esac
done
}
addtask do_deploy before do_build after do_image_fit
EXPORT_FUNCTIONS do_image_fit do_install do_deploy