bootimg.h 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /*
  2. * Copyright (C) 2008 The Android Open Source Project
  3. * All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions
  7. * are met:
  8. * * Redistributions of source code must retain the above copyright
  9. * notice, this list of conditions and the following disclaimer.
  10. * * Redistributions in binary form must reproduce the above copyright
  11. * notice, this list of conditions and the following disclaimer in
  12. * the documentation and/or other materials provided with the
  13. * distribution.
  14. *
  15. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  16. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  17. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  18. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  19. * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  20. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  21. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  22. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  23. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  24. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  25. * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  26. * SUCH DAMAGE.
  27. */
  28. #ifndef _BOOT_IMAGE_H_
  29. #define _BOOT_IMAGE_H_
  30. typedef struct boot_img_hdr boot_img_hdr;
  31. #define BOOT_MAGIC "ANDROID!"
  32. #define BOOT_MAGIC_SIZE 8
  33. #define BOOT_NAME_SIZE 16
  34. #define BOOT_ARGS_SIZE 512
  35. struct boot_img_hdr
  36. {
  37. unsigned char magic[BOOT_MAGIC_SIZE];
  38. unsigned kernel_size; /* size in bytes */
  39. unsigned kernel_addr; /* physical load addr */
  40. unsigned ramdisk_size; /* size in bytes */
  41. unsigned ramdisk_addr; /* physical load addr */
  42. unsigned second_size; /* size in bytes */
  43. unsigned second_addr; /* physical load addr */
  44. unsigned tags_addr; /* physical addr for kernel tags */
  45. unsigned page_size; /* flash page size we assume */
  46. unsigned unused[2]; /* future expansion: should be 0 */
  47. unsigned char name[BOOT_NAME_SIZE]; /* asciiz product name */
  48. unsigned char cmdline[BOOT_ARGS_SIZE];
  49. unsigned id[8]; /* timestamp / checksum / sha1 / etc */
  50. };
  51. /*
  52. ** +-----------------+
  53. ** | boot header | 1 page
  54. ** +-----------------+
  55. ** | kernel | n pages
  56. ** +-----------------+
  57. ** | ramdisk | m pages
  58. ** +-----------------+
  59. ** | second stage | o pages
  60. ** +-----------------+
  61. **
  62. ** n = (kernel_size + page_size - 1) / page_size
  63. ** m = (ramdisk_size + page_size - 1) / page_size
  64. ** o = (second_size + page_size - 1) / page_size
  65. **
  66. ** 0. all entities are page_size aligned in flash
  67. ** 1. kernel and ramdisk are required (size != 0)
  68. ** 2. second is optional (second_size == 0 -> no second)
  69. ** 3. load each element (kernel, ramdisk, second) at
  70. ** the specified physical address (kernel_addr, etc)
  71. ** 4. prepare tags at tag_addr. kernel_args[] is
  72. ** appended to the kernel commandline in the tags.
  73. ** 5. r0 = 0, r1 = MACHINE_TYPE, r2 = tags_addr
  74. ** 6. if second_size != 0: jump to second_addr
  75. ** else: jump to kernel_addr
  76. */
  77. boot_img_hdr *mkbootimg(void *kernel, unsigned kernel_size,
  78. void *ramdisk, unsigned ramdisk_size,
  79. void *second, unsigned second_size,
  80. unsigned page_size,
  81. unsigned *bootimg_size);
  82. void bootimg_set_cmdline(boot_img_hdr *hdr, const char *cmdline);
  83. #endif