image-android.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*
  2. * Copyright (c) 2011 Sebastian Andrzej Siewior <bigeasy@linutronix.de>
  3. *
  4. * SPDX-License-Identifier: GPL-2.0+
  5. */
  6. #include <common.h>
  7. #include <image.h>
  8. #include <android_image.h>
  9. static char andr_tmp_str[ANDR_BOOT_ARGS_SIZE + 1];
  10. int android_image_get_kernel(const struct andr_img_hdr *hdr, int verify,
  11. ulong *os_data, ulong *os_len)
  12. {
  13. /*
  14. * Not all Android tools use the id field for signing the image with
  15. * sha1 (or anything) so we don't check it. It is not obvious that the
  16. * string is null terminated so we take care of this.
  17. */
  18. strncpy(andr_tmp_str, hdr->name, ANDR_BOOT_NAME_SIZE);
  19. andr_tmp_str[ANDR_BOOT_NAME_SIZE] = '\0';
  20. if (strlen(andr_tmp_str))
  21. printf("Android's image name: %s\n", andr_tmp_str);
  22. printf("Kernel load addr 0x%08x size %u KiB\n",
  23. hdr->kernel_addr, DIV_ROUND_UP(hdr->kernel_size, 1024));
  24. strncpy(andr_tmp_str, hdr->cmdline, ANDR_BOOT_ARGS_SIZE);
  25. andr_tmp_str[ANDR_BOOT_ARGS_SIZE] = '\0';
  26. if (strlen(andr_tmp_str)) {
  27. printf("Kernel command line: %s\n", andr_tmp_str);
  28. setenv("bootargs", andr_tmp_str);
  29. }
  30. if (hdr->ramdisk_size)
  31. printf("RAM disk load addr 0x%08x size %u KiB\n",
  32. hdr->ramdisk_addr,
  33. DIV_ROUND_UP(hdr->ramdisk_size, 1024));
  34. if (os_data) {
  35. *os_data = (ulong)hdr;
  36. *os_data += hdr->page_size;
  37. }
  38. if (os_len)
  39. *os_len = hdr->kernel_size;
  40. return 0;
  41. }
  42. int android_image_check_header(const struct andr_img_hdr *hdr)
  43. {
  44. return memcmp(ANDR_BOOT_MAGIC, hdr->magic, ANDR_BOOT_MAGIC_SIZE);
  45. }
  46. ulong android_image_get_end(const struct andr_img_hdr *hdr)
  47. {
  48. u32 size = 0;
  49. /*
  50. * The header takes a full page, the remaining components are aligned
  51. * on page boundary
  52. */
  53. size += hdr->page_size;
  54. size += ALIGN(hdr->kernel_size, hdr->page_size);
  55. size += ALIGN(hdr->ramdisk_size, hdr->page_size);
  56. size += ALIGN(hdr->second_size, hdr->page_size);
  57. return size;
  58. }
  59. ulong android_image_get_kload(const struct andr_img_hdr *hdr)
  60. {
  61. return hdr->kernel_addr;
  62. }
  63. int android_image_get_ramdisk(const struct andr_img_hdr *hdr,
  64. ulong *rd_data, ulong *rd_len)
  65. {
  66. if (!hdr->ramdisk_size)
  67. return -1;
  68. *rd_data = (unsigned long)hdr;
  69. *rd_data += hdr->page_size;
  70. *rd_data += ALIGN(hdr->kernel_size, hdr->page_size);
  71. *rd_len = hdr->ramdisk_size;
  72. return 0;
  73. }