fixes #443: -udev stdout should replace 70-uuu.rules rather than be appended to it
[mfgtools.git] / libuuu / ffu_format.h
blob523400ab84357acbb6010a9bdbc5b556450a7ad3
1 /*
2 * Copyright 2020 NXP.
4 * Redistribution and use in source and binary forms, with or without modification,
5 * are permitted provided that the following conditions are met:
7 * Redistributions of source code must retain the above copyright notice, this
8 * list of conditions and the following disclaimer.
10 * Redistributions in binary form must reproduce the above copyright notice, this
11 * list of conditions and the following disclaimer in the documentation and/or
12 * other materials provided with the distribution.
14 * Neither the name of the NXP Semiconductor nor the names of its
15 * contributors may be used to endorse or promote products derived from this
16 * software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 * POSSIBILITY OF SUCH DAMAGE.
32 //ref: https://docs.microsoft.com/en-us/windows-hardware/manufacture/mobile/ffu-image-format
34 #ifndef LIBSPARSE_FFU_FORMAT_H
35 #define LIBSPARSE_FFU_FORMAT_H
37 #include <cstdint>
39 #define FFU_SECURITY_SIGNATURE "SignedImage "
41 #pragma pack(1)
43 typedef struct _FFU_SECURITY_HEADER
45 uint32_t cbSize; // size of struct, overall
46 uint8_t signature[12]; // "SignedImage "
47 uint32_t dwChunkSizeInKb; // size of a hashed chunk within the image
48 uint32_t dwAlgId; // algorithm used to hash
49 uint32_t dwCatalogSize; // size of catalog to validate
50 uint32_t dwHashTableSize; // size of hash table
51 } FFU_SECURITY_HEADER;
53 #define FFU_SIGNATURE "ImageFlash "
55 typedef struct _IMAGE_HEADER
57 uint32_t cbSize; // sizeof(ImageHeader)
58 uint8_t Signature[12]; // "ImageFlash "
59 uint32_t ManifestLength; // in bytes
60 uint32_t dwChunkSize; // Used only during image generation.
61 } FFU_IMAGE_HEADER;
63 typedef struct _STORE_HEADER
65 uint32_t dwUpdateType; // indicates partial or full flash
66 uint16_t MajorVersion, MinorVersion; // used to validate struct
67 uint16_t FullFlashMajorVersion, FullFlashMinorVersion; // FFU version, i.e. the image format
68 uint8_t szPlatformId[192]; // string which indicates what device this FFU is intended to be written to
69 uint32_t dwBlockSizeInBytes; // size of an image block in bytes - the device's actual sector size may differ
70 uint32_t dwWriteDescriptorCount; // number of write descriptors to iterate through
71 uint32_t dwWriteDescriptorLength; // total size of all the write descriptors, in bytes (included so they can be read out up front and interpreted later)
72 uint32_t dwValidateDescriptorCount; // number of validation descriptors to check
73 uint32_t dwValidateDescriptorLength; // total size of all the validation descriptors, in bytes
74 uint32_t dwInitialTableIndex; // block index in the payload of the initial (invalid) GPT
75 uint32_t dwInitialTableCount; // count of blocks for the initial GPT, i.e. the GPT spans blockArray[idx..(idx + count -1)]
76 uint32_t dwFlashOnlyTableIndex; // first block index in the payload of the flash-only GPT (included so safe flashing can be accomplished)
77 uint32_t dwFlashOnlyTableCount; // count of blocks in the flash-only GPT
78 uint32_t dwFinalTableIndex; // index in the table of the real GPT
79 uint32_t dwFinalTableCount; // number of blocks in the real GPT
80 uint16_t NumOfStores; // Total number of stores (V2 only)
81 uint16_t StoreIndex; // Current store index, 1-based (V2 only)
82 uint64_t StorePayloadSize; // Payload data only, excludes padding (V2 only)
83 uint16_t DevicePathLength; // Length of the device path (V2 only)
84 uint16_t DevicePath[1]; // Device path has no NUL at then end (V2 only)
85 } FFU_STORE_HEADER;
87 typedef struct _VALIDATION_ENTRY
89 uint32_t dwSectorIndex;
90 uint32_t dwSectorOffset;
91 uint32_t dwByteCount;
92 uint8_t rgCompareData[1]; // size is dwByteCount
93 } FFU_VALIDATION_ENTRY;
95 enum DISK_ACCESS_METHOD
97 DISK_BEGIN = 0,
98 DISK_END = 2
101 typedef struct _DISK_LOCATION
103 uint32_t dwDiskAccessMethod;
104 uint32_t dwBlockIndex;
105 } FFU_DISK_LOCATION;
107 typedef struct _BLOCK_DATA_ENTRY
109 uint32_t dwLocationCount;
110 uint32_t dwBlockCount;
111 FFU_DISK_LOCATION rgDiskLocations[1];
112 } FFU_BLOCK_DATA_ENTRY;
113 #pragma pack()
115 #endif // LIBSPARSE_FFU_FORMAT_H