summaryrefslogtreecommitdiffstats
path: root/libpit/Source
diff options
context:
space:
mode:
Diffstat (limited to 'libpit/Source')
-rw-r--r--libpit/Source/libpit.cpp85
-rw-r--r--libpit/Source/libpit.h149
2 files changed, 138 insertions, 96 deletions
diff --git a/libpit/Source/libpit.cpp b/libpit/Source/libpit.cpp
index 7953ea9..56903f9 100644
--- a/libpit/Source/libpit.cpp
+++ b/libpit/Source/libpit.cpp
@@ -25,18 +25,19 @@ using namespace libpit;
PitEntry::PitEntry()
{
- unused = false;
- chipIdentifier = 0;
- partitionIdentifier = 0;
- partitionFlags = 0;
- unknown1 = 0;
- partitionBlockSize = 0;
- partitionBlockCount = 0;
- unknown2 = 0;
- unknown3 = 0;
-
- memset(partitionName, 0, 32);
- memset(filename, 0, 64);
+ binaryType = false;
+ deviceType = 0;
+ identifier = 0;
+ attributes = 0;
+ updateAttributes = 0;
+ blockSize = 0;
+ blockCount = 0;
+ fileOffset = 0;
+ fileSize = 0;
+
+ memset(partitionName, 0, PitEntry::kPartitionNameMaxLength);
+ memset(flashFilename, 0, PitEntry::kFlashFilenameMaxLength);
+ memset(fotaFilename, 0, PitEntry::kFotaFilenameMaxLength);
}
PitEntry::~PitEntry()
@@ -45,10 +46,11 @@ PitEntry::~PitEntry()
bool PitEntry::Matches(const PitEntry *otherPitEntry) const
{
- if (unused == otherPitEntry->unused && chipIdentifier == otherPitEntry->chipIdentifier && partitionIdentifier == otherPitEntry->partitionIdentifier
- && partitionFlags == otherPitEntry->partitionFlags && unknown1 == otherPitEntry->unknown1 && partitionBlockSize == otherPitEntry->partitionBlockSize
- && partitionBlockCount == otherPitEntry->partitionBlockCount && unknown2 == otherPitEntry->unknown2 && unknown3 == otherPitEntry->unknown3
- && strcmp(partitionName, otherPitEntry->partitionName) == 0 && strcmp(filename, otherPitEntry->filename) == 0)
+ if (binaryType == otherPitEntry->binaryType && deviceType == otherPitEntry->deviceType && identifier == otherPitEntry->identifier
+ && attributes == otherPitEntry->attributes && updateAttributes == otherPitEntry->updateAttributes && blockSize == otherPitEntry->blockSize
+ && blockCount == otherPitEntry->blockCount && fileOffset == otherPitEntry->fileOffset && fileSize == otherPitEntry->fileSize
+ && strcmp(partitionName, otherPitEntry->partitionName) == 0 && strcmp(flashFilename, otherPitEntry->flashFilename) == 0
+ && strcmp(fotaFilename, otherPitEntry->fotaFilename) == 0)
{
return (true);
}
@@ -118,34 +120,35 @@ bool PitData::Unpack(const unsigned char *data)
entries[i] = new PitEntry();
integerValue = PitData::UnpackInteger(data, entryOffset);
- entries[i]->SetUnused((integerValue != 0) ? true : false);
+ entries[i]->SetBinaryType(integerValue);
integerValue = PitData::UnpackInteger(data, entryOffset + 4);
- entries[i]->SetChipIdentifier(integerValue);
+ entries[i]->SetDeviceType(integerValue);
integerValue = PitData::UnpackInteger(data, entryOffset + 8);
- entries[i]->SetPartitionIdentifier(integerValue);
+ entries[i]->SetIdentifier(integerValue);
integerValue = PitData::UnpackInteger(data, entryOffset + 12);
- entries[i]->SetPartitionFlags(integerValue);
+ entries[i]->SetAttributes(integerValue);
integerValue = PitData::UnpackInteger(data, entryOffset + 16);
- entries[i]->SetUnknown1(integerValue);
+ entries[i]->SetUpdateAttributes(integerValue);
integerValue = PitData::UnpackInteger(data, entryOffset + 20);
- entries[i]->SetPartitionBlockSize(integerValue);
+ entries[i]->SetBlockSize(integerValue);
integerValue = PitData::UnpackInteger(data, entryOffset + 24);
- entries[i]->SetPartitionBlockCount(integerValue);
+ entries[i]->SetBlockCount(integerValue);
integerValue = PitData::UnpackInteger(data, entryOffset + 28);
- entries[i]->SetUnknown2(integerValue);
+ entries[i]->SetFileOffset(integerValue);
integerValue = PitData::UnpackInteger(data, entryOffset + 32);
- entries[i]->SetUnknown3(integerValue);
+ entries[i]->SetFileSize(integerValue);
entries[i]->SetPartitionName((const char *)data + entryOffset + 36);
- entries[i]->SetFilename((const char *)data + entryOffset + 36 + PitEntry::kPartitionNameMaxLength);
+ entries[i]->SetFlashFilename((const char *)data + entryOffset + 36 + PitEntry::kPartitionNameMaxLength);
+ entries[i]->SetFotaFilename((const char *)data + entryOffset + 36 + PitEntry::kPartitionNameMaxLength + PitEntry::kFlashFilenameMaxLength);
}
return (true);
@@ -175,22 +178,24 @@ void PitData::Pack(unsigned char *data) const
{
entryOffset = PitData::kHeaderDataSize + i * PitEntry::kDataSize;
- PitData::PackInteger(data, entryOffset, (entries[i]->GetUnused()) ? 1 : 0);
+ PitData::PackInteger(data, entryOffset, entries[i]->GetBinaryType());
- PitData::PackInteger(data, entryOffset + 4, entries[i]->GetChipIdentifier());
- PitData::PackInteger(data, entryOffset + 8, entries[i]->GetPartitionIdentifier());
- PitData::PackInteger(data, entryOffset + 12, entries[i]->GetPartitionFlags());
+ PitData::PackInteger(data, entryOffset + 4, entries[i]->GetDeviceType());
+ PitData::PackInteger(data, entryOffset + 8, entries[i]->GetIdentifier());
+ PitData::PackInteger(data, entryOffset + 12, entries[i]->GetAttributes());
- PitData::PackInteger(data, entryOffset + 16, entries[i]->GetUnknown1());
+ PitData::PackInteger(data, entryOffset + 16, entries[i]->GetUpdateAttributes());
- PitData::PackInteger(data, entryOffset + 20, entries[i]->GetPartitionBlockSize());
- PitData::PackInteger(data, entryOffset + 24, entries[i]->GetPartitionBlockCount());
+ PitData::PackInteger(data, entryOffset + 20, entries[i]->GetBlockSize());
+ PitData::PackInteger(data, entryOffset + 24, entries[i]->GetBlockCount());
- PitData::PackInteger(data, entryOffset + 28, entries[i]->GetUnknown2());
- PitData::PackInteger(data, entryOffset + 32, entries[i]->GetUnknown3());
+ PitData::PackInteger(data, entryOffset + 28, entries[i]->GetFileOffset());
+ PitData::PackInteger(data, entryOffset + 32, entries[i]->GetFileSize());
memcpy(data + entryOffset + 36, entries[i]->GetPartitionName(), PitEntry::kPartitionNameMaxLength);
- memcpy(data + entryOffset + 36 + PitEntry::kPartitionNameMaxLength, entries[i]->GetPartitionName(), PitEntry::kFilenameMaxLength);
+ memcpy(data + entryOffset + 36 + PitEntry::kPartitionNameMaxLength, entries[i]->GetPartitionName(), PitEntry::kFlashFilenameMaxLength);
+ memcpy(data + entryOffset + 36 + PitEntry::kPartitionNameMaxLength + PitEntry::kFlashFilenameMaxLength,
+ entries[i]->GetFotaFilename(), PitEntry::kFotaFilenameMaxLength);
}
}
@@ -250,7 +255,7 @@ PitEntry *PitData::FindEntry(const char *partitionName)
{
for (unsigned int i = 0; i < entries.size(); i++)
{
- if (!entries[i]->GetUnused() && strcmp(entries[i]->GetPartitionName(), partitionName) == 0)
+ if (entries[i]->GetBlockCount() > 0 && strcmp(entries[i]->GetPartitionName(), partitionName) == 0)
return (entries[i]);
}
@@ -261,7 +266,7 @@ const PitEntry *PitData::FindEntry(const char *partitionName) const
{
for (unsigned int i = 0; i < entries.size(); i++)
{
- if (!entries[i]->GetUnused() && strcmp(entries[i]->GetPartitionName(), partitionName) == 0)
+ if (entries[i]->GetBlockCount() > 0 && strcmp(entries[i]->GetPartitionName(), partitionName) == 0)
return (entries[i]);
}
@@ -272,7 +277,7 @@ PitEntry *PitData::FindEntry(unsigned int partitionIdentifier)
{
for (unsigned int i = 0; i < entries.size(); i++)
{
- if (!entries[i]->GetUnused() && entries[i]->GetPartitionIdentifier() == partitionIdentifier)
+ if (entries[i]->GetBlockCount() > 0 && entries[i]->GetIdentifier() == partitionIdentifier)
return (entries[i]);
}
@@ -283,7 +288,7 @@ const PitEntry *PitData::FindEntry(unsigned int partitionIdentifier) const
{
for (unsigned int i = 0; i < entries.size(); i++)
{
- if (!entries[i]->GetUnused() && entries[i]->GetPartitionIdentifier() == partitionIdentifier)
+ if (entries[i]->GetBlockCount() > 0 && entries[i]->GetIdentifier() == partitionIdentifier)
return (entries[i]);
}
diff --git a/libpit/Source/libpit.h b/libpit/Source/libpit.h
index db8b6aa..40c7da5 100644
--- a/libpit/Source/libpit.h
+++ b/libpit/Source/libpit.h
@@ -43,32 +43,53 @@ namespace libpit
{
kDataSize = 132,
kPartitionNameMaxLength = 32,
- kFilenameMaxLength = 64
+ kFlashFilenameMaxLength = 32,
+ kFotaFilenameMaxLength = 32
};
enum
{
- kPartitionFlagWrite = 1 << 1
+ kBinaryTypeApplicationProcessor = 0,
+ kBinaryTypeCommunicationProcessor = 1
};
- private:
+ enum
+ {
+ kDeviceTypeOneNand = 0,
+ kDeviceTypeFile, // FAT
+ kDeviceTypeMMC,
+ kDeviceTypeAll // ?
+ };
+
+ enum
+ {
+ kAttributeWrite = 1,
+ kAttributeSTL = 1 << 1
+ };
- bool unused;
+ enum
+ {
+ kUpdateAttributeFota = 1,
+ kUpdateAttributeSecure = 1 << 1
+ };
- unsigned int chipIdentifier;
- unsigned int partitionIdentifier;
- unsigned int partitionFlags;
+ private:
- unsigned int unknown1;
+ unsigned int binaryType;
+ unsigned int deviceType;
+ unsigned int identifier;
+ unsigned int attributes;
+ unsigned int updateAttributes;
- unsigned int partitionBlockSize;
- unsigned int partitionBlockCount;
+ unsigned int blockSize;
+ unsigned int blockCount;
- unsigned int unknown2;
- unsigned int unknown3;
+ unsigned int fileOffset; // Obsolete
+ unsigned int fileSize; // Obsolete
char partitionName[kPartitionNameMaxLength];
- char filename[kFilenameMaxLength];
+ char flashFilename[kFlashFilenameMaxLength]; // USB flash filename
+ char fotaFilename[kFotaFilenameMaxLength]; // Firmware over the air
public:
@@ -77,94 +98,94 @@ namespace libpit
bool Matches(const PitEntry *otherPitEntry) const;
- bool GetUnused(void) const
+ unsigned int GetBinaryType(void) const
{
- return unused;
+ return binaryType;
}
- void SetUnused(bool unused)
+ void SetBinaryType(unsigned int binaryType)
{
- this->unused = unused;
+ this->binaryType = binaryType;
}
- unsigned int GetChipIdentifier(void) const
+ unsigned int GetDeviceType(void) const
{
- return chipIdentifier;
+ return deviceType;
}
- void SetChipIdentifier(unsigned int chipIdentifier)
+ void SetDeviceType(unsigned int deviceType)
{
- this->chipIdentifier = chipIdentifier;
+ this->deviceType = deviceType;
}
- unsigned int GetPartitionIdentifier(void) const
+ unsigned int GetIdentifier(void) const
{
- return partitionIdentifier;
+ return identifier;
}
- void SetPartitionIdentifier(unsigned int partitionIdentifier)
+ void SetIdentifier(unsigned int identifier)
{
- this->partitionIdentifier = partitionIdentifier;
+ this->identifier = identifier;
}
- unsigned int GetPartitionFlags(void) const
+ unsigned int GetAttributes(void) const
{
- return partitionFlags;
+ return attributes;
}
- void SetPartitionFlags(unsigned int partitionFlags)
+ void SetAttributes(unsigned int attributes)
{
- this->partitionFlags = partitionFlags;
+ this->attributes = attributes;
}
- unsigned int GetUnknown1(void) const
+ unsigned int GetUpdateAttributes(void) const
{
- return unknown1;
+ return updateAttributes;
}
- void SetUnknown1(unsigned int unknown1)
+ void SetUpdateAttributes(unsigned int updateAttributes)
{
- this->unknown1 = unknown1;
+ this->updateAttributes = updateAttributes;
}
- unsigned int GetPartitionBlockSize(void) const
+ unsigned int GetBlockSize(void) const
{
- return partitionBlockSize;
+ return blockSize;
}
- void SetPartitionBlockSize(unsigned int partitionBlockSize)
+ void SetBlockSize(unsigned int blockSize)
{
- this->partitionBlockSize = partitionBlockSize;
+ this->blockSize = blockSize;
}
- unsigned int GetPartitionBlockCount(void) const
+ unsigned int GetBlockCount(void) const
{
- return partitionBlockCount;
+ return blockCount;
}
- void SetPartitionBlockCount(unsigned int partitionBlockCount)
+ void SetBlockCount(unsigned int blockCount)
{
- this->partitionBlockCount = partitionBlockCount;
+ this->blockCount = blockCount;
}
- unsigned int GetUnknown2(void) const
+ unsigned int GetFileOffset(void) const
{
- return unknown2;
+ return fileOffset;
}
- void SetUnknown2(unsigned int unknown2)
+ void SetFileOffset(unsigned int fileOffset)
{
- this->unknown2 = unknown2;
+ this->fileOffset = fileOffset;
}
- unsigned int GetUnknown3(void) const
+ unsigned int GetFileSize(void) const
{
- return unknown3;
+ return fileSize;
}
- void SetUnknown3(unsigned int unknown3)
+ void SetFileSize(unsigned int fileSize)
{
- this->unknown3 = unknown3;
+ this->fileSize = fileSize;
}
const char *GetPartitionName(void) const
@@ -183,20 +204,36 @@ namespace libpit
memcpy(this->partitionName, partitionName, 63);
}
- const char *GetFilename(void) const
+ const char *GetFlashFilename(void) const
+ {
+ return flashFilename;
+ }
+
+ void SetFlashFilename(const char *flashFilename)
+ {
+ // This isn't strictly necessary but ensures no junk is left in our PIT file.
+ memset(this->flashFilename, 0, kFlashFilenameMaxLength);
+
+ if (strlen(partitionName) < 32)
+ strcpy(this->flashFilename, flashFilename);
+ else
+ memcpy(this->flashFilename, flashFilename, 31);
+ }
+
+ const char *GetFotaFilename(void) const
{
- return filename;
+ return fotaFilename;
}
- void SetFilename(const char *filename)
+ void SetFotaFilename(const char *fotaFilename)
{
// This isn't strictly necessary but ensures no junk is left in our PIT file.
- memset(this->filename, 0, 32);
+ memset(this->fotaFilename, 0, kFotaFilenameMaxLength);
if (strlen(partitionName) < 32)
- strcpy(this->filename, filename);
+ strcpy(this->fotaFilename, fotaFilename);
else
- memcpy(this->filename, filename, 31);
+ memcpy(this->fotaFilename, fotaFilename, 31);
}
};
@@ -217,7 +254,7 @@ namespace libpit
unsigned int unknown2; // 0x0C
unsigned short unknown3; // 0x10 (7508 = I9000, 7703 = I9100 & P1000)?
- unsigned short unknown4; // 0x12 (Always 65, probably flags of some sort)
+ unsigned short unknown4; // 0x12 (Always 65, probably attributes of some sort)
unsigned short unknown5; // 0x14
unsigned short unknown6; // 0x16