diff options
author | Haojian Zhuang <haojian.zhuang@linaro.org> | 2018-03-07 22:14:27 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-03-07 22:14:27 +0800 |
commit | c83e5073072544bc9b43eea04f4d3efdd41df2de (patch) | |
tree | 2eb053e13d66c1851008f20b04fa6600cdf96aef | |
parent | 0618f31f22d659cc6f87bd34924461479306d415 (diff) | |
parent | d3cd62f1dc9d7bb9db41d04fa604992843fc0839 (diff) | |
download | OpenPlatformPkg-c83e5073072544bc9b43eea04f4d3efdd41df2de.tar.gz |
Merge pull request #105 from hzhuang1/topic/sn_2
Topic/sn 2
4 files changed, 89 insertions, 10 deletions
diff --git a/Include/Library/UsbSerialNumberLib.h b/Include/Library/UsbSerialNumberLib.h index 3ae594b..0ab4cc7 100644 --- a/Include/Library/UsbSerialNumberLib.h +++ b/Include/Library/UsbSerialNumberLib.h @@ -37,6 +37,12 @@ GenerateUsbSN ( ); EFI_STATUS +AssignUsbSN ( + IN CHAR8 *AsciiCmd, + OUT CHAR16 *UnicodeSN + ); + +EFI_STATUS LoadSNFromBlock ( IN EFI_HANDLE FlashHandle, IN EFI_LBA Lba, diff --git a/Library/UsbSerialNumberLib/UsbSerialNumberLib.c b/Library/UsbSerialNumberLib/UsbSerialNumberLib.c index 2727d5c..550a973 100644 --- a/Library/UsbSerialNumberLib/UsbSerialNumberLib.c +++ b/Library/UsbSerialNumberLib/UsbSerialNumberLib.c @@ -28,6 +28,7 @@ #include <Protocol/DevicePath.h> +#define SERIAL_NUMBER_LEN 16 #define SERIAL_NUMBER_SIZE 17 #define RANDOM_MAX 0x7FFFFFFFFFFFFFFF @@ -105,6 +106,41 @@ GenerateUsbSN ( } EFI_STATUS +AssignUsbSN ( + IN CHAR8 *AsciiCmd, + OUT CHAR16 *UnicodeSN + ) +{ + CHAR8 Data; + UINTN Index; + RANDOM_SERIAL_NUMBER RandomSN; + + if ((AsciiCmd == NULL) || (UnicodeSN == NULL)) { + return EFI_INVALID_PARAMETER; + } + for (Index = 0; Index < SERIAL_NUMBER_LEN; Index++) { + Data = *(AsciiCmd + Index); + if (((Data >= '0') && (Data <= '9')) || + ((Data >= 'A') && (Data <= 'F'))) { + continue; + } + // Always use with upper case + if ((Data >= 'a') && (Data <= 'f')) { + *(AsciiCmd + Index) = Data - 'a' + 'A'; + continue; + } + if (Data == '\0') { + break; + } + return EFI_INVALID_PARAMETER; + } + ZeroMem (&RandomSN, sizeof (RANDOM_SERIAL_NUMBER)); + AsciiStrToUnicodeStr (AsciiCmd, RandomSN.UnicodeSN); + StrCpyS (UnicodeSN, SERIAL_NUMBER_SIZE * sizeof (CHAR16), RandomSN.UnicodeSN); + return EFI_SUCCESS; +} + +EFI_STATUS LoadSNFromBlock ( IN EFI_HANDLE FlashHandle, IN EFI_LBA Lba, @@ -207,6 +243,7 @@ StoreSNToBlock ( CHAR16 UnicodeStr[SERIAL_NUMBER_SIZE]; if (UnicodeSN == NULL) { +DEBUG ((DEBUG_ERROR, "#%a, %d\n", __func__, __LINE__)); return EFI_INVALID_PARAMETER; } Status = gBS->OpenProtocol ( @@ -236,10 +273,12 @@ StoreSNToBlock ( ZeroMem (UnicodeStr, SERIAL_NUMBER_SIZE * sizeof (CHAR16)); UnicodeSPrint (UnicodeStr, SERIAL_NUMBER_SIZE * sizeof (CHAR16), L"%lx", RandomSN->Data); if (StrLen (RandomSN->UnicodeSN) != StrLen (UnicodeStr)) { +DEBUG ((DEBUG_ERROR, "#%a, %d, strlen:%d, %d\n", __func__, __LINE__, StrLen (RandomSN->UnicodeSN), StrLen (UnicodeStr))); Status = EFI_INVALID_PARAMETER; goto Exit; } if (StrnCmp (RandomSN->UnicodeSN, UnicodeStr, StrLen (UnicodeStr)) != 0) { +DEBUG ((DEBUG_ERROR, "#%a, %d, %s, %s\n", __func__, __LINE__, RandomSN->UnicodeSN, UnicodeStr)); Status = EFI_INVALID_PARAMETER; goto Exit; } diff --git a/Platforms/Hisilicon/HiKey/HiKeyFastbootDxe/HiKeyFastbootDxe.c b/Platforms/Hisilicon/HiKey/HiKeyFastbootDxe/HiKeyFastbootDxe.c index a62c094..ee45b99 100644 --- a/Platforms/Hisilicon/HiKey/HiKeyFastbootDxe/HiKeyFastbootDxe.c +++ b/Platforms/Hisilicon/HiKey/HiKeyFastbootDxe/HiKeyFastbootDxe.c @@ -562,15 +562,32 @@ HiKeyFastbootPlatformOemCommand ( {
EFI_STATUS Status;
CHAR16 UnicodeSN[SERIAL_NUMBER_SIZE];
+ UINTN Size;
+ Size = AsciiStrLen ("serialno");
if (AsciiStrCmp (Command, "Demonstrate") == 0) {
DEBUG ((DEBUG_ERROR, "ARM OEM Fastboot command 'Demonstrate' received.\n"));
return EFI_SUCCESS;
- } else if (AsciiStrCmp (Command, "serialno") == 0) {
- Status = GenerateUsbSN (UnicodeSN);
- if (EFI_ERROR (Status)) {
- DEBUG ((DEBUG_ERROR, "Failed to generate USB Serial Number.\n"));
- return Status;
+ } else if (AsciiStrnCmp (Command, "serialno", Size) == 0) {
+ while (*(Command + Size) == ' ') {
+ Size++;
+ }
+ if (AsciiStrnCmp (Command + Size, "set", AsciiStrLen ("set")) == 0) {
+ Size += AsciiStrLen ("set");
+ while (*(Command + Size) == ' ') {
+ Size++;
+ }
+ Status = AssignUsbSN (Command + Size, UnicodeSN);
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_ERROR, "Failed to set USB Serial Number.\n"));
+ return Status;
+ }
+ } else {
+ Status = GenerateUsbSN (UnicodeSN);
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_ERROR, "Failed to generate USB Serial Number.\n"));
+ return Status;
+ }
}
Status = StoreSNToBlock (mFlashHandle, SERIAL_NUMBER_LBA, UnicodeSN);
return Status;
diff --git a/Platforms/Hisilicon/HiKey960/HiKey960FastbootDxe/HiKey960FastbootDxe.c b/Platforms/Hisilicon/HiKey960/HiKey960FastbootDxe/HiKey960FastbootDxe.c index c87040d..355119c 100644 --- a/Platforms/Hisilicon/HiKey960/HiKey960FastbootDxe/HiKey960FastbootDxe.c +++ b/Platforms/Hisilicon/HiKey960/HiKey960FastbootDxe/HiKey960FastbootDxe.c @@ -612,15 +612,32 @@ HiKey960FastbootPlatformOemCommand ( {
EFI_STATUS Status;
CHAR16 UnicodeSN[SERIAL_NUMBER_SIZE];
+ UINTN Size;
+ Size = AsciiStrLen ("serialno");
if (AsciiStrCmp (Command, "Demonstrate") == 0) {
DEBUG ((DEBUG_ERROR, "ARM OEM Fastboot command 'Demonstrate' received.\n"));
return EFI_SUCCESS;
- } else if (AsciiStrCmp (Command, "serialno") == 0) {
- Status = GenerateUsbSN (UnicodeSN);
- if (EFI_ERROR (Status)) {
- DEBUG ((DEBUG_ERROR, "Failed to generate USB Serial Number.\n"));
- return Status;
+ } else if (AsciiStrnCmp (Command, "serialno", Size) == 0) {
+ while (*(Command + Size) == ' ') {
+ Size++;
+ }
+ if (AsciiStrnCmp (Command + Size, "set", AsciiStrLen ("set")) == 0) {
+ Size += AsciiStrLen ("set");
+ while (*(Command + Size) == ' ') {
+ Size++;
+ }
+ Status = AssignUsbSN (Command + Size, UnicodeSN);
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_ERROR, "Failed to set USB Serial Number.\n"));
+ return Status;
+ }
+ } else {
+ Status = GenerateUsbSN (UnicodeSN);
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_ERROR, "Failed to generate USB Serial Number.\n"));
+ return Status;
+ }
}
Status = StoreSNToBlock (mFlashHandle, SERIAL_NUMBER_LBA, UnicodeSN);
return Status;
|