From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from EUR05-AM6-obe.outbound.protection.outlook.com (EUR05-AM6-obe.outbound.protection.outlook.com [40.107.22.62]) by mx.groups.io with SMTP id smtpd.web11.3951.1579714337736009443 for ; Wed, 22 Jan 2020 09:32:18 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@armh.onmicrosoft.com header.s=selector2-armh-onmicrosoft-com header.b=vEIoSI5S; spf=pass (domain: arm.com, ip: 40.107.22.62, 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=5iKbcydhlgtvk0j8L0ge0+EiUpJxbMyXdF8H37T7oEs=; b=vEIoSI5SG/l83YMoVEoP9hXtXUNF332ugVIIP/ZMlPUc4+Pvk+kQ8LjrfEpoupAJc8ZRUxZT4GgOwZseLL98ZV+2r+qicEKXPDKeNWWzeLk7XwkwcASYkL8AB/QWPv8fswNTIpfwa58tHe/NIJ8CUdxYoA6dG03VuTbq0KJpZXM= Received: from VI1PR08CA0110.eurprd08.prod.outlook.com (2603:10a6:800:d4::12) by DB6PR0802MB2216.eurprd08.prod.outlook.com (2603:10a6:4:85::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2644.25; Wed, 22 Jan 2020 17:32:15 +0000 Received: from AM5EUR03FT007.eop-EUR03.prod.protection.outlook.com (2a01:111:f400:7e08::200) by VI1PR08CA0110.outlook.office365.com (2603:10a6:800:d4::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2665.19 via Frontend Transport; Wed, 22 Jan 2020 17:32:14 +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 AM5EUR03FT007.mail.protection.outlook.com (10.152.16.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2665.18 via Frontend Transport; Wed, 22 Jan 2020 17:32:14 +0000 Received: ("Tessian outbound 4f3bc9719026:v40"); Wed, 22 Jan 2020 17:32:14 +0000 X-CR-MTA-TID: 64aa7808 Received: from 8c0bc7745eff.3 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 7F4EC648-E313-4E7A-A43C-19C57CCAD6F5.1; Wed, 22 Jan 2020 17:32:09 +0000 Received: from EUR01-DB5-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 8c0bc7745eff.3 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Wed, 22 Jan 2020 17:32:09 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=GBsKa+K3qk58UA0053HZORT3J51JN48APCnrDOzs5DgBe3jpRyXZMy9p71CbLvJGC5G5v2TxsNyGCzb5l7LONMzokBJjyWC/yXclnBC1X9kgFj4zTC4TeCm0/CdFYt8Azib5GQX1ZTBOptQ1PHu3ZnaKyoX9kEemA8yrmULvJOisZg/Sycxu89D2Y45wREovYd0zHNLAg7Tgzh2ir8/4Wuu3Ptbdz94TyHkJkMu93BiRNrD++hNPP8C66BWdhlm86kMpHhgHgG6ffIsaj6zQ0ow0NmqfhTzAVwKVlM2eHB+bx8PdOzpLCsEvP7xF/1uJZkok0jTqeih+6AdHYv4cfQ== 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=5iKbcydhlgtvk0j8L0ge0+EiUpJxbMyXdF8H37T7oEs=; b=b8Y5tOYyLcqkVaWiuZCpUBvNPWiPszrKjjKaXI6ds7/9ygydg7SbFnYS01HNRNtq2bhVwW8nwEe/Yp4OTVDtDyJiCyuykA6B0YXuu7ll8tbBSYmnilIZdVLErdR+RqSSUtz/BPJjmWco52uebZ12Q74AGr52fKhmT057wikXK4AzCojZLzRaxVxL67I+DzW9wX3OVgsuOk/laga4lvDr8BUxZnM50KwlwdIJA3ujTwhHRMieADUft0TNh+n43PxfLjvKvw58t8IQAdLTht8IxtXhJXnPyIiSHTb9m1NQKsNPgoAUZf43334couudXkep0GPOD7onvKAH8eLHzzvWGw== 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=5iKbcydhlgtvk0j8L0ge0+EiUpJxbMyXdF8H37T7oEs=; b=vEIoSI5SG/l83YMoVEoP9hXtXUNF332ugVIIP/ZMlPUc4+Pvk+kQ8LjrfEpoupAJc8ZRUxZT4GgOwZseLL98ZV+2r+qicEKXPDKeNWWzeLk7XwkwcASYkL8AB/QWPv8fswNTIpfwa58tHe/NIJ8CUdxYoA6dG03VuTbq0KJpZXM= Received: from DB7PR08MB3113.eurprd08.prod.outlook.com (52.134.111.149) by DB7PR08MB3452.eurprd08.prod.outlook.com (20.177.120.13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2644.23; Wed, 22 Jan 2020 17:32:06 +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.2644.027; Wed, 22 Jan 2020 17:32:06 +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 v2 1/1] BaseTools: Script for converting .aml to .hex Thread-Topic: [PATCH v2 1/1] BaseTools: Script for converting .aml to .hex Thread-Index: AQHVzVoPj34q6on+IkSh2c5wuHYPHaf2+PTQ Date: Wed, 22 Jan 2020 17:32:06 +0000 Message-ID: References: <20200117171734.10924-1-pierre.gondois@arm.com> In-Reply-To: <20200117171734.10924-1-pierre.gondois@arm.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ts-tracking-id: ce704b85-a6be-431d-a1d2-e1efef52765e.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: 274827f1-b073-4dd1-f407-08d79f610560 X-MS-TrafficTypeDiagnostic: DB7PR08MB3452:|DB7PR08MB3452:|DB6PR0802MB2216: x-ms-exchange-transport-forked: True X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true nodisclaimer: True x-ms-oob-tlc-oobclassifiers: OLM:655;OLM:655; x-forefront-prvs: 029097202E X-Forefront-Antispam-Report-Untrusted: SFV:NSPM;SFS:(10009020)(4636009)(366004)(346002)(39860400002)(136003)(396003)(376002)(199004)(189003)(66556008)(66446008)(55016002)(66946007)(66476007)(76116006)(64756008)(9686003)(4326008)(110136005)(54906003)(45080400002)(966005)(316002)(2906002)(186003)(7696005)(6506007)(33656002)(478600001)(8936002)(71200400001)(86362001)(26005)(81166006)(53546011)(5660300002)(8676002)(81156014)(52536014)(142923001);DIR:OUT;SFP:1101;SCL:1;SRVR:DB7PR08MB3452;H:DB7PR08MB3113.eurprd08.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;A:1;MX: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: Chqw8Puhphgr7wdnl+qI13V5pClt5cv7wz4OrjnKGxLf00O2DlAJSGr3U5uY5tHDwrj5ZY5tqQscllt30EXQ/2l3g2zukDWGy239kI4iyf9FnPmOz43nTgZ77iv2WiJP0AUXhdCCP6tPawuvXljIYzn/e/3dHIk4Hx/Pl742ydsY4F2cwKQ76sP5fs4HTtwlZvRyyqv9MZJldZ83uvNAaA5kl0OTtuCelS6Yd5td09Lu/krXubLW13VA2Q+6TWnHXnqPZKODwq9YZPsL3GH7JcoRH8m22EaTBhaFN1Whrhu/9+2KKHQ7XvQ0lx5MmYxEUuR6ZGWDffYrhOInNM+6rESAaDVJm4ENaJCco236Q7TRNoJwoRV2NJBQNn4hy8pF5NaPA4T/pS5Zxpi9lj3mKfvcw5ZGkNOgNpWywnb8AF3FkUUB39giYwSYAhyODa5fE++L3Dql+kA8Lv8OyHTDsinVGqvfHkDrLOEq9LzOK511VCQl85V/cAbQxoEHueTV4sDRyKz6XXQZwRiYNnIc9A== MIME-Version: 1.0 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB7PR08MB3452 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: AM5EUR03FT007.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)(39860400002)(376002)(346002)(189003)(199004)(70586007)(70206006)(26826003)(966005)(478600001)(2906002)(336012)(45080400002)(53546011)(6506007)(52536014)(33656002)(186003)(86362001)(26005)(4326008)(81156014)(110136005)(7696005)(316002)(8676002)(5660300002)(36906005)(81166006)(55016002)(356004)(54906003)(8936002)(9686003)(142923001);DIR:OUT;SFP:1101;SCL:1;SRVR:DB6PR0802MB2216;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: 0fe5402c-5dd0-444f-a379-08d79f610098 X-Forefront-PRVS: 029097202E X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: gRcM5UyiyI5FgQzbcJLydIbvcju5vG6uu9bPBgm6bIQdO8erY7dCMG1vUGovF8Q0wGiDQUFoTUSH+4gYBuv9WpthekiKcYrQoT5OAb1gMxv9ZbosghQECtHifuByEuoeP48yAowC1jx2BQf9vp3BDrSnfjWnqAEDU4tvwcQdZ68bsqCJdlfzbx2p9R+78adONtGIQAKKabpIdiZ5FA+jvFNckiVl8VujRkUxE7+SdtQKFKrnrrUfwlncxy/bs+5W7y0dk8+eK6f30zRXTcG9NqMpulVDNnKPPLZ8T39feciR9wI19OuvttM90AeNupBF0UCCzjcOZcG4Uxn5zIDJqfgaLv+g3QhsYcS62jvQD8D/kAwVh/oCrHNuZqWgsLhd9MU0AUGv/oYbDW+Z0lY115NEo3f2dQZqZpZpL5t0Bqq2U/oUqvi00FjwfxeaSUD1yPhgvJnYqgr3Ps5MvE5PrE1RBIlb+BaidJce9Gr7OV0pzmlyok4nfI6/KLZzkflZmODtFtJTHNtlTKHOqAWhUw== X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Jan 2020 17:32:14.6408 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 274827f1-b073-4dd1-f407-08d79f610560 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: DB6PR0802MB2216 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Hello everyone, Do you have any input on the patch? Regards, Pierre -----Original Message----- From: PierreGondois =20 Sent: 17 January 2020 17:18 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 v2 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/commits/718_as= l_to_hex_script_converter_2 Notes: v2: - Script converting AML to .hex file [Pierre] 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(+) 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..e8e7ace3a68532bc625afb1e744= 04c4e4b0205dd --- /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 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 + 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 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() + + # 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)'