-## @file
-# Automate the process of building the various reset vector types
-#
-# Copyright (c) 2009, Intel Corporation
-#
-# All rights reserved. This program and the accompanying materials
-# are licensed and made available under the terms and conditions of the BSD License
-# which accompanies this distribution. The full text of the license may be found at
-# http://opensource.org/licenses/bsd-license.php
-#
-# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
-# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
-#
-
-import glob
-import os
-import subprocess
-import sys
-
-def RunCommand(commandLine):
- #print ' '.join(commandLine)
- return subprocess.call(commandLine)
-
-for filename in glob.glob(os.path.join('Bin', '*.raw')):
- os.remove(filename)
-
-for arch in ('ia32', 'x64'):
- for debugType in (None, 'port80', 'serial'):
- output = os.path.join('Bin', 'ResetVector')
- output += '.' + arch
- if debugType is not None:
- output += '.' + debugType
- output += '.raw'
- commandLine = (
- 'nasm',
- '-D', 'ARCH_%s' % arch.upper(),
- '-D', 'DEBUG_%s' % str(debugType).upper(),
- '-o', output,
- 'ResetVectorCode.asm',
- )
- ret = RunCommand(commandLine)
- print '\tASM\t' + output
- if ret != 0: sys.exit(ret)
-
- commandLine = (
- 'python',
- 'Tools/FixupForRawSection.py',
- output,
- )
- print '\tFIXUP\t' + output
- ret = RunCommand(commandLine)
- if ret != 0: sys.exit(ret)
-
+## @file\r
+# Automate the process of building the various reset vector types\r
+#\r
+# Copyright (c) 2009 - 2021, Intel Corporation. All rights reserved.<BR>\r
+#\r
+# SPDX-License-Identifier: BSD-2-Clause-Patent\r
+#\r
+\r
+import os\r
+import subprocess\r
+import sys\r
+\r
+PAGE_TABLE_2M = 'PageTable2M'\r
+PAGE_TABLE_1G = 'PageTable1G'\r
+FILE_FORMAT = '.raw'\r
+ALL_RAW_FORMAT = '*' + FILE_FORMAT\r
+IA32 = 'IA32'\r
+X64 = 'X64'\r
+\r
+# Pre-Define a Macros for Page Table\r
+PAGE_TABLES = {\r
+ PAGE_TABLE_2M : "PAGE_TABLE_2M",\r
+ PAGE_TABLE_1G : "PAGE_TABLE_1G"\r
+}\r
+\r
+def RunCommand(commandLine):\r
+ return subprocess.call(commandLine)\r
+\r
+# Check for all raw binaries and delete them\r
+for root, dirs, files in os.walk('Bin'):\r
+ for file in files:\r
+ if file.endswith(FILE_FORMAT):\r
+ os.remove(os.path.join(root, file))\r
+\r
+for arch in ('ia32', 'x64'):\r
+ for debugType in (None, 'port80', 'serial'):\r
+ for pageTable in PAGE_TABLES.keys():\r
+ ret = True\r
+ if arch.lower() == X64.lower():\r
+ directory = os.path.join('Bin', X64, pageTable)\r
+ else:\r
+ directory = os.path.join('Bin', IA32)\r
+\r
+ # output raw binary name with arch type\r
+ fileName = 'ResetVector' + '.' + arch\r
+\r
+ if debugType is not None:\r
+ fileName += '.' + debugType\r
+ fileName += FILE_FORMAT\r
+\r
+ output = os.path.join(directory, fileName)\r
+\r
+ # if the directory not exists then create it\r
+ if not os.path.isdir(directory):\r
+ os.makedirs(directory)\r
+\r
+ # Prepare the command to execute the nasmb\r
+ commandLine = (\r
+ 'nasm',\r
+ '-D', 'ARCH_%s' % arch.upper(),\r
+ '-D', 'DEBUG_%s' % str(debugType).upper(),\r
+ '-D', PAGE_TABLES[pageTable].upper(),\r
+ '-o', output,\r
+ 'Vtf0.nasmb',\r
+ )\r
+\r
+ print(f"Command : {' '.join(commandLine)}")\r
+\r
+ try:\r
+ ret = RunCommand(commandLine)\r
+ except FileNotFoundError:\r
+ print("NASM not found")\r
+ except:\r
+ pass\r
+\r
+ if ret != 0:\r
+ print(f"something went wrong while executing {commandLine[-1]}")\r
+ sys.exit()\r
+ print('\tASM\t' + output)\r
+\r
+ commandLine = (\r
+ 'python',\r
+ 'Tools/FixupForRawSection.py',\r
+ output,\r
+ )\r
+ print('\tFIXUP\t' + output)\r
+ ret = RunCommand(commandLine)\r
+ if ret != 0: sys.exit(ret)\r
+\r