[edk2] [PATCH v1] NetworkPkg/Ip6Dxe: Clean the invalid IPv6 configuration during driver start.
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1448 This patch is to clean the invalid data and continue to start IP6 driver. Cc: Michael Turner Cc: Ye Ting Cc: Fu Siyuan Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Wu Jiaxin Signed-off-by: Michael Turner --- NetworkPkg/Ip6Dxe/Ip6Driver.c | 20 ++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/NetworkPkg/Ip6Dxe/Ip6Driver.c b/NetworkPkg/Ip6Dxe/Ip6Driver.c index 4c607125a6..1bd1c61da8 100644 --- a/NetworkPkg/Ip6Dxe/Ip6Driver.c +++ b/NetworkPkg/Ip6Dxe/Ip6Driver.c @@ -586,11 +586,19 @@ Ip6DriverBindingStart ( Ip6ConfigDataTypeManualAddress, DataItem->DataSize, DataItem->Data.Ptr ); if (EFI_ERROR(Status) && Status != EFI_NOT_READY) { - goto UNINSTALL_PROTOCOL; + // + // Clean the invalid ManualAddress configuration. + // + Status = Ip6Cfg->SetData ( + Ip6Cfg, + Ip6ConfigDataTypeManualAddress, + 0, + NULL + ); } } // // If there is any default gateway address, set it. @@ -602,11 +610,19 @@ Ip6DriverBindingStart ( Ip6ConfigDataTypeGateway, DataItem->DataSize, DataItem->Data.Ptr ); if (EFI_ERROR(Status)) { - goto UNINSTALL_PROTOCOL; + // + // Clean the invalid Gateway configuration. + // + Status = Ip6Cfg->SetData ( + Ip6Cfg, + Ip6ConfigDataTypeGateway, + 0, + NULL + ); } } // // ready to go: start the receiving and timer -- 2.17.1.windows.2 ___ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel
[edk2] [PATCH v1 1/2] MdeModulePkg/Ip4Dxe: Uninstall protocols when error happen in Driver Binding Start.
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1447 This patch is to uninstall Ip4ServiceBindingProtocol and Ip4Config2Protocol when error happen in Driver Binding Start. Cc: Michael Turner Cc: Ye Ting Cc: Fu Siyuan Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Wu Jiaxin Signed-off-by: Michael Turner --- MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Driver.c | 9 ++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Driver.c b/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Driver.c index 0f25581414..87ec968e7b 100644 --- a/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Driver.c +++ b/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Driver.c @@ -1,9 +1,9 @@ /** @file The driver binding and service binding protocol for IP4 driver. -Copyright (c) 2005 - 2018, Intel Corporation. All rights reserved. +Copyright (c) 2005 - 2019, Intel Corporation. All rights reserved. (C) Copyright 2015 Hewlett-Packard Development Company, L.P. 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 @@ -662,14 +662,17 @@ Ip4DriverBindingStart ( mIp4Id = (UINT16)NET_RANDOM (NetRandomInitSeed ()); return Status; UNINSTALL_PROTOCOL: - gBS->UninstallProtocolInterface ( + gBS->UninstallMultipleProtocolInterfaces ( ControllerHandle, , - >ServiceBinding + >ServiceBinding, + , + Ip4Cfg2, + NULL ); FREE_SERVICE: Ip4CleanService (IpSb); FreePool (IpSb); -- 2.17.1.windows.2 ___ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel
[edk2] [PATCH v1 0/2] Uninstall protocols when error happen in Driver Binding Start.
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1447 This patch is to uninstall Ip6ServiceBindingProtocol and Ip6ConfigProtocol when error happen in Driver Binding Start. Cc: Michael Turner Cc: Ye Ting Cc: Fu Siyuan Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Wu Jiaxin Signed-off-by: Michael Turner Jiaxin Wu (2): MdeModulePkg/Ip4Dxe: Uninstall protocols when error happen in DriverBinding Start. NetworkPkg/Ip6Dxe: Uninstall protocols when error happen in DriverBinding Start. MdeModulePkg//Universal/Network/Ip4Dxe/Ip4Driver.c | 9 -- NetworkPkg/Ip6Dxe/Ip6Driver.c | 28 +-- 2 files changed, 25 insertions(+), 12 deletions(-) -- 2.17.1.windows.2 ___ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel
[edk2] [PATCH v1 2/2] NetworkPkg/Ip6Dxe: Uninstall protocols when error happen in Driver Binding Start.
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1447 This patch is to uninstall Ip6ServiceBindingProtocol and Ip6ConfigProtocol when error happen in Driver Binding Start. Cc: Michael Turner Cc: Ye Ting Cc: Fu Siyuan Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Wu Jiaxin Signed-off-by: Michael Turner --- NetworkPkg/Ip6Dxe/Ip6Driver.c | 28 +++- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/NetworkPkg/Ip6Dxe/Ip6Driver.c b/NetworkPkg/Ip6Dxe/Ip6Driver.c index 0bda1687f0..4c607125a6 100644 --- a/NetworkPkg/Ip6Dxe/Ip6Driver.c +++ b/NetworkPkg/Ip6Dxe/Ip6Driver.c @@ -1,9 +1,9 @@ /** @file The driver binding and service binding protocol for IP6 driver. - Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved. + Copyright (c) 2009 - 2019, Intel Corporation. All rights reserved. (C) Copyright 2015 Hewlett-Packard Development Company, L.P. 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 @@ -562,20 +562,20 @@ Ip6DriverBindingStart ( , Ip6Cfg, NULL ); if (EFI_ERROR (Status)) { -goto ON_ERROR; +goto FREE_SERVICE; } // // Read the config data from NV variable again. // The default data can be changed by other drivers. // Status = Ip6ConfigReadConfigData (IpSb->MacString, >Ip6ConfigInstance); if (EFI_ERROR (Status)) { -goto ON_ERROR; +goto UNINSTALL_PROTOCOL; } // // If there is any default manual address, set it. // @@ -586,11 +586,11 @@ Ip6DriverBindingStart ( Ip6ConfigDataTypeManualAddress, DataItem->DataSize, DataItem->Data.Ptr ); if (EFI_ERROR(Status) && Status != EFI_NOT_READY) { - goto ON_ERROR; + goto UNINSTALL_PROTOCOL; } } // // If there is any default gateway address, set it. @@ -602,20 +602,20 @@ Ip6DriverBindingStart ( Ip6ConfigDataTypeGateway, DataItem->DataSize, DataItem->Data.Ptr ); if (EFI_ERROR(Status)) { - goto ON_ERROR; + goto UNINSTALL_PROTOCOL; } } // // ready to go: start the receiving and timer // Status = Ip6ReceiveFrame (Ip6AcceptFrame, IpSb); if (EFI_ERROR (Status)) { -goto ON_ERROR; +goto UNINSTALL_PROTOCOL; } // // The timer expires every 100 (IP6_TIMER_INTERVAL_IN_MS) milliseconds. // @@ -623,11 +623,11 @@ Ip6DriverBindingStart ( IpSb->FasterTimer, TimerPeriodic, TICKS_PER_MS * IP6_TIMER_INTERVAL_IN_MS ); if (EFI_ERROR (Status)) { -goto ON_ERROR; +goto UNINSTALL_PROTOCOL; } // // The timer expires every 1000 (IP6_ONE_SECOND_IN_MS) milliseconds. // @@ -635,21 +635,31 @@ Ip6DriverBindingStart ( IpSb->Timer, TimerPeriodic, TICKS_PER_MS * IP6_ONE_SECOND_IN_MS ); if (EFI_ERROR (Status)) { -goto ON_ERROR; +goto UNINSTALL_PROTOCOL; } // // Initialize the IP6 ID // mIp6Id = NET_RANDOM (NetRandomInitSeed ()); return EFI_SUCCESS; -ON_ERROR: +UNINSTALL_PROTOCOL: + gBS->UninstallMultipleProtocolInterfaces ( + ControllerHandle, + , + >ServiceBinding, + , + Ip6Cfg, + NULL + ); + +FREE_SERVICE: Ip6CleanService (IpSb); FreePool (IpSb); return Status; } -- 2.17.1.windows.2 ___ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel
[edk2] [Patch 0/3] BaseTools: Implement splitquoted function
BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=1509 On some Linux environment, there may be no distutils.util library for python3 that will cause build tool crash. This patch implement distutils.util.split_quoted in BaseTools so that the Basetools will be independent with distutils.util library. Feng, Bob C (3): BaseTools: Implement splitquoted function in Build tool BaseTools: Implement splitquoted function in UPT BaseTools: unit test for splitquoted function BaseTools/Source/Python/AutoGen/UniClassObject.py | 50 ++ BaseTools/Source/Python/UPT/Library/UniClassObject.py | 47 --- BaseTools/Tests/TestStringSplit.py| 38 ++ 3 files changed, 128 insertions(+), 7 deletions(-) create mode 100644 BaseTools/Tests/TestStringSplit.py -- 2.20.1.windows.1 ___ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel
[edk2] [Patch 3/3] BaseTools: unit test for splitquoted function
unit test for splitquoted function Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Bob Feng Cc: Liming Gao --- BaseTools/Tests/TestStringSplit.py | 38 ++ 1 file changed, 38 insertions(+) diff --git a/BaseTools/Tests/TestStringSplit.py b/BaseTools/Tests/TestStringSplit.py new file mode 100644 index 00..f24200ecfc --- /dev/null +++ b/BaseTools/Tests/TestStringSplit.py @@ -0,0 +1,38 @@ +## @file +# +# Copyright (c) 2019, Intel Corporation. All rights reserved. +# 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 +# http://opensource.org/licenses/bsd-license.php +# +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. + +import unittest +from AutoGen.UniClassObject import splitquoted + +class TestStringSplit(unittest.TestCase): +def test_split_string(self): +TestStr1 = """ 'hello "world"' """ +ExpStr1 = ['hello "world"'] +self.assertEqual(ExpStr1, splitquoted(TestStr1)) + +TestStr1 = """ "hello 'world'" """ +ExpStr1 = ["hello 'world'"] +self.assertEqual(ExpStr1, splitquoted(TestStr1)) + +TestStr1 = """ "hello 'world'" 'hello "abcd"' """ +ExpStr1 = ["hello 'world'", 'hello "abcd"'] +self.assertEqual(ExpStr1, splitquoted(TestStr1)) + +TestStr1 = """ "hello 'world'" 'hello "abcd"' \t\n\r\v\f \x64 """ +ExpStr1 = ["hello 'world'", 'hello "abcd"', '\x64'] +self.assertEqual(ExpStr1, splitquoted(TestStr1)) + +TestStr1 = """ "hello 'world'" 'hello "abcd" \t\n\r\v\f \x64' """ +ExpStr1 = ["hello 'world'", 'hello "abcd" \t\n\r\v\f \x64'] +self.assertEqual(ExpStr1, splitquoted(TestStr1)) + +if __name__ == '__main__': +unittest.main() -- 2.20.1.windows.1 ___ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel
[edk2] [Patch 1/3] BaseTools: Implement splitquoted function in Build tool
https://bugzilla.tianocore.org/show_bug.cgi?id=1509 On some Linux environment, there may be no distutils.util library for python3 that will cause build tool crash. This patch implement distutils.util.split_quoted in BaseTools so that the build tool will be independent with distutils.util library. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Bob Feng Cc: Liming Gao --- BaseTools/Source/Python/AutoGen/UniClassObject.py | 50 ++ 1 file changed, 46 insertions(+), 4 deletions(-) diff --git a/BaseTools/Source/Python/AutoGen/UniClassObject.py b/BaseTools/Source/Python/AutoGen/UniClassObject.py index d162387cc5..c4b39d25d4 100644 --- a/BaseTools/Source/Python/AutoGen/UniClassObject.py +++ b/BaseTools/Source/Python/AutoGen/UniClassObject.py @@ -16,11 +16,10 @@ ## # Import Modules # from __future__ import print_function import Common.LongFilePathOs as os, codecs, re -import distutils.util import Common.EdkLogger as EdkLogger from io import BytesIO from Common.BuildToolError import * from Common.StringUtils import GetLineNo from Common.Misc import PathClass @@ -41,11 +40,11 @@ NON_BREAKING_CHAR = u'\uFFF2' CR = u'\u000D' LF = u'\u000A' NULL = u'\u' TAB = u'\t' BACK_SLASH_PLACEHOLDER = u'\u0006' - +WHITESPACE = ' \t\n\r\v\f' gIncludePattern = re.compile("^#include +[\"<]+([^\"< >]+)[>\"]+$", re.MULTILINE | re.UNICODE) ## Convert a unicode string to a Hex list # # Convert a unicode string to a Hex list @@ -216,10 +215,54 @@ def StripComments(Line): CommentPos = Line.find (Comment, CommentPos + 1) else: return Line[:CommentPos].strip() return Line.strip() +# +# This function implement distutils.util.split_quoted in another way. +# +def splitquoted(s): +words = [] +word = [] +InQuoted = False +escaped = False +CurrentQ = "" +s = s.strip() +for ch in s: +if escaped: +# preserve whatever is escaped; +# This char will become part of the current word +word.append(ch) +escaped = False +continue + +if ch in WHITESPACE and not InQuoted: +# unescaped, unquoted whitespace: now +# we definitely have a word delimiter +if "".join(word): +words.append("".join(word)) +word = [] +continue +elif ch == "\\": +escaped = True +if not InQuoted: +continue +else: +# handle singly-quoted string or doubly-quoted string +if ch =='"' or ch == "'": +if not InQuoted: +InQuoted = True +CurrentQ = ch +continue +elif ch == CurrentQ: +InQuoted = False +continue +word.append(ch) +if word: +words.append("".join(word)) +return words + ## UniFileClassObject # # A structure for .uni file definition # class UniFileClassObject(object): @@ -232,16 +275,15 @@ class UniFileClassObject(object): self.OrderedStringListByToken = {} #{ u'LanguageIdentifier' : {Token: StringDefClassObject} } self.IsCompatibleMode = IsCompatibleMode self.IncludePathList = IncludePathList if len(self.FileList) > 0: self.LoadUniFiles(FileList) - # # Get Language definition # def GetLangDef(self, File, Line): -Lang = distutils.util.split_quoted((Line.split(u"//")[0])) +Lang = splitquoted((Line.split(u"//")[0])) if len(Lang) != 3: try: FileIn = UniFileClassObject.OpenUniFile(LongFilePath(File.Path)) except UnicodeError as X: EdkLogger.error("build", FILE_READ_FAILURE, "File read failure: %s" % str(X), ExtraData=File); -- 2.20.1.windows.1 ___ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel
[edk2] [Patch 2/3] BaseTools: Implement splitquoted function in UPT
On some Linux environment, there may be no distutils.util library for python3 that will cause UPT crash. This patch implement distutils.util.split_quoted in BaseTools so that the UPT tool will be independent with distutils.util library. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Bob Feng Cc: Liming Gao --- BaseTools/Source/Python/UPT/Library/UniClassObject.py | 47 --- 1 file changed, 44 insertions(+), 3 deletions(-) diff --git a/BaseTools/Source/Python/UPT/Library/UniClassObject.py b/BaseTools/Source/Python/UPT/Library/UniClassObject.py index bd7804b753..79aa252507 100644 --- a/BaseTools/Source/Python/UPT/Library/UniClassObject.py +++ b/BaseTools/Source/Python/UPT/Library/UniClassObject.py @@ -18,11 +18,10 @@ from __future__ import print_function ## # Import Modules # import os, codecs, re -import distutils.util from Logger import ToolError from Logger import Log as EdkLogger from Logger import StringTable as ST from Library.StringUtils import GetLineNo from Library.Misc import PathClass @@ -36,11 +35,11 @@ from Library.ParserValidate import CheckUTF16FileHeader UNICODE_WIDE_CHAR = u'\\wide' UNICODE_NARROW_CHAR = u'\\narrow' UNICODE_NON_BREAKING_CHAR = u'\\nbr' UNICODE_UNICODE_CR = '\r' UNICODE_UNICODE_LF = '\n' - +WHITESPACE = ' \t\n\r\v\f' NARROW_CHAR = u'\uFFF0' WIDE_CHAR = u'\uFFF1' NON_BREAKING_CHAR = u'\uFFF2' CR = u'\u000D' LF = u'\u000A' @@ -296,11 +295,53 @@ class StringDefClassObject(object): self.StringValue = self.StringValue + '\r\n' + Value else: self.StringValue = Value self.StringValueByteList = UniToHexList(self.StringValue) self.Length = len(self.StringValueByteList) +# +# This function implement distutils.util.split_quoted in another way. +# +def splitquoted(s): +words = [] +word = [] +InQuoted = False +escaped = False +CurrentQ = "" +s = s.strip() +for ch in s: +if escaped: +# preserve whatever is escaped; +# This char will become part of the current word +word.append(ch) +escaped = False +continue +if ch in WHITESPACE and not InQuoted: +# unescaped, unquoted whitespace: now +# we definitely have a word delimiter +if "".join(word): +words.append("".join(word)) +word = [] +continue +elif ch == "\\": +escaped = True +if not InQuoted: +continue +else: +# handle singly-quoted string or doubly-quoted string +if ch =='"' or ch == "'": +if not InQuoted: +InQuoted = True +CurrentQ = ch +continue +elif ch == CurrentQ: +InQuoted = False +continue +word.append(ch) +if word: +words.append("".join(word)) +return words ## UniFileClassObject # # A structure for .uni file definition # class UniFileClassObject(object): @@ -324,11 +365,11 @@ class UniFileClassObject(object): # # Get Language definition # def GetLangDef(self, File, Line): -Lang = distutils.util.split_quoted((Line.split(u"//")[0])) +Lang = splitquoted((Line.split(u"//")[0])) if len(Lang) != 3: try: FileIn = codecs.open(File.Path, mode='rb', encoding='utf_8').readlines() except UnicodeError as Xstr: FileIn = codecs.open(File.Path, mode='rb', encoding='utf_16').readlines() -- 2.20.1.windows.1 ___ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel
Re: [edk2] [MdePkg/BaseLib v1 1/1] MdePkg BaseLib: Add new API CalculateCrc16()
On 2/1/2019 8:25 PM, Gao, Liming wrote: > Ming: > What's usage model of new Crc16()? Can they use the same algorithm in > DebugAgent? It is used in check MAC read from eeprom. I think they cann't use the algorithm in DebugAgent. Thanks. > > Thanks > Liming >> -Original Message- >> From: edk2-devel [mailto:edk2-devel-boun...@lists.01.org] On Behalf Of Ming >> Huang >> Sent: Friday, February 1, 2019 3:12 PM >> To: Ni, Ray ; linaro-u...@lists.linaro.org; >> edk2-devel@lists.01.org; Kinney, Michael D ; >> Gao, Liming >> Cc: huangmin...@huawei.com; Dong, Eric ; >> zhangjinso...@huawei.com; wanghuiqi...@huawei.com; >> wai...@126.com; Zeng, Star ; huangda...@hisilicon.com >> Subject: Re: [edk2] [MdePkg/BaseLib v1 1/1] MdePkg BaseLib: Add new API >> CalculateCrc16() >> >> >> >> On 2/1/2019 2:37 PM, Ni, Ray wrote: >>> There is an CRC16 calculation implementation in >>> SourceLevelDebugPkg/Library/DebugAgent/DebugAgentCommon/DebugAgent.c >>> >>> Does your implementation generate the same CRC16 as above one? >> >> It is not the same with above one. >> >>> -Original Message- From: edk2-devel On Behalf Of Ming Huang Sent: Friday, February 1, 2019 2:02 PM To: linaro-u...@lists.linaro.org; edk2-devel@lists.01.org; Kinney, Michael D ; Gao, Liming Cc: huangmin...@huawei.com; Dong, Eric ; zhangjinso...@huawei.com; Zeng, Star ; wai...@126.com; wanghuiqi...@huawei.com; huangda...@hisilicon.com Subject: [edk2] [MdePkg/BaseLib v1 1/1] MdePkg BaseLib: Add new API CalculateCrc16() CalculateCrc16() bases on the initialized mCrcTable. When CalculateCrc16() is used, mCrcTable16 will take 512Bytes size in the image. When CalculateCrc16() is not used, mCrcTable16 will not be built in the image, and no size impact. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Ming Huang --- MdePkg/Include/Library/BaseLib.h | 20 ++ MdePkg/Library/BaseLib/CheckSum.c | 73 2 files changed, 93 insertions(+) diff --git a/MdePkg/Include/Library/BaseLib.h b/MdePkg/Include/Library/BaseLib.h index 1eb842384ee2..956b971e5c69 100644 --- a/MdePkg/Include/Library/BaseLib.h +++ b/MdePkg/Include/Library/BaseLib.h @@ -4855,6 +4855,26 @@ CalculateCrc32( IN UINTNLength ); +/** + Computes and returns a 16-bit CRC for a data buffer. + CRC16 value bases on CCITT. + + If Buffer is NULL, then ASSERT(). + If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT(). + + @param[in] Buffer A pointer to the buffer on which the 16-bit CRC is to be computed. + @param[in] Length The number of bytes in the buffer Data. + + @retval Crc16The 16-bit CRC was computed for the data buffer. + +**/ +UINT16 +EFIAPI +CalculateCrc16( + IN VOID *Buffer, + IN UINTNLength + ); + // // Base Library CPU Functions // diff --git a/MdePkg/Library/BaseLib/CheckSum.c b/MdePkg/Library/BaseLib/CheckSum.c index 03d49afc5e6c..4e27aebe44bc 100644 --- a/MdePkg/Library/BaseLib/CheckSum.c +++ b/MdePkg/Library/BaseLib/CheckSum.c @@ -630,3 +630,76 @@ CalculateCrc32( return Crc ^ 0x; } + +GLOBAL_REMOVE_IF_UNREFERENCED CONST UINT16 mCrcTable16[256] = { + 0x, 0x1021, 0x2042, 0x3063, 0x4084, 0x50A5, 0x60C6, 0x70E7, + 0x8108, 0x9129, 0xA14A, 0xB16B, 0xC18C, 0xD1AD, 0xE1CE, 0xF1EF, + 0x1231, 0x0210, 0x3273, 0x2252, 0x52B5, 0x4294, 0x72F7, 0x62D6, + 0x9339, 0x8318, 0xB37B, 0xA35A, 0xD3BD, 0xC39C, 0xF3FF, 0xE3DE, + 0x2462, 0x3443, 0x0420, 0x1401, 0x64E6, 0x74C7, 0x44A4, 0x5485, + 0xA56A, 0xB54B, 0x8528, 0x9509, 0xE5EE, 0xF5CF, 0xC5AC, 0xD58D, + 0x3653, 0x2672, 0x1611, 0x0630, 0x76D7, 0x66F6, 0x5695, 0x46B4, + 0xB75B, 0xA77A, 0x9719, 0x8738, 0xF7DF, 0xE7FE, 0xD79D, 0xC7BC, + 0x48C4, 0x58E5, 0x6886, 0x78A7, 0x0840, 0x1861, 0x2802, 0x3823, + 0xC9CC, 0xD9ED, 0xE98E, 0xF9AF, 0x8948, 0x9969, 0xA90A, 0xB92B, + 0x5AF5, 0x4AD4, 0x7AB7, 0x6A96, 0x1A71, 0x0A50, 0x3A33, 0x2A12, + 0xDBFD, 0xCBDC, 0xFBBF, 0xEB9E, 0x9B79, 0x8B58, 0xBB3B, 0xAB1A, + 0x6CA6, 0x7C87, 0x4CE4, 0x5CC5, 0x2C22, 0x3C03, 0x0C60, 0x1C41, + 0xEDAE, 0xFD8F, 0xCDEC, 0xDDCD, 0xAD2A, 0xBD0B, 0x8D68, 0x9D49, + 0x7E97, 0x6EB6, 0x5ED5, 0x4EF4, 0x3E13, 0x2E32, 0x1E51, 0x0E70, + 0xFF9F, 0xEFBE, 0xDFDD, 0xCFFC, 0xBF1B, 0xAF3A, 0x9F59, 0x8F78, + 0x9188, 0x81A9, 0xB1CA, 0xA1EB, 0xD10C, 0xC12D, 0xF14E, 0xE16F, + 0x1080, 0x00A1, 0x30C2, 0x20E3, 0x5004, 0x4025, 0x7046, 0x6067, + 0x83B9, 0x9398, 0xA3FB, 0xB3DA, 0xC33D, 0xD31C, 0xE37F, 0xF35E, + 0x02B1, 0x1290,
Re: [edk2] [MdePkg/BaseLib v1 1/1] MdePkg BaseLib: Add new API CalculateCrc16()
On 2/1/2019 5:56 PM, Ard Biesheuvel wrote: > On Fri, 1 Feb 2019 at 08:11, Ming Huang wrote: >> >> >> >> On 2/1/2019 2:37 PM, Ni, Ray wrote: >>> There is an CRC16 calculation implementation in >>> SourceLevelDebugPkg/Library/DebugAgent/DebugAgentCommon/DebugAgent.c >>> >>> Does your implementation generate the same CRC16 as above one? >> >> It is not the same with above one. >> > > So which polynomial is your CRC-16 implementation based on, and why > does it belong in BaseLib, i.e., what is the relevance for other > BaseLib users for this particular flavour of CRC I don't know which polynomial is base on, this CRC16 value bases on CCITT, I don't familiar with CRC algorithm. This move CRC16 to core patch is suggested by Leif. Thanks. > > Thanks, > Ard. > > >>> -Original Message- From: edk2-devel On Behalf Of Ming Huang Sent: Friday, February 1, 2019 2:02 PM To: linaro-u...@lists.linaro.org; edk2-devel@lists.01.org; Kinney, Michael D ; Gao, Liming Cc: huangmin...@huawei.com; Dong, Eric ; zhangjinso...@huawei.com; Zeng, Star ; wai...@126.com; wanghuiqi...@huawei.com; huangda...@hisilicon.com Subject: [edk2] [MdePkg/BaseLib v1 1/1] MdePkg BaseLib: Add new API CalculateCrc16() CalculateCrc16() bases on the initialized mCrcTable. When CalculateCrc16() is used, mCrcTable16 will take 512Bytes size in the image. When CalculateCrc16() is not used, mCrcTable16 will not be built in the image, and no size impact. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Ming Huang --- MdePkg/Include/Library/BaseLib.h | 20 ++ MdePkg/Library/BaseLib/CheckSum.c | 73 2 files changed, 93 insertions(+) diff --git a/MdePkg/Include/Library/BaseLib.h b/MdePkg/Include/Library/BaseLib.h index 1eb842384ee2..956b971e5c69 100644 --- a/MdePkg/Include/Library/BaseLib.h +++ b/MdePkg/Include/Library/BaseLib.h @@ -4855,6 +4855,26 @@ CalculateCrc32( IN UINTNLength ); +/** + Computes and returns a 16-bit CRC for a data buffer. + CRC16 value bases on CCITT. + + If Buffer is NULL, then ASSERT(). + If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT(). + + @param[in] Buffer A pointer to the buffer on which the 16-bit CRC is to be computed. + @param[in] Length The number of bytes in the buffer Data. + + @retval Crc16The 16-bit CRC was computed for the data buffer. + +**/ +UINT16 +EFIAPI +CalculateCrc16( + IN VOID *Buffer, + IN UINTNLength + ); + // // Base Library CPU Functions // diff --git a/MdePkg/Library/BaseLib/CheckSum.c b/MdePkg/Library/BaseLib/CheckSum.c index 03d49afc5e6c..4e27aebe44bc 100644 --- a/MdePkg/Library/BaseLib/CheckSum.c +++ b/MdePkg/Library/BaseLib/CheckSum.c @@ -630,3 +630,76 @@ CalculateCrc32( return Crc ^ 0x; } + +GLOBAL_REMOVE_IF_UNREFERENCED CONST UINT16 mCrcTable16[256] = { + 0x, 0x1021, 0x2042, 0x3063, 0x4084, 0x50A5, 0x60C6, 0x70E7, + 0x8108, 0x9129, 0xA14A, 0xB16B, 0xC18C, 0xD1AD, 0xE1CE, 0xF1EF, + 0x1231, 0x0210, 0x3273, 0x2252, 0x52B5, 0x4294, 0x72F7, 0x62D6, + 0x9339, 0x8318, 0xB37B, 0xA35A, 0xD3BD, 0xC39C, 0xF3FF, 0xE3DE, + 0x2462, 0x3443, 0x0420, 0x1401, 0x64E6, 0x74C7, 0x44A4, 0x5485, + 0xA56A, 0xB54B, 0x8528, 0x9509, 0xE5EE, 0xF5CF, 0xC5AC, 0xD58D, + 0x3653, 0x2672, 0x1611, 0x0630, 0x76D7, 0x66F6, 0x5695, 0x46B4, + 0xB75B, 0xA77A, 0x9719, 0x8738, 0xF7DF, 0xE7FE, 0xD79D, 0xC7BC, + 0x48C4, 0x58E5, 0x6886, 0x78A7, 0x0840, 0x1861, 0x2802, 0x3823, + 0xC9CC, 0xD9ED, 0xE98E, 0xF9AF, 0x8948, 0x9969, 0xA90A, 0xB92B, + 0x5AF5, 0x4AD4, 0x7AB7, 0x6A96, 0x1A71, 0x0A50, 0x3A33, 0x2A12, + 0xDBFD, 0xCBDC, 0xFBBF, 0xEB9E, 0x9B79, 0x8B58, 0xBB3B, 0xAB1A, + 0x6CA6, 0x7C87, 0x4CE4, 0x5CC5, 0x2C22, 0x3C03, 0x0C60, 0x1C41, + 0xEDAE, 0xFD8F, 0xCDEC, 0xDDCD, 0xAD2A, 0xBD0B, 0x8D68, 0x9D49, + 0x7E97, 0x6EB6, 0x5ED5, 0x4EF4, 0x3E13, 0x2E32, 0x1E51, 0x0E70, + 0xFF9F, 0xEFBE, 0xDFDD, 0xCFFC, 0xBF1B, 0xAF3A, 0x9F59, 0x8F78, + 0x9188, 0x81A9, 0xB1CA, 0xA1EB, 0xD10C, 0xC12D, 0xF14E, 0xE16F, + 0x1080, 0x00A1, 0x30C2, 0x20E3, 0x5004, 0x4025, 0x7046, 0x6067, + 0x83B9, 0x9398, 0xA3FB, 0xB3DA, 0xC33D, 0xD31C, 0xE37F, 0xF35E, + 0x02B1, 0x1290, 0x22F3, 0x32D2, 0x4235, 0x5214, 0x6277, 0x7256, + 0xB5EA, 0xA5CB, 0x95A8, 0x8589, 0xF56E, 0xE54F, 0xD52C, 0xC50D, + 0x34E2, 0x24C3, 0x14A0, 0x0481, 0x7466, 0x6447, 0x5424, 0x4405, + 0xA7DB, 0xB7FA, 0x8799, 0x97B8, 0xE75F, 0xF77E, 0xC71D, 0xD73C, + 0x26D3, 0x36F2, 0x0691, 0x16B0, 0x6657,
[edk2] [patch] MdeModulePkg/ReportStatusCodeLib: Avoid using AllocatePool if possible
From: Max Knutsen REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1114 When report status code with ExtendedData data, and the extended data can fit in the local static buffer, there is no need to use AllocatePool to hold the ExtendedData data. This patch is just to do the enhancement to avoid using AllocatePool. Cc: Jian J Wang Cc: Hao Wu Cc: Michael Turner Cc: Liming Gao Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Dandan Bi --- .../Library/DxeReportStatusCodeLib/ReportStatusCodeLib.c | 9 +++-- .../RuntimeDxeReportStatusCodeLib/ReportStatusCodeLib.c | 9 +++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/MdeModulePkg/Library/DxeReportStatusCodeLib/ReportStatusCodeLib.c b/MdeModulePkg/Library/DxeReportStatusCodeLib/ReportStatusCodeLib.c index b28dc5c3bb..c88be5a1a3 100644 --- a/MdeModulePkg/Library/DxeReportStatusCodeLib/ReportStatusCodeLib.c +++ b/MdeModulePkg/Library/DxeReportStatusCodeLib/ReportStatusCodeLib.c @@ -505,13 +505,18 @@ ReportStatusCodeEx ( // Tpl = gBS->RaiseTPL (TPL_HIGH_LEVEL); gBS->RestoreTPL (Tpl); StatusCodeData = NULL; - if (Tpl <= TPL_NOTIFY) { + if (ExtendedDataSize <= (MAX_EXTENDED_DATA_SIZE - sizeof (EFI_STATUS_CODE_DATA))) { // -// Allocate space for the Status Code Header and its buffer +// Use Buffer instead of allocating if possible. +// +StatusCodeData = (EFI_STATUS_CODE_DATA *)Buffer; + } else if (Tpl <= TPL_NOTIFY){ +// +// If Buffer is not big enough, allocate space for the Status Code Header and its buffer // gBS->AllocatePool (EfiBootServicesData, sizeof (EFI_STATUS_CODE_DATA) + ExtendedDataSize, (VOID **)); } if (StatusCodeData == NULL) { diff --git a/MdeModulePkg/Library/RuntimeDxeReportStatusCodeLib/ReportStatusCodeLib.c b/MdeModulePkg/Library/RuntimeDxeReportStatusCodeLib/ReportStatusCodeLib.c index b73103517a..3380469759 100644 --- a/MdeModulePkg/Library/RuntimeDxeReportStatusCodeLib/ReportStatusCodeLib.c +++ b/MdeModulePkg/Library/RuntimeDxeReportStatusCodeLib/ReportStatusCodeLib.c @@ -635,11 +635,14 @@ ReportStatusCodeEx ( if (mHaveExitedBootServices) { if (sizeof (EFI_STATUS_CODE_DATA) + ExtendedDataSize > MAX_EXTENDED_DATA_SIZE) { return EFI_OUT_OF_RESOURCES; } StatusCodeData = (EFI_STATUS_CODE_DATA *) StatusCodeBuffer; - } else { + } else if (sizeof (EFI_STATUS_CODE_DATA) + ExtendedDataSize > MAX_EXTENDED_DATA_SIZE) { +// +// Only use AllocatePool for larger ExtendedData. +// if (gBS == NULL || gBS->AllocatePool == NULL || gBS->FreePool == NULL) { return EFI_UNSUPPORTED; } // @@ -648,10 +651,12 @@ ReportStatusCodeEx ( StatusCodeData = NULL; gBS->AllocatePool (EfiBootServicesData, sizeof (EFI_STATUS_CODE_DATA) + ExtendedDataSize, (VOID **)); if (StatusCodeData == NULL) { return EFI_OUT_OF_RESOURCES; } + } else { +StatusCodeData = (EFI_STATUS_CODE_DATA *) StatusCodeBuffer; } // // Fill in the extended data header // @@ -678,11 +683,11 @@ ReportStatusCodeEx ( Status = InternalReportStatusCode (Type, Value, Instance, CallerId, StatusCodeData); // // Free the allocated buffer // - if (!mHaveExitedBootServices) { + if (!mHaveExitedBootServices && (StatusCodeData != (EFI_STATUS_CODE_DATA *) StatusCodeBuffer)) { gBS->FreePool (StatusCodeData); } return Status; } -- 2.18.0.windows.1 ___ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel