mktitanimg.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. #ifndef __MKTITANIMG_H
  2. #define __MKTITANIMG_H
  3. #ifndef CFGMGR_CKSUM_H
  4. #define CFGMGR_CKSUM_H
  5. #define CKSUM_MAGIC_NUMBER 0xC453DE23
  6. #include <inttypes.h>
  7. #include <stdio.h>
  8. #include <errno.h>
  9. int cs_is_tagged(FILE*);
  10. unsigned long cs_read_sum(FILE*);
  11. int cs_calc_sum(FILE*, unsigned long*, int);
  12. int cs_set_sum(FILE*, unsigned long, int);
  13. void cs_get_sum(FILE*, unsigned long*);
  14. unsigned long cs_calc_buf_sum(char*, int);
  15. int cs_validate_file(char*);
  16. #endif
  17. #ifndef ___CMDLINE_H___
  18. #define ___CMDLINE_H___
  19. /* ********* Library Configuration ********* */
  20. typedef struct CMDLINE_OPT
  21. {
  22. int min; /* Minimum number of arguments this option takes */
  23. int max; /* Maximum number of arguments this option takes */
  24. int flags; /* Controlling flags (whether to accept or not, etc) */
  25. } CMDLINE_OPT;
  26. typedef struct CMDLINE_CFG
  27. {
  28. CMDLINE_OPT opts[26]; /* Options 'a' through 'z' */
  29. CMDLINE_OPT global; /* Global option (outside 'a'..'z') */
  30. } CMDLINE_CFG;
  31. /* ******************************************** */
  32. #define CMDLINE_OPTFLAG_ALLOW 0x1 /* The option is allowed */
  33. #define CMDLINE_OPTFLAG_MANDAT 0x2 /* The option is mandatory */
  34. extern void cmdline_print(char* argv[]);
  35. extern int cmdline_configure(CMDLINE_CFG* p_cfg);
  36. extern int cmdline_read(int argc, char* argv[]);
  37. extern void* cmdline_getarg_list(char opt);
  38. extern int cmdline_getarg_count(void* list);
  39. extern int cmdline_getopt_count(char opt);
  40. extern int cmdline_getarg(void* list, int num);
  41. extern char* cmdline_error(int err);
  42. #endif
  43. #ifndef _NSPIMGHDR_H_
  44. #define _NSPIMGHDR_H_
  45. /* This file describes the header format for the single image. The image is broken
  46. up into several pieces. The image contains this header plus 1 or more sections.
  47. Each section contains a binary block that could be a kernel, filesystem, etc. The
  48. only garentee for this is that the very first section MUST be executable. Meaning
  49. that the bootloader will be able to take the address of the header start, add the
  50. header size, and execute that binary block. The header has its own checksum. It
  51. starts hdr_size-4 bytes from the start of the header.
  52. */
  53. struct nsp_img_hdr_head
  54. {
  55. unsigned int magic; /* Magic number to identify this image header */
  56. unsigned int boot_offset; /* Offset from start of header to kernel code. */
  57. unsigned int flags; /* Image flags. */
  58. unsigned int hdr_version; /* Version of this header. */
  59. unsigned int hdr_size; /* The complete size of all portions of the header */
  60. unsigned int prod_id; /* This product id */
  61. unsigned int rel_id; /* Which release this is */
  62. unsigned int version; /* name-MMM.nnn.ooo-rxx => 0xMMnnooxx. See comment
  63. below */
  64. unsigned int image_size; /* Image size (including header) */
  65. unsigned int info_offset; /* Offset from start of header to info block */
  66. unsigned int sect_info_offset; /* Offset from start of header to section desc */
  67. unsigned int chksum_offset; /* Offset from start of header to chksum block */
  68. // unsigned int pad1;
  69. };
  70. /* The patch id is a machine readable value that takes the normal patch level, and encodes
  71. the correct numbers inside of it. The format of the patches are name-MM.NN.oo-rxx.bin.
  72. Convert MM, NN, oo, and xx into hex, and encode them as 0xMMNNooxx. Thus:
  73. att-1.2.18-r14.bin => 0x0102120e */
  74. /* The following are the flag bits for the above flags variable */
  75. /* List of NSP status flags: */
  76. #define NSP_IMG_FLAG_FAILBACK_MASK 0xF8000000
  77. /* NSP Image status flag: Flag indicates individual sections image */
  78. #define NSP_IMG_FLAG_INDIVIDUAL 0x00000001
  79. /* NSP Image status flag 1: Image contains a bootable image when this bit is 0 */
  80. #define NSP_IMG_FLAG_FAILBACK_1 0x08000000
  81. /* NSP Image status flag 2: Image contains a non-bootable image when this bit is 0 */
  82. #define NSP_IMG_FLAG_FAILBACK_2 0x10000000
  83. /* NSP Image status flag 3: PSPBoot has tried the image when this bit is 0 */
  84. #define NSP_IMG_FLAG_FAILBACK_3 0x20000000
  85. /* NSP Image status flag 4: Image is now secondary image when this bit is 0 */
  86. #define NSP_IMG_FLAG_FAILBACK_4 0x40000000
  87. /* NSP Image status flag 5: Image contains a valid image when this bit is 0 */
  88. #define NSP_IMG_FLAG_FAILBACK_5 0x80000000
  89. /* NSP Single image magic number */
  90. #define NSP_IMG_MAGIC_NUMBER 0x4D544443
  91. struct nsp_img_hdr_info
  92. {
  93. char release_name[64]; /* Name of release */
  94. char image_filename[64]; /* name-mm.nn.oo-rxx.bin format */
  95. };
  96. struct nsp_img_hdr_section_info
  97. {
  98. unsigned int num_sects; /* Number of section (and section desc blocks) in this
  99. image */
  100. unsigned int sect_size; /* Size of a SINGLE section_desc block */
  101. unsigned int sections_offset; /* Offset to from start of header to the start of
  102. the section blocks */
  103. };
  104. /* There will be one of more of the following stuctures in the image header. Each
  105. section will have one of these blocks. */
  106. struct nsp_img_hdr_sections
  107. {
  108. unsigned int offset; /* Offset of section from start of NSP_IMG_HDR_HEAD */
  109. unsigned int total_size; /* Size of section (including pad size.) */
  110. unsigned int raw_size; /* Size of section only */
  111. unsigned int flags; /* Section flags */
  112. unsigned int chksum; /* Section checksum */
  113. unsigned int type; /* Section type. What kind of info does this section
  114. describe */
  115. char name[16]; /* Reference name for this section. */
  116. };
  117. #define NSP_IMG_SECTION_TYPE_KERNEL (0x01)
  118. #define NSP_IMG_SECTION_TYPE_FILESYSTEM_ROOT (0x02)
  119. #define NSP_IMG_SECTION_TYPE_FILESYSTEM (0x03)
  120. struct nsp_img_hdr
  121. {
  122. struct nsp_img_hdr_head head; /* Head portion */
  123. struct nsp_img_hdr_info info; /* Info */
  124. struct nsp_img_hdr_section_info sect_info; /* Section block */
  125. struct nsp_img_hdr_sections sections; /* 1 or more section_description blocks. More
  126. section_desc blocks will be appended here
  127. for each additional section needed */
  128. };
  129. struct nsp_img_hdr_chksum
  130. {
  131. unsigned int hdr_chksum; /* The checksum for the complete header. Excepting the
  132. checksum block */
  133. };
  134. struct nsp_img_hdr_sections *nsp_img_hdr_get_section_ptr_by_name(struct nsp_img_hdr *hdr, char *name);
  135. unsigned int nsp_img_hdr_get_section_offset_by_name(struct nsp_img_hdr *hdr, char *name);
  136. unsigned int nsp_img_hdr_get_section_size_by_name(struct nsp_img_hdr *hdr, char *name);
  137. #endif
  138. #endif /* __MKTITANIMG_H */