diff --git a/libuuu/rominfo.cpp b/libuuu/rominfo.cpp index 68fb4ddf..c92a647a 100644 --- a/libuuu/rominfo.cpp +++ b/libuuu/rominfo.cpp @@ -92,6 +92,7 @@ const ROM_INFO * search_rom_info(const ConfigItem *item) #define HASH_MAX_LEN 64 #define CONTAINER_HDR_ALIGNMENT 0x400 +#define CONTAINER_HDR_ALIGNMENT_V2 0x4000 static constexpr uint8_t CONTAINER_TAG = 0x87; #pragma pack (1) @@ -128,31 +129,43 @@ static constexpr uint32_t IMG_V2X = 0x0B; size_t GetContainerActualSize(shared_ptr p, size_t offset, bool bROMAPI, bool skipspl) { + uint32_t align = CONTAINER_HDR_ALIGNMENT; + if(bROMAPI) return p->size() - offset; - auto hdr = reinterpret_cast(p->data() + offset + CONTAINER_HDR_ALIGNMENT); + auto hdr = reinterpret_cast(p->data() + offset); + if (hdr->tag != CONTAINER_TAG) + { + return p->size() - offset; + } + else if (hdr->version >= 2) + { /* after imx943 align change to 0x4000 from 0x400 */ + align = CONTAINER_HDR_ALIGNMENT_V2; + } + + hdr = reinterpret_cast(p->data() + offset + align); if (hdr->tag != CONTAINER_TAG) { return p->size() - offset; } /* Check if include V2X container*/ - auto image = reinterpret_cast(p->data() + offset + CONTAINER_HDR_ALIGNMENT + auto image = reinterpret_cast(p->data() + offset + align + sizeof(struct rom_container)); unsigned int cindex = 1; if ((image->flags & 0xF) == IMG_V2X) { cindex = 2; - hdr = reinterpret_cast(p->data() + offset + cindex * CONTAINER_HDR_ALIGNMENT); + hdr = reinterpret_cast(p->data() + offset + cindex * align); if (hdr->tag != CONTAINER_TAG) { return p->size() - offset; } } - image = reinterpret_cast(p->data() + offset + cindex * CONTAINER_HDR_ALIGNMENT + image = reinterpret_cast(p->data() + offset + cindex * align + sizeof(struct rom_container) + sizeof(struct rom_bootimg) * (hdr->num_images - 1)); @@ -162,8 +175,9 @@ size_t GetContainerActualSize(shared_ptr p, size_t offset, bool bROM image--; } - uint32_t sz = image->size + image->offset + cindex * CONTAINER_HDR_ALIGNMENT; + uint32_t sz = image->size + image->offset + cindex * align; + /* keep v1 align for calculate spl size */ sz = round_up(sz, static_cast(CONTAINER_HDR_ALIGNMENT)); if (sz > (p->size() - offset))