/** @file
Source file for the component update driver. It parse the update
configuration file and pass the information to the update driver
so that the driver can perform updates accordingly.
Copyright (c) 2002 - 2010, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions
of the BSD License which accompanies this distribution. The
full text of the license may be found at
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#include "UpdateDriver.h"
/**
Copy one line data from buffer data to the line buffer.
@param Buffer Buffer data.
@param BufferSize Buffer Size.
@param LineBuffer Line buffer to store the found line data.
@param LineSize On input, size of the input line buffer.
On output, size of the actual line buffer.
@retval EFI_BUFFER_TOO_SMALL The size of input line buffer is not enough.
@retval EFI_SUCCESS Copy line data into the line buffer.
**/
)
{
//
// 0x0D indicates a line break. Otherwise there is no line break
//
if (*PtrBuf == 0x0D) {
break;
}
PtrBuf++;
}
//
// The buffer ends without any line break
// or it is the last character of the buffer
//
Length = BufferSize;
//
// Further check if a 0x0A follows. If yes, count 0xA
//
} else {
}
return EFI_BUFFER_TOO_SMALL;
}
return EFI_SUCCESS;
}
/**
Trim Buffer by removing all CR, LF, TAB, and SPACE chars in its head and tail.
@param Buffer On input, buffer data to be trimed.
On output, the trimmed buffer.
@param BufferSize On input, size of original buffer data.
On output, size of the trimmed buffer.
**/
)
{
if (*BufferSize == 0) {
return;
}
//
// Trim the tail first, include CR, LF, TAB, and SPACE.
//
Length = *BufferSize;
break;
}
PtrBuf --;
}
//
// all spaces, a blank line, return directly;
//
*BufferSize = 0;
return;
}
//
// Now skip the heading CR, LF, TAB and SPACE
//
break;
}
PtrBuf++;
}
//
// If no heading CR, LF, TAB or SPACE, directly return
//
*BufferSize = Length;
return;
}
//
// The first Buffer..PtrBuf characters are CR, LF, TAB or SPACE.
// Now move out all these characters.
//
Buffer++;
PtrBuf++;
}
return;
}
/**
Insert new comment item into comment head.
@param Buffer Comment buffer to be added.
@param BufferSize Size of comment buffer.
@param CommentHead Comment Item head entry.
@retval EFI_OUT_OF_RESOURCES No enough memory is allocated.
@retval EFI_SUCCESS New comment item is inserted.
**/
)
{
CommentItem = NULL;
if (CommentItem == NULL) {
return EFI_OUT_OF_RESOURCES;
}
//
// Add a trailing '\0'
//
return EFI_OUT_OF_RESOURCES;
}
return EFI_SUCCESS;
}
/**
Add new section item into Section head.
@param Buffer Section item data buffer.
@param BufferSize Size of section item.
@param SectionHead Section item head entry.
@retval EFI_OUT_OF_RESOURCES No enough memory is allocated.
@retval EFI_SUCCESS Section item is NULL or Section item is added.
**/
)
{
//
// The first character of Buffer is '[', now we want for ']'
//
if (*PtrBuf == ']') {
break;
}
PtrBuf --;
}
//
// Not found. Omit this line
//
return Status;
}
//
// excluding the heading '[' and tailing ']'
//
Buffer + 1,
);
//
// omit this line if the section name is null
//
if (Length == 0) {
return Status;
}
if (SectionItem == NULL) {
return EFI_OUT_OF_RESOURCES;
}
//
// Add a trailing '\0'
//
return EFI_OUT_OF_RESOURCES;
}
//
// excluding the heading '['
//
return EFI_SUCCESS;
}
/**
Add new section entry and entry value into Section head.
@param Buffer Section entry data buffer.
@param BufferSize Size of section entry.
@param SectionHead Section item head entry.
@retval EFI_OUT_OF_RESOURCES No enough memory is allocated.
@retval EFI_SUCCESS Section entry is NULL or Section entry is added.
**/
)
{
//
// First search for '='
//
if (*PtrBuf == '=') {
break;
}
PtrBuf++;
}
//
// Not found. Omit this line
//
return Status;
}
//
// excluding the tailing '='
//
);
//
// Omit this line if the entry name is null
//
if (Length == 0) {
return Status;
}
//
// Omit this line if no section header has been found before
//
if (*SectionHead == NULL) {
return Status;
}
if (SectionItem == NULL) {
return EFI_OUT_OF_RESOURCES;
}
//
// SectionName, add a trailing '\0'
//
return EFI_OUT_OF_RESOURCES;
}
//
// EntryName, add a trailing '\0'
//
return EFI_OUT_OF_RESOURCES;
}
//
// Next search for '#'
//
if (*PtrBuf == '#') {
break;
}
PtrBuf++;
}
);
if (Length > 0) {
//
// EntryValue, add a trailing '\0'
//
return EFI_OUT_OF_RESOURCES;
}
}
return EFI_SUCCESS;
}
/**
Free all comment entry and section entry.
@param Section Section entry list.
@param Comment Comment entry list.
**/
)
{
}
}
}
}
}
}
return;
}
/**
Get section entry value.
@param Section Section entry list.
@param SectionName Section name.
@param EntryName Section entry name.
@param EntryValue Point to the got entry value.
@retval EFI_NOT_FOUND Section is not found.
@retval EFI_SUCCESS Section entry value is got.
**/
)
{
*EntryValue = NULL;
break;
}
}
}
}
return EFI_NOT_FOUND;
}
return EFI_SUCCESS;
}
/**
Convert the dec or hex ascii string to value.
@param Str ascii string to be converted.
@return the converted value.
**/
)
{
Number = 0;
//
// Skip preceeding while spaces
//
while (*Str != '\0') {
if (*Str != 0x20) {
break;
}
Str++;
}
if (*Str == '\0') {
return Number;
}
//
// Find whether the string is prefixed by 0x.
// That is, it should be xtoi or atoi.
//
if (*Str == '0') {
}
}
while (*Str != '\0') {
} else {
break;
}
Str++;
}
return Number;
}
/**
Converts a decimal value to a Null-terminated ascii string.
@param Buffer Pointer to the output buffer for the produced Null-terminated
ASCII string.
@param Value The 64-bit sgned value to convert to a string.
@return The number of ASCII characters in Buffer not including the Null-terminator.
**/
)
{
Count = 0;
if (Value < 0) {
*BufferPtr = '-';
BufferPtr++;
Count++;
}
do {
//
// The first item of TempStr is not occupied. It's kind of flag
//
TempStr++;
Count++;
} while (Value != 0);
//
// Reverse temp string into Buffer.
//
while (TempStr != TempBuffer) {
BufferPtr++;
TempStr --;
}
*BufferPtr = 0;
return Count;
}
/**
Convert the input value to a ascii string,
and concatenates this string to the input string.
@param Str Pointer to a Null-terminated ASCII string.
@param Number The unsgned value to convert to a string.
**/
)
{
while (*Str != '\0') {
Str++;
}
return;
}
/**
Convert the input ascii string into GUID value.
@param Str Ascii GUID string to be converted.
@param Guid Pointer to the converted GUID value.
@retval EFI_OUT_OF_RESOURCES No enough memory is allocated.
@retval EFI_NOT_FOUND The input ascii string is not a valid GUID format string.
@retval EFI_SUCCESS GUID value is got.
**/
)
{
return EFI_OUT_OF_RESOURCES;
}
//
// Data1
//
while (*PtrBuffer != '\0') {
if (*PtrBuffer == '-') {
break;
}
PtrBuffer++;
}
if (*PtrBuffer == '\0') {
return EFI_NOT_FOUND;
}
*PtrBuffer = '\0';
//
// Data2
//
PtrBuffer++;
while (*PtrBuffer != '\0') {
if (*PtrBuffer == '-') {
break;
}
PtrBuffer++;
}
if (*PtrBuffer == '\0') {
return EFI_NOT_FOUND;
}
*PtrBuffer = '\0';
//
// Data3
//
PtrBuffer++;
while (*PtrBuffer != '\0') {
if (*PtrBuffer == '-') {
break;
}
PtrBuffer++;
}
if (*PtrBuffer == '\0') {
return EFI_NOT_FOUND;
}
*PtrBuffer = '\0';
//
// Data4[0..1]
//
PtrBuffer++;
return EFI_NOT_FOUND;
}
PtrBuffer++;
}
//
// skip the '-'
//
PtrBuffer++;
return EFI_NOT_FOUND;
}
//
// Data4[2..7]
//
PtrBuffer++;
return EFI_NOT_FOUND;
}
PtrBuffer++;
}
return EFI_SUCCESS;
}
/**
Pre process config data buffer into Section entry list and Comment entry list.
@param DataBuffer Config raw file buffer.
@param BufferSize Size of raw buffer.
@param SectionHead Pointer to the section entry list.
@param CommentHead Pointer to the comment entry list.
@retval EFI_OUT_OF_RESOURCES No enough memory is allocated.
@retval EFI_SUCCESS Config data buffer is preprocessed.
**/
)
{
*SectionHead = NULL;
*CommentHead = NULL;
return EFI_OUT_OF_RESOURCES;
}
while (CurrentPtr < BufferEnd) {
Source = CurrentPtr;
//
// With the assumption that line length is less than 512
// characters. Otherwise BUFFER_TOO_SMALL will be returned.
//
Status = ProfileGetLine (
);
if (Status == EFI_BUFFER_TOO_SMALL) {
//
// If buffer too small, re-allocate the buffer according
// to the returned LineLength and try again.
//
break;
}
Status = ProfileGetLine (
);
break;
}
} else {
break;
}
}
//
// Line got. Trim the line before processing it.
//
);
//
// Blank line
//
if (LineLength == 0) {
continue;
}
if (PtrLine[0] == '#') {
);
} else if (PtrLine[0] == '[') {
);
} else {
);
}
break;
}
}
//
// Free buffer
//
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.
**/
)
{
SectionHead = NULL;
CommentHead = NULL;
//
// First process the data buffer and get all sections and entries
//
);
return Status;
}
//
// Now get NumOfUpdate
//
(UINT8 *) "Head",
(UINT8 *) "NumOfUpdate",
);
return EFI_NOT_FOUND;
}
if (Num <= 0) {
return EFI_NOT_FOUND;
}
*NumOfUpdates = Num;
if (*UpdateArray == NULL) {
return EFI_OUT_OF_RESOURCES;
}
//
// Get the section name of each update
//
(UINT8 *) "Head",
);
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
//
(UINT8 *) SectionName,
(UINT8 *) "UpdateType",
);
return EFI_NOT_FOUND;
}
return Status;
}
//
// FvBaseAddress
//
(UINT8 *) SectionName,
(UINT8 *) "FvBaseAddress",
);
return EFI_NOT_FOUND;
}
//
// FileBuid
//
(UINT8 *) SectionName,
(UINT8 *) "FileGuid",
);
return EFI_NOT_FOUND;
}
return Status;
}
//
// FaultTolerant
// Default value is FALSE
//
(UINT8 *) SectionName,
(UINT8 *) "FaultTolerant",
);
return Status;
}
}
//
// Length
//
(UINT8 *) SectionName,
(UINT8 *) "Length",
);
return EFI_NOT_FOUND;
}
}
}
//
// Now all configuration data got. Free those temporary buffers
//
return EFI_SUCCESS;
}