ImageTool: Support XIP configuration

This commit is contained in:
Marvin Häuser 2023-06-11 22:15:52 +02:00 committed by MikhailKrichanov
parent 8957da50bb
commit 4166d3ffd3
16 changed files with 43 additions and 21 deletions

View File

@ -134,8 +134,8 @@
<Command.XCODE>
"$(CC)" $(DEPS_FLAGS) $(CC_FLAGS) -o ${dst} $(INC) ${src}
## Early stages on ARM/AArch64 execute with strict alignment enabled and will crash,
# when compiler generates misaligned access.
## Early stages on ARM/AArch64 execute with strict alignment enabled and will crash,
# when compiler generates misaligned access.
#
[C-Code-File.BASE.AARCH64,C-Code-File.SEC.AARCH64,C-Code-File.PEI_CORE.AARCH64,C-Code-File.PEIM.AARCH64,C-Code-File.BASE.ARM,C-Code-File.SEC.ARM,C-Code-File.PEI_CORE.ARM,C-Code-File.PEIM.ARM]
<InputFile>
@ -352,7 +352,7 @@
$(OUTPUT_DIR)(+)$(MODULE_NAME).map
<Command.MSFT, Command.INTEL, Command.CLANGPDB>
ImageTool GenImage -c PE -t $(MODULE_TYPE) -o ${dst} ${src}
ImageTool GenImage -c PE -x -t $(MODULE_TYPE) -o ${dst} ${src}
$(CP) ${dst} $(DEBUG_DIR)
$(CP) ${dst} $(BIN_DIR)(+)$(MODULE_NAME_GUID).efi
-$(CP) $(DEBUG_DIR)(+)*.map $(OUTPUT_DIR)
@ -362,7 +362,7 @@
$(CP) ${src} $(DEBUG_DIR)(+)$(MODULE_NAME).strip
$(OBJCOPY) $(OBJCOPY_STRIPFLAG) $(DEBUG_DIR)(+)$(MODULE_NAME).strip
ImageTool GenImage -c PE -t $(MODULE_TYPE) -o ${dst} $(DEBUG_DIR)(+)$(MODULE_NAME).strip
ImageTool GenImage -c PE -x -t $(MODULE_TYPE) -o ${dst} $(DEBUG_DIR)(+)$(MODULE_NAME).strip
$(CP) ${dst} $(DEBUG_DIR)
$(CP) ${dst} $(BIN_DIR)(+)$(MODULE_NAME_GUID).efi
@ -373,7 +373,7 @@
"$(MTOC)" -subsystem $(MODULE_TYPE) $(MTOC_FLAGS) ${src} $(DEBUG_DIR)(+)$(MODULE_NAME).pecoff
# create symbol file for GDB debug
-$(DSYMUTIL) ${src}
ImageTool GenImage -c PE -t $(MODULE_TYPE) -o ${dst} $(DEBUG_DIR)(+)$(MODULE_NAME).pecoff
ImageTool GenImage -c PE -x -t $(MODULE_TYPE) -o ${dst} $(DEBUG_DIR)(+)$(MODULE_NAME).pecoff
$(CP) ${dst} $(DEBUG_DIR)
$(CP) ${dst} $(BIN_DIR)(+)$(MODULE_NAME_GUID).efi
-$(CP) $(DEBUG_DIR)(+)*.map $(OUTPUT_DIR)

View File

@ -356,6 +356,7 @@ GenExecutable (
IN const char *FormatName,
IN const char *TypeName,
IN const char *BaseAddress,
IN bool Xip,
IN bool Strip,
IN bool FixedAddress
)
@ -411,6 +412,7 @@ GenExecutable (
BaseAddress != NULL,
NewBaseAddress,
InputFileName,
Xip,
Strip,
FixedAddress
);
@ -435,6 +437,7 @@ int main (int argc, const char *argv[])
const char *FormatName;
const char *TypeName;
const char *BaseAddress;
bool Xip;
bool Strip;
bool FixedAddress;
int ArgIndex;
@ -452,7 +455,7 @@ int main (int argc, const char *argv[])
if (strcmp (argv[1], "GenImage") == 0) {
if (argc < 5) {
fprintf (stderr, "ImageTool: Command arguments are missing\n");
fprintf (stderr, " Usage: ImageTool GenImage [-c Format] [-t ModuleType] [-b BaseAddress] [-s] [-f] -o OutputFile InputFile\n");
fprintf (stderr, " Usage: ImageTool GenImage [-c Format] [-t ModuleType] [-b BaseAddress] [-x] [-s] [-f] -o OutputFile InputFile\n");
raise ();
return -1;
}
@ -462,6 +465,7 @@ int main (int argc, const char *argv[])
FormatName = NULL;
TypeName = NULL;
BaseAddress = NULL;
Xip = false;
Strip = false;
FixedAddress = false;
for (ArgIndex = 2; ArgIndex < argc; ++ArgIndex) {
@ -497,6 +501,8 @@ int main (int argc, const char *argv[])
}
BaseAddress = argv[ArgIndex];
} else if (strcmp (argv[ArgIndex], "-x") == 0) {
Xip = true;
} else if (strcmp (argv[ArgIndex], "-s") == 0) {
Strip = true;
} else if (strcmp (argv[ArgIndex], "-f") == 0) {
@ -527,6 +533,7 @@ int main (int argc, const char *argv[])
FormatName,
TypeName,
BaseAddress,
Xip,
Strip,
FixedAddress
);

View File

@ -152,6 +152,7 @@ void *
ToolImageEmitPe (
image_tool_image_info_t *Image,
uint32_t *FileSize,
bool Xip,
bool Strip
);

View File

@ -94,6 +94,7 @@ ToolImageEmit (
IN bool Relocate,
IN uint64_t BaseAddress,
IN const char *SymbolsPath OPTIONAL,
IN bool Xip,
IN bool Strip,
IN bool FixedAddress
)
@ -158,7 +159,7 @@ ToolImageEmit (
OutputFile = NULL;
if (Format == UefiImageFormatPe) {
OutputFile = ToolImageEmitPe (&ImageInfo, OutputFileSize, Strip);
OutputFile = ToolImageEmitPe (&ImageInfo, OutputFileSize, Xip, Strip);
} else {
assert (false);
}

View File

@ -20,6 +20,7 @@ ToolImageEmit (
IN bool Relocate,
IN uint64_t BaseAddress,
IN const char *SymbolsPath OPTIONAL,
IN bool Xip,
IN bool Strip,
IN bool FixedAddress
);

View File

@ -7,6 +7,7 @@
#include "ImageTool.h"
#include "DynamicBuffer.h"
#include "PeEmitCommon.h"
#if PE_ARCH == 32
@ -644,8 +645,9 @@ ToolImageEmitPeFile (
#define ToolImageEmitPe PE_SUFFIX (ToolImageEmitPe)
void *
ToolImageEmitPe (
image_tool_image_info_t *Image,
uint32_t *FileSize
const image_tool_image_info_t *Image,
uint32_t *FileSize,
bool Xip
)
{
bool Success;
@ -659,8 +661,7 @@ ToolImageEmitPe (
ImageToolBufferInit (&Buffer);
// FIXME: Non-XIP is not well-supported right now.
Success = ToolImageEmitPeFile (&Buffer, Image, true);
Success = ToolImageEmitPeFile (&Buffer, Image, Xip);
if (!Success) {
raise ();
ImageToolBufferFree (&Buffer);

View File

@ -9,6 +9,7 @@ void *
ToolImageEmitPe (
image_tool_image_info_t *Image,
uint32_t *FileSize,
bool Xip,
bool Strip
)
{
@ -20,13 +21,13 @@ ToolImageEmitPe (
case IMAGE_FILE_MACHINE_I386:
case IMAGE_FILE_MACHINE_ARMTHUMB_MIXED:
{
return ToolImageEmitPe32 (Image, FileSize);
return ToolImageEmitPe32 (Image, FileSize, Xip);
}
case IMAGE_FILE_MACHINE_X64:
case IMAGE_FILE_MACHINE_ARM64:
{
return ToolImageEmitPe64 (Image, FileSize);
return ToolImageEmitPe64 (Image, FileSize, Xip);
}
default:

View File

@ -13,13 +13,15 @@
void *
ToolImageEmitPe32 (
const image_tool_image_info_t *Image,
uint32_t *FileSize
uint32_t *FileSize,
bool Xip
);
void *
ToolImageEmitPe64 (
const image_tool_image_info_t *Image,
uint32_t *FileSize
uint32_t *FileSize,
bool Xip
);
#endif // PE_EMIT_COMMON_H

View File

@ -3855,6 +3855,7 @@ Returns:
true,
NewBaseAddress,
NULL,
TRUE,
Strip,
FALSE
);

View File

@ -1456,6 +1456,7 @@ Returns:
true,
NewBaseAddress,
NULL,
TRUE,
FALSE,
TRUE
);

View File

@ -95,6 +95,7 @@ class DataSection (DataSectionClassObject):
GenFdsGlobalVariable.GenerateFirmwareImage(
StrippedFile,
GenFdsGlobalVariable.MacroExtend(self.SectFileName, Dict),
Xip=True,
Strip=True,
IsMakefile = IsMakefile
)

View File

@ -290,6 +290,7 @@ class EfiSection (EfiSectionClassObject):
GenFdsGlobalVariable.GenerateFirmwareImage(
StrippedFile,
File,
Xip=True,
Strip=True,
IsMakefile = IsMakefile
)

View File

@ -787,6 +787,7 @@ class FfsInfStatement(FfsInfStatementClassObject):
GenFdsGlobalVariable.GenerateFirmwareImage(
StrippedFile,
File,
Xip=True,
Strip=True,
IsMakefile=IsMakefile
)
@ -821,6 +822,7 @@ class FfsInfStatement(FfsInfStatementClassObject):
GenFdsGlobalVariable.GenerateFirmwareImage(
StrippedFile,
GenSecInputFile,
Xip=True,
Strip=True,
IsMakefile=IsMakefile
)

View File

@ -607,7 +607,7 @@ class GenFdsGlobalVariable:
GenFdsGlobalVariable.CallExternalTool(Cmd, "Failed to generate FV")
@staticmethod
def GenerateFirmwareImage(Output, Input, Format="Auto", Strip=False, IsMakefile=False):
def GenerateFirmwareImage(Output, Input, Format="Auto", Xip=False, Strip=False, IsMakefile=False):
if not GenFdsGlobalVariable.NeedsUpdate(Output, Input) and not IsMakefile:
return
GenFdsGlobalVariable.DebugLogger(EdkLogger.DEBUG_5, "%s needs update because of newer %s" % (Output, Input))
@ -615,6 +615,8 @@ class GenFdsGlobalVariable:
Cmd = ["ImageTool GenImage"]
if Format != "Auto":
Cmd += ("-c", Format)
if Xip:
Cmd.append("-x")
if Strip:
Cmd.append("-s")
Cmd += ("-o", Output, Input)

View File

@ -642,7 +642,7 @@ class ModuleReport(object):
if os.path.isfile(DefaultEFIfile):
Tempfile = os.path.join(OutputDir, self.ModuleName + "_hash.tmp")
# rebase the efi image since its base address may not zero
cmd = ["ImageTool GenImage -b 0 -o", Tempfile, DefaultEFIfile]
cmd = ["ImageTool GenImage -x -b 0 -o", Tempfile, DefaultEFIfile]
try:
PopenObject = subprocess.Popen(' '.join(cmd), stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
except Exception as X:

View File

@ -1524,16 +1524,16 @@ class Build():
#
# Update Image to new BaseAddress by ImageTool tool
#
LaunchCommand(["ImageTool", "GenImage", "-b", str(BaseAddress), "-o", ModuleOutputImage, ModuleOutputImage], ModuleInfo.OutputDir)
LaunchCommand(["ImageTool", "GenImage", "-b", str(BaseAddress), "-o", ModuleOutputImage, ModuleOutputImage], ModuleInfo.DebugDir)
LaunchCommand(["ImageTool", "GenImage", "-x", "-b", str(BaseAddress), "-o", ModuleOutputImage, ModuleOutputImage], ModuleInfo.OutputDir)
LaunchCommand(["ImageTool", "GenImage", "-x", "-b", str(BaseAddress), "-o", ModuleOutputImage, ModuleOutputImage], ModuleInfo.DebugDir)
## for SMM module in SMRAM, the SMRAM will be allocated from base to top.
else:
BaseAddress = AlignUp(BaseAddress, ModuleInfo.Image.SectionAlignment)
#
# Set new address to the section header only for SMM driver.
#
LaunchCommand(["ImageTool", "GenImage", "-f -b", str(BaseAddress), "-o", ModuleOutputImage, ModuleOutputImage], ModuleInfo.OutputDir)
LaunchCommand(["ImageTool", "GenImage", "-f -b", str(BaseAddress), "-o", ModuleOutputImage, ModuleOutputImage], ModuleInfo.DebugDir)
LaunchCommand(["ImageTool", "GenImage", "-x", "-f -b", str(BaseAddress), "-o", ModuleOutputImage, ModuleOutputImage], ModuleInfo.OutputDir)
LaunchCommand(["ImageTool", "GenImage", "-x", "-f -b", str(BaseAddress), "-o", ModuleOutputImage, ModuleOutputImage], ModuleInfo.DebugDir)
#
# Collect function address from Map file
#