/** Get section entry string value. @param[in] Context INI Config file context. @param[in] SectionName Section name. @param[in] EntryName Section entry name. @param[out] EntryValue Point to the got entry string value. @retval EFI_SUCCESS Section entry string value is got. @retval EFI_NOT_FOUND Section is not found. **/ EFI_STATUS EFIAPI GetStringFromDataFile( IN VOID *Context, IN CHAR8 *SectionName, IN CHAR8 *EntryName, OUT CHAR8 **EntryValue ) { INI_PARSING_LIB_CONTEXT *IniContext; EFI_STATUS Status; if (Context == NULL || SectionName == NULL || EntryName == NULL || EntryValue == NULL) { return EFI_INVALID_PARAMETER; } IniContext = Context; *EntryValue = NULL; Status = UpdateGetProfileString ( IniContext->SectionHead, SectionName, EntryName, EntryValue ); return Status; }
/** Parse Config data file to get the updated data array. @param DataBuffer Config raw file buffer. @param BufferSize Size of raw buffer. @param NumOfUpdates Pointer to the number of update data. @param UpdateArray Pointer to the config of update data. @retval EFI_NOT_FOUND No config data is found. @retval EFI_OUT_OF_RESOURCES No enough memory is allocated. @retval EFI_SUCCESS Parse the config file successfully. **/ EFI_STATUS ParseUpdateDataFile ( IN UINT8 *DataBuffer, IN UINTN BufferSize, IN OUT UINTN *NumOfUpdates, IN OUT UPDATE_CONFIG_DATA **UpdateArray ) { EFI_STATUS Status; CHAR8 *Value; CHAR8 *SectionName; CHAR8 Entry[MAX_LINE_LENGTH]; SECTION_ITEM *SectionHead; COMMENT_LINE *CommentHead; UINTN Num; UINTN Index; EFI_GUID FileGuid; SectionHead = NULL; CommentHead = NULL; // // First process the data buffer and get all sections and entries // Status = PreProcessDataFile ( DataBuffer, BufferSize, &SectionHead, &CommentHead ); if (EFI_ERROR (Status)) { FreeAllList (SectionHead, CommentHead); return Status; } // // Now get NumOfUpdate // Value = NULL; Status = UpdateGetProfileString ( SectionHead, (UINT8 *) "Head", (UINT8 *) "NumOfUpdate", (UINT8 **) &Value ); if (Value == NULL) { FreeAllList (SectionHead, CommentHead); return EFI_NOT_FOUND; } Num = UpdateAtoi((UINT8 *) Value); if (Num <= 0) { FreeAllList (SectionHead, CommentHead); return EFI_NOT_FOUND; } *NumOfUpdates = Num; *UpdateArray = AllocatePool ((sizeof (UPDATE_CONFIG_DATA) * Num)); if (*UpdateArray == NULL) { FreeAllList (SectionHead, CommentHead); return EFI_OUT_OF_RESOURCES; } for ( Index = 0 ; Index < *NumOfUpdates ; Index++) { // // Get the section name of each update // AsciiStrCpyS (Entry, MAX_LINE_LENGTH, "Update"); UpdateStrCatNumber ((UINT8 *) Entry, Index); Value = NULL; Status = UpdateGetProfileString ( SectionHead, (UINT8 *) "Head", (UINT8 *) Entry, (UINT8 **) &Value ); if (Value == NULL) { FreeAllList (SectionHead, CommentHead); return EFI_NOT_FOUND; } // // The section name of this update has been found. // Now looks for all the config data of this update // SectionName = Value; // // UpdateType // Value = NULL; Status = UpdateGetProfileString ( SectionHead, (UINT8 *) SectionName, (UINT8 *) "UpdateType", (UINT8 **) &Value ); if (Value == NULL) { FreeAllList (SectionHead, CommentHead); return EFI_NOT_FOUND; } Num = UpdateAtoi((UINT8 *) Value); if (( Num >= (UINTN) UpdateOperationMaximum)) { FreeAllList (SectionHead, CommentHead); return Status; } (*UpdateArray)[Index].Index = Index; (*UpdateArray)[Index].UpdateType = (UPDATE_OPERATION_TYPE) Num; // // FvBaseAddress // Value = NULL; Status = UpdateGetProfileString ( SectionHead, (UINT8 *) SectionName, (UINT8 *) "FvBaseAddress", (UINT8 **) &Value ); if (Value == NULL) { FreeAllList (SectionHead, CommentHead); return EFI_NOT_FOUND; } Num = AsciiStrHexToUintn ((CONST CHAR8 *) Value); (*UpdateArray)[Index].BaseAddress = (EFI_PHYSICAL_ADDRESS) Num; // // FileBuid // Value = NULL; Status = UpdateGetProfileString ( SectionHead, (UINT8 *) SectionName, (UINT8 *) "FileGuid", (UINT8 **) &Value ); if (Value == NULL) { FreeAllList (SectionHead, CommentHead); return EFI_NOT_FOUND; } Status = UpdateStringToGuid ((UINT8 *) Value, &FileGuid); if (EFI_ERROR (Status)) { FreeAllList (SectionHead, CommentHead); return Status; } CopyMem (&((*UpdateArray)[Index].FileGuid), &FileGuid, sizeof(EFI_GUID)); // // FaultTolerant // Default value is FALSE // Value = NULL; (*UpdateArray)[Index].FaultTolerant = FALSE; Status = UpdateGetProfileString ( SectionHead, (UINT8 *) SectionName, (UINT8 *) "FaultTolerant", (UINT8 **) &Value ); if (EFI_ERROR (Status) && (Status != EFI_NOT_FOUND)) { FreeAllList (SectionHead, CommentHead); return Status; } else if (Value != NULL) { if (AsciiStriCmp ((CONST CHAR8 *) Value, (CONST CHAR8 *) "TRUE") == 0) { (*UpdateArray)[Index].FaultTolerant = TRUE; } else if (AsciiStriCmp ((CONST CHAR8 *) Value, (CONST CHAR8 *) "FALSE") == 0) { (*UpdateArray)[Index].FaultTolerant = FALSE; } } if ((*UpdateArray)[Index].UpdateType == UpdateFvRange) { // // Length // Value = NULL; Status = UpdateGetProfileString ( SectionHead, (UINT8 *) SectionName, (UINT8 *) "Length", (UINT8 **) &Value ); if (Value == NULL) { FreeAllList (SectionHead, CommentHead); return EFI_NOT_FOUND; } Num = AsciiStrHexToUintn ((CONST CHAR8 *) Value); (*UpdateArray)[Index].Length = (UINTN) Num; } } // // Now all configuration data got. Free those temporary buffers // FreeAllList (SectionHead, CommentHead); return EFI_SUCCESS; }