From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from FRA01-PR2-obe.outbound.protection.outlook.com (FRA01-PR2-obe.outbound.protection.outlook.com [40.107.12.79]) by mx.groups.io with SMTP id smtpd.web12.6478.1580735996444341675 for ; Mon, 03 Feb 2020 05:19:57 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@armh.onmicrosoft.com header.s=selector2-armh-onmicrosoft-com header.b=11dE7Xph; spf=pass (domain: arm.com, ip: 40.107.12.79, 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=MQQduFszX69g8ywmKK+MtmCU1Xpolp9dYM8kisK2DJA=; b=11dE7XphZB+eDa+cXsAgD02A5RXghtmFR7qMxDKFvzQ2X1EQ9VEIuMjCw/EVq5/b8Si8/Hy7Pyyfy8cUxagxEs412wWtm4BISLBq4oQNzCkBf6A+Pxex6QvSLO93mws8mPdiQTOyMYB8Xc7yEaYjDoNwE1OZ93WwRXReUCNBIRs= Received: from HE1PR08CA0078.eurprd08.prod.outlook.com (2603:10a6:7:2a::49) by PR2PR08MB4859.eurprd08.prod.outlook.com (2603:10a6:101:28::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2686.29; Mon, 3 Feb 2020 13:19:53 +0000 Received: from AM5EUR03FT009.eop-EUR03.prod.protection.outlook.com (2a01:111:f400:7e08::201) by HE1PR08CA0078.outlook.office365.com (2603:10a6:7:2a::49) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2686.30 via Frontend Transport; Mon, 3 Feb 2020 13:19:53 +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 AM5EUR03FT009.mail.protection.outlook.com (10.152.16.110) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2665.18 via Frontend Transport; Mon, 3 Feb 2020 13:19:53 +0000 Received: ("Tessian outbound 0420f1404d58:v42"); Mon, 03 Feb 2020 13:19:53 +0000 X-CR-MTA-TID: 64aa7808 Received: from ae1fb72b6592.2 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 9828F7E3-B6A0-4026-A844-17CC67219C9A.1; Mon, 03 Feb 2020 13:19:47 +0000 Received: from EUR01-VE1-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id ae1fb72b6592.2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Mon, 03 Feb 2020 13:19:47 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jME/g8+xiHb6TjRareKl1ePVDwYJASewOt1NTJqDXjSZrT+dOfq6XP2JD4nP5PhRqobPdi1+tasaRaFRABGt2qdUtjqaidQs2TAhrbpPM6fS6didfPTkvI3BXsRXm0fm3IHEbf4O0+ZO2sFTwJPC5LeVO6E247neeq+rCA0E3WvLZPj8J2lj6W3/A58dijFMCuTgZH5qu3paSDlhWAxl82fZ3pc6w4ZQosLusQcq2vOZvOZ+YMIQdj5SvrPaE9bPwrGcPN1XjfnBl8thGkX/vzmk9OpveKlVi3ac5XD0QU6+V/9r2rIUGYCvMHMyL+/m5VCzdPxXATyJqe91HsVIGg== 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=MQQduFszX69g8ywmKK+MtmCU1Xpolp9dYM8kisK2DJA=; b=Mq3Ir1bevmFFnwd94dxvUpMkiWzNnsH1+m7yy9Y7+L5VuEFI4Xe5UHXG5CfNOcA41C1k3Tqw8VQ5+HZzoSFxCKOoEmWApaDkM9YROisdIH4+5d8LNCLEqyd+35maD9S9FqBEYpSqyp1jHPJz8l/WnrvdhS3YbAsgwtxTQRkoJm/3wxkNr4cFum0LxzzV045ysf8KpV6u4AYerf9T2uqxWZofDcQZuDCqUsJ+f/0iLPS0YSGcqgqttrZUnuTndNsUtShPh0h5puWziTUyINYRXdgdPC45W99qTu/971dQ/7U5ltbZy5De9GldyYJbm/YHNbX3FZVW9qOzic7W4cDt4Q== 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=MQQduFszX69g8ywmKK+MtmCU1Xpolp9dYM8kisK2DJA=; b=11dE7XphZB+eDa+cXsAgD02A5RXghtmFR7qMxDKFvzQ2X1EQ9VEIuMjCw/EVq5/b8Si8/Hy7Pyyfy8cUxagxEs412wWtm4BISLBq4oQNzCkBf6A+Pxex6QvSLO93mws8mPdiQTOyMYB8Xc7yEaYjDoNwE1OZ93WwRXReUCNBIRs= Received: from DB7PR08MB3113.eurprd08.prod.outlook.com (52.134.111.149) by DB7PR08MB3611.eurprd08.prod.outlook.com (20.177.121.90) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2686.32; Mon, 3 Feb 2020 13:19:46 +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.028; Mon, 3 Feb 2020 13:19:46 +0000 From: "PierreGondois" To: "devel@edk2.groups.io" , "liming.gao@intel.com" CC: "ard.biesheuvel@linaro.org" , "Feng, Bob C" , Sami Mujawar , nd Subject: Re: [edk2-devel] [PATCH v2 1/1] BaseTools: Script for converting .aml to .hex Thread-Topic: [edk2-devel] [PATCH v2 1/1] BaseTools: Script for converting .aml to .hex Thread-Index: AQHVzVoPj34q6on+IkSh2c5wuHYPHaf2+PTQgBJ+sICAABXUsA== Date: Mon, 3 Feb 2020 13:19:45 +0000 Message-ID: References: <20200117171734.10924-1-pierre.gondois@arm.com> <2d68ea8e33e64f34a5b64b970262cce4@intel.com> In-Reply-To: <2d68ea8e33e64f34a5b64b970262cce4@intel.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ts-tracking-id: db72918e-d340-4699-ae45-88cafd79de38.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: a6ffd873-556f-4c0d-f4b9-08d7a8abc142 X-MS-TrafficTypeDiagnostic: DB7PR08MB3611:|DB7PR08MB3611:|PR2PR08MB4859: x-ms-exchange-transport-forked: True X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true nodisclaimer: true x-ms-oob-tlc-oobclassifiers: OLM:525;OLM:525; x-forefront-prvs: 0302D4F392 X-Forefront-Antispam-Report-Untrusted: SFV:NSPM;SFS:(10009020)(4636009)(346002)(366004)(136003)(39860400002)(376002)(396003)(189003)(199004)(53546011)(6506007)(55016002)(71200400001)(86362001)(26005)(54906003)(110136005)(186003)(316002)(76116006)(5660300002)(81156014)(66946007)(8676002)(66476007)(66556008)(64756008)(66446008)(81166006)(8936002)(2906002)(7696005)(966005)(4326008)(52536014)(478600001)(45080400002)(9686003)(33656002)(30864003)(142923001);DIR:OUT;SFP:1101;SCL:1;SRVR:DB7PR08MB3611;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: aRy508a3Thg1Y1ndn6fegwhHphTy/EhHxIF83zyCVaSy4gL47Ulu/ydMrvMNE+8RlJF0CxOQ/PY2g9BHafEfTQyobQdwh+LOjuakZSAdQ/FuohrMjjmU7duCc1tsKf4icV6LOlqgG/oIf0dE6DrMsb8EdYfMn1YQcZX6LTwezdfXhEIDQbTeAPQOcCffVpISFTPvoK4G+4+aLQBo2az9f+3++9KvQ16/RDriAYuxUE5ROVfxHpKR48IzNpIT7qrzoUptPTZhnrE+Nx9pnFinm9CCEcFARJZ3Eky4L/LZHtFZ6y4qn+vyHUh8BFtdaUA90zal9bCQwdL5HIakVJ/K4Bn/Rt/7/L+bwnZ+ce+/9+Cv25ic4xq2YHoCkm55Ryo/MNWKb+XT2K9al7awha3waz4LtGMfrp6MLitnN7aaHc/yqWkiG5dk8cXyKGHlOOB5sCzaeNIAdIbEL+1KQCfhrK4YkXjw7Hikbr7tq46nmhaiV2B93YlIKVk6QGRSSDD+rBZPCX0DgAN2AMy3JgWgdGX1L80rqAhO/BAXQXf1mWg33BiaVkx9KwqRbibyKWQo x-ms-exchange-antispam-messagedata: h0q+zGclz1P6c6N1Yho9ZvtgTX5NzY1xwS0HDxw4kBagTSF+yHf+IaMPABfASotx9UKFAus5x6rLHQLjF0D74/DwJErOQGM+KCBwcBUEqDea8RFTqvanZeE4k76cID2sbozzaFxY0ZRe/6lpoNpQ+Q== MIME-Version: 1.0 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB7PR08MB3611 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: AM5EUR03FT009.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)(396003)(136003)(346002)(39860400002)(376002)(189003)(199004)(8936002)(30864003)(9686003)(86362001)(26005)(2906002)(336012)(55016002)(8676002)(966005)(45080400002)(26826003)(478600001)(81166006)(81156014)(186003)(52536014)(110136005)(70586007)(7696005)(53546011)(70206006)(54906003)(6506007)(356004)(33656002)(5660300002)(4326008)(316002)(36906005)(142923001);DIR:OUT;SFP:1101;SCL:1;SRVR:PR2PR08MB4859;H:64aa7808-outbound-1.mta.getcheckrecipient.com;FPR:;SPF:Pass;LANG:en;PTR:ec2-63-35-35-123.eu-west-1.compute.amazonaws.com;MX:1;A:1; X-MS-Office365-Filtering-Correlation-Id-Prvs: 60d681af-422a-48d1-b942-08d7a8abbd20 X-Forefront-PRVS: 0302D4F392 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: uXuQbL0wd0IOvkSSXjbjhOofWDhWXPumxhvXHN6yxNyXS25wX9lIFNDnDMoB+NTPoJ3XkXmvR7M9rRIbhx6cAQcYilIR1BsMbr5D7JAtI1oY8MTZ5pOt78ClJ1Llp1nqk4NlH0vWDNmz922M7X/YYt4NJxpt+TGsYyfPBmBOSl/Wa9M3YXBQIc/eKdxW2bjaHZIs0fnYm6nFPhhZ5/rfUdhnlaYS8v0let8Vcr8t0SM6iBEr0RLUECTE+8FbWejbwS/vNSSNe95AXdoiLy0//FQ1VxVPEd/UyaRIVJtLKKAPEYhRTTrhZSoUTL7FkMCK9q3lPKjzuUn+PYcNfeGryDIx+r4GOb7N6Af2mpHXmEgh/zg7v1F277VqcQlDVP6NfkqTfmElj0vWz95PIbM3wMQuHjj7MAIviQL9ZHdvEKfihE2wPf1D3gRGMdFOePrlQisyf9QAWvj2eKnLQ3xEMSyQlhl4QpTw7RcQBtO45o1aiM0D1sIYKpGtRWK+f1T9c3SI93WLSTmhYswveaS204kuZnnVHZh0Yp5rrLFjV9DPCSDV4RWcWCz3lO8fRArf X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Feb 2020 13:19:53.0568 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: a6ffd873-556f-4c0d-f4b9-08d7a8abc142 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: PR2PR08MB4859 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Hello Liming, Currently, the only ACPI tables which contain AML bytecode are the DSDT an= d SSDT tables. We don't need to generate a ".hex" file for other ACPI table= s or any other file since we would like to parse AML bytecode. However this is only a safety check and this can be removed if desired. Regards, Pierre -----Original Message----- From: devel@edk2.groups.io On Behalf Of Liming Gao = via Groups.Io Sent: 03 February 2020 11:58 To: Pierre Gondois ; devel@edk2.groups.io Cc: ard.biesheuvel@linaro.org; Feng, Bob C ; Sami Mu= jawar ; nd Subject: Re: [edk2-devel] [PATCH v2 1/1] BaseTools: Script for converting = .aml to .hex Pierre: Sorry for late response. I have one comment. Why only allows "DSDT" or "= SSDT" in Signature? Thanks Liming > -----Original Message----- > From: Pierre Gondois > Sent: Thursday, January 23, 2020 1:32 AM > To: Pierre Gondois ; devel@edk2.groups.io > Cc: ard.biesheuvel@linaro.org; Feng, Bob C ;=20 > Gao, Liming ; Sami Mujawar=20 > ; nd > Subject: RE: [PATCH v2 1/1] BaseTools: Script for converting .aml to=20 > .hex >=20 > Hello everyone, > Do you have any input on the patch? >=20 > Regards, > Pierre >=20 > -----Original Message----- > From: PierreGondois > Sent: 17 January 2020 17:18 > To: devel@edk2.groups.io > Cc: Pierre Gondois ;=20 > ard.biesheuvel@linaro.org; bob.c.feng@intel.com; liming.gao@intel.com;= =20 > Sami Mujawar ; nd > Subject: [PATCH v2 1/1] BaseTools: Script for converting .aml to .hex >=20 > From: Pierre Gondois >=20 > The "-tc" option of the iasl compiler allows to generate a .hex file con= taining a C array storing AML bytecode. >=20 > An online discussion suggested that this "-tc" option was specific to=20 > the iasl compiler and it shouldn't be relied on. This conversation is av= ailable at: > https://edk2.groups.io/g/devel/topic/39786201#49659 >=20 > A way to address this issue is to implement a compiler independent scrip= t that takes an AML file as input, and generates a .hex file. >=20 > This patch implements a Python script that converts an AML file to a .he= x file, containing a C array storing AML bytecode. > This scipt has been tested with the AML output from the following compil= ers supported by the EDKII implementation: > * Intel ASL compiler > * Microsoft ASL compiler >=20 > Signed-off-by: Pierre Gondois > --- >=20 > The changes can be seen at=20 > https://github.com/PierreARM/edk2/commits/718_asl_to_hex_script_conver > ter_2 >=20 > Notes: > v2: > - Script converting AML to .hex file [Pierre] >=20 > BaseTools/BinWrappers/PosixLike/AmlToHex | 14 ++ > BaseTools/BinWrappers/WindowsLike/AmlToHex.bat | 3 + > BaseTools/Conf/build_rule.template | 3 + > BaseTools/Source/Python/AmlToHex/AmlToHex.py | 155 ++++++++++++++++++= ++ > 4 files changed, 175 insertions(+) >=20 > diff --git a/BaseTools/BinWrappers/PosixLike/AmlToHex=20 > b/BaseTools/BinWrappers/PosixLike/AmlToHex > new file mode 100755 > index=20 > 0000000000000000000000000000000000000000..1dd28e966288f6ea4fc52d42e2dc > 7b1f74226c23 > --- /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=20 > +to python if command -v ${PYTHON_COMMAND} >/dev/null 2>&1; then > + python_exe=3D${PYTHON_COMMAND} > +fi > + > +full_cmd=3D${BASH_SOURCE:-$0} # see > +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 > +"$full_cmd") > + > +export PYTHONPATH=3D"$dir/../../Source/Python${PYTHONPATH:+:"$PYTHONPAT= H"}" > +exec "${python_exe:-python}" "$dir/../../Source/Python/$exe/$exe.py" "$= @" > diff --git a/BaseTools/BinWrappers/WindowsLike/AmlToHex.bat=20 > b/BaseTools/BinWrappers/WindowsLike/AmlToHex.bat > new file mode 100644 > index=20 > 0000000000000000000000000000000000000000..9616cd893bec9902451e6d8591f5 > 37cc408bd5e5 > --- /dev/null > +++ b/BaseTools/BinWrappers/WindowsLike/AmlToHex.bat > @@ -0,0 +1,3 @@ > +@setlocal > +@set ToolName=3D%~n0% > +@%PYTHON_COMMAND% > +%BASE_TOOLS_PATH%\Source\Python\%ToolName%\%ToolName%.py %* > diff --git a/BaseTools/Conf/build_rule.template=20 > b/BaseTools/Conf/build_rule.template > index=20 > 51748bc0655a5c656258a3007b4db6b2dc941ea0..0822b681fcd9f61c6508e6f93ffc > 31fa70fd7059 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=20 > reserved.
# Portions copyright (c) 2008 - 2010, Apple Inc. All=20 > 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}=20 > $(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.i > $(OUTPUT_DIR)(+)${s_dir}(+)${s_= base}.iii > Trim --source-code -l -o $(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.i= iii $(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.iii > "$(ASL)" $(ASL_FLAGS) $(ASL_OUTFLAGS)${dst}=20 > $(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.iiii > + -AmlToHex $(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.aml >=20 > > Trim --asl-file --asl-deps -o $(OUTPUT_DIR)(+)${s_dir}(+)${s_ba= se}.i -i $(INC_LIST) ${src} > "$(ASLPP)" $(DEPS_FLAGS) $(ASLPP_FLAGS) $(INC) -I${s_path}=20 > $(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.i > $(OUTPUT_DIR)(+)${s_dir}(+)${s_= base}.iii > Trim --source-code -l -o $(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.i= iii $(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.iii > "$(ASL)" $(ASL_FLAGS) $(ASL_OUTFLAGS)${dst}=20 > $(OUTPUT_DIR)(+)${s_dir}(+)${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=20 > b/BaseTools/Source/Python/AmlToHex/AmlToHex.py > new file mode 100644 > index=20 > 0000000000000000000000000000000000000000..e8e7ace3a68532bc625afb1e7440 > 4c4e4b0205dd > --- /dev/null > +++ b/BaseTools/Source/Python/AmlToHex/AmlToHex.py > @@ -0,0 +1,155 @@ > +## @file > +# > +# Convert an AML file to a .hex file containing the AML bytecode=20 > +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= =20 > +contains # the AML bytecode. > +# > +# Copyright (c) 2020, ARM Limited. All rights reserved.
# # > +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 > + 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.error(__file__, PARAMETER_INVALID, > + ExtraData=3DArgs.InputFile, > + Message=3D"Error: Invalid file type. " = + \ > + "File does not have a valid " += \ > + "DSDT or SSDT signature.") > + > + # 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 director= y. > + 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 +=20 > + ".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 fil= e. > +# > +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= stored > +# 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() > + > + # Convert an AML file to a .hex file containing the AML bytecod= e stored > + # in a C array. > + AmlToHex(CommandArguments.InputFile, CommandArguments.OutputFil= e, > + 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)' >=20