Subversion Repositories QNX 8.QNX8 IFS tool

Rev

Rev 20 | Rev 26 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
16 pmbaty 1
#ifndef IFSFILE_H
2
#define IFSFILE_H
3
 
4
 
5
#ifdef __cplusplus
6
extern "C" {
7
#endif
8
 
9
 
10
// standard C includes
11
#include <stdint.h>
12
#include <stdlib.h>
13
 
14
 
15
// compiler-specific glue
16
#ifdef _WIN32
17
#ifndef __BYTE_ORDER__
18
#define __ORDER_BIG_ENDIAN__    4321
19
#define __ORDER_LITTLE_ENDIAN__ 1234
20
#define __BYTE_ORDER__ __ORDER_LITTLE_ENDIAN__ // all Windows machines are little endian
21
#endif // !__BYTE_ORDER__
22
#ifndef __builtin_bswap64
23
#ifdef _MSC_VER
24
#define __builtin_bswap64(x) _byteswap_uint64 ((unsigned long long) (x))
25
#endif // _MSC_VER
26
#endif // !__builtin_bswap64
27
#ifndef __builtin_bswap32
28
#ifdef _MSC_VER
29
#define __builtin_bswap32(x) _byteswap_ulong ((unsigned long) (x))
30
#endif // _MSC_VER
31
#endif // !__builtin_bswap32
32
#ifndef __builtin_bswap16
33
#ifdef _MSC_VER
34
#define __builtin_bswap16(x) _byteswap_ushort ((unsigned short) (x))
35
#endif // _MSC_VER
36
#endif // !__builtin_bswap32
37
#endif // _WIN32
38
#ifdef _MSC_VER
39
#define START_OF_PACKED_STRUCT() __pragma(pack(push)) __pragma(pack(1))
40
#define END_OF_PACKED_STRUCT() __pragma(pack(pop))
41
#define PACKED(thing) thing
42
#else // !_MSC_VER
43
#define START_OF_PACKED_STRUCT()
44
#define END_OF_PACKED_STRUCT()
45
#define PACKED(thing) thing __attribute__((packed))
46
#endif // _MSC_VER
47
 
48
 
49
// bitmapped flags used in the flags1 member of the startup header
50
#define STARTUP_HDR_FLAGS1_VIRTUAL        (1 << 0)
51
#define STARTUP_HDR_FLAGS1_BIGENDIAN      (1 << 1)
52
//#define STARTUP_HDR_FLAGS1_COMPRESS_MASK  0x1c
53
//#define STARTUP_HDR_FLAGS1_COMPRESS_SHIFT 0x02
54
//#define STARTUP_HDR_FLAGS1_COMPRESS_NONE  0x00
22 pmbaty 55
//#define STARTUP_HDR_FLAGS1_COMPRESS_ZLIB  0x04 // TODO: add this compression scheme with libz
56
//#define STARTUP_HDR_FLAGS1_COMPRESS_LZO   0x08 // TODO: add this compression scheme with liblzo
57
//#define STARTUP_HDR_FLAGS1_COMPRESS_UCL   0x0c // TODO: add this compression scheme
16 pmbaty 58
#define STARTUP_HDR_FLAGS1_TRAILER_V2     (1 << 5) // if set, then a struct startup_trailer_v2 follows the startup. If the image is compressed, then the compressed imagefs is followed by a struct image_trailer_v2
59
 
60
 
61
// bitmapped flags used in the flags member of the image header
62
#define IMAGE_FLAGS_BIGENDIAN  (1 << 0) // header, trailer, dirents in big-endian format
63
#define IMAGE_FLAGS_READONLY   (1 << 1) // do not try to write to image (rom/flash)
64
#define IMAGE_FLAGS_INO_BITS   (1 << 2) // inode bits valid
65
#define IMAGE_FLAGS_SORTED     (1 << 3) // dirent section is sorted (by pathname)
66
#define IMAGE_FLAGS_TRAILER_V2 (1 << 4) // image uses struct image_trailer_v2
67
 
68
 
69
// bitmapped flags superposed to a filesystem entry's inode number
22 pmbaty 70
#define IFS_INO_PROCESSED_ELF (1 << 31)
71
#define IFS_INO_RUNONCE_ELF   (1 << 30)
72
#define IFS_INO_BOOTSTRAP_EXE (1 << 29)
16 pmbaty 73
 
74
 
22 pmbaty 75
// compiled boot script command types
76
#define SCRIPTCMD_TYPE_EXTERNAL        "\x00"
77
#define SCRIPTCMD_TYPE_WAITFOR         "\x01"
78
#define SCRIPTCMD_TYPE_REOPEN          "\x02"
79
#define SCRIPTCMD_TYPE_DISPLAY_MSG     "\x03"
80
#define SCRIPTCMD_TYPE_PROCMGR_SYMLINK "\x04"
81
#define SCRIPTCMD_TYPE_EXTSCHED_APS    "\x05"
16 pmbaty 82
 
83
 
22 pmbaty 84
// compiled boot script external command flags
85
#define SCRIPTCMD_FLAG_EXTSCHED   (1 << 0)
86
#define SCRIPTCMD_FLAG_SESSION    (1 << 1)
87
#define SCRIPTCMD_FLAG_SCHED_SET  (1 << 2)
88
#define SCRIPTCMD_FLAG_CPU_SET    (1 << 3)
89
#define SCRIPTCMD_FLAG_UNKNOWN1   (1 << 4) // ???
90
#define SCRIPTCMD_FLAG_BACKGROUND (1 << 5)
91
#define SCRIPTCMD_FLAG_KDEBUG     (1 << 6)
92
#define SCRIPTCMD_FLAG_UNKNOWN2   (1 << 7) // ???
16 pmbaty 93
 
94
 
22 pmbaty 95
// compiled boot script external command scheduling policies
96
#define SCRIPTCMD_SCHEDULERPOLICY_FIFO 1
97
#define SCRIPTCMD_SCHEDULERPOLICY_RR   2
16 pmbaty 98
 
99
 
100
START_OF_PACKED_STRUCT () // we need byte-alignment for this struct
101
typedef PACKED (struct) fsentry_s
102
{
103
   PACKED (struct) fsentry_header_s
104
   {
105
      uint16_t size; // size of dirent
106
      uint16_t extattr_offset; // if zero, no extattr data
107
      uint32_t ino; // if zero, skip entry
108
      uint32_t mode; // mode and perms of entry
109
      uint32_t gid;
110
      uint32_t uid;
111
      uint32_t mtime;
112
   } header;
113
   PACKED (union) fsentry_specific_u
114
   {
115
      PACKED (struct) fsentry_file_s // when (mode & S_IFMT) == S_IFREG
116
      {
117
         uint32_t offset; // offset from header
118
         uint32_t size;
119
         char *path; // null terminated path (no leading slash)
120
         uint8_t *UNSAVED_databuf; // file data blob buffer (convenience pointer, NOT SAVED IN THE IFS)
121
      } file;
122
      PACKED (struct) fsentry_dir_s // when (mode & S_IFMT) == S_IFDIR
123
      {
124
         char *path; // null terminated path (no leading slash)
125
      } dir;
126
      PACKED (struct) fsentry_symlink_s // when (mode & S_IFMT) == S_IFLNK
127
      {
128
         uint16_t sym_offset; // offset to 'contents' from 'path'
129
         uint16_t sym_size; // strlen (contents)
130
         char *path; // null terminated path (no leading slash)
131
         char *contents; // null terminated symlink contents
132
      } symlink;
133
      PACKED (struct) fsentry_device_s // when (mode & S_IFMT) == S_IF<CHR|BLK|FIFO|NAM|SOCK>
134
      {
135
         uint32_t dev;
136
         uint32_t rdev;
137
         char *path; // null terminated path (no leading slash)
138
      } device;
139
   } u;
140
   bool UNSAVED_was_data_written; // whether this entry's data was written to the image (convenience member, NOT SAVED IN THE IFS)
141
} fsentry_t;
142
END_OF_PACKED_STRUCT () // restore default alignment
143
 
144
 
145
START_OF_PACKED_STRUCT () // we need byte-alignment for this struct
146
typedef PACKED (struct) startup_header_s // size 256 bytes
147
{
148
   // I - used by the QNX IPL
149
   // S - used by the startup program
150
   uint8_t signature[4];   // [I ] Header signature, "\xeb\x7e\xff\x00"
151
   uint16_t version;       // [I ] Header version, i.e. 1
152
   uint8_t flags1;         // [IS] Misc flags, 0x21 (= 0x20 | STARTUP_HDR_FLAGS1_VIRTUAL)
153
   uint8_t flags2;         // [  ] No flags defined yet (0)
154
   uint16_t header_size;   // [ S] sizeof(struct startup_header), i.e. 256
155
   uint16_t machine;       // [IS] Machine type from elfdefinitions.h, i.e. 0x003E --> _ELF_DEFINE_EM(EM_X86_64, 62, "AMD x86-64 architecture")
156
   uint32_t startup_vaddr; // [I ] Virtual Address to transfer to after IPL is done, here 0x01403008 (appears in "Entry" column for "startup.*")
157
   uint32_t paddr_bias;    // [ S] Value to add to physical address to get a value to put into a pointer and indirected through, here 0 (no indirections)
158
   uint32_t image_paddr;   // [IS] Physical address of image, here 0x01400f30 (appears in "Offset" column for "startup-header" which is the first entry/start of file)
159
   uint32_t ram_paddr;     // [IS] Physical address of RAM to copy image to (startup_size bytes copied), here 0x01400f30 (same as above)
160
   uint32_t ram_size;      // [ S] Amount of RAM used by the startup program and executables contained in the file system, here 0x00cd6128 i.e. 13 459 752 dec. which is 13 Mb. i.e. IFS file size minus 0x9eee
161
   uint32_t startup_size;  // [I ] Size of startup (never compressed), here 0x02f148 or 192 840 bytes
162
   uint32_t stored_size;   // [I ] Size of entire image, here 0x00cd6128 (same as ram_size)
163
   uint32_t imagefs_paddr; // [IS] Set by IPL to where the imagefs is when startup runs (0)
164
   uint32_t imagefs_size;  // [ S] Size of uncompressed imagefs, here 0x00ca6fe0 or 13 266 912 bytes
165
   uint16_t preboot_size;  // [I ] Size of loaded before header, here 0xf30 or 3888 bytes (size of "bios.boot" file))
166
   uint16_t zero0;         // [  ] Zeros
167
   uint32_t zero[1];       // [  ] Zeros
168
   uint64_t addr_off;      // [ S] Offset to add to startup_vaddr, image_paddr, ram_paddr, and imagefs_paddr members, here zero (0)
169
   uint32_t info[48];      // [IS] Array of startup_info* structures (zero filled)
170
} startup_header_t;
171
END_OF_PACKED_STRUCT () // restore default alignment
172
 
173
 
174
START_OF_PACKED_STRUCT () // we need byte-alignment for this struct
175
typedef PACKED (struct) startup_trailer_s
176
{
177
   uint32_t cksum; // checksum from start of header to start of trailer
178
} startup_trailer_v1_t;
179
END_OF_PACKED_STRUCT () // restore default alignment
180
 
181
 
182
// NOTE: The checksums in this trailer will only be valid prior to entering startup.
183
// Because the startup binary is executed in-place, its data segment will change once the program is running.
184
// Hence, any checksum validation would need to be done by the boot loader / IFS.
185
START_OF_PACKED_STRUCT () // we need byte-alignment for this struct
186
typedef PACKED (struct) startup_trailer_v2_s
187
{
188
   uint8_t sha512[64]; // SHA512 from start of header to start of trailer
189
   uint32_t cksum; // checksum from start of header to start of this member
190
} startup_trailer_v2_t;
191
END_OF_PACKED_STRUCT () // restore default alignment
192
 
193
 
194
START_OF_PACKED_STRUCT () // we need byte-alignment for this struct
195
typedef PACKED (struct) image_header_s
196
{
197
   uint8_t signature[7]; // image filesystem signature, i.e. "imagefs"
198
   uint8_t flags; // endian neutral flags, 0x1c
199
   uint32_t image_size; // size from start of header to end of trailer (here 0xca6fe0 or 13 266 912)
200
   uint32_t hdr_dir_size; // size from start of header to last dirent (here 0x12b8 or 4792)
201
   uint32_t dir_offset; // offset from start of header to start of first dirent (here 0x5c or 92)
202
   uint32_t boot_ino[4]; // inode of files for bootstrap pgms (here 0xa0000002, 0, 0, 0)
203
   uint32_t script_ino; // inode of file for script (here 3)
204
   uint32_t chain_paddr; // offset to next filesystem signature (0)
205
   uint32_t spare[10]; // zerofill
206
   uint32_t mountflags; // default _MOUNT_* from sys/iomsg.h (0)
207
   char mountpoint[4]; // default mountpoint for image ("/" + "\0\0\0")
208
} image_header_t;
209
END_OF_PACKED_STRUCT () // restore default alignment
210
 
211
 
212
START_OF_PACKED_STRUCT () // we need byte-alignment for this struct
213
typedef PACKED (struct) image_trailer_v1_s
214
{
215
   uint32_t cksum; // checksum from start of header to start of trailer
216
} image_trailer_v1_t; // NOTE: this is the same structure as startup_trailer_v1_t
217
END_OF_PACKED_STRUCT () // restore default alignment
218
 
219
 
220
// NOTE: the checksums in this trailer will only be valid until the first non-startup bootstrap binary (e.g., startup-verifier, procnto, ...) is invoked.
221
// Because bootstrap binaries execute in-place, their data segments will change once the programs are running.
222
// Hence, any checksum validation would need to be done either by the boot loader / IFS or by the startup.
223
START_OF_PACKED_STRUCT () // we need byte-alignment for this struct
224
typedef PACKED (struct) image_trailer_v2_s
225
{
226
   uint8_t sha512[64]; // SHA512 from start of image header to start of trailer
227
   uint32_t cksum; // checksum from start of header to start of this member
228
} image_trailer_v2_t; // NOTE: this is the same structure as startup_trailer_v2_t
229
END_OF_PACKED_STRUCT () // restore default alignment
230
 
231
 
20 pmbaty 232
START_OF_PACKED_STRUCT () // we need byte-alignment for this struct
233
typedef PACKED (struct) bootargs_entry_s
234
{
235
   uint8_t size_lo; // includes entire structure
236
   uint8_t size_hi;
237
   uint8_t argc; // number of C-style strings that make up argv[] in args
238
   uint8_t envc; // number of C-style strings that make up envp[] in args after argv[]
239
   // if the actual startup header address cannot be represented in 32 bits, then shdr_addr is set to 0xFFFFFFFF and a uint64_t with the REAL shdr_address
240
   // immediately follows the last byte of the variable-length <args>. It will be included in the advertised <size_*> and is located at <bootargs_addr>+<size>-8
241
   uint32_t shdr_addr;
242
   //char *args; // variable length
243
} bootargs_entry_t;
244
END_OF_PACKED_STRUCT () // restore default alignment
245
 
246
 
16 pmbaty 247
// undefine the helpers we no longer need
248
#undef START_OF_PACKED_STRUCT
249
#undef END_OF_PACKED_STRUCT
250
#undef PACKED
251
 
252
 
253
#ifdef __cplusplus
254
}
255
#endif
256
 
257
 
258
#endif // IFSFILE_H