From 388127509abe978ab72cc379777302719cd53541 Mon Sep 17 00:00:00 2001 From: "Aaron Pop (from Dev Box)" Date: Thu, 17 Oct 2024 10:50:29 -0700 Subject: [PATCH 1/2] enable fdf parser to deal with FILE RAW = { SECTION COMPRESS { SECTION RAW statement --- edk2toollib/uefi/edk2/parsers/fdf_parser.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/edk2toollib/uefi/edk2/parsers/fdf_parser.py b/edk2toollib/uefi/edk2/parsers/fdf_parser.py index c78ea072..90075fa3 100644 --- a/edk2toollib/uefi/edk2/parsers/fdf_parser.py +++ b/edk2toollib/uefi/edk2/parsers/fdf_parser.py @@ -180,7 +180,9 @@ def ParseFile(self, filepath: str) -> None: self.FVs[section]["Files"][currentName][sectionType] = {} # TODO support guided sections # ex: SECTION UI = "GenericGopDriver" - elif sline.upper().startswith("SECTION"): # get the section + elif ( + sline.upper().startswith("SECTION") and sline.upper().count("=") > 0 + ): # get the section section_def = sline[7:].strip().split("=", 1) sectionType = section_def[0].strip() # UI in this example sectionValue = section_def[1].strip() From 8ca04802e723f784213b8b723a2bc869245b8e18 Mon Sep 17 00:00:00 2001 From: "Aaron Pop (from Dev Box)" Date: Thu, 17 Oct 2024 14:27:24 -0700 Subject: [PATCH 2/2] Added Unit test for different fdf sections --- tests.unit/parsers/test_fdf_parser.py | 78 +++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) diff --git a/tests.unit/parsers/test_fdf_parser.py b/tests.unit/parsers/test_fdf_parser.py index 178a321c..4b4436ed 100644 --- a/tests.unit/parsers/test_fdf_parser.py +++ b/tests.unit/parsers/test_fdf_parser.py @@ -101,3 +101,81 @@ def test_section_guided(): assert ( "bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb" in parser.FVs["MAINFV"]["Files"]["aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa"] ) + + +def test_file_raw_section_statements(): + """Check common file type statements from an FDF file""" + + SAMPLE_FDF_FILE1 = textwrap.dedent("""\ + [FV.MAINFV] + FILEFILE RAW = aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa { + SECTION COMPRESS { + SECTION RAW = $(OUTPUT_DIRECTORY)/$(TARGET)_$(TOOL_CHAIN_TAG)/FV/bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb.bin + } + } + """) + SAMPLE_FDF_FILE2 = textwrap.dedent("""\ + [FV.MAINFV] + FILEFILE RAW = aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa { + SECTION RAW = $(OUTPUT_DIRECTORY)/$(TARGET)_$(TOOL_CHAIN_TAG)/FV/something.bin + SECTION PE32 = $(OUTPUT_DIRECTORY)/$(TARGET)_$(TOOL_CHAIN_TAG>/FV/Exec.efi + } + """) + SAMPLE_FDF_FILE3 = textwrap.dedent("""\ + [FV.MAINFV] + FILEFILE RAW = aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa { + SECTION COMPRESS { + SECTION RAW = binary.bin + SECTION UI = a_ui.bin + SECTION PE32 = some_efi_file.efi + SECTION TE = some_te.te + } + } + """) + try: + with tempfile.NamedTemporaryFile(mode="w", encoding="utf-8", delete=False) as f: + f.write(SAMPLE_FDF_FILE1) + fdf_path = f.name + + parser = FdfParser() + parser.ParseFile(fdf_path) + finally: + os.remove(fdf_path) + + assert ( + "$(OUTPUT_DIRECTORY)/$(TARGET)_$(TOOL_CHAIN_TAG)/FV/bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb.bin" + in parser.FVs["MAINFV"]["Files"]["aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa"]["RAW"] + ) + + try: + with tempfile.NamedTemporaryFile(mode="w", encoding="utf-8", delete=False) as f: + f.write(SAMPLE_FDF_FILE2) + fdf_path = f.name + + parser = FdfParser() + parser.ParseFile(fdf_path) + finally: + os.remove(fdf_path) + assert ( + "$(OUTPUT_DIRECTORY)/$(TARGET)_$(TOOL_CHAIN_TAG)/FV/something.bin" + in parser.FVs["MAINFV"]["Files"]["aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa"]["RAW"] + ) + assert ( + "$(OUTPUT_DIRECTORY)/$(TARGET)_$(TOOL_CHAIN_TAG>/FV/Exec.efi" + in parser.FVs["MAINFV"]["Files"]["aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa"]["PE32"] + ) + + try: + with tempfile.NamedTemporaryFile(mode="w", encoding="utf-8", delete=False) as f: + f.write(SAMPLE_FDF_FILE3) + fdf_path = f.name + + parser = FdfParser() + parser.ParseFile(fdf_path) + finally: + os.remove(fdf_path) + + assert "binary.bin" in parser.FVs["MAINFV"]["Files"]["aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa"]["RAW"] + assert "a_ui.bin" in parser.FVs["MAINFV"]["Files"]["aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa"]["UI"] + assert "some_efi_file.efi" in parser.FVs["MAINFV"]["Files"]["aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa"]["PE32"] + assert "some_te.te" in parser.FVs["MAINFV"]["Files"]["aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa"]["TE"]