From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from EUR01-VE1-obe.outbound.protection.outlook.com (EUR01-VE1-obe.outbound.protection.outlook.com [40.107.14.43]) by mx.groups.io with SMTP id smtpd.web12.8016.1580831601145284856 for ; Tue, 04 Feb 2020 07:53:22 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@armh.onmicrosoft.com header.s=selector2-armh-onmicrosoft-com header.b=eRwQS4ZM; spf=pass (domain: arm.com, ip: 40.107.14.43, mailfrom: pierre.gondois@arm.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=s7nnpKs0mTZ+/VAhUCa2+ItCTiykEru0g2duLeQvttY=; b=eRwQS4ZMlB3xx2OLarbQXw5NK1SSmrEGKdP7B4eLlFXSLGISFMTl0hdYJ0fDCxxSKHb3NbC3XmpuaYxqdgQTITYPXTo8RmAqhtnmXxPhUj1zj+KCNpJ9+36URhfDUF3puibgIhRaaaguwpN+vbXr5S3guOFiwHyss8IXEKCI7iQ= Received: from VI1PR08CA0238.eurprd08.prod.outlook.com (2603:10a6:802:15::47) by AM0PR08MB3795.eurprd08.prod.outlook.com (2603:10a6:208:105::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2686.30; Tue, 4 Feb 2020 15:53:18 +0000 Received: from VE1EUR03FT032.eop-EUR03.prod.protection.outlook.com (2a01:111:f400:7e09::206) by VI1PR08CA0238.outlook.office365.com (2603:10a6:802:15::47) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2686.32 via Frontend Transport; Tue, 4 Feb 2020 15:53:18 +0000 Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; edk2.groups.io; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com;edk2.groups.io; dmarc=bestguesspass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 63.35.35.123 as permitted sender) receiver=protection.outlook.com; client-ip=63.35.35.123; helo=64aa7808-outbound-1.mta.getcheckrecipient.com; Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by VE1EUR03FT032.mail.protection.outlook.com (10.152.18.121) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2665.18 via Frontend Transport; Tue, 4 Feb 2020 15:53:17 +0000 Received: ("Tessian outbound d1ceabc7047e:v42"); Tue, 04 Feb 2020 15:53:17 +0000 X-CR-MTA-TID: 64aa7808 Received: from 5ca884a9ee65.3 by 64aa7808-outbound-1.mta.getcheckrecipient.com id A122EFD4-DF3E-46A8-B99A-BFC9213FC85C.1; Tue, 04 Feb 2020 15:53:12 +0000 Received: from EUR04-VI1-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 5ca884a9ee65.3 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Tue, 04 Feb 2020 15:53:12 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=C7WTL/Lnz/G65yMYaTrP7aESV9BBntlK9JV9bFB/WbFetWtY4Ii2sK6HhSebIk3Xu7RlTxVXexKhuHs1cr1F921UxLxVjjWJt17cSyYTibDSGAsdmSGR7DNkXCPXsZOChwqykBGQE6nVygy+0TfJUPpFpHw9Ub3w0kotZQn/pazPIwBxHdA+i9gUiDJyxH0Q6pLmw+7RazMIzumcYsYyK9aCgpuSSn2HfmWH+R7Kcn7ghI96yK5F9Jt6HCnMViIUM1dWZ9I5NsuJx+L5yzDL3u98h6c4dPCHyJLMje73E65yafNJJbjxhe6AEVPcDLpkMmR4BojMKO7BeuIVRtpE9Q== 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-SenderADCheck; bh=s7nnpKs0mTZ+/VAhUCa2+ItCTiykEru0g2duLeQvttY=; b=i9kxsHzWLIuE2HWwAetCU+o0IdDXJqFgnekjCLWxRV30e4CiCazv/brLZ4gkqSQ5DKbWMSEj+hHVRiNqGQXD0t4yAYEq14fnZjVxIk+7owPm9DArl3sjrPa+yCFeQR6YkI8ICssGKlKlKhdxo3ZWKodJzrsAHFnY9y4fkQF2wKdwOP0GDmH9EI+ba4bKw45PRPie+zro63GiQLJA1g27kB8sf29kLXsC59CNAnmCxFVI3HUm1k6uwMZefOdmto2pZU2mUg8M2y+n1tB3Fb4HcBomWytfw0yQCfk8/APnQ8svWTnkcKTl5TJWGriR4CG84qwyKRdmQJV3W+XvnEIdSA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=arm.com; dmarc=pass action=none header.from=arm.com; dkim=pass header.d=arm.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=s7nnpKs0mTZ+/VAhUCa2+ItCTiykEru0g2duLeQvttY=; b=eRwQS4ZMlB3xx2OLarbQXw5NK1SSmrEGKdP7B4eLlFXSLGISFMTl0hdYJ0fDCxxSKHb3NbC3XmpuaYxqdgQTITYPXTo8RmAqhtnmXxPhUj1zj+KCNpJ9+36URhfDUF3puibgIhRaaaguwpN+vbXr5S3guOFiwHyss8IXEKCI7iQ= Received: from DB7PR08MB3113.eurprd08.prod.outlook.com (52.134.111.149) by DB7PR08MB3001.eurprd08.prod.outlook.com (52.135.129.29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2686.32; Tue, 4 Feb 2020 15:53:09 +0000 Received: from DB7PR08MB3113.eurprd08.prod.outlook.com ([fe80::6d14:b899:9fc4:d248]) by DB7PR08MB3113.eurprd08.prod.outlook.com ([fe80::6d14:b899:9fc4:d248%4]) with mapi id 15.20.2686.034; Tue, 4 Feb 2020 15:53:09 +0000 From: "PierreGondois" To: Pierre Gondois , "devel@edk2.groups.io" CC: "ard.biesheuvel@linaro.org" , "bob.c.feng@intel.com" , "liming.gao@intel.com" , Sami Mujawar , nd Subject: Re: [PATCH v3 1/1] BaseTools: Script for converting .aml to .hex Thread-Topic: [PATCH v3 1/1] BaseTools: Script for converting .aml to .hex Thread-Index: AQHV23KYtAWG5JfKZEaK5q6+VFVa26gLLnEw Date: Tue, 4 Feb 2020 15:53:09 +0000 Message-ID: References: <20200204154818.27368-1-pierre.gondois@arm.com> In-Reply-To: <20200204154818.27368-1-pierre.gondois@arm.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ts-tracking-id: a656bd33-406b-406f-98c7-e1bd8ac5c818.0 x-checkrecipientchecked: true Authentication-Results-Original: spf=none (sender IP is ) smtp.mailfrom=Pierre.Gondois@arm.com; x-originating-ip: [217.140.106.52] x-ms-publictraffictype: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 3d0e984e-e5ca-4c5d-9280-08d7a98a5a41 X-MS-TrafficTypeDiagnostic: DB7PR08MB3001:|DB7PR08MB3001:|AM0PR08MB3795: x-ms-exchange-transport-forked: True X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true nodisclaimer: true x-ms-oob-tlc-oobclassifiers: OLM:1850;OLM:1850; x-forefront-prvs: 03030B9493 X-Forefront-Antispam-Report-Untrusted: SFV:NSPM;SFS:(10009020)(4636009)(376002)(346002)(136003)(396003)(366004)(39860400002)(189003)(199004)(33656002)(2906002)(7696005)(86362001)(966005)(71200400001)(26005)(81166006)(81156014)(186003)(4326008)(8676002)(8936002)(316002)(110136005)(6506007)(54906003)(52536014)(478600001)(5660300002)(53546011)(66446008)(76116006)(66946007)(66556008)(66476007)(9686003)(64756008)(45080400002)(55016002)(142923001);DIR:OUT;SFP:1101;SCL:1;SRVR:DB7PR08MB3001;H:DB7PR08MB3113.eurprd08.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;MX:1;A:1; received-spf: None (protection.outlook.com: arm.com does not designate permitted sender hosts) X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: MpOki5ahV/oC0W1R9zwoDU+BXHRJ0OzJ4zCJm7eNd7V50hZNYyR7pcYBZJWLPyr8A21mso9CcAb/iKvMXygDr1MWEfGs3TN+al8nZ7j5WlAtSxGlTU66WagNJdzpHz4sE8sQtTuiczZj1vurPeSNs8xD8F2Amvvlm3vCUII2DvZ/Us32kUD2kXyPaJm5SVOO5c4t4bfKV99DMdPmOOYhOxmlSLbpQbrM5XINHRVLpLLtti11rlqgsN2qAMvSbCWQfwApEEJlLyO68f1Xo5TgTj3nhvt2sAUvpFZDAAfwAbOYir0LPAffcnrH+OyrgBdZ2mL6YPWBUWuOYFgen553t4EYkp1i7kGAiJoS9/XVNMDudbxZgx3o/ZmUL31RZCM/6OOry93ro3VyDJAEh2D8wbNhv2FpFRtlaOevOdVpGmX5M7ksEYyXrAOnkr2fv47A/uy0T7y8VXvSfDiQpbpJ2xiNaDqDBNSvvgA6UF7MwN8k89Aj/Jv/4SFJeBlPz/EjjnG0F6YRGTJmCLLoGN43xvmI6UpRetReb8jjy54VDkPBUJBhmVIbOyDDE25d1i/J x-ms-exchange-antispam-messagedata: lDqEqsalysAX5liq1s8Exyo6cC4mLag8nVHn/C/AeTwyeHbHJLEfz3eTK9dOzQomRXnW1kMLn+D3Nw64QPqGbS6nFGweHZ3vQXVM6kWt8jzG3aNOa9HMNu1BDscLfU/6nb/9m5T69caV3AQCAWcktw== MIME-Version: 1.0 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB7PR08MB3001 Original-Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Pierre.Gondois@arm.com; Return-Path: Pierre.Gondois@arm.com X-EOPAttributedMessage: 0 X-MS-Exchange-Transport-CrossTenantHeadersStripped: VE1EUR03FT032.eop-EUR03.prod.protection.outlook.com X-Forefront-Antispam-Report: CIP:63.35.35.123;IPV:CAL;SCL:-1;CTRY:IE;EFV:NLI;SFV:NSPM;SFS:(10009020)(4636009)(346002)(39860400002)(376002)(396003)(136003)(199004)(189003)(86362001)(4326008)(2906002)(26826003)(478600001)(966005)(70206006)(70586007)(336012)(45080400002)(356004)(55016002)(9686003)(36906005)(316002)(110136005)(54906003)(8676002)(8936002)(6506007)(33656002)(52536014)(26005)(7696005)(81166006)(81156014)(5660300002)(53546011)(186003)(142923001);DIR:OUT;SFP:1101;SCL:1;SRVR:AM0PR08MB3795;H:64aa7808-outbound-1.mta.getcheckrecipient.com;FPR:;SPF:Pass;LANG:en;PTR:ec2-63-35-35-123.eu-west-1.compute.amazonaws.com;A:1;MX:1; X-MS-Office365-Filtering-Correlation-Id-Prvs: e4c7c58e-bbca-4826-c6ae-08d7a98a553f X-Forefront-PRVS: 03030B9493 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 2M/3Zvc4cXILKprB4Dtf0aivUW4edCDdYwQu7HeUwof+/Oj3BfNTk6MpuEIyBrxZk+vb5S5OaLtNW4EJbz7z41C6j1NAZ8Rmvnrl0Ykg4EBOmawZNY2HkGGAKV5+xCVew4n9yQwUtYx5KisDv+4yIc2Kvsqts3L4XV2Um0bIjg1/Mx31MJKIbGE2if6B09KuRcMWtt73/iGl0PcysLjzb7JUp/SDQ1Bw1aN/ve6nmJTDMJK60xSAbUejhbSdSNkSywx1j6IYlRAO7NdQwAYxQn3Hh1cF6U+ZrFv+HTlMVSifLt8sO7INv6lPSzIFXGaOQv+p9NKBpQEveyl01Mv/2pkL7E9vEX8P6SuvGXdbFcmwf3dEtdtWJ3dqhdnA0FafEOK2yeJwpZnbw9EzPlETEStnlsbOs3mmD+K1YO8GqaU/1zXbUCVS1TXwKpIz8ff1cNa7XHp3RMx77DVdRZ8BzoBrrk4gIdoAr9SC79xf/Y3YX7gx7rf4pToHGYVVZ9lecHWWHl25IN/O3e+r0AzBj+UOVIAhse/62JNcSpQ4XuxaxAlsgZ6vxbDTULNgySJz X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Feb 2020 15:53:17.9621 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 3d0e984e-e5ca-4c5d-9280-08d7a98a5a41 X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d;Ip=[63.35.35.123];Helo=[64aa7808-outbound-1.mta.getcheckrecipient.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR08MB3795 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable [From Liming] > If so, this is not the error for other ACPI table. I suggest to print INF= O message and directly return with success return value. I've put a EdkLogger.warn(), so it doesn't stop the execution of the script= and the message has a log level high enough to be printed. Regards, Pierre =20 -----Original Message----- From: PierreGondois =20 Sent: 04 February 2020 15:48 To: devel@edk2.groups.io Cc: Pierre Gondois ; ard.biesheuvel@linaro.org; bob= .c.feng@intel.com; liming.gao@intel.com; Sami Mujawar ; nd Subject: [PATCH v3 1/1] BaseTools: Script for converting .aml to .hex From: Pierre Gondois The "-tc" option of the iasl compiler allows to generate a .hex file contai= ning a C array storing AML bytecode. An online discussion suggested that this "-tc" option was specific to the i= asl compiler and it shouldn't be relied on. This conversation is available = at: https://edk2.groups.io/g/devel/topic/39786201#49659 A way to address this issue is to implement a compiler independent script t= hat takes an AML file as input, and generates a .hex file. This patch implements a Python script that converts an AML file to a .hex f= ile, containing a C array storing AML bytecode. This scipt has been tested with the AML output from the following compilers= supported by the EDKII implementation: * Intel ASL compiler * Microsoft ASL compiler Signed-off-by: Pierre Gondois --- The changes can be seen at https://github.com/PierreARM/edk2/tree/718_asl_t= o_hex_script_converter_v3 Notes: v3: - When a file without a DSDT or SSDT signature is given as input, give a warning instead of an error. [Pierre] - Return None value instead of nothing in functions. [Pierre] BaseTools/BinWrappers/PosixLike/AmlToHex | 14 ++ BaseTools/BinWrappers/WindowsLike/AmlToHex.bat | 3 + BaseTools/Conf/build_rule.template | 3 + BaseTools/Source/Python/AmlToHex/AmlToHex.py | 158 ++++++++++++++++++++ 4 files changed, 178 insertions(+) diff --git a/BaseTools/BinWrappers/PosixLike/AmlToHex b/BaseTools/BinWrappe= rs/PosixLike/AmlToHex new file mode 100755 index 0000000000000000000000000000000000000000..1dd28e966288f6ea4fc52d42e2d= c7b1f74226c23 --- /dev/null +++ b/BaseTools/BinWrappers/PosixLike/AmlToHex @@ -0,0 +1,14 @@ +#!/usr/bin/env bash +#python `dirname $0`/RunToolFromSource.py `basename $0` $* + +# If a ${PYTHON_COMMAND} command is available, use it in preference to=20 +python if command -v ${PYTHON_COMMAND} >/dev/null 2>&1; then + python_exe=3D${PYTHON_COMMAND} +fi + +full_cmd=3D${BASH_SOURCE:-$0} # see=20 +http://mywiki.wooledge.org/BashFAQ/028 for a discussion of why $0 is=20 +not a good choice here dir=3D$(dirname "$full_cmd") exe=3D$(basename=20 +"$full_cmd") + +export PYTHONPATH=3D"$dir/../../Source/Python${PYTHONPATH:+:"$PYTHONPATH"}= " +exec "${python_exe:-python}" "$dir/../../Source/Python/$exe/$exe.py" "$@" diff --git a/BaseTools/BinWrappers/WindowsLike/AmlToHex.bat b/BaseTools/Bin= Wrappers/WindowsLike/AmlToHex.bat new file mode 100644 index 0000000000000000000000000000000000000000..9616cd893bec9902451e6d8591f= 537cc408bd5e5 --- /dev/null +++ b/BaseTools/BinWrappers/WindowsLike/AmlToHex.bat @@ -0,0 +1,3 @@ +@setlocal +@set ToolName=3D%~n0% +@%PYTHON_COMMAND%=20 +%BASE_TOOLS_PATH%\Source\Python\%ToolName%\%ToolName%.py %* diff --git a/BaseTools/Conf/build_rule.template b/BaseTools/Conf/build_rule= .template index 51748bc0655a5c656258a3007b4db6b2dc941ea0..0822b681fcd9f61c6508e6f93ff= c31fa70fd7059 100755 --- a/BaseTools/Conf/build_rule.template +++ b/BaseTools/Conf/build_rule.template @@ -1,6 +1,7 @@ # # Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.
= # Portions copyright (c) 2008 - 2010, Apple Inc. All rights reserved.
+# Copyright (c) 2020, ARM Ltd. All rights reserved.
# SPDX-License-Identifier: BSD-2-Clause-Patent # =20 @@ -427,12 +428,14 @@ "$(ASLPP)" $(DEPS_FLAGS) $(ASLPP_FLAGS) $(INC) /I${s_path} $(OUTPU= T_DIR)(+)${s_dir}(+)${s_base}.i > $(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.iii Trim --source-code -l -o $(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.iiii= $(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.iii=20 "$(ASL)" $(ASL_FLAGS) $(ASL_OUTFLAGS)${dst} $(OUTPUT_DIR)(+)${s_di= r}(+)${s_base}.iiii + -AmlToHex $(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.aml =20 Trim --asl-file --asl-deps -o $(OUTPUT_DIR)(+)${s_dir}(+)${s_base}= .i -i $(INC_LIST) ${src} "$(ASLPP)" $(DEPS_FLAGS) $(ASLPP_FLAGS) $(INC) -I${s_path} $(OUTPU= T_DIR)(+)${s_dir}(+)${s_base}.i > $(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.iii Trim --source-code -l -o $(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.iiii= $(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.iii=20 "$(ASL)" $(ASL_FLAGS) $(ASL_OUTFLAGS)${dst} $(OUTPUT_DIR)(+)${s_di= r}(+)${s_base}.iiii + -AmlToHex $(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.aml =20 [C-Code-File.AcpiTable] diff --git a/BaseTools/Source/Python/AmlToHex/AmlToHex.py b/BaseTools/Sourc= e/Python/AmlToHex/AmlToHex.py new file mode 100644 index 0000000000000000000000000000000000000000..7fe294a5aad6b6d3e32316a6847= 8db5938ec856a --- /dev/null +++ b/BaseTools/Source/Python/AmlToHex/AmlToHex.py @@ -0,0 +1,158 @@ +## @file +# +# Convert an AML file to a .hex file containing the AML bytecode stored=20 +in a # C array. +# By default, "Tables\Dsdt.aml" will generate "Tables\Dsdt.hex". +# "Tables\Dsdt.hex" will contain a C array named "dsdt_aml_code" that=20 +contains # the AML bytecode. +# +# Copyright (c) 2020, ARM Limited. All rights reserved.
# #=20 +SPDX-License-Identifier: BSD-2-Clause-Patent # + +import argparse +import Common.EdkLogger as EdkLogger +from Common.BuildToolError import * +import sys +import os + +## Parse the command line arguments. +# +# @retval A argparse.NameSpace instance, containing parsed values. +# +def ParseArgs(): + # Initialize the parser. + Parser =3D argparse.ArgumentParser( + description=3D"Convert an AML file to a .hex file containing the AML= " + \ + "bytecode stored in a C array. By default, " + \ + "\"Tables\\Dsdt.aml\" will generate" + \ + "\"Tables\\Dsdt.hex\". \"Tables\\Dsdt.hex\" will " + \ + "contain a C array named \"dsdt_aml_code\" that " + \ + "contains the AML bytecode." + ) + + # Define the possible arguments. + Parser.add_argument( + dest=3D"InputFile", + help=3D"Path to an input AML file to generate a .hex file from." + ) + Parser.add_argument( + "-o", "--out-dir", dest=3D"OutDir", + help=3D"Output directory where the .hex file will be generated. " + = \ + "Default is the input file's directory." + ) + + # Parse the input arguments. + Args =3D Parser.parse_args() + SplitInputName =3D "" + + if not os.path.exists(Args.InputFile): + EdkLogger.error(__file__, FILE_OPEN_FAILURE, + ExtraData=3DArgs.InputFile) + return None + else: + with open(Args.InputFile, "rb") as fIn: + Signature =3D str(fIn.read(4)) + if ("DSDT" not in Signature) and ("SSDT" not in Signature): + EdkLogger.warn(__file__, + "Warning: Invalid file type. " + \ + "File does not have a valid " + \ + "DSDT or SSDT signature.", + ExtraData=3DArgs.InputFile) + return None + + # Get the basename of the input file. + SplitInputName =3D os.path.splitext(Args.InputFile) + BaseName =3D os.path.basename(SplitInputName[0]) + + # If no output directory is specified, output to the input directory. + if not Args.OutDir: + Args.OutputFile =3D os.path.join( + os.path.dirname(Args.InputFile), + BaseName + ".hex" + ) + else: + if not os.path.exists(Args.OutDir): + os.mkdir(Args.OutDir) + Args.OutputFile =3D os.path.join(Args.OutDir, BaseName + ".hex") + + Args.BaseName =3D BaseName + + return Args + +## Convert an AML file to a .hex file containing the AML bytecode=20 +stored # in a C array. +# +# @param InputFile Path to the input AML file. +# @param OutputFile Path to the output .hex file to generate. +# @param BaseName Base name of the input file. +# This is also the name of the generated .hex file. +# +def AmlToHex(InputFile, OutputFile, BaseName): + + MacroName =3D "__{}_HEX__".format(BaseName.upper()) + ArrayName =3D BaseName.lower() + "_aml_code" + + with open(InputFile, "rb") as fIn, open(OutputFile, "w") as fOut: + # Write header. + fOut.write("// This file has been generated from:\n" + \ + "// \tPython script: " + \ + os.path.abspath(__file__) + "\n" + \ + "// \tInput AML file: " + \ + os.path.abspath(InputFile) + "\n\n" + \ + "#ifndef {}\n".format(MacroName) + \ + "#define {}\n\n".format(MacroName) + ) + + # Write the array and its content. + fOut.write("unsigned char {}[] =3D {{\n ".format(ArrayName)) + cnt =3D 0 + byte =3D fIn.read(1) + while len(byte) !=3D 0: + fOut.write("0x{0:02X}, ".format(ord(byte))) + cnt +=3D 1 + if (cnt % 8) =3D=3D 0: + fOut.write("\n ") + byte =3D fIn.read(1) + fOut.write("\n};\n") + + # Write footer. + fOut.write("#endif // {}\n".format(MacroName)) + +## Main method +# +# This method: +# 1- Initialize an EdkLogger instance. +# 2- Parses the input arguments. +# 3- Converts an AML file to a .hex file containing the AML bytecode st= ored +# in a C array. +# +# @retval 0 Success. +# @retval 1 Error. +# +def Main(): + # Initialize an EdkLogger instance. + EdkLogger.Initialize() + + try: + # Parse the input arguments. + CommandArguments =3D ParseArgs() + if not CommandArguments: + return 1 + + # Convert an AML file to a .hex file containing the AML bytecode s= tored + # in a C array. + AmlToHex(CommandArguments.InputFile, CommandArguments.OutputFile, + CommandArguments.BaseName) + except Exception as e: + print(e) + return 1 + + return 0 + +if __name__ =3D=3D '__main__': + r =3D Main() + # 0-127 is a safe return range, and 1 is a standard default error + if r < 0 or r > 127: r =3D 1 + sys.exit(r) -- 'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)'