#include <Common/UefiBaseTypes.h>\r
#include <Common/PiFirmwareFile.h>\r
#include <IndustryStandard/PeImage.h>\r
+#include <Guid/FfsSectionAlignmentPadding.h>\r
\r
#include "CommonLib.h"\r
#include "ParseInf.h"\r
\r
STATIC EFI_GUID mZeroGuid = {0};\r
\r
+STATIC EFI_GUID mEfiFfsSectionAlignmentPaddingGuid = EFI_FFS_SECTION_ALIGNMENT_PADDING_GUID;\r
+\r
STATIC\r
VOID \r
Version (\r
STATIC\r
EFI_STATUS\r
GetSectionContents (\r
- IN CHAR8 **InputFileName,\r
- IN UINT32 *InputFileAlign,\r
- IN UINT32 InputFileNum,\r
- OUT UINT8 *FileBuffer,\r
- OUT UINT32 *BufferLength,\r
- OUT UINT32 *MaxAlignment,\r
- OUT UINT8 *PESectionNum\r
+ IN CHAR8 **InputFileName,\r
+ IN UINT32 *InputFileAlign,\r
+ IN UINT32 InputFileNum,\r
+ IN EFI_FFS_FILE_ATTRIBUTES FfsAttrib,\r
+ OUT UINT8 *FileBuffer,\r
+ OUT UINT32 *BufferLength,\r
+ OUT UINT32 *MaxAlignment,\r
+ OUT UINT8 *PESectionNum\r
)\r
/*++\r
\r
EFI_BUFFER_TOO_SMALL FileBuffer is not enough to contain all file data.\r
--*/\r
{\r
- UINT32 Size;\r
- UINT32 Offset;\r
- UINT32 FileSize;\r
- UINT32 Index;\r
- FILE *InFile;\r
- EFI_COMMON_SECTION_HEADER *SectHeader;\r
- EFI_COMMON_SECTION_HEADER2 TempSectHeader;\r
- EFI_TE_IMAGE_HEADER TeHeader;\r
- UINT32 TeOffset;\r
- EFI_GUID_DEFINED_SECTION GuidSectHeader;\r
- EFI_GUID_DEFINED_SECTION2 GuidSectHeader2;\r
- UINT32 HeaderSize;\r
-\r
- Size = 0;\r
- Offset = 0;\r
- TeOffset = 0;\r
+ UINT32 Size;\r
+ UINT32 Offset;\r
+ UINT32 FileSize;\r
+ UINT32 Index;\r
+ FILE *InFile;\r
+ EFI_FREEFORM_SUBTYPE_GUID_SECTION *SectHeader;\r
+ EFI_COMMON_SECTION_HEADER2 TempSectHeader;\r
+ EFI_TE_IMAGE_HEADER TeHeader;\r
+ UINT32 TeOffset;\r
+ EFI_GUID_DEFINED_SECTION GuidSectHeader;\r
+ EFI_GUID_DEFINED_SECTION2 GuidSectHeader2;\r
+ UINT32 HeaderSize;\r
+ UINT32 MaxEncounteredAlignment;\r
+\r
+ Size = 0;\r
+ Offset = 0;\r
+ TeOffset = 0;\r
+ MaxEncounteredAlignment = 1;\r
\r
//\r
// Go through our array of file names and copy their contents\r
Size++;\r
}\r
\r
- //\r
- // Get the Max alignment of all input file datas\r
- //\r
- if (*MaxAlignment < InputFileAlign [Index]) {\r
- *MaxAlignment = InputFileAlign [Index];\r
- }\r
-\r
// \r
// Open file and read contents\r
//\r
}\r
\r
//\r
- // make sure section data meet its alignment requirement by adding one raw pad section.\r
+ // make sure section data meet its alignment requirement by adding one pad section.\r
// But the different sections have the different section header. Necessary or not?\r
// Based on section type to adjust offset? Todo\r
//\r
// The maximal alignment is 64K, the raw section size must be less than 0xffffff\r
//\r
memset (FileBuffer + Size, 0, Offset);\r
- SectHeader = (EFI_COMMON_SECTION_HEADER *) (FileBuffer + Size);\r
- SectHeader->Type = EFI_SECTION_RAW;\r
- SectHeader->Size[0] = (UINT8) (Offset & 0xff);\r
- SectHeader->Size[1] = (UINT8) ((Offset & 0xff00) >> 8);\r
- SectHeader->Size[2] = (UINT8) ((Offset & 0xff0000) >> 16);\r
+ SectHeader = (EFI_FREEFORM_SUBTYPE_GUID_SECTION *) (FileBuffer + Size);\r
+ SectHeader->CommonHeader.Size[0] = (UINT8) (Offset & 0xff);\r
+ SectHeader->CommonHeader.Size[1] = (UINT8) ((Offset & 0xff00) >> 8);\r
+ SectHeader->CommonHeader.Size[2] = (UINT8) ((Offset & 0xff0000) >> 16);\r
+\r
+ //\r
+ // Only add a special reducible padding section if\r
+ // - this FFS has the FFS_ATTRIB_FIXED attribute,\r
+ // - none of the preceding sections have alignment requirements,\r
+ // - the size of the padding is sufficient for the\r
+ // EFI_SECTION_FREEFORM_SUBTYPE_GUID header.\r
+ //\r
+ if ((FfsAttrib & FFS_ATTRIB_FIXED) != 0 &&\r
+ MaxEncounteredAlignment <= 1 &&\r
+ Offset >= sizeof (EFI_FREEFORM_SUBTYPE_GUID_SECTION)) {\r
+ SectHeader->CommonHeader.Type = EFI_SECTION_FREEFORM_SUBTYPE_GUID;\r
+ SectHeader->SubTypeGuid = mEfiFfsSectionAlignmentPaddingGuid;\r
+ } else {\r
+ SectHeader->CommonHeader.Type = EFI_SECTION_RAW;\r
+ }\r
}\r
DebugMsg (NULL, 0, 9, "Pad raw section for section data alignment", \r
"Pad Raw section size is %u", (unsigned) Offset);\r
Size = Size + Offset;\r
}\r
\r
+ //\r
+ // Get the Max alignment of all input file datas\r
+ //\r
+ if (MaxEncounteredAlignment < InputFileAlign [Index]) {\r
+ MaxEncounteredAlignment = InputFileAlign [Index];\r
+ }\r
+\r
//\r
// Now read the contents of the file into the buffer\r
// Buffer must be enough to contain the file content.\r
fclose (InFile);\r
Size += FileSize;\r
}\r
- \r
+\r
+ *MaxAlignment = MaxEncounteredAlignment;\r
+\r
//\r
// Set the actual length of the data.\r
//\r
InputFileName,\r
InputFileAlign,\r
InputFileNum,\r
+ FfsAttrib,\r
FileBuffer,\r
&FileSize,\r
&MaxAlignment,\r
InputFileName,\r
InputFileAlign,\r
InputFileNum,\r
+ FfsAttrib,\r
FileBuffer,\r
&FileSize,\r
&MaxAlignment,\r
--- /dev/null
+/** @file\r
+ Copyright (c) 2015, Linaro Ltd. All rights reserved.<BR>\r
+\r
+ This program and the accompanying materials are licensed and made available\r
+ under the terms and conditions of the BSD License which accompanies this\r
+ distribution. The full text of the license may be found at\r
+ http://opensource.org/licenses/bsd-license.php\r
+\r
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#ifndef __FFS_SECTION_ALIGNMENT_PADDING_GUID_H__\r
+#define __FFS_SECTION_ALIGNMENT_PADDING_GUID_H__\r
+\r
+#define EFI_FFS_SECTION_ALIGNMENT_PADDING_GUID \\r
+ { \\r
+ 0x04132C8D, 0x0A22, 0x4FA8, {0x82, 0x6E, 0x8B, 0xBF, 0xEF, 0xDB, 0x83, 0x6C } \\r
+ }\r
+\r
+#endif\r