Freescale u-boot repository
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

264 lines
7.2 KiB

image: add support for Android's boot image format This patch adds support for the Android boot-image format. The header file is from the Android project and got slightly alterted so the struct + its defines are not generic but have something like a namespace. The header file is from bootloader/legacy/include/boot/bootimg.h. The header parsing has been written from scratch and I looked at bootloader/legacy/usbloader/usbloader.c for some details. The image contains the physical address (load address) of the kernel and ramdisk. This address is considered only for the kernel image. The "second image" defined in the image header is currently not supported. I haven't found anything that is creating this. v3 (Rob Herring): This is based on http://patchwork.ozlabs.org/patch/126797/ with the following changes: - Rebased to current mainline - Moved android image handling to separate functions in common/image-android.c - s/u8/char/ in header to fix string function warnings - Use SPDX identifiers for licenses - Cleaned-up file source information: android_image.h is from file include/boot/bootimg.h in repository: https://android.googlesource.com/platform/bootable/bootloader/legacy The git commit hash is 4205b865141ff2e255fe1d3bd16de18e217ef06a usbloader.c would be from the same commit, but it does not appear to have been used for any actual code. v4: - s/andriod/android/ - Use a separate flag ep_found to track if the entry point has been set rather than using a magic value. Cc: Wolfgang Denk <wd@denx.de> Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de> Signed-off-by: Rob Herring <robh@kernel.org> Reviewed-by: Tom Rini <trini@ti.com> Reviewed-by: Lukasz Majewski <l.majewski@samsung.com>
7 years ago
image: add support for Android's boot image format This patch adds support for the Android boot-image format. The header file is from the Android project and got slightly alterted so the struct + its defines are not generic but have something like a namespace. The header file is from bootloader/legacy/include/boot/bootimg.h. The header parsing has been written from scratch and I looked at bootloader/legacy/usbloader/usbloader.c for some details. The image contains the physical address (load address) of the kernel and ramdisk. This address is considered only for the kernel image. The "second image" defined in the image header is currently not supported. I haven't found anything that is creating this. v3 (Rob Herring): This is based on http://patchwork.ozlabs.org/patch/126797/ with the following changes: - Rebased to current mainline - Moved android image handling to separate functions in common/image-android.c - s/u8/char/ in header to fix string function warnings - Use SPDX identifiers for licenses - Cleaned-up file source information: android_image.h is from file include/boot/bootimg.h in repository: https://android.googlesource.com/platform/bootable/bootloader/legacy The git commit hash is 4205b865141ff2e255fe1d3bd16de18e217ef06a usbloader.c would be from the same commit, but it does not appear to have been used for any actual code. v4: - s/andriod/android/ - Use a separate flag ep_found to track if the entry point has been set rather than using a magic value. Cc: Wolfgang Denk <wd@denx.de> Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de> Signed-off-by: Rob Herring <robh@kernel.org> Reviewed-by: Tom Rini <trini@ti.com> Reviewed-by: Lukasz Majewski <l.majewski@samsung.com>
7 years ago
image: add support for Android's boot image format This patch adds support for the Android boot-image format. The header file is from the Android project and got slightly alterted so the struct + its defines are not generic but have something like a namespace. The header file is from bootloader/legacy/include/boot/bootimg.h. The header parsing has been written from scratch and I looked at bootloader/legacy/usbloader/usbloader.c for some details. The image contains the physical address (load address) of the kernel and ramdisk. This address is considered only for the kernel image. The "second image" defined in the image header is currently not supported. I haven't found anything that is creating this. v3 (Rob Herring): This is based on http://patchwork.ozlabs.org/patch/126797/ with the following changes: - Rebased to current mainline - Moved android image handling to separate functions in common/image-android.c - s/u8/char/ in header to fix string function warnings - Use SPDX identifiers for licenses - Cleaned-up file source information: android_image.h is from file include/boot/bootimg.h in repository: https://android.googlesource.com/platform/bootable/bootloader/legacy The git commit hash is 4205b865141ff2e255fe1d3bd16de18e217ef06a usbloader.c would be from the same commit, but it does not appear to have been used for any actual code. v4: - s/andriod/android/ - Use a separate flag ep_found to track if the entry point has been set rather than using a magic value. Cc: Wolfgang Denk <wd@denx.de> Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de> Signed-off-by: Rob Herring <robh@kernel.org> Reviewed-by: Tom Rini <trini@ti.com> Reviewed-by: Lukasz Majewski <l.majewski@samsung.com>
7 years ago
image: add support for Android's boot image format This patch adds support for the Android boot-image format. The header file is from the Android project and got slightly alterted so the struct + its defines are not generic but have something like a namespace. The header file is from bootloader/legacy/include/boot/bootimg.h. The header parsing has been written from scratch and I looked at bootloader/legacy/usbloader/usbloader.c for some details. The image contains the physical address (load address) of the kernel and ramdisk. This address is considered only for the kernel image. The "second image" defined in the image header is currently not supported. I haven't found anything that is creating this. v3 (Rob Herring): This is based on http://patchwork.ozlabs.org/patch/126797/ with the following changes: - Rebased to current mainline - Moved android image handling to separate functions in common/image-android.c - s/u8/char/ in header to fix string function warnings - Use SPDX identifiers for licenses - Cleaned-up file source information: android_image.h is from file include/boot/bootimg.h in repository: https://android.googlesource.com/platform/bootable/bootloader/legacy The git commit hash is 4205b865141ff2e255fe1d3bd16de18e217ef06a usbloader.c would be from the same commit, but it does not appear to have been used for any actual code. v4: - s/andriod/android/ - Use a separate flag ep_found to track if the entry point has been set rather than using a magic value. Cc: Wolfgang Denk <wd@denx.de> Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de> Signed-off-by: Rob Herring <robh@kernel.org> Reviewed-by: Tom Rini <trini@ti.com> Reviewed-by: Lukasz Majewski <l.majewski@samsung.com>
7 years ago
image: add support for Android's boot image format This patch adds support for the Android boot-image format. The header file is from the Android project and got slightly alterted so the struct + its defines are not generic but have something like a namespace. The header file is from bootloader/legacy/include/boot/bootimg.h. The header parsing has been written from scratch and I looked at bootloader/legacy/usbloader/usbloader.c for some details. The image contains the physical address (load address) of the kernel and ramdisk. This address is considered only for the kernel image. The "second image" defined in the image header is currently not supported. I haven't found anything that is creating this. v3 (Rob Herring): This is based on http://patchwork.ozlabs.org/patch/126797/ with the following changes: - Rebased to current mainline - Moved android image handling to separate functions in common/image-android.c - s/u8/char/ in header to fix string function warnings - Use SPDX identifiers for licenses - Cleaned-up file source information: android_image.h is from file include/boot/bootimg.h in repository: https://android.googlesource.com/platform/bootable/bootloader/legacy The git commit hash is 4205b865141ff2e255fe1d3bd16de18e217ef06a usbloader.c would be from the same commit, but it does not appear to have been used for any actual code. v4: - s/andriod/android/ - Use a separate flag ep_found to track if the entry point has been set rather than using a magic value. Cc: Wolfgang Denk <wd@denx.de> Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de> Signed-off-by: Rob Herring <robh@kernel.org> Reviewed-by: Tom Rini <trini@ti.com> Reviewed-by: Lukasz Majewski <l.majewski@samsung.com>
7 years ago
image: add support for Android's boot image format This patch adds support for the Android boot-image format. The header file is from the Android project and got slightly alterted so the struct + its defines are not generic but have something like a namespace. The header file is from bootloader/legacy/include/boot/bootimg.h. The header parsing has been written from scratch and I looked at bootloader/legacy/usbloader/usbloader.c for some details. The image contains the physical address (load address) of the kernel and ramdisk. This address is considered only for the kernel image. The "second image" defined in the image header is currently not supported. I haven't found anything that is creating this. v3 (Rob Herring): This is based on http://patchwork.ozlabs.org/patch/126797/ with the following changes: - Rebased to current mainline - Moved android image handling to separate functions in common/image-android.c - s/u8/char/ in header to fix string function warnings - Use SPDX identifiers for licenses - Cleaned-up file source information: android_image.h is from file include/boot/bootimg.h in repository: https://android.googlesource.com/platform/bootable/bootloader/legacy The git commit hash is 4205b865141ff2e255fe1d3bd16de18e217ef06a usbloader.c would be from the same commit, but it does not appear to have been used for any actual code. v4: - s/andriod/android/ - Use a separate flag ep_found to track if the entry point has been set rather than using a magic value. Cc: Wolfgang Denk <wd@denx.de> Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de> Signed-off-by: Rob Herring <robh@kernel.org> Reviewed-by: Tom Rini <trini@ti.com> Reviewed-by: Lukasz Majewski <l.majewski@samsung.com>
7 years ago
image: add support for Android's boot image format This patch adds support for the Android boot-image format. The header file is from the Android project and got slightly alterted so the struct + its defines are not generic but have something like a namespace. The header file is from bootloader/legacy/include/boot/bootimg.h. The header parsing has been written from scratch and I looked at bootloader/legacy/usbloader/usbloader.c for some details. The image contains the physical address (load address) of the kernel and ramdisk. This address is considered only for the kernel image. The "second image" defined in the image header is currently not supported. I haven't found anything that is creating this. v3 (Rob Herring): This is based on http://patchwork.ozlabs.org/patch/126797/ with the following changes: - Rebased to current mainline - Moved android image handling to separate functions in common/image-android.c - s/u8/char/ in header to fix string function warnings - Use SPDX identifiers for licenses - Cleaned-up file source information: android_image.h is from file include/boot/bootimg.h in repository: https://android.googlesource.com/platform/bootable/bootloader/legacy The git commit hash is 4205b865141ff2e255fe1d3bd16de18e217ef06a usbloader.c would be from the same commit, but it does not appear to have been used for any actual code. v4: - s/andriod/android/ - Use a separate flag ep_found to track if the entry point has been set rather than using a magic value. Cc: Wolfgang Denk <wd@denx.de> Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de> Signed-off-by: Rob Herring <robh@kernel.org> Reviewed-by: Tom Rini <trini@ti.com> Reviewed-by: Lukasz Majewski <l.majewski@samsung.com>
7 years ago
image: add support for Android's boot image format This patch adds support for the Android boot-image format. The header file is from the Android project and got slightly alterted so the struct + its defines are not generic but have something like a namespace. The header file is from bootloader/legacy/include/boot/bootimg.h. The header parsing has been written from scratch and I looked at bootloader/legacy/usbloader/usbloader.c for some details. The image contains the physical address (load address) of the kernel and ramdisk. This address is considered only for the kernel image. The "second image" defined in the image header is currently not supported. I haven't found anything that is creating this. v3 (Rob Herring): This is based on http://patchwork.ozlabs.org/patch/126797/ with the following changes: - Rebased to current mainline - Moved android image handling to separate functions in common/image-android.c - s/u8/char/ in header to fix string function warnings - Use SPDX identifiers for licenses - Cleaned-up file source information: android_image.h is from file include/boot/bootimg.h in repository: https://android.googlesource.com/platform/bootable/bootloader/legacy The git commit hash is 4205b865141ff2e255fe1d3bd16de18e217ef06a usbloader.c would be from the same commit, but it does not appear to have been used for any actual code. v4: - s/andriod/android/ - Use a separate flag ep_found to track if the entry point has been set rather than using a magic value. Cc: Wolfgang Denk <wd@denx.de> Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de> Signed-off-by: Rob Herring <robh@kernel.org> Reviewed-by: Tom Rini <trini@ti.com> Reviewed-by: Lukasz Majewski <l.majewski@samsung.com>
7 years ago
image: add support for Android's boot image format This patch adds support for the Android boot-image format. The header file is from the Android project and got slightly alterted so the struct + its defines are not generic but have something like a namespace. The header file is from bootloader/legacy/include/boot/bootimg.h. The header parsing has been written from scratch and I looked at bootloader/legacy/usbloader/usbloader.c for some details. The image contains the physical address (load address) of the kernel and ramdisk. This address is considered only for the kernel image. The "second image" defined in the image header is currently not supported. I haven't found anything that is creating this. v3 (Rob Herring): This is based on http://patchwork.ozlabs.org/patch/126797/ with the following changes: - Rebased to current mainline - Moved android image handling to separate functions in common/image-android.c - s/u8/char/ in header to fix string function warnings - Use SPDX identifiers for licenses - Cleaned-up file source information: android_image.h is from file include/boot/bootimg.h in repository: https://android.googlesource.com/platform/bootable/bootloader/legacy The git commit hash is 4205b865141ff2e255fe1d3bd16de18e217ef06a usbloader.c would be from the same commit, but it does not appear to have been used for any actual code. v4: - s/andriod/android/ - Use a separate flag ep_found to track if the entry point has been set rather than using a magic value. Cc: Wolfgang Denk <wd@denx.de> Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de> Signed-off-by: Rob Herring <robh@kernel.org> Reviewed-by: Tom Rini <trini@ti.com> Reviewed-by: Lukasz Majewski <l.majewski@samsung.com>
7 years ago
image: add support for Android's boot image format This patch adds support for the Android boot-image format. The header file is from the Android project and got slightly alterted so the struct + its defines are not generic but have something like a namespace. The header file is from bootloader/legacy/include/boot/bootimg.h. The header parsing has been written from scratch and I looked at bootloader/legacy/usbloader/usbloader.c for some details. The image contains the physical address (load address) of the kernel and ramdisk. This address is considered only for the kernel image. The "second image" defined in the image header is currently not supported. I haven't found anything that is creating this. v3 (Rob Herring): This is based on http://patchwork.ozlabs.org/patch/126797/ with the following changes: - Rebased to current mainline - Moved android image handling to separate functions in common/image-android.c - s/u8/char/ in header to fix string function warnings - Use SPDX identifiers for licenses - Cleaned-up file source information: android_image.h is from file include/boot/bootimg.h in repository: https://android.googlesource.com/platform/bootable/bootloader/legacy The git commit hash is 4205b865141ff2e255fe1d3bd16de18e217ef06a usbloader.c would be from the same commit, but it does not appear to have been used for any actual code. v4: - s/andriod/android/ - Use a separate flag ep_found to track if the entry point has been set rather than using a magic value. Cc: Wolfgang Denk <wd@denx.de> Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de> Signed-off-by: Rob Herring <robh@kernel.org> Reviewed-by: Tom Rini <trini@ti.com> Reviewed-by: Lukasz Majewski <l.majewski@samsung.com>
7 years ago
image: add support for Android's boot image format This patch adds support for the Android boot-image format. The header file is from the Android project and got slightly alterted so the struct + its defines are not generic but have something like a namespace. The header file is from bootloader/legacy/include/boot/bootimg.h. The header parsing has been written from scratch and I looked at bootloader/legacy/usbloader/usbloader.c for some details. The image contains the physical address (load address) of the kernel and ramdisk. This address is considered only for the kernel image. The "second image" defined in the image header is currently not supported. I haven't found anything that is creating this. v3 (Rob Herring): This is based on http://patchwork.ozlabs.org/patch/126797/ with the following changes: - Rebased to current mainline - Moved android image handling to separate functions in common/image-android.c - s/u8/char/ in header to fix string function warnings - Use SPDX identifiers for licenses - Cleaned-up file source information: android_image.h is from file include/boot/bootimg.h in repository: https://android.googlesource.com/platform/bootable/bootloader/legacy The git commit hash is 4205b865141ff2e255fe1d3bd16de18e217ef06a usbloader.c would be from the same commit, but it does not appear to have been used for any actual code. v4: - s/andriod/android/ - Use a separate flag ep_found to track if the entry point has been set rather than using a magic value. Cc: Wolfgang Denk <wd@denx.de> Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de> Signed-off-by: Rob Herring <robh@kernel.org> Reviewed-by: Tom Rini <trini@ti.com> Reviewed-by: Lukasz Majewski <l.majewski@samsung.com>
7 years ago
image: add support for Android's boot image format This patch adds support for the Android boot-image format. The header file is from the Android project and got slightly alterted so the struct + its defines are not generic but have something like a namespace. The header file is from bootloader/legacy/include/boot/bootimg.h. The header parsing has been written from scratch and I looked at bootloader/legacy/usbloader/usbloader.c for some details. The image contains the physical address (load address) of the kernel and ramdisk. This address is considered only for the kernel image. The "second image" defined in the image header is currently not supported. I haven't found anything that is creating this. v3 (Rob Herring): This is based on http://patchwork.ozlabs.org/patch/126797/ with the following changes: - Rebased to current mainline - Moved android image handling to separate functions in common/image-android.c - s/u8/char/ in header to fix string function warnings - Use SPDX identifiers for licenses - Cleaned-up file source information: android_image.h is from file include/boot/bootimg.h in repository: https://android.googlesource.com/platform/bootable/bootloader/legacy The git commit hash is 4205b865141ff2e255fe1d3bd16de18e217ef06a usbloader.c would be from the same commit, but it does not appear to have been used for any actual code. v4: - s/andriod/android/ - Use a separate flag ep_found to track if the entry point has been set rather than using a magic value. Cc: Wolfgang Denk <wd@denx.de> Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de> Signed-off-by: Rob Herring <robh@kernel.org> Reviewed-by: Tom Rini <trini@ti.com> Reviewed-by: Lukasz Majewski <l.majewski@samsung.com>
7 years ago
image: add support for Android's boot image format This patch adds support for the Android boot-image format. The header file is from the Android project and got slightly alterted so the struct + its defines are not generic but have something like a namespace. The header file is from bootloader/legacy/include/boot/bootimg.h. The header parsing has been written from scratch and I looked at bootloader/legacy/usbloader/usbloader.c for some details. The image contains the physical address (load address) of the kernel and ramdisk. This address is considered only for the kernel image. The "second image" defined in the image header is currently not supported. I haven't found anything that is creating this. v3 (Rob Herring): This is based on http://patchwork.ozlabs.org/patch/126797/ with the following changes: - Rebased to current mainline - Moved android image handling to separate functions in common/image-android.c - s/u8/char/ in header to fix string function warnings - Use SPDX identifiers for licenses - Cleaned-up file source information: android_image.h is from file include/boot/bootimg.h in repository: https://android.googlesource.com/platform/bootable/bootloader/legacy The git commit hash is 4205b865141ff2e255fe1d3bd16de18e217ef06a usbloader.c would be from the same commit, but it does not appear to have been used for any actual code. v4: - s/andriod/android/ - Use a separate flag ep_found to track if the entry point has been set rather than using a magic value. Cc: Wolfgang Denk <wd@denx.de> Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de> Signed-off-by: Rob Herring <robh@kernel.org> Reviewed-by: Tom Rini <trini@ti.com> Reviewed-by: Lukasz Majewski <l.majewski@samsung.com>
7 years ago
  1. /*
  2. * Copyright (c) 2011 Sebastian Andrzej Siewior <bigeasy@linutronix.de>
  3. *
  4. * Copyright (C) 2015-2016 Freescale Semiconductor, Inc.
  5. * Copyright 2017 NXP
  6. *
  7. * SPDX-License-Identifier: GPL-2.0+
  8. */
  9. #include <common.h>
  10. #include <image.h>
  11. #include <android_image.h>
  12. #include <malloc.h>
  13. #include <errno.h>
  14. #include <asm/bootm.h>
  15. #include <asm/imx-common/boot_mode.h>
  16. #define ANDROID_IMAGE_DEFAULT_KERNEL_ADDR 0x10008000
  17. static char andr_tmp_str[ANDR_BOOT_ARGS_SIZE + 1];
  18. #ifdef CONFIG_FSL_BOOTCTL
  19. #include <linux/usb/ch9.h>
  20. #include <linux/usb/gadget.h>
  21. #include "../drivers/usb/gadget/bootctrl.h"
  22. #endif
  23. static ulong android_image_get_kernel_addr(const struct andr_img_hdr *hdr)
  24. {
  25. /*
  26. * All the Android tools that generate a boot.img use this
  27. * address as the default.
  28. *
  29. * Even though it doesn't really make a lot of sense, and it
  30. * might be valid on some platforms, we treat that adress as
  31. * the default value for this field, and try to execute the
  32. * kernel in place in such a case.
  33. *
  34. * Otherwise, we will return the actual value set by the user.
  35. */
  36. if (hdr->kernel_addr == ANDROID_IMAGE_DEFAULT_KERNEL_ADDR)
  37. return (ulong)hdr + hdr->page_size;
  38. return hdr->kernel_addr;
  39. }
  40. /**
  41. * android_image_get_kernel() - processes kernel part of Android boot images
  42. * @hdr: Pointer to image header, which is at the start
  43. * of the image.
  44. * @verify: Checksum verification flag. Currently unimplemented.
  45. * @os_data: Pointer to a ulong variable, will hold os data start
  46. * address.
  47. * @os_len: Pointer to a ulong variable, will hold os data length.
  48. *
  49. * This function returns the os image's start address and length. Also,
  50. * it appends the kernel command line to the bootargs env variable.
  51. *
  52. * Return: Zero, os start address and length on success,
  53. * otherwise on failure.
  54. */
  55. int android_image_get_kernel(const struct andr_img_hdr *hdr, int verify,
  56. ulong *os_data, ulong *os_len)
  57. {
  58. u32 kernel_addr = android_image_get_kernel_addr(hdr);
  59. /*
  60. * Not all Android tools use the id field for signing the image with
  61. * sha1 (or anything) so we don't check it. It is not obvious that the
  62. * string is null terminated so we take care of this.
  63. */
  64. strncpy(andr_tmp_str, hdr->name, ANDR_BOOT_NAME_SIZE);
  65. andr_tmp_str[ANDR_BOOT_NAME_SIZE] = '\0';
  66. if (strlen(andr_tmp_str))
  67. printf("Android's image name: %s\n", andr_tmp_str);
  68. printf("Kernel load addr 0x%08x size %u KiB\n",
  69. kernel_addr, DIV_ROUND_UP(hdr->kernel_size, 1024));
  70. char newbootargs[512] = {0};
  71. char commandline[1024] = {0};
  72. char *bootargs = getenv("bootargs");
  73. if (bootargs) {
  74. strcpy(commandline, bootargs);
  75. } else if (*hdr->cmdline) {
  76. strcat(commandline, hdr->cmdline);
  77. }
  78. #ifdef CONFIG_SERIAL_TAG
  79. struct tag_serialnr serialnr;
  80. get_board_serial(&serialnr);
  81. sprintf(newbootargs,
  82. " androidboot.serialno=%08x%08x",
  83. serialnr.high,
  84. serialnr.low);
  85. strcat(commandline, newbootargs);
  86. #endif
  87. /* append soc type into bootargs */
  88. char *soc_type = getenv("soc_type");
  89. if (soc_type) {
  90. sprintf(newbootargs,
  91. " androidboot.soc_type=%s",
  92. soc_type);
  93. strcat(commandline, newbootargs);
  94. }
  95. int bootdev = get_boot_device();
  96. if (bootdev == SD1_BOOT || bootdev == SD2_BOOT ||
  97. bootdev == SD3_BOOT || bootdev == SD4_BOOT) {
  98. sprintf(newbootargs,
  99. " androidboot.storage_type=sd gpt");
  100. } else if (bootdev == MMC1_BOOT || bootdev == MMC2_BOOT ||
  101. bootdev == MMC3_BOOT || bootdev == MMC4_BOOT) {
  102. sprintf(newbootargs,
  103. " androidboot.storage_type=emmc");
  104. } else if (bootdev == NAND_BOOT) {
  105. sprintf(newbootargs,
  106. " androidboot.storage_type=nand");
  107. } else
  108. printf("boot device type is incorrect.\n");
  109. strcat(commandline, newbootargs);
  110. #ifdef CONFIG_FSL_BOOTCTL
  111. sprintf(newbootargs, " androidboot.slot_suffix=%s", get_slot_suffix());
  112. strcat(commandline, newbootargs);
  113. #endif
  114. #ifdef CONFIG_AVB_SUPPORT
  115. /* secondary cmdline added by avb */
  116. char *bootargs_sec = getenv("bootargs_sec");
  117. if (bootargs_sec) {
  118. strcat(commandline, " ");
  119. strcat(commandline, bootargs_sec);
  120. }
  121. #endif
  122. #ifdef CONFIG_SYSTEM_RAMDISK_SUPPORT
  123. /* Normal boot:
  124. * cmdline to bypass ramdisk in boot.img, but use the system.img
  125. * Recovery boot:
  126. * Use the ramdisk in boot.img
  127. */
  128. char *bootargs_3rd = getenv("bootargs_3rd");
  129. if (bootargs_3rd) {
  130. strcat(commandline, " ");
  131. strcat(commandline, bootargs_3rd);
  132. }
  133. #endif
  134. printf("Kernel command line: %s\n", commandline);
  135. setenv("bootargs", commandline);
  136. if (os_data) {
  137. *os_data = (ulong)hdr;
  138. *os_data += hdr->page_size;
  139. }
  140. if (os_len)
  141. *os_len = hdr->kernel_size;
  142. return 0;
  143. }
  144. int android_image_check_header(const struct andr_img_hdr *hdr)
  145. {
  146. return memcmp(ANDR_BOOT_MAGIC, hdr->magic, ANDR_BOOT_MAGIC_SIZE);
  147. }
  148. ulong android_image_get_end(const struct andr_img_hdr *hdr)
  149. {
  150. ulong end;
  151. /*
  152. * The header takes a full page, the remaining components are aligned
  153. * on page boundary
  154. */
  155. end = (ulong)hdr;
  156. end += hdr->page_size;
  157. end += ALIGN(hdr->kernel_size, hdr->page_size);
  158. end += ALIGN(hdr->ramdisk_size, hdr->page_size);
  159. end += ALIGN(hdr->second_size, hdr->page_size);
  160. return end;
  161. }
  162. ulong android_image_get_kload(const struct andr_img_hdr *hdr)
  163. {
  164. return android_image_get_kernel_addr(hdr);
  165. }
  166. int android_image_get_ramdisk(const struct andr_img_hdr *hdr,
  167. ulong *rd_data, ulong *rd_len)
  168. {
  169. if (!hdr->ramdisk_size) {
  170. *rd_data = *rd_len = 0;
  171. return -1;
  172. }
  173. printf("RAM disk load addr 0x%08x size %u KiB\n",
  174. hdr->ramdisk_addr, DIV_ROUND_UP(hdr->ramdisk_size, 1024));
  175. *rd_data = (unsigned long)hdr;
  176. *rd_data += hdr->page_size;
  177. *rd_data += ALIGN(hdr->kernel_size, hdr->page_size);
  178. *rd_len = hdr->ramdisk_size;
  179. return 0;
  180. }
  181. #if !defined(CONFIG_SPL_BUILD)
  182. /**
  183. * android_print_contents - prints out the contents of the Android format image
  184. * @hdr: pointer to the Android format image header
  185. *
  186. * android_print_contents() formats a multi line Android image contents
  187. * description.
  188. * The routine prints out Android image properties
  189. *
  190. * returns:
  191. * no returned results
  192. */
  193. void android_print_contents(const struct andr_img_hdr *hdr)
  194. {
  195. const char * const p = IMAGE_INDENT_STRING;
  196. printf("%skernel size: %x\n", p, hdr->kernel_size);
  197. printf("%skernel address: %x\n", p, hdr->kernel_addr);
  198. printf("%sramdisk size: %x\n", p, hdr->ramdisk_size);
  199. printf("%sramdisk addrress: %x\n", p, hdr->ramdisk_addr);
  200. printf("%ssecond size: %x\n", p, hdr->second_size);
  201. printf("%ssecond address: %x\n", p, hdr->second_addr);
  202. printf("%stags address: %x\n", p, hdr->tags_addr);
  203. printf("%spage size: %x\n", p, hdr->page_size);
  204. printf("%sname: %s\n", p, hdr->name);
  205. printf("%scmdline: %s\n", p, hdr->cmdline);
  206. }
  207. #endif
  208. int android_image_get_fdt(const struct andr_img_hdr *hdr,
  209. ulong *fdt_data, ulong *fdt_len)
  210. {
  211. if (!hdr->second_size)
  212. return -1;
  213. printf("FDT load addr 0x%08x size %u KiB\n",
  214. hdr->second_addr, DIV_ROUND_UP(hdr->second_size, 1024));
  215. *fdt_data = (unsigned long)hdr;
  216. *fdt_data += hdr->page_size;
  217. *fdt_data += ALIGN(hdr->kernel_size, hdr->page_size);
  218. *fdt_data += ALIGN(hdr->ramdisk_size, hdr->page_size);
  219. *fdt_len = hdr->second_size;
  220. return 0;
  221. }
  222. #define ARM64_IMAGE_MAGIC 0x644d5241
  223. bool image_arm64(void *images)
  224. {
  225. struct header_image *ih;
  226. ih = (struct header_image *)images;
  227. debug("image magic: %x\n", ih->magic);
  228. if (ih->magic == le32_to_cpu(ARM64_IMAGE_MAGIC))
  229. return true;
  230. return false;
  231. }