Reviewed-by: Liming Gao <liming....@intel.com>

> -----Original Message-----
> From: Feng, YunhuaX <yunhuax.f...@intel.com>
> Sent: Wednesday, February 12, 2020 2:24 PM
> To: devel@edk2.groups.io
> Cc: Gao, Liming <liming....@intel.com>; Feng, Bob C <bob.c.f...@intel.com>
> Subject: [PATCH] [edk2-staging/FceFmmt]BaseTools: Support no UI section FFS
> 
> REF: https://bugzilla.tianocore.org/show_bug.cgi?id=2521
> 
> 1. If FFS file has no UI section, its FILE_GUID will be used as its name.
> FMMT tool -d/-a/-r option can be updated to support such FFS file.
> 2. -v option will print FILE_GUID if no UI section
> 
> Cc: Bob Feng <bob.c.f...@intel.com>
> Cc: Liming Gao <liming....@intel.com>
> Signed-off-by: Yunhua Feng<yunhuax.f...@intel.com>
> ---
>  BaseTools/Source/C/FMMT/FirmwareModuleManagement.c | 22 +++++++--
>  BaseTools/Source/C/FMMT/FmmtLib.c                  | 56 
> ++++++++++++++++++++++
>  2 files changed, 73 insertions(+), 5 deletions(-)
> 
> diff --git a/BaseTools/Source/C/FMMT/FirmwareModuleManagement.c 
> b/BaseTools/Source/C/FMMT/FirmwareModuleManagement.c
> index e4fbb5461f..a786113899 100644
> --- a/BaseTools/Source/C/FMMT/FirmwareModuleManagement.c
> +++ b/BaseTools/Source/C/FMMT/FirmwareModuleManagement.c
> @@ -79,11 +79,11 @@ Usage (
>              Delete the entire FV in an FD binary\n");
> 
>    //
>    // Command Line for Delete file from FV
>    //
> -  fprintf (stdout, "  -d <input-binary-file> <FV-id> <File-Name> [<FV-id> 
> <File-Name> ...] <output-binary-file>\n\
> +  fprintf (stdout, "  -d <input-binary-file> <FV-id> <File-Name|File-Guid> 
> [<FV-id> <File-Name|File-Guid> ...] <output-binary-file>\n\
>              Delete a file (or files) from the firmware volume in an FD 
> binary\n");
> 
>    //
>    // Command Line for Add
>    //
> @@ -91,11 +91,11 @@ Usage (
>              Add a file (or files) to the firmware volume in an FD binary\n");
> 
>    //
>    // Command Line for Replace
>    //
> -  fprintf (stdout, "  -r <input-binary-file> <FV-id> <File-Name> 
> <NewFilePath> [<FV-id> <File-Name> <NewFilePath> ...] <output-binary-
> file>\n\
> +  fprintf (stdout, "  -r <input-binary-file> <FV-id> <File-Name|File-Guid> 
> <NewFilePath> [<FV-id> <File-Name|File-Guid>
> <NewFilePath> ...] <output-binary-file>\n\
>              The replace command combines the functionality of remove and add 
> into a single operation.\n");
> 
>    fprintf (stdout, "\nNote:\n");
>    fprintf (stdout, "  <FV-id> is the sequence of the firmware volume 
> included in the FD image, it both support the sequentially format like
> FV0, FV1 and the FV's file guid value format.\n");
>    return;
> @@ -583,10 +583,11 @@ NeedNewPath(FV_INFORMATION *FvInFd, CHAR8 *FvId, UINT32 
> FileIndex, BOOLEAN IsAdd
>  static UINT32 FindFile(FV_INFORMATION *FvInFd, UINT8 FvLevel, CHAR8 *File, 
> UINT32 *MatchIndex) {
>    UINT32 Index = 0;
>    CHAR16 *UIName;
>    CHAR16 *FfsUIName;
>    UINT32 FileNumber = 0;
> +  EFI_GUID Guid;
> 
>    UIName = (CHAR16 *)malloc(_MAX_PATH);
>    if (NULL == UIName) {
>      return 0;
>    }
> @@ -612,11 +613,22 @@ static UINT32 FindFile(FV_INFORMATION *FvInFd, UINT8 
> FvLevel, CHAR8 *File, UINT3
>      }
> 
>    }
>    free(UIName);
>    free(FfsUIName);
> -
> +  if (FileNumber == 0) {
> +    StringToGuid(File, &Guid);
> +    for (Index = 0; Index <= FvInFd->FfsNumbers; Index++) {
> +      if (CompareGuid (&Guid, &FvInFd->FfsAttuibutes[Index].GuidName) == 0) {
> +        FileNumber += 1;
> +        *MatchIndex = Index;
> +        if (FileNumber > 1) {
> +          break;
> +        }
> +      }
> +    }
> +  }
>    return FileNumber;
>  }
> 
>  /**
>    Search the config file from the path list.
> @@ -1089,11 +1101,11 @@ FmmtImageAdd(
>              goto FAILED;
>          }
>          HasUISection = FALSE;
>          HasUISection = ParseSection(InputFfs);
>          if (!HasUISection) {
> -            printf ("WARNING: The newly add file must have a user interface 
> (UI) section, otherwise it cannot be deleted or replaced. \n");
> +            printf ("WARNING: The newly add file not have a user interface 
> (UI) section. \n");
>          }
>          if (NeedNewPath(FvInFd, FvId, 0, TRUE)) {
>              do {
>                  NewFile = NewFileNode->FileName;
>                  //
> @@ -1845,11 +1857,11 @@ FmmtImageReplace (
>              return EFI_ABORTED;
>          }
>          HasUISection = FALSE;
>          HasUISection = ParseSection(InputFfs);
>          if (!HasUISection) {
> -            printf ("WARNING: The newly replace file must have a user 
> interface (UI) section, otherwise it cannot be deleted or replaced. \n");
> +            printf ("WARNING: The newly replace file not have a user 
> interface (UI) section. \n");
>          }
>          if (FfsFoundFlag && NeedNewPath(FvInFd, FvId, Index, FALSE)) {
>              do {
>                  OldFile = OldFileNode -> FileName;
>                  NewFile = NewFileNode -> FileName;
> diff --git a/BaseTools/Source/C/FMMT/FmmtLib.c 
> b/BaseTools/Source/C/FMMT/FmmtLib.c
> index 78b6f3a21d..685ef634f2 100644
> --- a/BaseTools/Source/C/FMMT/FmmtLib.c
> +++ b/BaseTools/Source/C/FMMT/FmmtLib.c
> @@ -824,10 +824,11 @@ LibParseSection (
>    UINT16              GuidAttr;
>    UINT16              DataOffset;
>    CHAR8               *UIFileName;
>    CHAR8               *ToolInputFileName;
>    CHAR8               *ToolOutputFileName;
> +  BOOLEAN              HasUiSection;
> 
>    DataOffset                 = 0;
>    GuidAttr                   = 0;
>    ParsedLength               = 0;
>    ToolOutputLength           = 0;
> @@ -858,10 +859,11 @@ LibParseSection (
>    ToolInputFileName          = NULL;
>    ToolOutputFileFullName     = NULL;
>    HasDepexSection            = FALSE;
>    EncapDataNeedUpdata        = TRUE;
>    LargeHeaderOffset          = 0;
> +  HasUiSection               = FALSE;
> 
> 
>    while (ParsedLength < BufferLength) {
>      Ptr           = SectionBuffer + ParsedLength;
> 
> @@ -888,10 +890,11 @@ LibParseSection (
>      switch (Type) {
> 
>      case EFI_SECTION_FIRMWARE_VOLUME_IMAGE:
> 
>        EncapDataNeedUpdata = TRUE;
> +      HasUiSection = TRUE;
> 
>        Level ++;
>        NumberOfSections ++;
> 
>        CurrentFv->FfsAttuibutes[*FfsCount].IsLeaf = FALSE;
> @@ -988,10 +991,11 @@ LibParseSection (
>      case EFI_SECTION_COMPRESSION:
>        Level ++;
>        NumberOfSections ++;
> 
>        EncapDataNeedUpdata = TRUE;
> +      HasUiSection = TRUE;
>        //
>        // Put in encapsulate data information.
>        //
>        LocalEncapData = *CurrentFvEncapData;
>        if (LocalEncapData->NextNode != NULL) {
> @@ -1166,10 +1170,11 @@ LibParseSection (
>        // a GUID defined FV section.
>        //
>        Level ++;
>        NumberOfSections++;
>        EncapDataNeedUpdata = TRUE;
> +      HasUiSection = TRUE;
>        //
>        // Put in encapsulate data information.
>        //
>        LocalEncapData = *CurrentFvEncapData;
>        if (LocalEncapData->NextNode != NULL) {
> @@ -1593,10 +1598,11 @@ LibParseSection (
>        memcpy(CurrentFv->FfsAttuibutes[*FfsCount].Depex, Ptr, SectionLength);
>        CurrentFv->FfsAttuibutes[*FfsCount].DepexLen = SectionLength;
>        break;
> 
>      case EFI_SECTION_USER_INTERFACE:
> +      HasUiSection = TRUE;
>        NumberOfSections ++;
>        CurrentFv->FfsAttuibutes[*FfsCount].Level = Level;
> 
>        UiSectionLength = GetLength (((EFI_USER_INTERFACE_SECTION *) 
> Ptr)->CommonHeader.Size);
>      if (UiSectionLength == 0xffffff) {
> @@ -1669,10 +1675,34 @@ LibParseSection (
>    if (ParsedLength < BufferLength) {
>      Error ("FMMT", 0, 0003, "sections do not completely fill the sectioned 
> buffer being parsed", NULL);
>      return EFI_SECTION_ERROR;
>    }
> 
> +  if (ViewFlag && !HasUiSection) {
> +    //
> +    //print FILE FFS GUID name
> +    //
> +    BlankChar = LibConstructBlankChar( CurrentFv->FvLevel * 2);
> +    if (BlankChar == NULL) {
> +      return EFI_OUT_OF_RESOURCES;
> +    }
> +
> +    fprintf(stdout, "%sFile 
> \"%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x\"\n", BlankChar,
> +                        CurrentFile->Name.Data1,
> +                        CurrentFile->Name.Data2,
> +                        CurrentFile->Name.Data3,
> +                        CurrentFile->Name.Data4[0],
> +                        CurrentFile->Name.Data4[1],
> +                        CurrentFile->Name.Data4[2],
> +                        CurrentFile->Name.Data4[3],
> +                        CurrentFile->Name.Data4[4],
> +                        CurrentFile->Name.Data4[5],
> +                        CurrentFile->Name.Data4[6],
> +                        CurrentFile->Name.Data4[7]
> +                        );
> +    free(BlankChar);
> +  }
> 
>    return EFI_SUCCESS;
>  }
> 
>  /**
> @@ -1819,16 +1849,18 @@ LibGetFileInfo (
>    UINT8               GuidBuffer[PRINTED_GUID_BUFFER_SIZE];
>    ENCAP_INFO_DATA     *LocalEncapData;
>    BOOLEAN             EncapDataNeedUpdateFlag;
>    BOOLEAN             IsGeneratedFfs;
>    UINT32              FfsFileHeaderSize;
> +  CHAR8               *BlankChar;
> 
>    Status = EFI_SUCCESS;
> 
>    LocalEncapData  = NULL;
>    EncapDataNeedUpdateFlag = TRUE;
>    IsGeneratedFfs   = FALSE;
> +  BlankChar        = NULL;
> 
>    FfsFileHeaderSize = GetFfsHeaderLength  ((EFI_FFS_FILE_HEADER *) 
> CurrentFile);
>    FileLength        = GetFfsFileLength ((EFI_FFS_FILE_HEADER *) CurrentFile);
> 
>    //
> @@ -1999,10 +2031,34 @@ LibGetFileInfo (
> 
>     if ( CurrentFile->Type == EFI_FV_FILETYPE_RAW){
>        CurrentFv->FfsAttuibutes[*FfsCount].Level = Level;
>        if (!ViewFlag){
>          LibGenFfsFile(CurrentFile, CurrentFv, FvName, Level, FfsCount, 
> ErasePolarity);
> +      } else {
> +        //
> +        // print EFI_FV_FILETYPE_RAW GUID
> +        //
> +        BlankChar = LibConstructBlankChar( CurrentFv->FvLevel * 2);
> +        if (BlankChar == NULL) {
> +          return EFI_OUT_OF_RESOURCES;
> +        }
> +
> +        fprintf(stdout, "%sFile 
> \"%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x\"\n", BlankChar,
> +                        CurrentFile->Name.Data1,
> +                        CurrentFile->Name.Data2,
> +                        CurrentFile->Name.Data3,
> +                        CurrentFile->Name.Data4[0],
> +                        CurrentFile->Name.Data4[1],
> +                        CurrentFile->Name.Data4[2],
> +                        CurrentFile->Name.Data4[3],
> +                        CurrentFile->Name.Data4[4],
> +                        CurrentFile->Name.Data4[5],
> +                        CurrentFile->Name.Data4[6],
> +                        CurrentFile->Name.Data4[7]
> +                        );
> +        free(BlankChar);
> +
>        }
>      } else if( CurrentFile->Type == EFI_FV_FILETYPE_FFS_PAD){
>        //EFI_FV_FILETYPE_FFS_PAD
>      } else {
>      //
> --
> 2.12.2.windows.2


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#54639): https://edk2.groups.io/g/devel/message/54639
Mute This Topic: https://groups.io/mt/71210722/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-

Reply via email to