Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1 | inherit kernel-uboot |
| 2 | |
| 3 | python __anonymous () { |
He Zhe | fe76b1e | 2016-05-25 04:47:16 -0400 | [diff] [blame] | 4 | kerneltypes = d.getVar('KERNEL_IMAGETYPES', True) or "" |
| 5 | if 'fitImage' in kerneltypes.split(): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 6 | depends = d.getVar("DEPENDS", True) |
| 7 | depends = "%s u-boot-mkimage-native dtc-native" % depends |
| 8 | d.setVar("DEPENDS", depends) |
| 9 | |
| 10 | # Override KERNEL_IMAGETYPE_FOR_MAKE variable, which is internal |
| 11 | # to kernel.bbclass . We have to override it, since we pack zImage |
| 12 | # (at least for now) into the fitImage . |
He Zhe | fe76b1e | 2016-05-25 04:47:16 -0400 | [diff] [blame] | 13 | typeformake = d.getVar("KERNEL_IMAGETYPE_FOR_MAKE", True) or "" |
| 14 | if 'fitImage' in typeformake.split(): |
| 15 | d.setVar('KERNEL_IMAGETYPE_FOR_MAKE', typeformake.replace('fitImage', 'zImage')) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 16 | |
| 17 | image = d.getVar('INITRAMFS_IMAGE', True) |
| 18 | if image: |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 19 | d.appendVarFlag('do_assemble_fitimage_initramfs', 'depends', ' ${INITRAMFS_IMAGE}:do_image_complete') |
| 20 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 21 | } |
| 22 | |
Yannick Gicquel | d5813b4 | 2016-04-27 16:20:55 +0200 | [diff] [blame] | 23 | # Options for the device tree compiler passed to mkimage '-D' feature: |
| 24 | UBOOT_MKIMAGE_DTCOPTS ??= "" |
| 25 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 26 | # |
| 27 | # Emit the fitImage ITS header |
| 28 | # |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 29 | # $1 ... .its filename |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 30 | fitimage_emit_fit_header() { |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 31 | cat << EOF >> ${1} |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 32 | /dts-v1/; |
| 33 | |
| 34 | / { |
| 35 | description = "U-Boot fitImage for ${DISTRO_NAME}/${PV}/${MACHINE}"; |
| 36 | #address-cells = <1>; |
| 37 | EOF |
| 38 | } |
| 39 | |
| 40 | # |
| 41 | # Emit the fitImage section bits |
| 42 | # |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 43 | # $1 ... .its filename |
| 44 | # $2 ... Section bit type: imagestart - image section start |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 45 | # confstart - configuration section start |
| 46 | # sectend - section end |
| 47 | # fitend - fitimage end |
| 48 | # |
| 49 | fitimage_emit_section_maint() { |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 50 | case $2 in |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 51 | imagestart) |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 52 | cat << EOF >> ${1} |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 53 | |
| 54 | images { |
| 55 | EOF |
| 56 | ;; |
| 57 | confstart) |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 58 | cat << EOF >> ${1} |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 59 | |
| 60 | configurations { |
| 61 | EOF |
| 62 | ;; |
| 63 | sectend) |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 64 | cat << EOF >> ${1} |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 65 | }; |
| 66 | EOF |
| 67 | ;; |
| 68 | fitend) |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 69 | cat << EOF >> ${1} |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 70 | }; |
| 71 | EOF |
| 72 | ;; |
| 73 | esac |
| 74 | } |
| 75 | |
| 76 | # |
| 77 | # Emit the fitImage ITS kernel section |
| 78 | # |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 79 | # $1 ... .its filename |
| 80 | # $2 ... Image counter |
| 81 | # $3 ... Path to kernel image |
| 82 | # $4 ... Compression type |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 83 | fitimage_emit_section_kernel() { |
| 84 | |
| 85 | kernel_csum="sha1" |
| 86 | |
| 87 | ENTRYPOINT=${UBOOT_ENTRYPOINT} |
| 88 | if test -n "${UBOOT_ENTRYSYMBOL}"; then |
| 89 | ENTRYPOINT=`${HOST_PREFIX}nm ${S}/vmlinux | \ |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 90 | awk '$4=="${UBOOT_ENTRYSYMBOL}" {print $2}'` |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 91 | fi |
| 92 | |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 93 | cat << EOF >> ${1} |
| 94 | kernel@${2} { |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 95 | description = "Linux kernel"; |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 96 | data = /incbin/("${3}"); |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 97 | type = "kernel"; |
| 98 | arch = "${UBOOT_ARCH}"; |
| 99 | os = "linux"; |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 100 | compression = "${4}"; |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 101 | load = <${UBOOT_LOADADDRESS}>; |
| 102 | entry = <${ENTRYPOINT}>; |
| 103 | hash@1 { |
| 104 | algo = "${kernel_csum}"; |
| 105 | }; |
| 106 | }; |
| 107 | EOF |
| 108 | } |
| 109 | |
| 110 | # |
| 111 | # Emit the fitImage ITS DTB section |
| 112 | # |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 113 | # $1 ... .its filename |
| 114 | # $2 ... Image counter |
| 115 | # $3 ... Path to DTB image |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 116 | fitimage_emit_section_dtb() { |
| 117 | |
| 118 | dtb_csum="sha1" |
| 119 | |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 120 | cat << EOF >> ${1} |
| 121 | fdt@${2} { |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 122 | description = "Flattened Device Tree blob"; |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 123 | data = /incbin/("${3}"); |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 124 | type = "flat_dt"; |
| 125 | arch = "${UBOOT_ARCH}"; |
| 126 | compression = "none"; |
| 127 | hash@1 { |
| 128 | algo = "${dtb_csum}"; |
| 129 | }; |
| 130 | }; |
| 131 | EOF |
| 132 | } |
| 133 | |
| 134 | # |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 135 | # Emit the fitImage ITS ramdisk section |
| 136 | # |
| 137 | # $1 ... .its filename |
| 138 | # $2 ... Image counter |
| 139 | # $3 ... Path to ramdisk image |
| 140 | fitimage_emit_section_ramdisk() { |
| 141 | |
| 142 | ramdisk_csum="sha1" |
| 143 | |
| 144 | cat << EOF >> ${1} |
| 145 | ramdisk@${2} { |
| 146 | description = "ramdisk image"; |
| 147 | data = /incbin/("${3}"); |
| 148 | type = "ramdisk"; |
| 149 | arch = "${UBOOT_ARCH}"; |
| 150 | os = "linux"; |
| 151 | compression = "none"; |
| 152 | load = <${UBOOT_RD_LOADADDRESS}>; |
| 153 | entry = <${UBOOT_RD_ENTRYPOINT}>; |
| 154 | hash@1 { |
| 155 | algo = "${ramdisk_csum}"; |
| 156 | }; |
| 157 | }; |
| 158 | EOF |
| 159 | } |
| 160 | |
| 161 | # |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 162 | # Emit the fitImage ITS configuration section |
| 163 | # |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 164 | # $1 ... .its filename |
| 165 | # $2 ... Linux kernel ID |
| 166 | # $3 ... DTB image ID |
| 167 | # $4 ... ramdisk ID |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 168 | fitimage_emit_section_config() { |
| 169 | |
| 170 | conf_csum="sha1" |
| 171 | |
| 172 | # Test if we have any DTBs at all |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 173 | if [ -z "${3}" -a -z "${4}" ] ; then |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 174 | conf_desc="Boot Linux kernel" |
| 175 | fdt_line="" |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 176 | ramdisk_line="" |
| 177 | elif [ -z "${4}" ]; then |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 178 | conf_desc="Boot Linux kernel with FDT blob" |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 179 | fdt_line="fdt = \"fdt@${3}\";" |
| 180 | ramdisk_line="" |
| 181 | elif [ -z "${3}" ]; then |
| 182 | conf_desc="Boot Linux kernel with ramdisk" |
| 183 | fdt_line="" |
| 184 | ramdisk_line="ramdisk = \"ramdisk@${4}\";" |
| 185 | else |
| 186 | conf_desc="Boot Linux kernel with FDT blob, ramdisk" |
| 187 | fdt_line="fdt = \"fdt@${3}\";" |
| 188 | ramdisk_line="ramdisk = \"ramdisk@${4}\";" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 189 | fi |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 190 | kernel_line="kernel = \"kernel@${2}\";" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 191 | |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 192 | cat << EOF >> ${1} |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 193 | default = "conf@1"; |
| 194 | conf@1 { |
| 195 | description = "${conf_desc}"; |
| 196 | ${kernel_line} |
| 197 | ${fdt_line} |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 198 | ${ramdisk_line} |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 199 | hash@1 { |
| 200 | algo = "${conf_csum}"; |
| 201 | }; |
| 202 | }; |
| 203 | EOF |
| 204 | } |
| 205 | |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 206 | # |
| 207 | # Assemble fitImage |
| 208 | # |
| 209 | # $1 ... .its filename |
| 210 | # $2 ... fitImage name |
| 211 | # $3 ... include ramdisk |
| 212 | fitimage_assemble() { |
| 213 | kernelcount=1 |
| 214 | dtbcount="" |
| 215 | ramdiskcount=${3} |
| 216 | rm -f ${1} arch/${ARCH}/boot/${2} |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 217 | |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 218 | fitimage_emit_fit_header ${1} |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 219 | |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 220 | # |
| 221 | # Step 1: Prepare a kernel image section. |
| 222 | # |
| 223 | fitimage_emit_section_maint ${1} imagestart |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 224 | |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 225 | uboot_prep_kimage |
| 226 | fitimage_emit_section_kernel ${1} "${kernelcount}" linux.bin "${linux_comp}" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 227 | |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 228 | # |
| 229 | # Step 2: Prepare a DTB image section |
| 230 | # |
| 231 | if test -n "${KERNEL_DEVICETREE}"; then |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 232 | dtbcount=1 |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 233 | for DTB in ${KERNEL_DEVICETREE}; do |
| 234 | if echo ${DTB} | grep -q '/dts/'; then |
| 235 | bbwarn "${DTB} contains the full path to the the dts file, but only the dtb name should be used." |
| 236 | DTB=`basename ${DTB} | sed 's,\.dts$,.dtb,g'` |
| 237 | fi |
| 238 | DTB_PATH="arch/${ARCH}/boot/dts/${DTB}" |
| 239 | if [ ! -e "${DTB_PATH}" ]; then |
| 240 | DTB_PATH="arch/${ARCH}/boot/${DTB}" |
| 241 | fi |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 242 | |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 243 | fitimage_emit_section_dtb ${1} ${dtbcount} ${DTB_PATH} |
| 244 | dtbcount=`expr ${dtbcount} + 1` |
| 245 | done |
| 246 | fi |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 247 | |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 248 | # |
| 249 | # Step 3: Prepare a ramdisk section. |
| 250 | # |
| 251 | if [ "x${ramdiskcount}" = "x1" ] ; then |
| 252 | copy_initramfs |
| 253 | fitimage_emit_section_ramdisk ${1} "${ramdiskcount}" usr/${INITRAMFS_IMAGE}-${MACHINE}.cpio |
| 254 | fi |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 255 | |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 256 | fitimage_emit_section_maint ${1} sectend |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 257 | |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 258 | # Force the first Kernel and DTB in the default config |
| 259 | kernelcount=1 |
| 260 | dtbcount=1 |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 261 | |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 262 | # |
| 263 | # Step 4: Prepare a configurations section |
| 264 | # |
| 265 | fitimage_emit_section_maint ${1} confstart |
| 266 | |
| 267 | fitimage_emit_section_config ${1} ${kernelcount} ${dtbcount} ${ramdiskcount} |
| 268 | |
| 269 | fitimage_emit_section_maint ${1} sectend |
| 270 | |
| 271 | fitimage_emit_section_maint ${1} fitend |
| 272 | |
| 273 | # |
| 274 | # Step 5: Assemble the image |
| 275 | # |
| 276 | uboot-mkimage \ |
| 277 | ${@'-D "${UBOOT_MKIMAGE_DTCOPTS}"' if len('${UBOOT_MKIMAGE_DTCOPTS}') else ''} \ |
| 278 | -f ${1} \ |
| 279 | arch/${ARCH}/boot/${2} |
| 280 | } |
| 281 | |
| 282 | do_assemble_fitimage() { |
| 283 | if echo ${KERNEL_IMAGETYPES} | grep -wq "fitImage"; then |
| 284 | cd ${B} |
| 285 | fitimage_assemble fit-image.its fitImage |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 286 | fi |
| 287 | } |
| 288 | |
| 289 | addtask assemble_fitimage before do_install after do_compile |
| 290 | |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 291 | do_assemble_fitimage_initramfs() { |
| 292 | if echo ${KERNEL_IMAGETYPES} | grep -wq "fitImage" && \ |
| 293 | test -n "${INITRAMFS_IMAGE}" ; then |
| 294 | cd ${B} |
| 295 | fitimage_assemble fit-image-${INITRAMFS_IMAGE}.its fitImage-${INITRAMFS_IMAGE} 1 |
| 296 | fi |
| 297 | } |
| 298 | |
| 299 | addtask assemble_fitimage_initramfs before do_deploy after do_install |
| 300 | |
| 301 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 302 | kernel_do_deploy[vardepsexclude] = "DATETIME" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 303 | kernel_do_deploy_append() { |
| 304 | # Update deploy directory |
He Zhe | fe76b1e | 2016-05-25 04:47:16 -0400 | [diff] [blame] | 305 | if echo ${KERNEL_IMAGETYPES} | grep -wq "fitImage"; then |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 306 | cd ${B} |
| 307 | echo "Copying fit-image.its source file..." |
He Zhe | fe76b1e | 2016-05-25 04:47:16 -0400 | [diff] [blame] | 308 | its_base_name="fitImage-its-${PV}-${PR}-${MACHINE}-${DATETIME}" |
| 309 | its_symlink_name=fitImage-its-${MACHINE} |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 310 | install -m 0644 fit-image.its ${DEPLOYDIR}/${its_base_name}.its |
He Zhe | fe76b1e | 2016-05-25 04:47:16 -0400 | [diff] [blame] | 311 | linux_bin_base_name="fitImage-linux.bin-${PV}-${PR}-${MACHINE}-${DATETIME}" |
| 312 | linux_bin_symlink_name=fitImage-linux.bin-${MACHINE} |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 313 | install -m 0644 linux.bin ${DEPLOYDIR}/${linux_bin_base_name}.bin |
| 314 | |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 315 | if [ -n "${INITRAMFS_IMAGE}" ]; then |
| 316 | echo "Copying fit-image-${INITRAMFS_IMAGE}.its source file..." |
| 317 | its_initramfs_base_name="${KERNEL_IMAGETYPE}-its-${INITRAMFS_IMAGE}-${PV}-${PR}-${MACHINE}-${DATETIME}" |
| 318 | its_initramfs_symlink_name=${KERNEL_IMAGETYPE}-its-${INITRAMFS_IMAGE}-${MACHINE} |
| 319 | install -m 0644 fit-image-${INITRAMFS_IMAGE}.its ${DEPLOYDIR}/${its_initramfs_base_name}.its |
| 320 | fit_initramfs_base_name="${KERNEL_IMAGETYPE}-${INITRAMFS_IMAGE}-${PV}-${PR}-${MACHINE}-${DATETIME}" |
| 321 | fit_initramfs_symlink_name=${KERNEL_IMAGETYPE}-${INITRAMFS_IMAGE}-${MACHINE} |
| 322 | install -m 0644 arch/${ARCH}/boot/fitImage-${INITRAMFS_IMAGE} ${DEPLOYDIR}/${fit_initramfs_base_name}.bin |
| 323 | fi |
| 324 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 325 | cd ${DEPLOYDIR} |
| 326 | ln -sf ${its_base_name}.its ${its_symlink_name}.its |
| 327 | ln -sf ${linux_bin_base_name}.bin ${linux_bin_symlink_name}.bin |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 328 | |
| 329 | if [ -n "${INITRAMFS_IMAGE}" ]; then |
| 330 | ln -sf ${its_initramfs_base_name}.its ${its_initramfs_symlink_name}.its |
| 331 | ln -sf ${fit_initramfs_base_name}.bin ${fit_initramfs_symlink_name}.bin |
| 332 | fi |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 333 | fi |
| 334 | } |