From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) by mx.groups.io with SMTP id smtpd.web10.12465.1580997568669286506 for ; Thu, 06 Feb 2020 05:59:28 -0800 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: intel.com, ip: 134.134.136.31, mailfrom: bob.c.feng@intel.com) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga104.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 06 Feb 2020 05:59:28 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.70,409,1574150400"; d="scan'208";a="225014482" Received: from fmsmsx105.amr.corp.intel.com ([10.18.124.203]) by orsmga008.jf.intel.com with ESMTP; 06 Feb 2020 05:59:28 -0800 Received: from shsmsx601.ccr.corp.intel.com (10.109.6.141) by FMSMSX105.amr.corp.intel.com (10.18.124.203) with Microsoft SMTP Server (TLS) id 14.3.439.0; Thu, 6 Feb 2020 05:59:27 -0800 Received: from shsmsx601.ccr.corp.intel.com (10.109.6.141) by SHSMSX601.ccr.corp.intel.com (10.109.6.141) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1713.5; Thu, 6 Feb 2020 21:59:25 +0800 Received: from shsmsx601.ccr.corp.intel.com ([10.109.6.141]) by SHSMSX601.ccr.corp.intel.com ([10.109.6.141]) with mapi id 15.01.1713.004; Thu, 6 Feb 2020 21:59:25 +0800 From: "Bob Feng" To: "devel@edk2.groups.io" , "Feng, Bob C" , "pierre.gondois@arm.com" CC: "ard.biesheuvel@linaro.org" , "Gao, Liming" , "sami.mujawar@arm.com" , "nd@arm.com" Subject: Re: [edk2-devel] [PATCH v4 1/1] BaseTools: Script for converting .aml to .hex Thread-Topic: [edk2-devel] [PATCH v4 1/1] BaseTools: Script for converting .aml to .hex Thread-Index: AQHV3DPjEcmT+RdBwkOyQ3ORlb/jq6gN8kVwgABAkpA= Date: Thu, 6 Feb 2020 13:59:25 +0000 Message-ID: References: <20200205145203.39708-1-pierre.gondois@arm.com> <15F0C851F3A2C8A4.6836@groups.io> In-Reply-To: <15F0C851F3A2C8A4.6836@groups.io> Accept-Language: zh-CN, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-titus-metadata-40: eyJDYXRlZ29yeUxhYmVscyI6IiIsIk1ldGFkYXRhIjp7Im5zIjoiaHR0cDpcL1wvd3d3LnRpdHVzLmNvbVwvbnNcL0ludGVsMyIsImlkIjoiZDI2NWFlMzItNDc5Ni00ZDI0LTlkZjUtY2JlZmEyZTJhZDEzIiwicHJvcHMiOlt7Im4iOiJDVFBDbGFzc2lmaWNhdGlvbiIsInZhbHMiOlt7InZhbHVlIjoiQ1RQX05UIn1dfV19LCJTdWJqZWN0TGFiZWxzIjpbXSwiVE1DVmVyc2lvbiI6IjE3LjEwLjE4MDQuNDkiLCJUcnVzdGVkTGFiZWxIYXNoIjoicjRlUG42bWJmMDh6eVl6aWZFNE1aRUpQbk5hcDUrNlFDd3EyeldzNHJ4eExvXC9NQ2hxSVp5c2FmcU40XC9vTVh2In0= dlp-version: 11.2.0.6 dlp-product: dlpe-windows x-ctpclassification: CTP_NT dlp-reaction: no-action x-originating-ip: [10.239.127.36] MIME-Version: 1.0 Return-Path: bob.c.feng@intel.com Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Pushed.=20 -----Original Message----- From: devel@edk2.groups.io On Behalf Of Bob Feng Sent: Thursday, February 6, 2020 6:09 PM To: devel@edk2.groups.io; pierre.gondois@arm.com Cc: ard.biesheuvel@linaro.org; Gao, Liming ; sami.mu= jawar@arm.com; nd@arm.com Subject: Re: [edk2-devel] [PATCH v4 1/1] BaseTools: Script for converting = .aml to .hex Reviewed-by: Bob Feng -----Original Message----- From: devel@edk2.groups.io On Behalf Of PierreGondo= is Sent: Wednesday, February 5, 2020 10:52 PM To: devel@edk2.groups.io Cc: Pierre Gondois ; ard.biesheuvel@linaro.org; Fe= ng, Bob C ; Gao, Liming ; sami.= mujawar@arm.com; nd@arm.com Subject: [edk2-devel] [PATCH v4 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 conta= ining a C array storing AML bytecode. An online discussion suggested that this "-tc" option was specific to the = iasl 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 = that 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 = file, containing a C array storing AML bytecode. This scipt has been tested with the AML output from the following compiler= s 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_= to_hex_script_converter_v4 Notes: v4: - Replacing warning message by info message [Pierre] BaseTools/BinWrappers/PosixLike/AmlToHex | 14 ++ BaseTools/BinWrappers/WindowsLike/AmlToHex.bat | 3 + BaseTools/Conf/build_rule.template | 3 + BaseTools/Source/Python/AmlToHex/AmlToHex.py | 156 ++++++++++++++++++++ 4 files changed, 176 insertions(+) diff --git a/BaseTools/BinWrappers/PosixLike/AmlToHex b/BaseTools/BinWrapp= ers/PosixLike/AmlToHex new file mode 100755 index 0000000000000000000000000000000000000000..1dd28e966288f6ea4fc52d42e2= dc7b1f74226c23 --- /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 +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:+:"$PYTHONPATH"= }" +exec "${python_exe:-python}" "$dir/../../Source/Python/$exe/$exe.py" "$@" diff --git a/BaseTools/BinWrappers/WindowsLike/AmlToHex.bat b/BaseTools/Bi= nWrappers/WindowsLike/AmlToHex.bat new file mode 100644 index 0000000000000000000000000000000000000000..9616cd893bec9902451e6d8591= f537cc408bd5e5 --- /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 b/BaseTools/Conf/build_rul= e.template index 51748bc0655a5c656258a3007b4db6b2dc941ea0..0822b681fcd9f61c6508e6f93f= fc31fa70fd7059 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} $(OUTP= UT_DIR)(+)${s_dir}(+)${s_base}.i > $(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.iii Trim --source-code -l -o $(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.iii= i $(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.iii=20 "$(ASL)" $(ASL_FLAGS) $(ASL_OUTFLAGS)${dst} $(OUTPUT_DIR)(+)${s_d= ir}(+)${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} $(OUTP= UT_DIR)(+)${s_dir}(+)${s_base}.i > $(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.iii Trim --source-code -l -o $(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.iii= i $(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.iii=20 "$(ASL)" $(ASL_FLAGS) $(ASL_OUTFLAGS)${dst} $(OUTPUT_DIR)(+)${s_d= ir}(+)${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/Sour= ce/Python/AmlToHex/AmlToHex.py new file mode 100644 index 0000000000000000000000000000000000000000..643db2910e37acfdd80ac18d28= 8c921320a79ce1 --- /dev/null +++ b/BaseTools/Source/Python/AmlToHex/AmlToHex.py @@ -0,0 +1,156 @@ +## @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.
# # +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 AM= L " + \ + "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.info("Invalid file type. " + \ + "File does not have a valid " + \ + "DSDT or SSDT signature: %s" % Args.Input= File) + 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 s= tored +# 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 = stored + # 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)'