Skip to content

Commit

Permalink
Add container v2 support.
Browse files Browse the repository at this point in the history
V2 container change alignment to 0x4000 from 0x400.

Signed-off-by: Frank Li <[email protected]>
  • Loading branch information
nxpfrankli committed Jan 8, 2025
1 parent 0163981 commit 03f16e5
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions libuuu/rominfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -128,31 +129,43 @@ static constexpr uint32_t IMG_V2X = 0x0B;

size_t GetContainerActualSize(shared_ptr<DataBuffer> p, size_t offset, bool bROMAPI, bool skipspl)
{
uint32_t align = CONTAINER_HDR_ALIGNMENT;

if(bROMAPI)
return p->size() - offset;

auto hdr = reinterpret_cast<struct rom_container *>(p->data() + offset + CONTAINER_HDR_ALIGNMENT);
auto hdr = reinterpret_cast<struct rom_container *>(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<struct rom_container *>(p->data() + offset + align);
if (hdr->tag != CONTAINER_TAG)
{
return p->size() - offset;
}

/* Check if include V2X container*/
auto image = reinterpret_cast<struct rom_bootimg *>(p->data() + offset + CONTAINER_HDR_ALIGNMENT
auto image = reinterpret_cast<struct rom_bootimg *>(p->data() + offset + align
+ sizeof(struct rom_container));

unsigned int cindex = 1;
if ((image->flags & 0xF) == IMG_V2X)
{
cindex = 2;
hdr = reinterpret_cast<struct rom_container *>(p->data() + offset + cindex * CONTAINER_HDR_ALIGNMENT);
hdr = reinterpret_cast<struct rom_container *>(p->data() + offset + cindex * align);
if (hdr->tag != CONTAINER_TAG)
{
return p->size() - offset;
}
}

image = reinterpret_cast<struct rom_bootimg *>(p->data() + offset + cindex * CONTAINER_HDR_ALIGNMENT
image = reinterpret_cast<struct rom_bootimg *>(p->data() + offset + cindex * align
+ sizeof(struct rom_container)
+ sizeof(struct rom_bootimg) * (hdr->num_images - 1));

Expand All @@ -162,8 +175,9 @@ size_t GetContainerActualSize(shared_ptr<DataBuffer> 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<uint32_t>(CONTAINER_HDR_ALIGNMENT));

if (sz > (p->size() - offset))
Expand Down

0 comments on commit 03f16e5

Please sign in to comment.