mirror of https://github.com/acidanthera/audk.git
Fix track EDKT213: PCD value size should be specificed when generate const variable for String type, PATCHABLE_IN_MODULE type PCD.
The fixing work is translate the ANSIC string or Unicode string to byte array for PATCHABLE_IN_MODULE PCD. git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@1399 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
parent
6ffd3b0cd2
commit
a3222f6a71
Tools/Source/PcdTools/org/tianocore/pcd/entity
|
@ -828,6 +828,131 @@ public class Token {
|
|||
public String getStringTypeString () {
|
||||
return getDefaultSku().value.substring(2, getDefaultSku().value.length() - 1);
|
||||
}
|
||||
|
||||
/**
|
||||
Judge whether a datum string is byte array.
|
||||
|
||||
@param datum datum string
|
||||
|
||||
@return boolean true - is byte array, false - not byte array
|
||||
**/
|
||||
public static boolean isByteArrayDatum(String datum) {
|
||||
if (datum == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
String trimedStr = datum.trim();
|
||||
|
||||
if (trimedStr.length() == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (trimedStr.startsWith("{") &&
|
||||
trimedStr.endsWith("}")) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
Judge whether a datum string is unicode.
|
||||
|
||||
@param datum datum string
|
||||
|
||||
@return boolean true - is unicode, false - not unicode
|
||||
**/
|
||||
public static boolean isUnicodeDatum(String datum) {
|
||||
if (datum == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
String trimedStr = datum.trim();
|
||||
if (trimedStr.length() == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (trimedStr.startsWith("L") &&
|
||||
trimedStr.charAt(1) == '"' &&
|
||||
trimedStr.endsWith("\"")) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
Judge whether a datum string is ANSCI string.
|
||||
|
||||
@param datum datum string
|
||||
|
||||
@return boolean true - is ANSIC, false - not ANSIC
|
||||
**/
|
||||
public static boolean isAnsciDatum(String datum) {
|
||||
if (datum == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
String trimedStr = datum.trim();
|
||||
|
||||
if (trimedStr.length() == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (datum.startsWith("\"") &&
|
||||
datum.endsWith("\"")) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
Get byte array string for POINTER type Datum.
|
||||
|
||||
@param datum the datum whose type is POINTER
|
||||
|
||||
@return String the byte array string
|
||||
**/
|
||||
public String getByteArrayForPointerDatum(String datum) {
|
||||
String byteArray = "{";
|
||||
|
||||
if (datumType != Token.DATUM_TYPE.POINTER) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (Token.isAnsciDatum(datum)) {
|
||||
String trimedStr = datum.trim();
|
||||
trimedStr = trimedStr.substring(1, trimedStr.length() - 1);
|
||||
char charArray[] = trimedStr.toCharArray();
|
||||
for (int index = 0; index < charArray.length; index++) {
|
||||
byteArray += String.format("0x%02x ", (byte)charArray[index]);
|
||||
if (index != (charArray.length - 1)) {
|
||||
byteArray += ",";
|
||||
}
|
||||
}
|
||||
} else if (Token.isUnicodeDatum(datum)) {
|
||||
String trimedStr = datum.trim();
|
||||
trimedStr = trimedStr.substring(2, trimedStr.length() - 1);
|
||||
for (int index = 0; index < trimedStr.length(); index++) {
|
||||
short unicodeVal = (short)trimedStr.codePointAt(index);
|
||||
byteArray += String.format("0x%02x, 0x%02x",
|
||||
(byte)unicodeVal,
|
||||
(byte)((unicodeVal & 0xFF00) >> 8));
|
||||
if (index != (trimedStr.length() - 1)) {
|
||||
byteArray += " ,";
|
||||
}
|
||||
}
|
||||
} else if (Token.isByteArrayDatum(datum)){
|
||||
return datum;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
||||
byteArray += "}";
|
||||
|
||||
return byteArray;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -327,7 +327,7 @@ public class UsageInstance {
|
|||
}
|
||||
break;
|
||||
case PATCHABLE_IN_MODULE:
|
||||
if (isByteArray) {
|
||||
if (parentToken.datumType == Token.DATUM_TYPE.POINTER) {
|
||||
//
|
||||
// Example autogen string for following generation:
|
||||
// "extern UINT8 _gPcd_BinaryPatch_PcdSampleToken[];"
|
||||
|
@ -342,6 +342,21 @@ public class UsageInstance {
|
|||
Token.GetAutogenDefinedatumTypeString(parentToken.datumType),
|
||||
parentToken.cName,
|
||||
parentToken.cName);
|
||||
//
|
||||
// Example autogen string for following generation:
|
||||
// "#define _PCD_SET_MODE_8_PcdSampleToken(SizeOfBuffer, Buffer) CopyMem (_gPcd_BinaryPatch_PcdSampleToken, (Buffer), (SizeOfBuffer))"
|
||||
//
|
||||
hAutogenStr += String.format("#define _PCD_PATCHABLE_%s_SIZE %d\r\n",
|
||||
parentToken.cName,
|
||||
parentToken.datumSize);
|
||||
hAutogenStr += String.format("#define _PCD_SET_MODE_%s_%s(SizeOfBuffer, Buffer) "+
|
||||
"LibPatchPcdSetPtr (_gPcd_BinaryPatch_%s, (UINTN)_PCD_PATCHABLE_%s_SIZE, "+
|
||||
"(SizeOfBuffer), (Buffer))\r\n",
|
||||
Token.GetAutogenDefinedatumTypeString(parentToken.datumType),
|
||||
parentToken.cName,
|
||||
parentToken.cName,
|
||||
parentToken.cName);
|
||||
|
||||
} else {
|
||||
//
|
||||
// Example autogen string for following generation:
|
||||
|
@ -358,27 +373,6 @@ public class UsageInstance {
|
|||
Token.GetAutogenDefinedatumTypeString(parentToken.datumType),
|
||||
parentToken.cName,
|
||||
parentToken.cName);
|
||||
}
|
||||
|
||||
//
|
||||
// Generate _PCD_SET_MODE_xx macro for using set BinaryPatch value via PcdSet macro
|
||||
//
|
||||
if (parentToken.datumType == Token.DATUM_TYPE.POINTER) {
|
||||
//
|
||||
// Example autogen string for following generation:
|
||||
// "#define _PCD_SET_MODE_8_PcdSampleToken(SizeOfBuffer, Buffer) CopyMem (_gPcd_BinaryPatch_PcdSampleToken, (Buffer), (SizeOfBuffer))"
|
||||
//
|
||||
hAutogenStr += String.format("#define _PCD_PATCHABLE_%s_SIZE %d\r\n",
|
||||
parentToken.cName,
|
||||
parentToken.datumSize);
|
||||
hAutogenStr += String.format("#define _PCD_SET_MODE_%s_%s(SizeOfBuffer, Buffer) "+
|
||||
"LibPatchPcdSetPtr (_gPcd_BinaryPatch_%s, (UINTN)_PCD_PATCHABLE_%s_SIZE, "+
|
||||
"(SizeOfBuffer), (Buffer))\r\n",
|
||||
Token.GetAutogenDefinedatumTypeString(parentToken.datumType),
|
||||
parentToken.cName,
|
||||
parentToken.cName,
|
||||
parentToken.cName);
|
||||
} else {
|
||||
//
|
||||
// Example autogen string for following generation:
|
||||
// "#define _PCD_SET_MODE_8_PcdSampleToken(Value) (_gPcd_BinaryPatch_PcdSampleToken = (Value))"
|
||||
|
@ -390,6 +384,9 @@ public class UsageInstance {
|
|||
}
|
||||
|
||||
if (!isBuildUsedLibrary) {
|
||||
if (parentToken.datumType == Token.DATUM_TYPE.POINTER) {
|
||||
printDatum = parentToken.getByteArrayForPointerDatum(printDatum);
|
||||
}
|
||||
//
|
||||
// Example autogen string for following generation:
|
||||
// "#define _PCD_VALUE_PcdSampleToken 0x111"
|
||||
|
@ -397,7 +394,7 @@ public class UsageInstance {
|
|||
hAutogenStr += String.format("#define _PCD_VALUE_%s %s\r\n",
|
||||
parentToken.cName,
|
||||
printDatum);
|
||||
if (isByteArray) {
|
||||
if (parentToken.datumType == Token.DATUM_TYPE.POINTER) {
|
||||
//
|
||||
// Example autogen string for following generation:
|
||||
// "GLOBAL_REMOVE_IF_UNREFERENCED UINT8 _gPcd_BinaryPatch_PcdSampleToken[] = _PCD_VALUE_PcdSampleToken;"
|
||||
|
|
Loading…
Reference in New Issue