MCPcopy Create free account
hub / github.com/LongSoft/UEFITool / parseIntelImage

Method parseIntelImage

ffsengine.cpp:249–634  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

247}
248
249UINT8 FfsEngine::parseIntelImage(const QByteArray & intelImage, QModelIndex & index, const QModelIndex & parent)
250{
251 // Sanity check
252 if (intelImage.isEmpty())
253 return EFI_INVALID_PARAMETER;
254
255 // Store the beginning of descriptor as descriptor base address
256 const UINT8* descriptor = (const UINT8*)intelImage.constData();
257 UINT32 descriptorBegin = 0;
258 UINT32 descriptorEnd = FLASH_DESCRIPTOR_SIZE;
259
260 // Check for buffer size to be greater or equal to descriptor region size
261 if (intelImage.size() < FLASH_DESCRIPTOR_SIZE) {
262 msg(tr("parseIntelImage: input file is smaller than minimum descriptor size of 1000h (4096) bytes"));
263 return ERR_INVALID_FLASH_DESCRIPTOR;
264 }
265
266 // Parse descriptor map
267 const FLASH_DESCRIPTOR_MAP* descriptorMap = (const FLASH_DESCRIPTOR_MAP*)(descriptor + sizeof(FLASH_DESCRIPTOR_HEADER));
268 const FLASH_DESCRIPTOR_UPPER_MAP* upperMap = (const FLASH_DESCRIPTOR_UPPER_MAP*)(descriptor + FLASH_DESCRIPTOR_UPPER_MAP_BASE);
269
270 // Check sanity of base values
271 if (descriptorMap->MasterBase > FLASH_DESCRIPTOR_MAX_BASE
272 || descriptorMap->MasterBase == descriptorMap->RegionBase
273 || descriptorMap->MasterBase == descriptorMap->ComponentBase) {
274 msg(tr("parseIntelImage: invalid descriptor master base %1h").hexarg2(descriptorMap->MasterBase, 2));
275 return ERR_INVALID_FLASH_DESCRIPTOR;
276 }
277 if (descriptorMap->RegionBase > FLASH_DESCRIPTOR_MAX_BASE
278 || descriptorMap->RegionBase == descriptorMap->ComponentBase) {
279 msg(tr("parseIntelImage: invalid descriptor region base %1h").hexarg2(descriptorMap->RegionBase, 2));
280 return ERR_INVALID_FLASH_DESCRIPTOR;
281 }
282 if (descriptorMap->ComponentBase > FLASH_DESCRIPTOR_MAX_BASE) {
283 msg(tr("parseIntelImage: invalid descriptor component base %1h").hexarg2(descriptorMap->ComponentBase, 2));
284 return ERR_INVALID_FLASH_DESCRIPTOR;
285 }
286
287 const FLASH_DESCRIPTOR_REGION_SECTION* regionSection = (const FLASH_DESCRIPTOR_REGION_SECTION*)calculateAddress8(descriptor, descriptorMap->RegionBase);
288 const FLASH_DESCRIPTOR_COMPONENT_SECTION* componentSection = (const FLASH_DESCRIPTOR_COMPONENT_SECTION*)calculateAddress8(descriptor, descriptorMap->ComponentBase);
289
290 // Check for legacy descriptor version by getting hardcoded value of FlashParameters.ReadClockFrequency
291 UINT8 descriptorVersion = 2; // Skylake+ descriptor
292 if (componentSection->FlashParameters.ReadClockFrequency == FLASH_FREQUENCY_20MHZ) // Legacy descriptor
293 descriptorVersion = 1;
294
295 // ME region
296 QByteArray me;
297 UINT32 meBegin = 0;
298 UINT32 meEnd = 0;
299 if (regionSection->MeLimit) {
300 meBegin = calculateRegionOffset(regionSection->MeBase);
301 meEnd = calculateRegionSize(regionSection->MeBase, regionSection->MeLimit);
302 me = intelImage.mid(meBegin, meEnd);
303 meEnd += meBegin;
304 }
305 // BIOS region
306 QByteArray bios;

Callers

nothing calls this directly

Calls 4

calculateAddress8Function · 0.85
calculateRegionOffsetFunction · 0.85
calculateRegionSizeFunction · 0.85
addItemMethod · 0.80

Tested by

no test coverage detected