Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support FFSv3 sections for both parsing and reconstructing. #90

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions ffs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,10 @@ UINT32 sizeOfSectionHeader(const EFI_COMMON_SECTION_HEADER* header)
if (!header)
return 0;

const bool extended = false;
/*if (uint24ToUint32(header->Size) == EFI_SECTION2_IS_USED) {
bool extended = false;
if (uint24ToUint32(header->Size) == EFI_SECTION2_IS_USED) {
extended = true;
}*/
}

switch (header->Type)
{
Expand Down
32 changes: 29 additions & 3 deletions ffsengine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -989,8 +989,9 @@ UINT8 FfsEngine::parseVolume(const QByteArray & volume, QModelIndex & index, co
// Check for volume structure to be known
bool volumeIsUnknown = true;

// Check for FFS v2 volume
if (FFSv2Volumes.contains(QByteArray::fromRawData((const char*)volumeHeader->FileSystemGuid.Data, sizeof(EFI_GUID)))) {
// Check for FFS v2 or v3 volume
if (FFSv2Volumes.contains(QByteArray::fromRawData((const char*)volumeHeader->FileSystemGuid.Data, sizeof(EFI_GUID)))
|| FFSv3Volumes.contains(QByteArray::fromRawData((const char*)volumeHeader->FileSystemGuid.Data, sizeof(EFI_GUID)))) {
volumeIsUnknown = false;
}

Expand Down Expand Up @@ -1384,6 +1385,12 @@ UINT8 FfsEngine::getSectionSize(const QByteArray & file, const UINT32 sectionOff
return ERR_INVALID_FILE;
const EFI_COMMON_SECTION_HEADER* sectionHeader = (const EFI_COMMON_SECTION_HEADER*)(file.constData() + sectionOffset);
sectionSize = uint24ToUint32(sectionHeader->Size);
if (sectionSize != 0xFFFFFF)
return ERR_SUCCESS;

// this is a header2 type
const EFI_COMMON_SECTION_HEADER2* sectionHeader2 = (const EFI_COMMON_SECTION_HEADER2*)(file.constData() + sectionOffset);
sectionSize = sectionHeader2->ExtendedSize;
return ERR_SUCCESS;
}

Expand Down Expand Up @@ -3577,6 +3584,11 @@ UINT8 FfsEngine::reconstructFile(const QModelIndex& index, const UINT8 revision,
model->action(index) == Actions::Rebuild) {
QByteArray header = model->header(index);
EFI_FFS_FILE_HEADER* fileHeader = (EFI_FFS_FILE_HEADER*)header.data();
if(header.size() >= 0xFFFFFF)
{
msg(tr("reconstructFile: extended header"), index);
return ERR_INVALID_PARAMETER;
}

// Check erase polarity
if (erasePolarity == ERASE_POLARITY_UNKNOWN) {
Expand Down Expand Up @@ -3732,6 +3744,12 @@ UINT8 FfsEngine::reconstructSection(const QModelIndex& index, const UINT32 base,
model->action(index) == Actions::Rebase) {
QByteArray header = model->header(index);
EFI_COMMON_SECTION_HEADER* commonHeader = (EFI_COMMON_SECTION_HEADER*)header.data();
bool extended = false;

if(uint24ToUint32(commonHeader->Size) == 0xFFFFFF)
{
extended = true;
}

// Reconstruct section with children
if (model->rowCount(index)) {
Expand Down Expand Up @@ -3832,7 +3850,15 @@ UINT8 FfsEngine::reconstructSection(const QModelIndex& index, const UINT32 base,
}

// Correct section size
uint32ToUint24(header.size() + reconstructed.size(), commonHeader->Size);
if (extended)
{
EFI_COMMON_SECTION_HEADER2 * extHeader
= (EFI_COMMON_SECTION_HEADER2*) commonHeader;;
extHeader->ExtendedSize = header.size() + reconstructed.size();
uint32ToUint24(0xFFFFFF, commonHeader->Size);
} else {
uint32ToUint24(header.size() + reconstructed.size(), commonHeader->Size);
}
}
// Leaf section
else
Expand Down