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