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

@ -352,7 +352,7 @@
$(OUTPUT_DIR)(+)$(MODULE_NAME).map $(OUTPUT_DIR)(+)$(MODULE_NAME).map
<Command.MSFT, Command.INTEL, Command.CLANGPDB> <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} $(DEBUG_DIR)
$(CP) ${dst} $(BIN_DIR)(+)$(MODULE_NAME_GUID).efi $(CP) ${dst} $(BIN_DIR)(+)$(MODULE_NAME_GUID).efi
-$(CP) $(DEBUG_DIR)(+)*.map $(OUTPUT_DIR) -$(CP) $(DEBUG_DIR)(+)*.map $(OUTPUT_DIR)
@ -362,7 +362,7 @@
$(CP) ${src} $(DEBUG_DIR)(+)$(MODULE_NAME).strip $(CP) ${src} $(DEBUG_DIR)(+)$(MODULE_NAME).strip
$(OBJCOPY) $(OBJCOPY_STRIPFLAG) $(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} $(DEBUG_DIR)
$(CP) ${dst} $(BIN_DIR)(+)$(MODULE_NAME_GUID).efi $(CP) ${dst} $(BIN_DIR)(+)$(MODULE_NAME_GUID).efi
@ -373,7 +373,7 @@
"$(MTOC)" -subsystem $(MODULE_TYPE) $(MTOC_FLAGS) ${src} $(DEBUG_DIR)(+)$(MODULE_NAME).pecoff "$(MTOC)" -subsystem $(MODULE_TYPE) $(MTOC_FLAGS) ${src} $(DEBUG_DIR)(+)$(MODULE_NAME).pecoff
# create symbol file for GDB debug # create symbol file for GDB debug
-$(DSYMUTIL) ${src} -$(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} $(DEBUG_DIR)
$(CP) ${dst} $(BIN_DIR)(+)$(MODULE_NAME_GUID).efi $(CP) ${dst} $(BIN_DIR)(+)$(MODULE_NAME_GUID).efi
-$(CP) $(DEBUG_DIR)(+)*.map $(OUTPUT_DIR) -$(CP) $(DEBUG_DIR)(+)*.map $(OUTPUT_DIR)

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -642,7 +642,7 @@ class ModuleReport(object):
if os.path.isfile(DefaultEFIfile): if os.path.isfile(DefaultEFIfile):
Tempfile = os.path.join(OutputDir, self.ModuleName + "_hash.tmp") Tempfile = os.path.join(OutputDir, self.ModuleName + "_hash.tmp")
# rebase the efi image since its base address may not zero # 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: try:
PopenObject = subprocess.Popen(' '.join(cmd), stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) PopenObject = subprocess.Popen(' '.join(cmd), stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
except Exception as X: except Exception as X:

View File

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