Commit 5eb21386c94711e332b4ec8a4bd1dd5d3249e99d
Committed by
Ji Luo
1 parent
5bc03ddaf4
Exists in
smarc_8mm-imx_v2018.03_4.14.98_2.0.0_ga
and in
5 other branches
[iot] Copy fdt from the end of the kernel image
Bug: 78601846 Test: Boots with new boot image layout. Change-Id: I7c2cc7f62ad58756d76ef0d83ca6729fea9c07e9
Showing 2 changed files with 83 additions and 18 deletions Side-by-side Diff
CleanSpec.mk
1 | +# Copyright (C) 2018 The Android Open Source Project | |
2 | +# | |
3 | +# Licensed under the Apache License, Version 2.0 (the "License"); | |
4 | +# you may not use this file except in compliance with the License. | |
5 | +# You may obtain a copy of the License at | |
6 | +# | |
7 | +# http://www.apache.org/licenses/LICENSE-2.0 | |
8 | +# | |
9 | +# Unless required by applicable law or agreed to in writing, software | |
10 | +# distributed under the License is distributed on an "AS IS" BASIS, | |
11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
12 | +# See the License for the specific language governing permissions and | |
13 | +# limitations under the License. | |
14 | +# | |
15 | + | |
16 | +# If you don't need to do a full clean build but would like to touch | |
17 | +# a file or delete some intermediate files, add a clean step to the end | |
18 | +# of the list. These steps will only be run once, if they haven't been | |
19 | +# run before. | |
20 | +# | |
21 | +# E.g.: | |
22 | +# $(call add-clean-step, touch -c external/sqlite/sqlite3.h) | |
23 | +# $(call add-clean-step, rm -rf $(PRODUCT_OUT)/obj/STATIC_LIBRARIES/libz_intermediates) | |
24 | +# | |
25 | +# Always use "touch -c" and "rm -f" or "rm -rf" to gracefully deal with | |
26 | +# files that are missing or have been moved. | |
27 | +# | |
28 | +# Use $(PRODUCT_OUT) to get to the "out/target/product/blah/" directory. | |
29 | +# Use $(OUT_DIR) to refer to the "out" directory. | |
30 | +# | |
31 | +# If you need to re-do something that's already mentioned, just copy | |
32 | +# the command and add it to the bottom of the list. E.g., if a change | |
33 | +# that you made last week required touching a file and a change you | |
34 | +# made today requires touching the same file, just copy the old | |
35 | +# touch step and add it to the end of the list. | |
36 | +# | |
37 | +# ************************************************ | |
38 | +# NEWER CLEAN STEPS MUST BE AT THE END OF THE LIST | |
39 | +# ************************************************ | |
40 | + | |
41 | +# For example: | |
42 | +#$(call add-clean-step, rm -rf $(OUT_DIR)/target/common/obj/APPS/AndroidTests_intermediates) | |
43 | +#$(call add-clean-step, rm -rf $(OUT_DIR)/target/common/obj/JAVA_LIBRARIES/core_intermediates) | |
44 | +#$(call add-clean-step, find $(OUT_DIR) -type f -name "IGTalkSession*" -print0 | xargs -0 rm -f) | |
45 | +#$(call add-clean-step, rm -rf $(PRODUCT_OUT)/data/*) | |
46 | + | |
47 | +$(call add-clean-step, rm -rf $(TARGET_OUT_INTERMEDIATES)/UBOOT_OBJ) | |
48 | + | |
49 | +# ************************************************ | |
50 | +# NEWER CLEAN STEPS MUST BE AT THE END OF THE LIST | |
51 | +# ************************************************ |
drivers/usb/gadget/f_fastboot.c
... | ... | @@ -117,6 +117,10 @@ |
117 | 117 | #define AT_OEM_PART_SIZE 17 |
118 | 118 | #define AT_OEM_DEV_SIZE 6 |
119 | 119 | |
120 | +/* Offset (in u32's) of start and end fields in the zImage header. */ | |
121 | +#define ZIMAGE_START_ADDR 10 | |
122 | +#define ZIMAGE_END_ADDR 11 | |
123 | + | |
120 | 124 | /* common variables of fastboot getvar command */ |
121 | 125 | char *fastboot_common_var[FASTBOOT_COMMON_VAR_NUM] = { |
122 | 126 | "version", |
... | ... | @@ -1871,7 +1875,8 @@ |
1871 | 1875 | } |
1872 | 1876 | |
1873 | 1877 | #ifdef CONFIG_ANDROID_THINGS_SUPPORT |
1874 | -static int android_things_load_fdt(const char *slot, struct andr_img_hdr *hdrload) { | |
1878 | +static int android_things_load_fdt(const char *slot, | |
1879 | + struct andr_img_hdr *hdrload, u32 *fdt_size) { | |
1875 | 1880 | /* check for kernel.dtb in oem_bootloader */ |
1876 | 1881 | char oem_bootloader[AT_OEM_PART_SIZE]; |
1877 | 1882 | snprintf(oem_bootloader, AT_OEM_PART_SIZE, AT_OEM_PART_NAME "%s", slot); |
... | ... | @@ -1887,9 +1892,9 @@ |
1887 | 1892 | if (fs_set_blk_dev("mmc", dev_part, FS_TYPE_EXT) != 0) |
1888 | 1893 | return -1; |
1889 | 1894 | |
1890 | - loff_t dtb_size; | |
1891 | - if (!fs_read(AT_OEM_DTB, hdrload->second_addr, 0, 0, &dtb_size) && dtb_size) { | |
1892 | - hdrload->second_size = dtb_size; | |
1895 | + loff_t size; | |
1896 | + if (!fs_read(AT_OEM_DTB, hdrload->second_addr, 0, 0, &size) && size) { | |
1897 | + *fdt_size = size; | |
1893 | 1898 | return 0; |
1894 | 1899 | } |
1895 | 1900 | |
1896 | 1901 | |
1897 | 1902 | |
... | ... | @@ -2156,15 +2161,21 @@ |
2156 | 2161 | + ALIGN(hdr->kernel_size, hdr->page_size), hdr->ramdisk_size); |
2157 | 2162 | #endif |
2158 | 2163 | #ifdef CONFIG_OF_LIBFDT |
2164 | + u32 fdt_size = 0; | |
2159 | 2165 | bool fdt_loaded = false; |
2160 | 2166 | #ifdef CONFIG_ANDROID_THINGS_SUPPORT |
2161 | - fdt_loaded = !android_things_load_fdt(slot, hdr); | |
2167 | + fdt_loaded = !android_things_load_fdt(slot, hdr, &fdt_size); | |
2162 | 2168 | #endif /* CONFIG_ANDROID_THINGS_SUPPORT */ |
2163 | 2169 | /* load the dtb file */ |
2164 | - if (!fdt_loaded && hdr->second_size && hdr->second_addr) { | |
2165 | - memcpy((void *)(ulong)hdr->second_addr, (void *)(ulong)hdr->kernel_addr | |
2166 | - + ALIGN(hdr->kernel_size, hdr->page_size) | |
2167 | - + ALIGN(hdr->ramdisk_size, hdr->page_size), hdr->second_size); | |
2170 | + if (!fdt_loaded && hdr->second_addr) { | |
2171 | + /* The fdt is appended to the zImage. Use the address and size of the kernel | |
2172 | + section of the boot image and the kernel size from the zImage to | |
2173 | + calculate the address and size of the fdt. */ | |
2174 | + u32 zimage_size = ((u32 *)hdr->kernel_addr)[ZIMAGE_END_ADDR] | |
2175 | + - ((u32 *)hdr->kernel_addr)[ZIMAGE_START_ADDR]; | |
2176 | + fdt_size = hdr->kernel_size - zimage_size; | |
2177 | + memcpy((void *)(ulong)hdr->second_addr, | |
2178 | + (void*)(ulong)hdr->kernel_addr + zimage_size, fdt_size); | |
2168 | 2179 | } |
2169 | 2180 | #endif /*CONFIG_OF_LIBFDT*/ |
2170 | 2181 | if (check_image_arm64) { |
... | ... | @@ -2176,8 +2187,8 @@ |
2176 | 2187 | printf("kernel @ %08x (%d)\n", hdr->kernel_addr, hdr->kernel_size); |
2177 | 2188 | printf("ramdisk @ %08x (%d)\n", hdr->ramdisk_addr, hdr->ramdisk_size); |
2178 | 2189 | #ifdef CONFIG_OF_LIBFDT |
2179 | - if (hdr->second_size) | |
2180 | - printf("fdt @ %08x (%d)\n", hdr->second_addr, hdr->second_size); | |
2190 | + if (fdt_size) | |
2191 | + printf("fdt @ %08x (%d)\n", hdr->second_addr, fdt_size); | |
2181 | 2192 | #endif /*CONFIG_OF_LIBFDT*/ |
2182 | 2193 | |
2183 | 2194 | char boot_addr_start[12]; |
... | ... | @@ -2206,7 +2217,7 @@ |
2206 | 2217 | |
2207 | 2218 | #ifdef CONFIG_IMX_TRUSTY_OS |
2208 | 2219 | /* Trusty keymaster needs some parameters before it work */ |
2209 | - trusty_setbootparameter(hdrload, avb_result); | |
2220 | + trusty_setbootparameter(hdr, avb_result); | |
2210 | 2221 | /* put ql-tipc to release resource for Linux */ |
2211 | 2222 | trusty_ipc_shutdown(); |
2212 | 2223 | #endif |
2213 | 2224 | |
... | ... | @@ -2340,11 +2351,14 @@ |
2340 | 2351 | + ALIGN(hdr->kernel_size, hdr->page_size), hdr->ramdisk_size); |
2341 | 2352 | |
2342 | 2353 | #ifdef CONFIG_OF_LIBFDT |
2354 | + u32 fdt_size = 0; | |
2343 | 2355 | /* load the dtb file */ |
2344 | - if (hdr->second_size && hdr->second_addr) { | |
2345 | - memcpy((void *)hdr->second_addr, (void *)hdr->kernel_addr | |
2346 | - + ALIGN(hdr->kernel_size, hdr->page_size) | |
2347 | - + ALIGN(hdr->ramdisk_size, hdr->page_size), hdr->second_size); | |
2356 | + if (hdr->second_addr) { | |
2357 | + u32 zimage_size = ((u32 *)hdrload->kernel_addr)[ZIMAGE_END_ADDR] | |
2358 | + - ((u32 *)hdrload->kernel_addr)[ZIMAGE_START_ADDR]; | |
2359 | + fdt_size = hdrload->kernel_size - zimage_size; | |
2360 | + memcpy((void *)(ulong)hdrload->second_addr, | |
2361 | + (void*)(ulong)hdrload->kernel_addr + zimage_size, fdt_size); | |
2348 | 2362 | } |
2349 | 2363 | #endif /*CONFIG_OF_LIBFDT*/ |
2350 | 2364 | |
... | ... | @@ -2359,8 +2373,8 @@ |
2359 | 2373 | printf("kernel @ %08x (%d)\n", hdr->kernel_addr, hdr->kernel_size); |
2360 | 2374 | printf("ramdisk @ %08x (%d)\n", hdr->ramdisk_addr, hdr->ramdisk_size); |
2361 | 2375 | #ifdef CONFIG_OF_LIBFDT |
2362 | - if (hdr->second_size) | |
2363 | - printf("fdt @ %08x (%d)\n", hdr->second_addr, hdr->second_size); | |
2376 | + if (fdt_size) | |
2377 | + printf("fdt @ %08x (%d)\n", hdr->second_addr, fdt_size); | |
2364 | 2378 | #endif /*CONFIG_OF_LIBFDT*/ |
2365 | 2379 | |
2366 | 2380 |