Skip to content
Merged
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
1 change: 1 addition & 0 deletions UEFIExtract/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ SET(PROJECT_SOURCES
../common/nvramparser.cpp
../common/meparser.cpp
../common/ffsparser.cpp
../common/amd_microcode.cpp
../common/fitparser.cpp
../common/ffsreport.cpp
../common/peimage.cpp
Expand Down
1 change: 1 addition & 0 deletions UEFIFind/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ SET(PROJECT_SOURCES
../common/nvram.cpp
../common/nvramparser.cpp
../common/ffsparser.cpp
../common/amd_microcode.cpp
../common/fitparser.cpp
../common/peimage.cpp
../common/treeitem.cpp
Expand Down
1 change: 1 addition & 0 deletions UEFITool/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ SET(PROJECT_SOURCES
../common/utility.cpp
../common/ffsbuilder.cpp
../common/ffsparser.cpp
../common/amd_microcode.cpp
../common/ffsreport.cpp
../common/treeitem.cpp
../common/treemodel.cpp
Expand Down
2 changes: 2 additions & 0 deletions UEFITool/uefitool.pro
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ HEADERS += uefitool.h \
../common/treeitem.h \
../common/intel_fit.h \
../common/intel_microcode.h \
../common/amd_microcode.h \
../common/treemodel.h \
../common/LZMA/LzmaCompress.h \
../common/LZMA/LzmaDecompress.h \
Expand Down Expand Up @@ -109,6 +110,7 @@ SOURCES += uefitool_main.cpp \
../common/utility.cpp \
../common/ffsbuilder.cpp \
../common/ffsparser.cpp \
../common/amd_microcode.cpp \
../common/ffsreport.cpp \
../common/treeitem.cpp \
../common/treemodel.cpp \
Expand Down
77 changes: 77 additions & 0 deletions common/amd_microcode.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#include "amd_microcode.h"
#include "basetypes.h"

UINT32 getDataSizeMicrocodeAmd(const AMD_MICROCODE_HEADER *ucodeHeader) {
if (ucodeHeader->LoaderID >= 0x8005) {
return ((ucodeHeader->InitializationFlag << 8) | ucodeHeader->DataSize) * 0x10;
}

return ucodeHeader->DataSize;
}

UINT32 getSizeMicrocodeAmd(const AMD_MICROCODE_HEADER *ucodeHeader) {
UINT32 microcodeDataLen = getDataSizeMicrocodeAmd(ucodeHeader);
UINT32 cpuIdByte = (getCpuIdMicrocodeAmd(ucodeHeader) >> 16) & 0xFF;
UINT32 microcodeLen = 0;

if (microcodeDataLen == 0x20) {
microcodeLen = 0x3C0;
} else if (microcodeDataLen == 0x10) {
microcodeLen = 0x200;
} else if (microcodeDataLen) {
microcodeLen = microcodeDataLen;
} else if (cpuIdByte == 0x50) {
microcodeLen = 0x620;
} else if (cpuIdByte == 0x58) {
microcodeLen = 0x567;
} else if (cpuIdByte == 0x60 || cpuIdByte == 0x61 || cpuIdByte == 0x63 || cpuIdByte == 0x66 || cpuIdByte <= 0x67) {
microcodeLen = 0xA20;
} else if (cpuIdByte == 0x68 || cpuIdByte == 0x69) {
microcodeLen = 0x980;
} else if (cpuIdByte == 0x70 || cpuIdByte == 0x73) {
microcodeLen = 0xD60;
} else if (cpuIdByte >= 0x80 && cpuIdByte <= 0x83 || cpuIdByte >= 0x85 && cpuIdByte <= 0x8A) {
microcodeLen = 0xC80;
} else if (cpuIdByte >= 0xA0 && cpuIdByte <= 0xA7 || cpuIdByte == 0xAA) {
microcodeLen = 0x15C0;
} else if (cpuIdByte == 0xB4) {
microcodeLen = 0x3820;
}

return microcodeLen;
}

UINT32 getCpuIdMicrocodeAmd(const AMD_MICROCODE_HEADER *ucodeHeader) {
return (((ucodeHeader->ProcessorSignature >> 8) & 0xFF) << 16) | (0x0f << 8) |
(ucodeHeader->ProcessorSignature & 0xff);
}

UINT16 getYearMicrocodeAmd(const AMD_MICROCODE_HEADER *ucodeHeader) {
if (getCpuIdMicrocodeAmd(ucodeHeader) == 0x00800F11 && ucodeHeader->UpdateRevision == 0x8001105 &&
ucodeHeader->DateYear == 0x2016) {
return 0x2017;
}

return ucodeHeader->DateYear;
}

UINT8 getMonthMicrocodeAmd(const AMD_MICROCODE_HEADER *ucodeHeader) {
if (getCpuIdMicrocodeAmd(ucodeHeader) == 0x00300F10 && ucodeHeader->UpdateRevision == 0x3000027 &&
ucodeHeader->DateMonth == 0x13) {
return 0x12;
} else if (getCpuIdMicrocodeAmd(ucodeHeader) == 0x00730F01 && ucodeHeader->UpdateRevision == 0x7030106 &&
ucodeHeader->DateMonth == 0x09) {
return 0x02;
}

return ucodeHeader->DateMonth;
}

UINT8 getDayMicrocodeAmd(const AMD_MICROCODE_HEADER *ucodeHeader) {
if (getCpuIdMicrocodeAmd(ucodeHeader) == 0x00730F01 && ucodeHeader->UpdateRevision == 0x7030106 &&
ucodeHeader->DateDay == 0x02) {
return 0x09;
}

return ucodeHeader->DateDay;
}
41 changes: 41 additions & 0 deletions common/amd_microcode.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#ifndef AMD_MICROCODE_H
#define AMD_MICROCODE_H

#include "basetypes.h"
#include "ubytearray.h"

// Make sure we use right packing rules
#pragma pack(push, 1)

typedef struct AMD_MICROCODE_HEADER_ {
UINT16 DateYear;
UINT8 DateDay;
UINT8 DateMonth;
UINT32 UpdateRevision;
UINT16 LoaderID;
UINT8 DataSize;
UINT8 InitializationFlag;
UINT32 DataChecksum;
UINT16 NorthBridgeVEN_ID;
UINT16 NorthBridgeDEV_ID;
UINT16 SouthBridgeVEN_ID;
UINT16 SouthBridgeDEV_ID;
UINT16 ProcessorSignature;
UINT8 NorthBridgeREV_ID;
UINT8 SouthBridgeREV_ID;
UINT8 BiosApiRevision;
UINT8 LoadControl;
UINT8 Reserved_1E;
UINT8 Reserved_1F;
} AMD_MICROCODE_HEADER;

UINT32 getDataSizeMicrocodeAmd(const AMD_MICROCODE_HEADER *ucodeHeader);
UINT32 getSizeMicrocodeAmd(const AMD_MICROCODE_HEADER *ucodeHeader);
UINT32 getCpuIdMicrocodeAmd(const AMD_MICROCODE_HEADER *ucodeHeader);
UINT16 getYearMicrocodeAmd(const AMD_MICROCODE_HEADER *ucodeHeader);
UINT8 getMonthMicrocodeAmd(const AMD_MICROCODE_HEADER *ucodeHeader);
UINT8 getDayMicrocodeAmd(const AMD_MICROCODE_HEADER *ucodeHeader);

#pragma pack(pop)

#endif // AMD_MICROCODE_H
4 changes: 4 additions & 0 deletions common/ffs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ extern const UByteArray EFI_DXE_CORE_GUID // D6A2CB7F-6A18-4E2F-B43B-9920A733700
extern const UByteArray AMD_COMPRESSED_RAW_FILE_GUID //20BC8AC9-94D1-4208-AB28-5D673FD73487
("\xC9\x8A\xBC\x20\xD1\x94\x08\x42\xAB\x28\x5D\x67\x3F\xD7\x34\x87", 16);

// TE/PE files containing AMD microcode
extern const UByteArray AMD_MICROCODE_FILE_GUID // DE3E049C-A218-4891-8658-5FC0FA84C788
("\x9C\x04\x3E\xDE\x18\xA2\x91\x48\x86\x58\x5F\xC0\xFA\x84\xC7\x88", 16);

// Insyde Flash Device Map GUIDs
extern const UByteArray INSYDE_FLASH_MAP_REGION_BOOT_FV_GUID
("\x56\x6d\xd7\xe3\x8a\x98\x6b\x4d\x89\x13\x64\xf2\xdf\x1d\xf6\xa6", 16);
Expand Down
3 changes: 3 additions & 0 deletions common/ffs.h
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,9 @@ extern const UByteArray EFI_DXE_CORE_GUID; // D6A2CB7F-6A18-4E2F-B43B-9920A73370
// AMD compressed raw file
extern const UByteArray AMD_COMPRESSED_RAW_FILE_GUID; //20BC8AC9-94D1-4208-AB28-5D673FD73487

// TE/PE files containing AMD microcode
extern const UByteArray AMD_MICROCODE_FILE_GUID; // DE3E049C-A218-4891-8658-5FC0FA84C788

// FFS size conversion routines
extern VOID uint32ToUint24(UINT32 size, UINT8* ffsSize);
extern UINT32 uint24ToUint32(const UINT8* ffsSize);
Expand Down
Loading
Loading