## @file\r
# Automate the process of building the various reset vector types\r
#\r
-# Copyright (c) 2009, Intel Corporation. All rights reserved.<BR>\r
+# Copyright (c) 2009 - 2021, Intel Corporation. All rights reserved.<BR>\r
#\r
# SPDX-License-Identifier: BSD-2-Clause-Patent\r
#\r
\r
-import glob\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
- #print ' '.join(commandLine)\r
return subprocess.call(commandLine)\r
\r
-for filename in glob.glob(os.path.join('Bin', '*.raw')):\r
- os.remove(filename)\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
- output = os.path.join('Bin', 'ResetVector')\r
- output += '.' + arch\r
- if debugType is not None:\r
- output += '.' + debugType\r
- output += '.raw'\r
- commandLine = (\r
- 'nasm',\r
- '-D', 'ARCH_%s' % arch.upper(),\r
- '-D', 'DEBUG_%s' % str(debugType).upper(),\r
- '-o', output,\r
- 'Vtf0.nasmb',\r
- )\r
- ret = RunCommand(commandLine)\r
- print '\tASM\t' + output\r
- if ret != 0: sys.exit(ret)\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
+ 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