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: |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 19 | d.appendVarFlag('do_assemble_fitimage', 'depends', ' ${INITRAMFS_IMAGE}:do_image_complete') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 20 | } |
| 21 | |
Yannick Gicquel | d5813b4 | 2016-04-27 16:20:55 +0200 | [diff] [blame^] | 22 | # Options for the device tree compiler passed to mkimage '-D' feature: |
| 23 | UBOOT_MKIMAGE_DTCOPTS ??= "" |
| 24 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 25 | # |
| 26 | # Emit the fitImage ITS header |
| 27 | # |
| 28 | fitimage_emit_fit_header() { |
| 29 | cat << EOF >> fit-image.its |
| 30 | /dts-v1/; |
| 31 | |
| 32 | / { |
| 33 | description = "U-Boot fitImage for ${DISTRO_NAME}/${PV}/${MACHINE}"; |
| 34 | #address-cells = <1>; |
| 35 | EOF |
| 36 | } |
| 37 | |
| 38 | # |
| 39 | # Emit the fitImage section bits |
| 40 | # |
| 41 | # $1 ... Section bit type: imagestart - image section start |
| 42 | # confstart - configuration section start |
| 43 | # sectend - section end |
| 44 | # fitend - fitimage end |
| 45 | # |
| 46 | fitimage_emit_section_maint() { |
| 47 | case $1 in |
| 48 | imagestart) |
| 49 | cat << EOF >> fit-image.its |
| 50 | |
| 51 | images { |
| 52 | EOF |
| 53 | ;; |
| 54 | confstart) |
| 55 | cat << EOF >> fit-image.its |
| 56 | |
| 57 | configurations { |
| 58 | EOF |
| 59 | ;; |
| 60 | sectend) |
| 61 | cat << EOF >> fit-image.its |
| 62 | }; |
| 63 | EOF |
| 64 | ;; |
| 65 | fitend) |
| 66 | cat << EOF >> fit-image.its |
| 67 | }; |
| 68 | EOF |
| 69 | ;; |
| 70 | esac |
| 71 | } |
| 72 | |
| 73 | # |
| 74 | # Emit the fitImage ITS kernel section |
| 75 | # |
| 76 | # $1 ... Image counter |
| 77 | # $2 ... Path to kernel image |
| 78 | # $3 ... Compression type |
| 79 | fitimage_emit_section_kernel() { |
| 80 | |
| 81 | kernel_csum="sha1" |
| 82 | |
| 83 | ENTRYPOINT=${UBOOT_ENTRYPOINT} |
| 84 | if test -n "${UBOOT_ENTRYSYMBOL}"; then |
| 85 | ENTRYPOINT=`${HOST_PREFIX}nm ${S}/vmlinux | \ |
| 86 | awk '$3=="${UBOOT_ENTRYSYMBOL}" {print $1}'` |
| 87 | fi |
| 88 | |
| 89 | cat << EOF >> fit-image.its |
| 90 | kernel@${1} { |
| 91 | description = "Linux kernel"; |
| 92 | data = /incbin/("${2}"); |
| 93 | type = "kernel"; |
| 94 | arch = "${UBOOT_ARCH}"; |
| 95 | os = "linux"; |
| 96 | compression = "${3}"; |
| 97 | load = <${UBOOT_LOADADDRESS}>; |
| 98 | entry = <${ENTRYPOINT}>; |
| 99 | hash@1 { |
| 100 | algo = "${kernel_csum}"; |
| 101 | }; |
| 102 | }; |
| 103 | EOF |
| 104 | } |
| 105 | |
| 106 | # |
| 107 | # Emit the fitImage ITS DTB section |
| 108 | # |
| 109 | # $1 ... Image counter |
| 110 | # $2 ... Path to DTB image |
| 111 | fitimage_emit_section_dtb() { |
| 112 | |
| 113 | dtb_csum="sha1" |
| 114 | |
| 115 | cat << EOF >> fit-image.its |
| 116 | fdt@${1} { |
| 117 | description = "Flattened Device Tree blob"; |
| 118 | data = /incbin/("${2}"); |
| 119 | type = "flat_dt"; |
| 120 | arch = "${UBOOT_ARCH}"; |
| 121 | compression = "none"; |
| 122 | hash@1 { |
| 123 | algo = "${dtb_csum}"; |
| 124 | }; |
| 125 | }; |
| 126 | EOF |
| 127 | } |
| 128 | |
| 129 | # |
| 130 | # Emit the fitImage ITS configuration section |
| 131 | # |
| 132 | # $1 ... Linux kernel ID |
| 133 | # $2 ... DTB image ID |
| 134 | fitimage_emit_section_config() { |
| 135 | |
| 136 | conf_csum="sha1" |
| 137 | |
| 138 | # Test if we have any DTBs at all |
| 139 | if [ -z "${2}" ] ; then |
| 140 | conf_desc="Boot Linux kernel" |
| 141 | fdt_line="" |
| 142 | else |
| 143 | conf_desc="Boot Linux kernel with FDT blob" |
| 144 | fdt_line="fdt = \"fdt@${2}\";" |
| 145 | fi |
| 146 | kernel_line="kernel = \"kernel@${1}\";" |
| 147 | |
| 148 | cat << EOF >> fit-image.its |
| 149 | default = "conf@1"; |
| 150 | conf@1 { |
| 151 | description = "${conf_desc}"; |
| 152 | ${kernel_line} |
| 153 | ${fdt_line} |
| 154 | hash@1 { |
| 155 | algo = "${conf_csum}"; |
| 156 | }; |
| 157 | }; |
| 158 | EOF |
| 159 | } |
| 160 | |
| 161 | do_assemble_fitimage() { |
Andrew Bradford | c6b8b14 | 2016-08-04 13:40:40 -0400 | [diff] [blame] | 162 | cd ${B} |
He Zhe | fe76b1e | 2016-05-25 04:47:16 -0400 | [diff] [blame] | 163 | if echo ${KERNEL_IMAGETYPES} | grep -wq "fitImage"; then |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 164 | kernelcount=1 |
| 165 | dtbcount="" |
| 166 | rm -f fit-image.its |
| 167 | |
| 168 | fitimage_emit_fit_header |
| 169 | |
| 170 | # |
| 171 | # Step 1: Prepare a kernel image section. |
| 172 | # |
| 173 | fitimage_emit_section_maint imagestart |
| 174 | |
| 175 | uboot_prep_kimage |
| 176 | fitimage_emit_section_kernel "${kernelcount}" linux.bin "${linux_comp}" |
| 177 | |
| 178 | # |
| 179 | # Step 2: Prepare a DTB image section |
| 180 | # |
| 181 | if test -n "${KERNEL_DEVICETREE}"; then |
| 182 | dtbcount=1 |
| 183 | for DTB in ${KERNEL_DEVICETREE}; do |
| 184 | if echo ${DTB} | grep -q '/dts/'; then |
| 185 | bbwarn "${DTB} contains the full path to the the dts file, but only the dtb name should be used." |
| 186 | DTB=`basename ${DTB} | sed 's,\.dts$,.dtb,g'` |
| 187 | fi |
| 188 | DTB_PATH="arch/${ARCH}/boot/dts/${DTB}" |
| 189 | if [ ! -e "${DTB_PATH}" ]; then |
| 190 | DTB_PATH="arch/${ARCH}/boot/${DTB}" |
| 191 | fi |
| 192 | |
| 193 | fitimage_emit_section_dtb ${dtbcount} ${DTB_PATH} |
| 194 | dtbcount=`expr ${dtbcount} + 1` |
| 195 | done |
| 196 | fi |
| 197 | |
| 198 | fitimage_emit_section_maint sectend |
| 199 | |
| 200 | # Force the first Kernel and DTB in the default config |
| 201 | kernelcount=1 |
| 202 | dtbcount=1 |
| 203 | |
| 204 | # |
| 205 | # Step 3: Prepare a configurations section |
| 206 | # |
| 207 | fitimage_emit_section_maint confstart |
| 208 | |
| 209 | fitimage_emit_section_config ${kernelcount} ${dtbcount} |
| 210 | |
| 211 | fitimage_emit_section_maint sectend |
| 212 | |
| 213 | fitimage_emit_section_maint fitend |
| 214 | |
| 215 | # |
| 216 | # Step 4: Assemble the image |
| 217 | # |
Yannick Gicquel | d5813b4 | 2016-04-27 16:20:55 +0200 | [diff] [blame^] | 218 | uboot-mkimage \ |
| 219 | ${@'-D "${UBOOT_MKIMAGE_DTCOPTS}"' if len('${UBOOT_MKIMAGE_DTCOPTS}') else ''} \ |
| 220 | -f fit-image.its \ |
| 221 | arch/${ARCH}/boot/fitImage |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 222 | fi |
| 223 | } |
| 224 | |
| 225 | addtask assemble_fitimage before do_install after do_compile |
| 226 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 227 | kernel_do_deploy[vardepsexclude] = "DATETIME" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 228 | kernel_do_deploy_append() { |
| 229 | # Update deploy directory |
He Zhe | fe76b1e | 2016-05-25 04:47:16 -0400 | [diff] [blame] | 230 | if echo ${KERNEL_IMAGETYPES} | grep -wq "fitImage"; then |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 231 | cd ${B} |
| 232 | echo "Copying fit-image.its source file..." |
He Zhe | fe76b1e | 2016-05-25 04:47:16 -0400 | [diff] [blame] | 233 | its_base_name="fitImage-its-${PV}-${PR}-${MACHINE}-${DATETIME}" |
| 234 | its_symlink_name=fitImage-its-${MACHINE} |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 235 | install -m 0644 fit-image.its ${DEPLOYDIR}/${its_base_name}.its |
He Zhe | fe76b1e | 2016-05-25 04:47:16 -0400 | [diff] [blame] | 236 | linux_bin_base_name="fitImage-linux.bin-${PV}-${PR}-${MACHINE}-${DATETIME}" |
| 237 | linux_bin_symlink_name=fitImage-linux.bin-${MACHINE} |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 238 | install -m 0644 linux.bin ${DEPLOYDIR}/${linux_bin_base_name}.bin |
| 239 | |
| 240 | cd ${DEPLOYDIR} |
| 241 | ln -sf ${its_base_name}.its ${its_symlink_name}.its |
| 242 | ln -sf ${linux_bin_base_name}.bin ${linux_bin_symlink_name}.bin |
| 243 | fi |
| 244 | } |