From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by mx.groups.io with SMTP id smtpd.web11.522.1653631161049145682 for ; Thu, 26 May 2022 22:59:21 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="unable to parse pub key" header.i=@intel.com header.s=intel header.b=CZ/MpIk5; spf=pass (domain: intel.com, ip: 192.55.52.151, mailfrom: guo.dong@intel.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1653631161; x=1685167161; h=from:to:cc:subject:date:message-id:references: in-reply-to:content-transfer-encoding:mime-version; bh=26sq6KGMfo9NL6U0C5/su2Klp6Xl6fxou10W1Iu25l0=; b=CZ/MpIk5GL4eoKJq57J7LyRVaHtTPyjIF9xzs601NVC6bv+tKFmKt9ci s15h4QRNIwgDMDuYe5dtsCfzmfUH0ZJvtGBSozllE/rUVYTCRMvxY0Lof WnxoWC4ZRLwthZpgIpDPmNcZ8UzZCXqlsUtF2N9/F6J/Q+7DtBA4/JIwN /Za2cyBQgvYTcejp6c7VAM9Y5k2Kg7CqckPFbLNcISvWeudbk9g2twDqb GKnK475rODNgTj0ZceNPSMpweVf3+10g0FV9WzH9APkbTQ+w7kIqmddp5 o71VhqJ2jzeR9wUxTiA81ONmMX5KGQLzXxEt1MVuqqKIxF0b4kdzmNFaN A==; X-IronPort-AV: E=McAfee;i="6400,9594,10359"; a="254884689" X-IronPort-AV: E=Sophos;i="5.91,254,1647327600"; d="scan'208";a="254884689" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 May 2022 22:59:20 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.91,254,1647327600"; d="scan'208";a="603671672" Received: from fmsmsx604.amr.corp.intel.com ([10.18.126.84]) by orsmga008.jf.intel.com with ESMTP; 26 May 2022 22:59:20 -0700 Received: from fmsmsx611.amr.corp.intel.com (10.18.126.91) by fmsmsx604.amr.corp.intel.com (10.18.126.84) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.27; Thu, 26 May 2022 22:59:19 -0700 Received: from fmsmsx612.amr.corp.intel.com (10.18.126.92) by fmsmsx611.amr.corp.intel.com (10.18.126.91) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.27; Thu, 26 May 2022 22:59:19 -0700 Received: from fmsedg602.ED.cps.intel.com (10.1.192.136) by fmsmsx612.amr.corp.intel.com (10.18.126.92) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.27 via Frontend Transport; Thu, 26 May 2022 22:59:19 -0700 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (104.47.55.100) by edgegateway.intel.com (192.55.55.71) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2308.27; Thu, 26 May 2022 22:59:19 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=YWTYnR3D9LLtvurSpfORzeAkmmzx9MviVX/hpaDvx7vHfNXjfLZJOaYZMJtg7pOX9tT5nUMAoOjMU3BpwHpAUwuiBX9FVnHTjhhnKItpEszJtgJOuef/3qkaU8Ov3H5RNKkHvsXXhb6g+0ov1A7woDcGLuwxyjMjjQpJ+T/ypzRmf8uh7OQ+tolLqtGzMkOQzxWG8XzHqI+yA4E1pY8OYA+I3Yr82YySWZRAn6HKiBWGHTaCOoooUh1a0AVa4m3cekzSn02TPxLiYBd9eXvmmvn58W4/iG9KRuU1RdT4znvUs5MX/Oq0wzsgH8oHWMEJ9SvlnJxZ3gb+zIsgjo8zJQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=AV4HzbxNYdYOvqjfh7BaG5nahPKvVb0xgzw+LKJn6hY=; b=XrptZy6nO6ksfWb8W3nXwhGdsIH04BkDJcdmgm3j5E2RLo7VBtUutFECrmj2s64H4x79wFXjz8qUiBi6bkMSreB1qZCiKG7bwjEzic1ULdXooHJaskuYVSlWA9Dhnv0c3geP7LKr8vjxH4g2dmfEXNHbM34q+NXn4nMyx/rCaLyKeJUz/lWUE88dNp0g0ypz5LcmBDi0RmO4q4pYYgS2qSSlGrd4rNZLERF9AEzv4OkIVRYy7GmZOh2Vd9q3NdYu5r4G3wUp0XfREfNrexKKpeleTKAbS2FPzlzFFraD+jKQQGX/Vq4DkQxUImesoF/1qw1X8Wn1CmdX/HkkdjlXiA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none Received: from CY5PR11MB6260.namprd11.prod.outlook.com (2603:10b6:930:23::16) by DM5PR11MB1769.namprd11.prod.outlook.com (2603:10b6:3:10a::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5293.13; Fri, 27 May 2022 05:59:17 +0000 Received: from CY5PR11MB6260.namprd11.prod.outlook.com ([fe80::5b4:6917:c874:80b1]) by CY5PR11MB6260.namprd11.prod.outlook.com ([fe80::5b4:6917:c874:80b1%9]) with mapi id 15.20.5293.015; Fri, 27 May 2022 05:59:17 +0000 From: "Guo Dong" To: "devel@edk2.groups.io" , "benjamin.doron00@gmail.com" CC: "Ni, Ray" , Maurice Ma , "You, Benjamin" , "Rhodes, Sean" Subject: Re: [edk2-devel] [PATCH v2] UefiPayloadPkg: Add support for logging to CBMEM console Thread-Topic: [edk2-devel] [PATCH v2] UefiPayloadPkg: Add support for logging to CBMEM console Thread-Index: AQHYbgx6niUmLQ6+pESw9Y8nF62sY60yQBtw Date: Fri, 27 May 2022 05:59:17 +0000 Message-ID: References: <20220522184708.1015315-1-benjamin.doron00@gmail.com> In-Reply-To: <20220522184708.1015315-1-benjamin.doron00@gmail.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: dlp-product: dlpe-windows dlp-reaction: no-action dlp-version: 11.6.500.17 authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=intel.com; x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: bfc46c9c-2a11-444a-7b4a-08da3fa608cb x-ms-traffictypediagnostic: DM5PR11MB1769:EE_ x-ld-processed: 46c98d88-e344-4ed4-8496-4ed7712e255d,ExtAddr x-microsoft-antispam-prvs: x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: qoez+tV2/qlTlZ7B3i3XlmQxRAF2wQVCzNWCO5/fpQjGvEsorKG6PiNedXEZWS9hfVuQH/sW7ex/2Ng34+yfZ5rCTgvPeAZSQ/o8rAyPzwVTp8SH4TH8regwlUrkW6mM5E20vWCCN0Z8tjBKtaqOrS6rTW4ZHMrkqF9W4Tn8HbxBTcEwpBcjTBOSNmlOU1GR/mJT/gP0XYODWr+d3+v9UsC2IRt9gIgPt9aKs5/4uizcCGzrp0nvyyHC2hvRMvsXSQyKo4O2ZxTtTIHn05Mk/ZuqwmPl9c15Tk+xKS2wWbJ9SYUJ8iHcUTizLVF91zGCFOV7dcoQEo/Zcy0bWE2LM13RL/Rjff8hDN/5K21ubxDFpmIrJdaYkwRrXtF3GykSgIwe+MwiUA9ogEG1FGtMVPWs4QYBWx4HYqI5GT1RBLTEU2hpTLrBFnHto5j29Op4leDPXjM/RAyqFunyWJMoEs+nfiyyDVWg1CEPdNBhVrEKmowFY0na2kJ7XltLPgeeIWP8SEJEclNTgD/4RupP1ReauwF+IA3PUnEOBjDZO4Pg6gYIrM0qpiSDrfigU2kC+SmS6uS2j6lvDnXfiU6EngvFfHhBwSTgKf0ksl8BQm19mOynbfq/jSLw3TKrqFGTaOd7uIfbKDrIVLnjmWsoQ7bUt83zVk5gJvja6an/MKC8v8hnMGojImIpsB0ZUbh3v6SmdhhVXw+yv2Uh/MY+hNAQTWMnyIpkTFGSO5az067dwXwinXYin20o8+hOXkxRzfmjeCYpw406dNi8/xrcmBICC+FHPHF1RqnAghDH354BAoXpR/dnfpZvCR38amCY+AnvhOTnMtCpN+FG2OQIvA== x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:CY5PR11MB6260.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230001)(366004)(83380400001)(30864003)(9686003)(6506007)(316002)(76116006)(8936002)(33656002)(71200400001)(82960400001)(26005)(508600001)(122000001)(54906003)(7696005)(110136005)(53546011)(38070700005)(8676002)(4326008)(38100700002)(186003)(52536014)(64756008)(66446008)(86362001)(5660300002)(66556008)(66476007)(2906002)(66946007)(55016003)(966005);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?ybScTOqATnAgCheP0zuD2R03jQFdo1PYlykwColUy7rbWKF0yTKQkXmn0o3L?= =?us-ascii?Q?V0VMzcYOUMH4zDcuhanBFASObaDfFTyfY0yAEnvbY8x+GQCgQUC6F5ZtZUys?= =?us-ascii?Q?26wNY9rSFxFn71isK+5ICkT45j8UN3jfoCwxF/6wrcwLYfQ7Y3Cgxi73Ft1w?= =?us-ascii?Q?wkcGRyfpOEvYZNnilCIGnJe2J3yTJ40/RgUMPJAMX1ptfKDUQ+9gOp9husWU?= =?us-ascii?Q?iM4k4WT8o7ljJeKBYDP2MSV/rri9dX2sD+7MMo6/MzhS65Rpz57qTgUhJyoK?= =?us-ascii?Q?kA7WG+3erqv7LurneKvHP7QfMEU66ocYf5zibB0tg8kjVgWFVjXUidfgm1Tf?= =?us-ascii?Q?VWhkTSZp8wEeuiv7X36REOSQ/avDJhR/SJZN8ohLbBfC9NgncJ0U87vQ330A?= =?us-ascii?Q?c2e3Mk9pwCAAOfr1jV4lQRWKvWAaz4rUVIH2y4TI+IHbo/AGVQE62BfGAizn?= =?us-ascii?Q?X76KOKaP+RIR1C3rqQVkp4bTM3s4xdcukj/6MgsEC6NW8QymcyH2/dmJ0RWI?= =?us-ascii?Q?K4qGGDCPx68Fmv+dL0rOX8OtgjqoNb0/gSejTE/cDATTWZOzlzig0NXo/uco?= =?us-ascii?Q?XTGmH59z2t3r2sswgsVJV85h0YwNy7fH1iLtapb+GyfDitoTT1jQPi1nUHBr?= =?us-ascii?Q?POQ1WBMGA/gX3MDM4Xbj4FYU3Eu8g/BN5G7527hcUM0czVNe/f5cl4KvOsyV?= =?us-ascii?Q?SKDZauxf44B3rAd4UfER67mkMOauUukrMhNbC2QXbTMRdBp4RYrxa9XIkvlG?= =?us-ascii?Q?jpcB6pEQTboBtMPm/d4/Lt8VYLI0Db3GKuSJimFIW530qi9mbXy1pO5NmuOX?= =?us-ascii?Q?kYbkUaiUH3d8fhQgTHi0u40Q3xn3Kzhv8/6qw4AR7F91+ZqMFvHsPUm6iILD?= =?us-ascii?Q?kg2EO4CMMZAQkswSYZ0i06yuYnGbfLtpHuKdhHNc/7hhMdUDDGBHGkw8MOHK?= =?us-ascii?Q?p0b+z6oaEw+RhnABeKCl1JSkBasAxWIPDsot+ae7iHneWff3DudQ/AbxLO9T?= =?us-ascii?Q?eV6hCnZxfTD0muB1CherYzoGTr6gsECgOOwuSlq1BFB3pTadgsAm1f6sgR+E?= =?us-ascii?Q?d4loKT80MDpwOJ9b/ht3Vu8B6wXtsIG9PRXZ0s2Tt16mUP/XCzyrH9xXGwqO?= =?us-ascii?Q?aTr3x35z0Hxcvj66haLsrbphpqo3JtvSBhNKrGR6TmHZnXXJwE5S9hb6QNfK?= =?us-ascii?Q?3sg1LAyBVtdm3Ue9YNZzMUuV/FZjIo30A2bIsriKeTHF/GLj383PKqSALIWj?= =?us-ascii?Q?isd8yPZoN3SXD74vaG+UZ2yEh1sgVtPdT2M2I2to33ai6M6EbdpBKAi+mc4x?= =?us-ascii?Q?NdoovNeR/KvCgQ1hsEL0k+kIffig67AvCuZr9uBZH6Phpv78ALIEfl7gw8xf?= =?us-ascii?Q?s1J83kvhFwvYqpoW5Nlbxf25dCS5JtpX30ro2GE94JAtBuUMhLhWy54Cwp4c?= =?us-ascii?Q?4m1ZCE0AZQWrl7WC7FfWwiIFRpsmC+UKcHlccVDG9+laPCnn/tvDq2ebekII?= =?us-ascii?Q?JVw7+SBImTytRvAphPCU/LDfDBGR5ZhC5VFXvjBsTwdsCeN+VMoXClsGDPdj?= =?us-ascii?Q?PXIGOb0RTvcmerbcFRWsqj5LOdTJValxZXeKRQNvPfs6nSh4nESjNZrTcM38?= =?us-ascii?Q?cfoIjFOaIwPhQt85ETJdVeqdQBlg6n6YSg28H6SJnavaCS3ofxBsZBhYhwBu?= =?us-ascii?Q?oGu+cPwm0VnURu6i0lr87RffSnP9o7zS5xDXCqxTq3DCNlJ3CAN61J9m+ler?= =?us-ascii?Q?jBjHVRMmuA=3D=3D?= MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: CY5PR11MB6260.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: bfc46c9c-2a11-444a-7b4a-08da3fa608cb X-MS-Exchange-CrossTenant-originalarrivaltime: 27 May 2022 05:59:17.0863 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: Ob2B4MxXI+kQFg0Scw8oQeiHD8Gh14hapQ2EIBnPZ/7aCaDh5reVup1vc1Tl2XhED1dgiXZEPjKmXLMslBxXHw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR11MB1769 Return-Path: guo.dong@intel.com X-OriginatorOrg: intel.com Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable It would be great if you could add some comments to the newly added cbmem. = It looks cb_cbmem_ref size was not used in this patch. Is it expected? +struct cb_cbmem_ref { + UINT32 tag; + UINT32 size; + UINT64 cbmem_addr; +}; + +struct cbmem_console { + UINT32 size; + UINT32 cursor; + UINT8 body[0]; +} __attribute__((packed)); + Rename gCbConsole to mCbConsole since this global variable is only used in = this module. +STATIC struct cbmem_console *gCbConsole =3D NULL; Thanks, Guo -----Original Message----- From: devel@edk2.groups.io On Behalf Of Benjamin Dor= on Sent: Sunday, May 22, 2022 11:47 AM To: devel@edk2.groups.io Cc: Dong, Guo ; Ni, Ray ; Maurice Ma = ; You, Benjamin ; Rhodes, Sea= n Subject: [edk2-devel] [PATCH v2] UefiPayloadPkg: Add support for logging to= CBMEM console Writes TianoCore debug logs into the CBMEM console ringbuffer, from where t= he user can retrieve them with the `cbmem` userspace utility. The intention is to aid in debugging non-fatal issues even in release build= s, or simply make TianoCore's logs available to those interested. Consequently, MDEPKG_NDEBUG must be masked. As an in-memory debug logging l= ibrary, ASSERTs must be non-fatal to be seen, so they neither dead-loop nor= create a breakpoint. It is assumed that ASSERT() neither enforces fatal co= nditions nor security integrity, as release builds do not call DebugAssert(= ) from the ASSERT macro. More detailed debug logs are produced with the DEBUG_CODE macro, but this g= uards other debug-related code throughout the codebase. To avoid changing b= ehaviour on release builds, this is only set for debug builds. Tested on QEMU, dumping the appropriate memory region in the UEFI shell sho= ws the TianoCore log. An improved revision of the debug library used in sev= eral coreboot-related EDK2 forks, including MrChromebox's. Previous revisions also tested on an Acer Aspire VN7-572G laptop. Cc: Guo Dong Cc: Ray Ni Cc: Maurice Ma Cc: Benjamin You Cc: Sean Rhodes Signed-off-by: Benjamin Doron --- UefiPayloadPkg/Include/Coreboot.h | 12 + UefiPayloadPkg/Library/CbSerialPortLib/CbSerialPortLib.c | 258 +++++++++= +++++++++++ UefiPayloadPkg/Library/CbSerialPortLib/CbSerialPortLib.inf | 30 +++ UefiPayloadPkg/UefiPayloadPkg.dsc | 25 +- 4 files changed, 320 insertions(+), 5 deletions(-) diff --git a/UefiPayloadPkg/Include/Coreboot.h b/UefiPayloadPkg/Include/Cor= eboot.h index a3e1109fe84e..4c9cf965519b 100644 --- a/UefiPayloadPkg/Include/Coreboot.h +++ b/UefiPayloadPkg/Include/Coreboot.h @@ -199,6 +199,12 @@ struct cb_forward { UINT64 forward; }; +struct cb_cbmem_ref {+ UINT32 tag;+ UINT32 size= ;+ UINT64 cbmem_addr;+};+ #define CB_TAG_FRAMEBUFFER 0x0012 struct cb_fra= mebuffer { UINT32 tag;@@ -229,6 +235,12 @@ struct cb_vdat { #define CB_TAG_TIMESTAMPS 0x0016 #define CB_TAG_CBMEM_CONSOLE 0x0017= +struct cbmem_console {+ UINT32 size;+ UINT32 cursor;+ UINT8 body[0];+}= __attribute__((packed));+ #define CB_TAG_MRC_CACHE 0x0018 struct cb_c= bmem_tab { UINT32 tag;diff --git a/UefiPayloadPkg/Library/CbSerialPort= Lib/CbSerialPortLib.c b/UefiPayloadPkg/Library/CbSerialPortLib/CbSerialPort= Lib.c new file mode 100644 index 000000000000..f7c06b0f41e9 --- /dev/null +++ b/UefiPayloadPkg/Library/CbSerialPortLib/CbSerialPortLib.c @@ -0,0 +1,258 @@ +/** @file+ CBMEM console SerialPortLib instance++ Copyright (c) 2022, Ba= ruch Binyamin Doron+ SPDX-License-Identifier: BSD-2-Clause-Patent++**/++#i= nclude +#include ++#include +#= include +#include ++// Upper= nibble contains flags+#define CBMC_CURSOR_MASK ((1 << 28) - 1)+#define CBM= C_OVERFLOW (1 << 31)++STATIC struct cbmem_console *gCbConsole =3D NULL;++/= **+ Find coreboot record with given Tag.+ NOTE: This coreboot-specific fu= nction definition is absent+ from the common BlParseLib header.++ = @param Tag The tag id to be found++ @retval NULL = The Tag is not found.+ @retval Others The pointer to the re= cord found.++**/+VOID *+FindCbTag (+ IN UINT32 Tag+ );++/**+ In= itialize the serial device hardware.++ If no initialization is required, t= hen return RETURN_SUCCESS.+ If the serial device was successfully initiali= zed, then return RETURN_SUCCESS.+ If the serial device could not be initia= lized, then return RETURN_DEVICE_ERROR.++ @retval RETURN_SUCCESS Th= e serial device was initialized.+ @retval RETURN_DEVICE_ERROR The serial= device could not be initialized.++**/+RETURN_STATUS+EFIAPI+SerialPortIniti= alize (+ VOID+ )+{+ struct cb_cbmem_ref *cbref =3D FindCbTag(CB_TAG_CBME= M_CONSOLE);+ if (!cbref) {+ return RETURN_DEVICE_ERROR;+ }++ gCbConso= le =3D (VOID *)(UINTN)cbref->cbmem_addr; // Support PEI and DXE+ if (gCbC= onsole =3D=3D NULL) {+ return RETURN_DEVICE_ERROR;+ }++ return RETURN_= SUCCESS;+}++/**+ Write data from buffer to serial device.++ Writes Number= OfBytes data bytes from Buffer to the serial device.+ The number of bytes = actually written to the serial device is returned.+ If the return value is= less than NumberOfBytes, then the write operation failed.+ If Buffer is N= ULL, then ASSERT().+ If NumberOfBytes is zero, then return 0.++ @param B= uffer Pointer to the data buffer to be written.+ @param NumberO= fBytes Number of bytes to written to the serial device.++ @retval 0 = NumberOfBytes is 0.+ @retval >0 The number of by= tes written to the serial device.+ If this value = is less than NumberOfBytes, then the write operation failed.++**/+UINTN+EFI= API+SerialPortWrite (+ IN UINT8 *Buffer,+ IN UINTN NumberOfBytes+= )+{+ UINT32 cursor;+ UINT32 flags;++ if (Buffer = =3D=3D NULL || NumberOfBytes =3D=3D 0) {+ return 0;+ }++ if (!gCbConso= le) {+ return 0;+ }++ cursor =3D gCbConsole->cursor & CBMC_CURSOR_MASK= ;+ flags =3D gCbConsole->cursor & ~CBMC_CURSOR_MASK;+ if (cursor >=3D gCb= Console->size) {+ // Already overflowed; bail out. TODO: Is this unneces= sarily cautious?+ // - Supports old coreboot version with legacy overflo= w mechanism.+ return 0;+ }++ if (cursor + NumberOfBytes > gCbConsole->= size) {+ // Will overflow, zero cursor and set flag.+ cursor =3D 0;+ = flags |=3D CBMC_OVERFLOW;+ }++ // Longest debug messages supported by = a DebugLib seems to be CHAR16[0x100] =3D=3D 512.+ // So, no chance that on= e message could overflow even the smallest buffer.+ CopyMem (&gCbConsole->= body[cursor], Buffer, NumberOfBytes);+ cursor +=3D NumberOfBytes;++ if (c= ursor =3D=3D gCbConsole->size) {+ // Next message will overflow, zero cu= rsor.+ // - But not overflowed yet. Do not set flag.+ cursor =3D 0;+ = }++ gCbConsole->cursor =3D flags | cursor;++ return NumberOfBytes;+}++/*= *+ Read data from serial device and save the datas in buffer.++ Reads Num= berOfBytes data bytes from a serial device into the buffer+ specified by B= uffer. The number of bytes actually read is returned.+ If Buffer is NULL, = then ASSERT().+ If NumberOfBytes is zero, then return 0.++ @param Buffer= Pointer to the data buffer to store the data read from the seria= l device.+ @param NumberOfBytes Number of bytes which will be read.++ = @retval 0 Read data failed, no data is to be read.+ @retva= l >0 Actual number of bytes read from serial device.++**/+UIN= TN+EFIAPI+SerialPortRead (+ OUT UINT8 *Buffer,+ IN UINTN NumberO= fBytes+)+{+ return 0;+}++/**+ Polls a serial device to see if there is an= y data waiting to be read.++ @retval TRUE Data is waiting to b= e read from the serial device.+ @retval FALSE There is no data = waiting to be read from the serial device.++**/+BOOLEAN+EFIAPI+SerialPortPo= ll (+ VOID+ )+{+ return FALSE;+}++/**+ Sets the control bits on a seria= l device.++ @param Control Sets the bits of Control that ar= e settable.++ @retval RETURN_SUCCESS The new control bits were set = on the serial device.+ @retval RETURN_UNSUPPORTED The serial device doe= s not support this operation.+ @retval RETURN_DEVICE_ERROR The serial de= vice is not functioning correctly.++**/+RETURN_STATUS+EFIAPI+SerialPortSetC= ontrol (+ IN UINT32 Control+ )+{+ return RETURN_UNSUPPORTED;+}++/**+ Re= trieve the status of the control bits on a serial device.++ @param Control= A pointer to return the current control signals from the se= rial device.++ @retval RETURN_SUCCESS The control bits were read fr= om the serial device.+ @retval RETURN_UNSUPPORTED The serial device doe= s not support this operation.+ @retval RETURN_DEVICE_ERROR The serial de= vice is not functioning correctly.++**/+RETURN_STATUS+EFIAPI+SerialPortGetC= ontrol (+ OUT UINT32 *Control+ )+{+ return RETURN_UNSUPPORTED;+}++/**+ = Sets the baud rate, receive FIFO depth, transmit/receive time out, parity,+= data bits, and stop bits on a serial device.++ @param BaudRate = The requested baud rate. A BaudRate value of 0 will use the+ = device's default interface speed.+ = On output, the value actually set.+ @param ReceiveFifoDepth The request= ed depth of the FIFO on the receive side of the+ = serial interface. A ReceiveFifoDepth value of 0 will use+ = the device's default FIFO depth.+ On = output, the value actually set.+ @param Timeout The requested t= ime out for a single character in microseconds.+ = This timeout applies to both the transmit and receive side of the+ = interface. A Timeout value of 0 will use the device's d= efault time+ out value.+ = On output, the value actually set.+ @param Parity The type= of parity to use on this serial device. A Parity value of+ = DefaultParity will use the device's default parity value.+ = On output, the value actually set.+ @param DataBits= The number of data bits to use on the serial device. A DataBits+= value of 0 will use the device's default data b= it setting.+ On output, the value actually set.+= @param StopBits The number of stop bits to use on this serial d= evice. A StopBits+ value of DefaultStopBits will= use the device's default number of+ stop bits.+= On output, the value actually set.++ @retval R= ETURN_SUCCESS The new attributes were set on the serial device.+= @retval RETURN_UNSUPPORTED The serial device does not support this= operation.+ @retval RETURN_INVALID_PARAMETER One or more of the attribut= es has an unsupported value.+ @retval RETURN_DEVICE_ERROR The serial= device is not functioning correctly.++**/+RETURN_STATUS+EFIAPI+SerialPortS= etAttributes (+ IN OUT UINT64 *BaudRate,+ IN OUT UINT32 = *ReceiveFifoDepth,+ IN OUT UINT32 *Timeout,+ IN OUT EF= I_PARITY_TYPE *Parity,+ IN OUT UINT8 *DataBits,+ IN OUT E= FI_STOP_BITS_TYPE *StopBits+ )+{+ return RETURN_UNSUPPORTED;+}+diff --git= a/UefiPayloadPkg/Library/CbSerialPortLib/CbSerialPortLib.inf b/UefiPayload= Pkg/Library/CbSerialPortLib/CbSerialPortLib.inf new file mode 100644 index 000000000000..3df6a0c736a5 --- /dev/null +++ b/UefiPayloadPkg/Library/CbSerialPortLib/CbSerialPortLib.inf @@ -0,0 +1,30 @@ +## @file+# Component description file for CbSerialPortLib library.+#+# C= opyright (c) 2022, Baruch Binyamin Doron+# SPDX-License-Identifier: BSD-2-= Clause-Patent+#+##++[Defines]+ INF_VERSION =3D 0x000100= 05+ BASE_NAME =3D CbSerialPortLib+ FILE_GUID = =3D 0DB3EF12-1426-4086-B012-113184C4CE11+ MODULE_TYPE = =3D BASE+ VERSION_STRING =3D 1.0+ # Recall t= hat debug logging can be unsafe to core. Route over RSC.+ LIBRARY_CLASS = =3D SerialPortLib+ CONSTRUCTOR =3D Seria= lPortInitialize++[Packages]+ MdePkg/MdePkg.dec+ MdeModulePkg/MdeModulePkg= .dec+ UefiPayloadPkg/UefiPayloadPkg.dec++[LibraryClasses]+ BaseMemoryLib+= BlParseLib++[Sources]+ CbSerialPortLib.c+diff --git a/UefiPayloadPkg/Uef= iPayloadPkg.dsc b/UefiPayloadPkg/UefiPayloadPkg.dsc index 4d9bbc80c866..0e4248767756 100644 --- a/UefiPayloadPkg/UefiPayloadPkg.dsc +++ b/UefiPayloadPkg/UefiPayloadPkg.dsc @@ -37,6 +37,7 @@ DEFINE ABOVE_4G_MEMORY =3D TRUE DEFINE BOOT_MANAGER_ESCAP= E =3D FALSE DEFINE SD_MMC_TIMEOUT =3D 1000000+ DE= FINE USE_CBMEM_FOR_CONSOLE =3D FALSE # # SBL: UEFI payload = for Slim Bootloader # COREBOOT: UEFI payload for coreboot@@ -121,10 +122,= 11 @@ [BuildOptions] *_*_*_CC_FLAGS =3D -D DISABLE_NEW_DEPREC= ATED_INTERFACES- GCC:*_UNIXGCC_*_CC_FLAGS =3D -DMDEPKG_NDEBUG+!if $(= USE_CBMEM_FOR_CONSOLE) =3D=3D FALSE GCC:RELEASE_*_*_CC_FLAGS =3D -D= MDEPKG_NDEBUG INTEL:RELEASE_*_*_CC_FLAGS =3D /D MDEPKG_NDEBUG MSFT:= RELEASE_*_*_CC_FLAGS =3D /D MDEPKG_NDEBUG+!endif [BuildOptions.common= .EDKII.DXE_RUNTIME_DRIVER] GCC:*_*_*_DLINK_FLAGS =3D -z common-page-= size=3D0x1000@@ -231,8 +233,13 @@ TimerLib|UefiPayloadPkg/Library/AcpiTimerLib/AcpiTimerLib.inf !endif R= esetSystemLib|UefiPayloadPkg/Library/ResetSystemLib/ResetSystemLib.inf+!if = $(USE_CBMEM_FOR_CONSOLE) =3D=3D TRUE+ SerialPortLib|UefiPayloadPkg/Library= /CbSerialPortLib/CbSerialPortLib.inf+ PlatformHookLib|MdeModulePkg/Library= /BasePlatformHookLibNull/BasePlatformHookLibNull.inf+!else SerialPortLib|= MdeModulePkg/Library/BaseSerialPortLib16550/BaseSerialPortLib16550.inf Pl= atformHookLib|UefiPayloadPkg/Library/PlatformHookLib/PlatformHookLib.inf+!e= ndif PlatformBootManagerLib|UefiPayloadPkg/Library/PlatformBootManagerLib= /PlatformBootManagerLib.inf IoApicLib|PcAtChipsetPkg/Library/BaseIoApicLi= b/BaseIoApicLib.inf @@ -422,10 +429,18 @@ gEfiMdeModulePkgTokenSpaceGuid.PcdBootManagerMenuFile|{ 0x21, 0xaa, 0x2c= , 0x46, 0x14, 0x76, 0x03, 0x45, 0x83, 0x6e, 0x8a, 0xb6, 0xf4, 0x66, 0x23, 0= x31 } gEfiMdePkgTokenSpaceGuid.PcdReportStatusCodePropertyMask|0x7 gEfi= MdePkgTokenSpaceGuid.PcdDebugPrintErrorLevel|0x8000004F-!if $(SOURCE_DEBUG_= ENABLE)- gEfiMdePkgTokenSpaceGuid.PcdDebugPropertyMask|0x17+!if $(USE_CBME= M_FOR_CONSOLE) =3D=3D FALSE+ !if $(SOURCE_DEBUG_ENABLE)+ gEfiMdePkgToke= nSpaceGuid.PcdDebugPropertyMask|0x17+ !else+ gEfiMdePkgTokenSpaceGuid.P= cdDebugPropertyMask|0x2F+ !endif !else- gEfiMdePkgTokenSpaceGuid.PcdDebug= PropertyMask|0x2F+ !if $(TARGET) =3D=3D DEBUG+ gEfiMdePkgTokenSpaceGuid= .PcdDebugPropertyMask|0x07+ !else+ gEfiMdePkgTokenSpaceGuid.PcdDebugPro= pertyMask|0x03+ !endif !endif gEfiMdeModulePkgTokenSpaceGuid.PcdMaxSizeN= onPopulateCapsule|$(MAX_SIZE_NON_POPULATE_CAPSULE) #@@ -471,7 +486,7 @@ gUefiCpuPkgTokenSpaceGuid.PcdCpuApLoopMode gUefiCpuPkgTokenSpaceGuid.P= cdCpuMicrocodePatchAddress gUefiCpuPkgTokenSpaceGuid.PcdCpuMicrocodePatch= RegionSize-!if $(TARGET) =3D=3D DEBUG+!if ($(TARGET) =3D=3D DEBUG || $(USE_= CBMEM_FOR_CONSOLE) =3D=3D TRUE) gEfiMdeModulePkgTokenSpaceGuid.PcdStatusC= odeUseSerial|TRUE !else gEfiMdeModulePkgTokenSpaceGuid.PcdStatusCodeUseSe= rial|FALSE--=20 2.36.1 -=3D-=3D-=3D-=3D-=3D-=3D Groups.io Links: You receive all messages sent to this group. View/Reply Online (#89944): https://edk2.groups.io/g/devel/message/89944 Mute This Topic: https://groups.io/mt/91273919/1781375 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [guo.dong@intel.com] -=3D= -=3D-=3D-=3D-=3D-=3D