VirtualBox

Ignore:
Timestamp:
Aug 14, 2024 1:16:30 PM (9 months ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
164367
Message:

Devices/EFI/FirmwareNew: Merge edk2-stable-202405 and make it build on aarch64, bugref:4643

Location:
trunk/src/VBox/Devices/EFI/FirmwareNew
Files:
32 added
43 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/EFI/FirmwareNew

  • trunk/src/VBox/Devices/EFI/FirmwareNew/BaseTools/Conf/target.template

    r80721 r105670  
    5252#                                             If not specified, all applicable TagName tools will be
    5353#                                             used for the build.  The list uses space character separation.
    54 TOOL_CHAIN_TAG        = VS2015x86
     54TOOL_CHAIN_TAG        = VS2019
    5555
    5656# MAX_CONCURRENT_THREAD_NUMBER  NUMBER  Optional  The number of concurrent threads. If not specified or set
  • trunk/src/VBox/Devices/EFI/FirmwareNew/BaseTools/Conf/tools_def.template

    r101291 r105670  
    18601860DEFINE CLANGDWARF_X64_TARGET              = -target x86_64-pc-linux-gnu
    18611861
    1862 DEFINE CLANGDWARF_WARNING_OVERRIDES    = -Wno-parentheses-equality -Wno-tautological-compare -Wno-tautological-constant-out-of-range-compare -Wno-empty-body -Wno-unused-const-variable -Wno-varargs -Wno-unknown-warning-option -Wno-unused-but-set-variable -Wno-unused-const-variable -Wno-unaligned-access -Wno-unneeded-internal-declaration
     1862DEFINE CLANGDWARF_WARNING_OVERRIDES    = -Wno-parentheses-equality -Wno-empty-body -Wno-unused-const-variable -Wno-varargs -Wno-unknown-warning-option -Wno-unused-but-set-variable -Wno-unused-const-variable -Wno-unaligned-access -Wno-unneeded-internal-declaration
    18631863DEFINE CLANGDWARF_ALL_CC_FLAGS         = DEF(GCC48_ALL_CC_FLAGS) DEF(CLANGDWARF_WARNING_OVERRIDES) -fno-stack-protector -mms-bitfields -Wno-address -Wno-shift-negative-value -Wno-unknown-pragmas -Wno-incompatible-library-redeclaration -fno-asynchronous-unwind-tables -mno-sse -mno-mmx -msoft-float -mno-implicit-float  -ftrap-function=undefined_behavior_has_been_optimized_away_by_clang -funsigned-char -fno-ms-extensions -Wno-null-dereference
    18641864
     
    20162016*_CLANGDWARF_AARCH64_VFRPP_FLAGS    = DEF(GCC_VFRPP_FLAGS) DEF(CLANGDWARF_AARCH64_TARGET) $(PLATFORM_FLAGS)
    20172017*_CLANGDWARF_AARCH64_ASLPP_FLAGS    = DEF(GCC_ASLPP_FLAGS) DEF(CLANGDWARF_AARCH64_TARGET)
    2018 *_CLANGDWARF_AARCH64_CC_XIPFLAGS    = DEF(GCC_AARCH64_CC_XIPFLAGS)
     2018*_CLANGDWARF_AARCH64_CC_XIPFLAGS    = -mstrict-align
    20192019
    20202020  DEBUG_CLANGDWARF_AARCH64_CC_FLAGS    = DEF(CLANGDWARF_AARCH64_CC_FLAGS) $(PLATFORM_FLAGS) -flto -O1
  • trunk/src/VBox/Devices/EFI/FirmwareNew/BaseTools/Scripts/GetMaintainer.py

    r99404 r105670  
    7777       matching the provided path in the provided section."""
    7878    maintainers = []
     79    reviewers = []
    7980    lists = []
    8081    nowarn_status = ['Supported', 'Maintained']
     
    8485            if status not in nowarn_status:
    8586                print('WARNING: Maintained status for "%s" is \'%s\'!' % (path, status))
    86         for address in section['maintainer'], section['reviewer']:
     87        for address in section['maintainer']:
    8788            # Convert to list if necessary
    8889            if isinstance(address, list):
    8990                maintainers += address
    9091            else:
    91                 lists += [address]
     92                maintainers += [address]
     93        for address in section['reviewer']:
     94            # Convert to list if necessary
     95            if isinstance(address, list):
     96                reviewers += address
     97            else:
     98                reviewers += [address]
    9299        for address in section['list']:
    93100            # Convert to list if necessary
     
    97104                lists += [address]
    98105
    99     return maintainers, lists
     106    return {'maintainers': maintainers, 'reviewers': reviewers, 'lists': lists}
    100107
    101108def get_maintainers(path, sections, level=0):
     
    103110       for matching ones."""
    104111    maintainers = []
     112    reviewers = []
    105113    lists = []
    106114    for section in sections:
    107         tmp_maint, tmp_lists = get_section_maintainers(path, section)
    108         if tmp_maint:
    109             maintainers += tmp_maint
    110         if tmp_lists:
    111             lists += tmp_lists
     115        recipients = get_section_maintainers(path, section)
     116        maintainers += recipients['maintainers']
     117        reviewers += recipients['reviewers']
     118        lists += recipients['lists']
    112119
    113120    if not maintainers:
     
    116123        print('"%s": no maintainers found, looking for default' % path)
    117124        if level == 0:
    118             maintainers = get_maintainers('<default>', sections, level=level + 1)
     125            recipients = get_maintainers('<default>', sections, level=level + 1)
     126            maintainers += recipients['maintainers']
     127            reviewers += recipients['reviewers']
     128            lists += recipients['lists']
    119129        else:
    120130            print("No <default> maintainers set for project.")
     
    122132            return None
    123133
    124     return maintainers + lists
     134    return {'maintainers': maintainers, 'reviewers': reviewers, 'lists': lists}
    125135
    126136def parse_maintainers_line(line):
     
    183193        FILES = get_modified_files(REPO, ARGS)
    184194
    185     ADDRESSES = []
    186 
     195    # Accumulate a sorted list of addresses
     196    ADDRESSES = set([])
    187197    for file in FILES:
    188198        print(file)
    189         addresslist = get_maintainers(file, SECTIONS)
    190         if addresslist:
    191             ADDRESSES += addresslist
    192 
    193     for address in list(OrderedDict.fromkeys(ADDRESSES)):
     199        recipients = get_maintainers(file, SECTIONS)
     200        ADDRESSES |= set(recipients['maintainers'] + recipients['reviewers'] + recipients['lists'])
     201    ADDRESSES = list(ADDRESSES)
     202    ADDRESSES.sort()
     203
     204    for address in ADDRESSES:
    194205        if '<' in address and '>' in address:
    195206            address = address.split('>', 1)[0] + '>'
  • trunk/src/VBox/Devices/EFI/FirmwareNew/BaseTools/Scripts/GetUtcDateTime.py

    r80721 r105670  
    3030        PARSER.print_help()
    3131
    32     today = datetime.datetime.utcnow()
     32    today = datetime.datetime.now(datetime.timezone.utc)
    3333    if ARGS.year:
    3434        ReversedNumber = str(today.year)[::-1]
  • trunk/src/VBox/Devices/EFI/FirmwareNew/BaseTools/Scripts/PatchCheck.py

    r101291 r105670  
    44#  Copyright (c) 2015 - 2021, Intel Corporation. All rights reserved.<BR>
    55#  Copyright (C) 2020, Red Hat, Inc.<BR>
    6 #  Copyright (c) 2020, ARM Ltd. All rights reserved.<BR>
     6#  Copyright (c) 2020 - 2023, Arm Limited. All rights reserved.<BR>
    77#
    88#  SPDX-License-Identifier: BSD-2-Clause-Patent
     
    2727    level = NORMAL
    2828
     29class PatchCheckConf:
     30    ignore_change_id = False
     31    ignore_multi_package = False
     32
    2933class EmailAddressCheck:
    3034    """Checks an email address."""
     
    8387                       mo.group(3))
    8488
    85         if ' via Groups.Io' in name and mo.group(3).endswith('@groups.io'):
     89        if mo.group(3) == '[email protected]':
    8690            self.error("Email rewritten by lists DMARC / DKIM / SPF: " +
    8791                       email)
    8892
     93        if ' via groups.io' in name.lower() and mo.group(3).endswith('@groups.io'):
     94            self.error("Email rewritten by lists DMARC / DKIM / SPF: " +
     95                       email)
     96
    8997class CommitMessageCheck:
    9098    """Checks the contents of a git commit message."""
     
    92100    def __init__(self, subject, message, author_email):
    93101        self.ok = True
     102        self.ignore_multi_package = False
    94103
    95104        if subject is None and  message is None:
     
    112121            self.check_misc_signatures()
    113122            self.check_overall_format()
     123            if not PatchCheckConf.ignore_change_id:
     124                self.check_change_id_format()
     125            self.check_ci_options_format()
    114126        self.report_message_result()
    115127
     
    194206                self.error("There should be a space after '" + sig + ":'")
    195207
    196             EmailAddressCheck(s[3], sig)
     208            self.ok &= EmailAddressCheck(s[3], sig).ok
    197209
    198210        return sigs
     
    221233
    222234    def check_misc_signatures(self):
    223         for sig in self.sig_types:
    224             self.find_signatures(sig)
     235        for sigtype in self.sig_types:
     236            sigs = self.find_signatures(sigtype)
     237            if sigtype == 'Cc' and len(sigs) == 0:
     238                self.error('No Cc: tags for maintainers/reviewers found!')
    225239
    226240    cve_re = re.compile('CVE-[0-9]{4}-[0-9]{5}[^0-9]')
     
    308322            last_sig_line = line.strip()
    309323
     324    def check_change_id_format(self):
     325        cid='Change-Id:'
     326        if self.msg.find(cid) != -1:
     327            self.error('\"%s\" found in commit message:' % cid)
     328            return
     329
     330    def check_ci_options_format(self):
     331        cio='Continuous-integration-options:'
     332        for line in self.msg.splitlines():
     333            if not line.startswith(cio):
     334                continue
     335            options = line.split(':', 1)[1].split()
     336            if 'PatchCheck.ignore-multi-package' in options:
     337                self.ignore_multi_package = True
     338
    310339(START, PRE_PATCH, PATCH) = range(3)
    311340
     
    364393                self.force_crlf = True
    365394                self.force_notabs = True
     395                if self.filename.endswith('.rtf'):
     396                    self.force_crlf = False
     397                    self.force_notabs = False
    366398                if self.filename.endswith('.sh') or \
    367399                    self.filename.startswith('BaseTools/BinWrappers/PosixLike/') or \
     
    417449            self.line_num += 1
    418450        elif self.state == PATCH:
    419             if self.binary:
     451            if self.binary or self.filename.endswith(".rtf"):
    420452                pass
    421453            elif line.startswith('-'):
     
    542574        msg_check = CommitMessageCheck(self.commit_subject, self.commit_msg, self.author_email)
    543575        msg_ok = msg_check.ok
     576        self.ignore_multi_package = msg_check.ignore_multi_package
    544577
    545578        diff_ok = True
     
    652685
    653686    def __init__(self, rev_spec, max_count):
     687        dec_files = self.read_dec_files_from_git()
    654688        commits = self.read_commit_list_from_git(rev_spec, max_count)
    655689        if len(commits) == 1 and Verbose.level > Verbose.ONELINE:
     
    667701            self.ok &= EmailAddressCheck(email, 'Committer').ok
    668702            patch = self.read_patch_from_git(commit)
    669             self.ok &= CheckOnePatch(commit, patch).ok
     703            check_patch = CheckOnePatch(commit, patch)
     704            self.ok &= check_patch.ok
     705            ignore_multi_package = check_patch.ignore_multi_package
     706            if PatchCheckConf.ignore_multi_package:
     707                ignore_multi_package = True
     708            prefix = 'WARNING: ' if ignore_multi_package else ''
     709            check_parent = self.check_parent_packages (dec_files, commit, prefix)
     710            if not ignore_multi_package:
     711                self.ok &= check_parent
     712
    670713        if not commits:
    671714            print("Couldn't find commit matching: '{}'".format(rev_spec))
     715
     716    def check_parent_packages(self, dec_files, commit, prefix):
     717        ok = True
     718        modified = self.get_parent_packages (dec_files, commit, 'AM')
     719        if len (modified) > 1:
     720            print("{}The commit adds/modifies files in multiple packages:".format(prefix))
     721            print(" *", '\n * '.join(modified))
     722            ok = False
     723        deleted = self.get_parent_packages (dec_files, commit, 'D')
     724        if len (deleted) > 1:
     725            print("{}The commit deletes files from multiple packages:".format(prefix))
     726            print(" *", '\n * '.join(deleted))
     727            ok = False
     728        return ok
     729
     730    def get_parent_packages(self, dec_files, commit, filter):
     731        filelist = self.read_files_modified_from_git (commit, filter)
     732        parents = set()
     733        for file in filelist:
     734            dec_found = False
     735            for dec_file in dec_files:
     736                if os.path.commonpath([dec_file, file]):
     737                    dec_found = True
     738                    parents.add(dec_file)
     739            if not dec_found and os.path.dirname (file):
     740                # No DEC file found and file is in a subdir
     741                # Covers BaseTools, .github, .azurepipelines, .pytool
     742                parents.add(file.split('/')[0])
     743        return list(parents)
     744
     745    def read_dec_files_from_git(self):
     746        # run git ls-files *.dec
     747        out = self.run_git('ls-files', '*.dec')
     748        # return list of .dec files
     749        try:
     750            return out.split()
     751        except:
     752            return []
     753
     754    def read_files_modified_from_git(self, commit, filter):
     755        # run git diff-tree --no-commit-id --name-only -r <commit>
     756        out = self.run_git('diff-tree', '--no-commit-id', '--name-only',
     757                           '--diff-filter=' + filter, '-r', commit)
     758        try:
     759            return out.split()
     760        except:
     761            return []
    672762
    673763    def read_commit_list_from_git(self, rev_spec, max_count):
     
    778868                           action="store_true",
    779869                           help="Print nothing")
     870        group.add_argument("--ignore-change-id",
     871                           action="store_true",
     872                           help="Ignore the presence of 'Change-Id:' tags in commit message")
     873        group.add_argument("--ignore-multi-package",
     874                           action="store_true",
     875                           help="Ignore if commit modifies files in multiple packages")
    780876        self.args = parser.parse_args()
    781877        if self.args.oneline:
     
    783879        if self.args.silent:
    784880            Verbose.level = Verbose.SILENT
     881        if self.args.ignore_change_id:
     882            PatchCheckConf.ignore_change_id = True
     883        if self.args.ignore_multi_package:
     884            PatchCheckConf.ignore_multi_package = True
    785885
    786886if __name__ == "__main__":
  • trunk/src/VBox/Devices/EFI/FirmwareNew/BaseTools/Source/C/GenFv/GenFvInternalLib.c

    r101291 r105670  
    117117};
    118118
    119 //
    120 // This data array will be located at the base of the Firmware Volume Header (FVH)
    121 // in the boot block.  It must not exceed 14 bytes of code.  The last 2 bytes
    122 // will be used to keep the FVH checksum consistent.
    123 // This code will be run in response to a startup IPI for HT-enabled systems.
    124 //
    125 #define SIZEOF_STARTUP_DATA_ARRAY 0x10
    126 
    127 UINT8                                   m128kRecoveryStartupApDataArray[SIZEOF_STARTUP_DATA_ARRAY] = {
    128   //
    129   // EA D0 FF 00 F0               ; far jmp F000:FFD0
    130   // 0, 0, 0, 0, 0, 0, 0, 0, 0,   ; Reserved bytes
    131   // 0, 0                         ; Checksum Padding
    132   //
    133   0xEA,
    134   0xD0,
    135   0xFF,
    136   0x0,
    137   0xF0,
    138   0x00,
    139   0x00,
    140   0x00,
    141   0x00,
    142   0x00,
    143   0x00,
    144   0x00,
    145   0x00,
    146   0x00,
    147   0x00,
    148   0x00
    149 };
    150 
    151 UINT8                                   m64kRecoveryStartupApDataArray[SIZEOF_STARTUP_DATA_ARRAY] = {
    152   //
    153   // EB CE                               ; jmp short ($-0x30)
    154   // ; (from offset 0x0 to offset 0xFFD0)
    155   // 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ; Reserved bytes
    156   // 0, 0                                ; Checksum Padding
    157   //
    158   0xEB,
    159   0xCE,
    160   0x00,
    161   0x00,
    162   0x00,
    163   0x00,
    164   0x00,
    165   0x00,
    166   0x00,
    167   0x00,
    168   0x00,
    169   0x00,
    170   0x00,
    171   0x00,
    172   0x00,
    173   0x00
    174 };
    175 
    176119FV_INFO                     mFvDataInfo;
    177120CAP_INFO                    mCapDataInfo;
     
    15691512  INT32                     Ia32SecEntryOffset;
    15701513  UINT32                    *Ia32ResetAddressPtr;
    1571   UINT8                     *BytePointer;
    1572   UINT8                     *BytePointer2;
    1573   UINT16                    *WordPointer;
    1574   UINT16                    CheckSum;
    1575   UINT32                    IpiVector;
    1576   UINTN                     Index;
    15771514  EFI_FFS_FILE_STATE        SavedState;
    15781515  BOOLEAN                   Vtf0Detected;
     
    17461683    *Ia32ResetAddressPtr  = (UINT32) (FvInfo->BaseAddress);
    17471684    DebugMsg (NULL, 0, 9, "update BFV base address in the top FV image", "BFV base address = 0x%llX.", (unsigned long long) FvInfo->BaseAddress);
    1748 
    1749     //
    1750     // Update the Startup AP in the FVH header block ZeroVector region.
    1751     //
    1752     BytePointer   = (UINT8 *) ((UINTN) FvImage->FileImage);
    1753     if (FvInfo->Size <= 0x10000) {
    1754       BytePointer2 = m64kRecoveryStartupApDataArray;
    1755     } else if (FvInfo->Size <= 0x20000) {
    1756       BytePointer2 = m128kRecoveryStartupApDataArray;
    1757     } else {
    1758       BytePointer2 = m128kRecoveryStartupApDataArray;
    1759       //
    1760       // Find the position to place Ap reset vector, the offset
    1761       // between the position and the end of Fvrecovery.fv file
    1762       // should not exceed 128kB to prevent Ap reset vector from
    1763       // outside legacy E and F segment
    1764       //
    1765       Status = FindApResetVectorPosition (FvImage, &BytePointer);
    1766       if (EFI_ERROR (Status)) {
    1767         Error (NULL, 0, 3000, "Invalid", "FV image does not have enough space to place AP reset vector. The FV image needs to reserve at least 4KB of unused space.");
    1768         return EFI_ABORTED;
    1769       }
    1770     }
    1771 
    1772     for (Index = 0; Index < SIZEOF_STARTUP_DATA_ARRAY; Index++) {
    1773       BytePointer[Index] = BytePointer2[Index];
    1774     }
    1775     //
    1776     // Calculate the checksum
    1777     //
    1778     CheckSum              = 0x0000;
    1779     WordPointer = (UINT16 *) (BytePointer);
    1780     for (Index = 0; Index < SIZEOF_STARTUP_DATA_ARRAY / 2; Index++) {
    1781       CheckSum = (UINT16) (CheckSum + ((UINT16) *WordPointer));
    1782       WordPointer++;
    1783     }
    1784     //
    1785     // Update the checksum field
    1786     //
    1787     WordPointer   = (UINT16 *) (BytePointer + SIZEOF_STARTUP_DATA_ARRAY - 2);
    1788     *WordPointer  = (UINT16) (0x10000 - (UINT32) CheckSum);
    1789 
    1790     //
    1791     // IpiVector at the 4k aligned address in the top 2 blocks in the PEI FV.
    1792     //
    1793     IpiVector  = (UINT32) (FV_IMAGES_TOP_ADDRESS - ((UINTN) FvImage->Eof - (UINTN) BytePointer));
    1794     DebugMsg (NULL, 0, 9, "Startup AP Vector address", "IpiVector at 0x%X", (unsigned) IpiVector);
    1795     if ((IpiVector & 0xFFF) != 0) {
    1796       Error (NULL, 0, 3000, "Invalid", "Startup AP Vector address are not 4K aligned, because the FV size is not 4K aligned");
    1797       return EFI_ABORTED;
    1798     }
    1799     IpiVector  = IpiVector >> 12;
    1800     IpiVector  = IpiVector & 0xFF;
    1801 
    1802     //
    1803     // Write IPI Vector at Offset FvrecoveryFileSize - 8
    1804     //
    1805     Ia32ResetAddressPtr   = (UINT32 *) ((UINTN) FvImage->Eof - 8);
    1806     *Ia32ResetAddressPtr  = IpiVector;
    18071685  } else if (MachineType == IMAGE_FILE_MACHINE_ARMTHUMB_MIXED) {
    18081686    //
     
    41924070
    41934071EFI_STATUS
    4194 FindApResetVectorPosition (
    4195   IN  MEMORY_FILE  *FvImage,
    4196   OUT UINT8        **Pointer
    4197   )
    4198 /*++
    4199 
    4200 Routine Description:
    4201 
    4202   Find the position in this FvImage to place Ap reset vector.
    4203 
    4204 Arguments:
    4205 
    4206   FvImage       Memory file for the FV memory image.
    4207   Pointer       Pointer to pointer to position.
    4208 
    4209 Returns:
    4210 
    4211   EFI_NOT_FOUND   - No satisfied position is found.
    4212   EFI_SUCCESS     - The suitable position is return.
    4213 
    4214 --*/
    4215 {
    4216   EFI_FFS_FILE_HEADER   *PadFile;
    4217   UINT32                Index;
    4218   EFI_STATUS            Status;
    4219   UINT8                 *FixPoint;
    4220   UINT32                FileLength;
    4221 
    4222   for (Index = 1; ;Index ++) {
    4223     //
    4224     // Find Pad File to add ApResetVector info
    4225     //
    4226     Status = GetFileByType (EFI_FV_FILETYPE_FFS_PAD, Index, &PadFile);
    4227     if (EFI_ERROR (Status) || (PadFile == NULL)) {
    4228       //
    4229       // No Pad file to be found.
    4230       //
    4231       break;
    4232     }
    4233     //
    4234     // Get Pad file size.
    4235     //
    4236     FileLength = GetFfsFileLength(PadFile);
    4237     FileLength = (FileLength + EFI_FFS_FILE_HEADER_ALIGNMENT - 1) & ~(EFI_FFS_FILE_HEADER_ALIGNMENT - 1);
    4238     //
    4239     // FixPoint must be align on 0x1000 relative to FvImage Header
    4240     //
    4241     FixPoint = (UINT8*) PadFile + GetFfsHeaderLength(PadFile);
    4242     FixPoint = FixPoint + 0x1000 - (((UINTN) FixPoint - (UINTN) FvImage->FileImage) & 0xFFF);
    4243     //
    4244     // FixPoint be larger at the last place of one fv image.
    4245     //
    4246     while (((UINTN) FixPoint + SIZEOF_STARTUP_DATA_ARRAY - (UINTN) PadFile) <= FileLength) {
    4247       FixPoint += 0x1000;
    4248     }
    4249     FixPoint -= 0x1000;
    4250 
    4251     if ((UINTN) FixPoint < ((UINTN) PadFile + GetFfsHeaderLength(PadFile))) {
    4252       //
    4253       // No alignment FixPoint in this Pad File.
    4254       //
    4255       continue;
    4256     }
    4257 
    4258     if ((UINTN) FvImage->Eof - (UINTN)FixPoint <= 0x20000) {
    4259       //
    4260       // Find the position to place ApResetVector
    4261       //
    4262       *Pointer = FixPoint;
    4263       return EFI_SUCCESS;
    4264     }
    4265   }
    4266 
    4267   return EFI_NOT_FOUND;
    4268 }
    4269 
    4270 EFI_STATUS
    42714072ParseCapInf (
    42724073  IN  MEMORY_FILE  *InfFile,
  • trunk/src/VBox/Devices/EFI/FirmwareNew/BaseTools/Source/C/GenFw/Elf64Convert.c

    r101291 r105670  
    15751575            // relocation) into an ADD instruction - this is handled above.
    15761576            //
    1577             Offset = (Sym->st_value - (Rel->r_offset & ~0xfff)) >> 12;
     1577            // In order to handle Cortex-A53 erratum #843419, the GCC toolchain
     1578            // may convert an ADRP instruction at the end of a page (0xffc
     1579            // offset) into an ADR instruction. If so, be sure to calculate the
     1580            // offset for an ADR instead of ADRP.
     1581            //
     1582            if ((*(UINT32 *)Targ & BIT31) == 0) {
     1583              //
     1584              // Calculate the offset for an ADR.
     1585              //
     1586              Offset = (Sym->st_value & ~0xfff) - Rel->r_offset;
     1587              if (Offset < -0x100000 || Offset > 0xfffff) {
     1588                Error (NULL, 0, 3000, "Invalid", "WriteSections64(): %s  due to its size (> 1 MB), unable to relocate ADR.",
     1589                  mInImageName);
     1590                break;
     1591              }
     1592            } else {
     1593              //
     1594              // Calculate the offset for an ADRP.
     1595              //
     1596              Offset = (Sym->st_value - (Rel->r_offset & ~0xfff)) >> 12;
     1597            }
    15781598
    15791599            *(UINT32 *)Targ &= 0x9000001f;
     
    17911811          case R_LARCH_TLS_GD_PC_HI20:
    17921812          case R_LARCH_TLS_GD64_HI20:
     1813          case R_LARCH_32_PCREL:
    17931814          case R_LARCH_RELAX:
     1815          case R_LARCH_DELETE:
     1816          case R_LARCH_ALIGN:
     1817          case R_LARCH_PCREL20_S2:
     1818          case R_LARCH_CFA:
     1819          case R_LARCH_ADD6:
     1820          case R_LARCH_SUB6:
     1821          case R_LARCH_ADD_ULEB128:
     1822          case R_LARCH_SUB_ULEB128:
     1823          case R_LARCH_64_PCREL:
    17941824            //
    17951825            // These types are not used or do not require fixup.
     
    21982228              case R_LARCH_TLS_GD_PC_HI20:
    21992229              case R_LARCH_TLS_GD64_HI20:
     2230              case R_LARCH_32_PCREL:
    22002231              case R_LARCH_RELAX:
     2232              case R_LARCH_DELETE:
     2233              case R_LARCH_ALIGN:
     2234              case R_LARCH_PCREL20_S2:
     2235              case R_LARCH_CFA:
     2236              case R_LARCH_ADD6:
     2237              case R_LARCH_SUB6:
     2238              case R_LARCH_ADD_ULEB128:
     2239              case R_LARCH_SUB_ULEB128:
     2240              case R_LARCH_64_PCREL:
    22012241                //
    22022242                // These types are not used or do not require fixup in PE format files.
  • trunk/src/VBox/Devices/EFI/FirmwareNew/BaseTools/Source/C/GenFw/GenFw.c

    r101291 r105670  
    9191BOOLEAN mIsConvertXip = FALSE;
    9292BOOLEAN mExportFlag = FALSE;
     93BOOLEAN mNoNxCompat = FALSE;
    9394
    9495STATIC
     
    286287                        This option can be used together with -e.\n\
    287288                        It doesn't work for other options.\n");
     289  fprintf (stdout, "  --nonxcompat          Do not set the IMAGE_DLLCHARACTERISTICS_NX_COMPAT bit \n\
     290                        of the optional header in the PE header even if the \n\
     291                        requirements are met.\n");
    288292  fprintf (stdout, "  -v, --verbose         Turn on verbose output with informational messages.\n");
    289293  fprintf (stdout, "  -q, --quiet           Disable all messages except key message and fatal error\n");
     
    444448
    445449  return STATUS_SUCCESS;
     450}
     451
     452/**
     453
     454  Checks if the Pe image is nxcompat compliant.
     455
     456  Must meet the following conditions:
     457  1. The PE is 64bit
     458  2. The section alignment is evenly divisible by 4k
     459  3. No section is writable and executable.
     460
     461  @param  PeHdr     - The PE header
     462
     463  @retval TRUE      - The PE is nx compat compliant
     464  @retval FALSE     - The PE is not nx compat compliant
     465
     466**/
     467STATIC
     468BOOLEAN
     469IsNxCompatCompliant (
     470  EFI_IMAGE_OPTIONAL_HEADER_UNION  *PeHdr
     471  )
     472{
     473  EFI_IMAGE_SECTION_HEADER     *SectionHeader;
     474  UINT32                       Index;
     475  UINT32                       Mask;
     476
     477  // Must have an optional header to perform verification
     478  if (PeHdr->Pe32.FileHeader.SizeOfOptionalHeader == 0) {
     479    return FALSE;
     480  }
     481
     482  // Verify PE is 64 bit
     483  if (!(PeHdr->Pe32.OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC)) {
     484    return FALSE;
     485  }
     486
     487  // Verify Section Alignment is divisible by 4K
     488  if (!((PeHdr->Pe32Plus.OptionalHeader.SectionAlignment % EFI_PAGE_SIZE) == 0)) {
     489    return FALSE;
     490  }
     491
     492  // Verify sections are not Write & Execute
     493  Mask = EFI_IMAGE_SCN_MEM_EXECUTE | EFI_IMAGE_SCN_MEM_WRITE;
     494  SectionHeader = (EFI_IMAGE_SECTION_HEADER *) ((UINT8 *) &(PeHdr->Pe32Plus.OptionalHeader) + PeHdr->Pe32Plus.FileHeader.SizeOfOptionalHeader);
     495  for (Index = 0; Index < PeHdr->Pe32Plus.FileHeader.NumberOfSections; Index ++, SectionHeader ++) {
     496    if ((SectionHeader->Characteristics & Mask) == Mask) {
     497      return FALSE;
     498    }
     499  }
     500
     501  // Passed all requirements, return TRUE
     502  return TRUE;
    446503}
    447504
     
    14571514    }
    14581515
     1516    if (stricmp (argv[0], "--nonxcompat") == 0) {
     1517      mNoNxCompat = TRUE;
     1518      argc --;
     1519      argv ++;
     1520      continue;
     1521    }
     1522
    14591523    if (argv[0][0] == '-') {
    14601524      Error (NULL, 0, 1000, "Unknown option", argv[0]);
     
    24632527    TEImageHeader.ImageBase           = (UINT64) (Optional64->ImageBase);
    24642528
     2529    // Set NxCompat flag
     2530    if (IsNxCompatCompliant (PeHdr) && !mNoNxCompat) {
     2531      Optional64->DllCharacteristics |= IMAGE_DLLCHARACTERISTICS_NX_COMPAT;
     2532    }
     2533
    24652534    if (Optional64->NumberOfRvaAndSizes > EFI_IMAGE_DIRECTORY_ENTRY_BASERELOC) {
    24662535      TEImageHeader.DataDirectory[EFI_TE_IMAGE_DIRECTORY_ENTRY_BASERELOC].VirtualAddress = Optional64->DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_BASERELOC].VirtualAddress;
  • trunk/src/VBox/Devices/EFI/FirmwareNew/BaseTools/Source/C/GenFw/elf_common.h

    r101291 r105670  
    11451145#define R_LARCH_TLS_GD_PC_HI20             97
    11461146#define R_LARCH_TLS_GD64_HI20              98
    1147 #define R_LARCH_RELAX                      99
     1147#define R_LARCH_32_PCREL                   99
     1148#define R_LARCH_RELAX                      100
     1149#define R_LARCH_DELETE                     101
     1150#define R_LARCH_ALIGN                      102
     1151#define R_LARCH_PCREL20_S2                 103
     1152#define R_LARCH_CFA                        104
     1153#define R_LARCH_ADD6                       105
     1154#define R_LARCH_SUB6                       106
     1155#define R_LARCH_ADD_ULEB128                107
     1156#define R_LARCH_SUB_ULEB128                108
     1157#define R_LARCH_64_PCREL                   109
     1158
    11481159#endif /* !_SYS_ELF_COMMON_H_ */
  • trunk/src/VBox/Devices/EFI/FirmwareNew/BaseTools/Source/C/Include/Common/UefiInternalFormRepresentation.h

    r85718 r105670  
    15571557  EfiKeyPrint,
    15581558  EfiKeySLck,
    1559   EfiKeyPause
     1559  EfiKeyPause,
     1560  EfiKeyIntl0,
     1561  EfiKeyIntl1,
     1562  EfiKeyIntl2,
     1563  EfiKeyIntl3,
     1564  EfiKeyIntl4,
     1565  EfiKeyIntl5,
     1566  EfiKeyIntl6,
     1567  EfiKeyIntl7,
     1568  EfiKeyIntl8,
     1569  EfiKeyIntl9
    15601570} EFI_KEY;
    15611571
  • trunk/src/VBox/Devices/EFI/FirmwareNew/BaseTools/Source/Python/AmlToC/AmlToC.py

    r89983 r105670  
    1818import os
    1919
    20 __description__ = """
     20__description__ = r"""
    2121Convert an AML file to a .c file containing the AML bytecode stored in a C
    2222array. By default, Tables\Dsdt.aml will generate Tables\Dsdt.c.
  • trunk/src/VBox/Devices/EFI/FirmwareNew/BaseTools/Source/Python/AutoGen/BuildEngine.py

    r99404 r105670  
    307307
    308308    _PATH_SEP = "(+)"
    309     _FileTypePattern = re.compile("^[_a-zA-Z][_\-0-9a-zA-Z]*$")
     309    _FileTypePattern = re.compile(r"^[_a-zA-Z][_\-0-9a-zA-Z]*$")
    310310    _BinaryFileRule = FileBuildRule(TAB_DEFAULT_BINARY_FILE, [], [os.path.join("$(OUTPUT_DIR)", "${s_name}")],
    311311                                    ["$(CP) ${src} ${dst}"], [])
  • trunk/src/VBox/Devices/EFI/FirmwareNew/BaseTools/Source/Python/AutoGen/GenC.py

    r89983 r105670  
    13721372        if Info.ModuleType in [SUP_MODULE_BASE, SUP_MODULE_SEC, SUP_MODULE_USER_DEFINED, SUP_MODULE_HOST_APPLICATION]:
    13731373            AutoGenC.Append(gLibraryString[SUP_MODULE_BASE].Replace(Dict))
     1374            if Info.ModuleType == SUP_MODULE_SEC and Info.AutoGenVersion >= 0x0001001E:
     1375                AutoGenH.Append(("\n"
     1376                                 "// ProcessLibraryConstructorList() declared here because SEC has no standard entry point.\n"
     1377                                 "VOID\n"
     1378                                 "EFIAPI\n"
     1379                                 "ProcessLibraryConstructorList (\n"
     1380                                 "  VOID\n"
     1381                                 "  );\n"))
    13741382        elif Info.ModuleType in SUP_MODULE_SET_PEI:
    13751383            AutoGenC.Append(gLibraryString['PEI'].Replace(Dict))
  • trunk/src/VBox/Devices/EFI/FirmwareNew/BaseTools/Source/Python/AutoGen/GenDepex.py

    r80721 r105670  
    127127    # open and close brace must be taken as individual tokens
    128128    #
    129     TokenPattern = re.compile("(\(|\)|\{[^{}]+\{?[^{}]+\}?[ ]*\}|\w+)")
     129    TokenPattern = re.compile(r"(\(|\)|\{[^{}]+\{?[^{}]+\}?[ ]*\}|\w+)")
    130130
    131131    ## Constructor
  • trunk/src/VBox/Devices/EFI/FirmwareNew/BaseTools/Source/Python/AutoGen/GenMake.py

    r99404 r105670  
    2929
    3030## Regular expression for matching macro used in header file inclusion
    31 gMacroPattern = re.compile("([_A-Z][_A-Z0-9]*)[ \t]*\((.+)\)", re.UNICODE)
     31gMacroPattern = re.compile("([_A-Z][_A-Z0-9]*)[ \t]*\\((.+)\\)", re.UNICODE)
    3232
    3333gIsFileMap = {}
  • trunk/src/VBox/Devices/EFI/FirmwareNew/BaseTools/Source/Python/AutoGen/IdfClassObject.py

    r80721 r105670  
    1919from .UniClassObject import StripComments
    2020
    21 IMAGE_TOKEN = re.compile('IMAGE_TOKEN *\(([A-Z0-9_]+) *\)', re.MULTILINE | re.UNICODE)
     21IMAGE_TOKEN = re.compile(r'IMAGE_TOKEN *\(([A-Z0-9_]+) *\)', re.MULTILINE | re.UNICODE)
    2222
    2323#
  • trunk/src/VBox/Devices/EFI/FirmwareNew/BaseTools/Source/Python/AutoGen/ModuleAutoGen.py

    r99404 r105670  
    5252# Match name = variable
    5353#
    54 gEfiVarStoreNamePattern = re.compile("\s*name\s*=\s*(\w+)")
     54gEfiVarStoreNamePattern = re.compile(r"\s*name\s*=\s*(\w+)")
    5555#
    5656# The format of guid in efivarstore statement likes following and must be correct:
    5757# guid = {0xA04A27f4, 0xDF00, 0x4D42, {0xB5, 0x52, 0x39, 0x51, 0x13, 0x02, 0x11, 0x3D}}
    5858#
    59 gEfiVarStoreGuidPattern = re.compile("\s*guid\s*=\s*({.*?{.*?}\s*})")
     59gEfiVarStoreGuidPattern = re.compile(r"\s*guid\s*=\s*({.*?{.*?}\s*})")
    6060
    6161#
  • trunk/src/VBox/Devices/EFI/FirmwareNew/BaseTools/Source/Python/AutoGen/PlatformAutoGen.py

    r89983 r105670  
    708708        self._DynamicPcdList.sort()
    709709        allskuset = [(SkuName, Sku.SkuId) for pcd in self._DynamicPcdList for (SkuName, Sku) in pcd.SkuInfoList.items()]
     710        # Remove duplicate sets in the list
     711        allskuset = list(set(allskuset))
    710712        for pcd in self._DynamicPcdList:
    711713            if len(pcd.SkuInfoList) == 1:
  • trunk/src/VBox/Devices/EFI/FirmwareNew/BaseTools/Source/Python/AutoGen/StrGather.py

    r80721 r105670  
    5555CHAR_ARRAY_DEFIN = 'unsigned char'
    5656COMMON_FILE_NAME = 'Strings'
    57 STRING_TOKEN = re.compile('STRING_TOKEN *\(([A-Z0-9_]+) *\)', re.MULTILINE | re.UNICODE)
     57STRING_TOKEN = re.compile(r'STRING_TOKEN *\(([A-Z0-9_]+) *\)', re.MULTILINE | re.UNICODE)
    5858
    5959EFI_HII_ARRAY_SIZE_LENGTH = 4
  • trunk/src/VBox/Devices/EFI/FirmwareNew/BaseTools/Source/Python/AutoGen/WorkspaceAutoGen.py

    r89983 r105670  
    2727
    2828## Regular expression for splitting Dependency Expression string into tokens
    29 gDepexTokenPattern = re.compile("(\(|\)|\w+| \S+\.inf)")
     29gDepexTokenPattern = re.compile(r"(\(|\)|\w+| \S+\.inf)")
    3030
    3131## Regular expression for match: PCD(xxxx.yyy)
     
    161161    def CollectPlatformGuids(self):
    162162        oriInfList = []
    163         oriPkgSet = set()
    164         PlatformPkg = set()
     163        pkgSet = set()
    165164        for Arch in self.ArchList:
    166165            Platform = self.BuildDatabase[self.MetaFile, Arch, self.BuildTarget, self.ToolChain]
     
    168167            for ModuleFile in oriInfList:
    169168                ModuleData = self.BuildDatabase[ModuleFile, Platform._Arch, Platform._Target, Platform._Toolchain]
    170                 oriPkgSet.update(ModuleData.Packages)
    171                 for Pkg in oriPkgSet:
    172                     Guids = Pkg.Guids
    173                     GlobalData.gGuidDict.update(Guids)
     169                pkgSet.update(ModuleData.Packages)
    174170            if Platform.Packages:
    175                 PlatformPkg.update(Platform.Packages)
    176                 for Pkg in PlatformPkg:
    177                     Guids = Pkg.Guids
    178                     GlobalData.gGuidDict.update(Guids)
     171                pkgSet.update(Platform.Packages)
     172        for Pkg in pkgSet:
     173            Guids = Pkg.Guids
     174            GlobalData.gGuidDict.update(Guids)
    179175
    180176    @cached_property
     
    440436            for mb in [self.BuildDatabase[m, Arch, self.BuildTarget, self.ToolChain] for m in Platform.Modules]:
    441437                PkgSet.update(mb.Packages)
     438
     439            for lb in [self.BuildDatabase[l, Arch, self.BuildTarget, self.ToolChain] for l in Platform.LibraryInstances]:
     440                PkgSet.update(lb.Packages)
     441
    442442            for Inf in ModuleList:
    443443                ModuleFile = PathClass(NormPath(Inf), GlobalData.gWorkspace, Arch)
     
    969969    def CreateAsBuiltInf(self):
    970970        return
    971 
  • trunk/src/VBox/Devices/EFI/FirmwareNew/BaseTools/Source/Python/Common/Expression.py

    r99404 r105670  
    4242
    4343__ValidString = re.compile(r'[_a-zA-Z][_0-9a-zA-Z]*$')
    44 _ReLabel = re.compile('LABEL\((\w+)\)')
    45 _ReOffset = re.compile('OFFSET_OF\((\w+)\)')
     44_ReLabel = re.compile(r'LABEL\((\w+)\)')
     45_ReOffset = re.compile(r'OFFSET_OF\((\w+)\)')
    4646PcdPattern = re.compile(r'^[_a-zA-Z][0-9A-Za-z_]*\.[_a-zA-Z][0-9A-Za-z_]*$')
    4747
     
    243243
    244244    SymbolPattern = re.compile("("
    245                                  "\$\([A-Z][A-Z0-9_]*\)|\$\(\w+\.\w+\)|\w+\.\w+|"
    246                                  "&&|\|\||!(?!=)|"
    247                                  "(?<=\W)AND(?=\W)|(?<=\W)OR(?=\W)|(?<=\W)NOT(?=\W)|(?<=\W)XOR(?=\W)|"
    248                                  "(?<=\W)EQ(?=\W)|(?<=\W)NE(?=\W)|(?<=\W)GT(?=\W)|(?<=\W)LT(?=\W)|(?<=\W)GE(?=\W)|(?<=\W)LE(?=\W)"
     245                                 r"\$\([A-Z][A-Z0-9_]*\)|\$\(\w+\.\w+\)|\w+\.\w+|"
     246                                 r"&&|\|\||!(?!=)|"
     247                                 r"(?<=\W)AND(?=\W)|(?<=\W)OR(?=\W)|(?<=\W)NOT(?=\W)|(?<=\W)XOR(?=\W)|"
     248                                 r"(?<=\W)EQ(?=\W)|(?<=\W)NE(?=\W)|(?<=\W)GT(?=\W)|(?<=\W)LT(?=\W)|(?<=\W)GE(?=\W)|(?<=\W)LE(?=\W)"
    249249                               ")")
    250250
     
    738738            return self._Token
    739739        elif Expr.startswith('UINT'):
    740             Re = re.compile('(?:UINT8|UINT16|UINT32|UINT64)\((.+)\)')
     740            Re = re.compile(r'(?:UINT8|UINT16|UINT32|UINT64)\((.+)\)')
    741741            try:
    742742                RetValue = Re.search(Expr).group(1)
     
    976976                                if Item.startswith(TAB_GUID) and Item.endswith(')'):
    977977                                    try:
    978                                         TokenSpaceGuidName = re.search('GUID\((\w+)\)', Item).group(1)
     978                                        TokenSpaceGuidName = re.search(r'GUID\((\w+)\)', Item).group(1)
    979979                                    except:
    980980                                        pass
  • trunk/src/VBox/Devices/EFI/FirmwareNew/BaseTools/Source/Python/Common/GlobalData.py

    r99404 r105670  
    3434
    3535# definition for a MACRO name.  used to create regular expressions below.
    36 _MacroNamePattern = "[A-Z][A-Z0-9_]*"
     36_MacroNamePattern = r"[A-Z][A-Z0-9_]*"
    3737
    3838## Regular expression for matching macro used in DSC/DEC/INF file inclusion
    39 gMacroRefPattern = re.compile("\$\(({})\)".format(_MacroNamePattern), re.UNICODE)
     39gMacroRefPattern = re.compile(r"\$\(({})\)".format(_MacroNamePattern), re.UNICODE)
    4040gMacroDefPattern = re.compile("^(DEFINE|EDK_GLOBAL)[ \t]+")
    4141gMacroNamePattern = re.compile("^{}$".format(_MacroNamePattern))
  • trunk/src/VBox/Devices/EFI/FirmwareNew/BaseTools/Source/Python/Common/Misc.py

    r100498 r105670  
    4242import struct
    4343
    44 ArrayIndex = re.compile("\[\s*[0-9a-fA-FxX]*\s*\]")
     44ArrayIndex = re.compile(r"\[\s*[0-9a-fA-FxX]*\s*\]")
    4545## Regular expression used to find out place holders in string template
    46 gPlaceholderPattern = re.compile("\$\{([^$()\s]+)\}", re.MULTILINE | re.UNICODE)
     46gPlaceholderPattern = re.compile(r"\$\{([^$()\s]+)\}", re.MULTILINE | re.UNICODE)
    4747
    4848## regular expressions for map file processing
    49 startPatternGeneral = re.compile("^Start[' ']+Length[' ']+Name[' ']+Class")
    50 addressPatternGeneral = re.compile("^Address[' ']+Publics by Value[' ']+Rva\+Base")
    51 valuePatternGcc = re.compile('^([\w_\.]+) +([\da-fA-Fx]+) +([\da-fA-Fx]+)$')
    52 pcdPatternGcc = re.compile('^([\da-fA-Fx]+) +([\da-fA-Fx]+)')
    53 secReGeneral = re.compile('^([\da-fA-F]+):([\da-fA-F]+) +([\da-fA-F]+)[Hh]? +([.\w\$]+) +(\w+)', re.UNICODE)
     49startPatternGeneral = re.compile(r"^Start[' ']+Length[' ']+Name[' ']+Class")
     50addressPatternGeneral = re.compile(r"^Address[' ']+Publics by Value[' ']+Rva\+Base")
     51valuePatternGcc = re.compile(r'^([\w_\.]+) +([\da-fA-Fx]+) +([\da-fA-Fx]+)$')
     52pcdPatternGcc = re.compile(r'^([\da-fA-Fx]+) +([\da-fA-Fx]+)')
     53secReGeneral = re.compile(r'^([\da-fA-F]+):([\da-fA-F]+) +([\da-fA-F]+)[Hh]? +([.\w\$]+) +(\w+)', re.UNICODE)
    5454
    5555StructPattern = re.compile(r'[_a-zA-Z][0-9A-Za-z_]*$')
     
    111111    if len(lines) == 0: return None
    112112    firstline = lines[0].strip()
    113     if re.match('^\s*Address\s*Size\s*Align\s*Out\s*In\s*Symbol\s*$', firstline):
     113    if re.match(r'^\s*Address\s*Size\s*Align\s*Out\s*In\s*Symbol\s*$', firstline):
    114114        return _parseForXcodeAndClang9(lines, efifilepath, varnames)
    115115    if (firstline.startswith("Archive member included ") and
     
    125125    for line in lines:
    126126        line = line.strip()
    127         if status == 0 and (re.match('^\s*Address\s*Size\s*Align\s*Out\s*In\s*Symbol\s*$', line) \
     127        if status == 0 and (re.match(r'^\s*Address\s*Size\s*Align\s*Out\s*In\s*Symbol\s*$', line) \
    128128            or line == "# Symbols:"):
    129129            status = 1
     
    133133                if varname in line:
    134134                    # cannot pregenerate this RegEx since it uses varname from varnames.
    135                     m = re.match('^([\da-fA-FxX]+)([\s\S]*)([_]*%s)$' % varname, line)
     135                    m = re.match(r'^([\da-fA-FxX]+)([\s\S]*)([_]*%s)$' % varname, line)
    136136                    if m is not None:
    137137                        ret.append((varname, m.group(1)))
     
    199199    secs  = []    # key = section name
    200200    varoffset = []
    201     symRe = re.compile('^([\da-fA-F]+):([\da-fA-F]+) +([\.:\\\\\w\?@\$-]+) +([\da-fA-F]+)', re.UNICODE)
     201    symRe = re.compile(r'^([\da-fA-F]+):([\da-fA-F]+) +([\.:\\\\\w\?@\$-]+) +([\da-fA-F]+)', re.UNICODE)
    202202
    203203    for line in lines:
     
    19551955#
    19561956def RemoveCComments(ctext):
    1957     return re.sub('//.*?\n|/\*.*?\*/', '\n', ctext, flags=re.S)
     1957    return re.sub('//.*?\n|/\\*.*?\\*/', '\n', ctext, flags=re.S)
  • trunk/src/VBox/Devices/EFI/FirmwareNew/BaseTools/Source/Python/Common/ToolDefClassObject.py

    r89983 r105670  
    3131# Static variables used for pattern
    3232#
    33 gMacroRefPattern = re.compile('(DEF\([^\(\)]+\))')
    34 gEnvRefPattern = re.compile('(ENV\([^\(\)]+\))')
    35 gMacroDefPattern = re.compile("DEFINE\s+([^\s]+)")
     33gMacroRefPattern = re.compile(r'(DEF\([^\(\)]+\))')
     34gEnvRefPattern = re.compile(r'(ENV\([^\(\)]+\))')
     35gMacroDefPattern = re.compile(r"DEFINE\s+([^\s]+)")
    3636gDefaultToolsDefFile = "tools_def.txt"
    3737
  • trunk/src/VBox/Devices/EFI/FirmwareNew/BaseTools/Source/Python/FMMT/FMMT.py

    r99404 r105670  
    3838                        Currently supports two formats: json, txt. More formats will be added in the future")
    3939parser.add_argument("-c", "--ConfigFilePath", dest="ConfigFilePath", nargs='+',
    40                     help="Provide the target FmmtConf.ini file path: '-c C:\Code\FmmtConf.ini' \
     40                    help="Provide the target FmmtConf.ini file path: '-c C:\\Code\\FmmtConf.ini' \
    4141                        FmmtConf file saves the target guidtool used in compress/uncompress process.\
    4242                        If do not provide, FMMT tool will search the inputfile folder for FmmtConf.ini firstly, if not found,\
     
    8585        elif filetype == '.sec':
    8686            ROOT_TYPE = ROOT_SECTION_TREE
     87        elif filetype == '.elf':
     88            ROOT_TYPE = ROOT_ELF_TREE
    8789        else:
    8890            ROOT_TYPE = ROOT_TREE
  • trunk/src/VBox/Devices/EFI/FirmwareNew/BaseTools/Source/Python/FMMT/core/BinaryFactoryProduct.py

    r99404 r105670  
    1616
    1717ROOT_TREE = 'ROOT'
     18ROOT_ELF_TREE = 'ROOT_ELF_TREE'
    1819ROOT_FV_TREE = 'ROOT_FV_TREE'
    1920ROOT_FFS_TREE = 'ROOT_FFS_TREE'
    2021ROOT_SECTION_TREE = 'ROOT_SECTION_TREE'
    2122
     23ELF_TREE = 'ELF'
     24ELF_SECTION_TREE = 'ELF_SECTION_TREE'
    2225FV_TREE = 'FV'
    2326DATA_FV_TREE = 'DATA_FV'
     
    4952    def ParserData():
    5053        pass
     54
     55class ElfFactory(BinaryFactory):
     56    type = [ROOT_ELF_TREE, ELF_TREE]
     57
     58    def Create_Product():
     59        return ElfProduct()
    5160
    5261class SectionFactory(BinaryFactory):
     
    355364        return Fd_Struct
    356365
     366class ElfSectionProduct(BinaryProduct):
     367    ## Decompress the compressed section.
     368    def ParserData(self, Section_Tree, whole_Data: bytes, Rel_Whole_Offset: int=0) -> None:
     369        pass
     370    def ParserSectionData(self, Section_Tree, whole_Data: bytes, Rel_Whole_Offset: int=0) -> None:
     371        pass
     372    def ParserProgramData(self, Section_Tree, whole_Data: bytes, Rel_Whole_Offset: int=0) -> None:
     373        pass
     374
     375class ElfProduct(BinaryProduct):
     376
     377    def ParserData(self, ParTree, Whole_Data: bytes, Rel_Whole_Offset: int=0) -> None:
     378        Elf_Info = ElfNode(Whole_Data)
     379        if Elf_Info.Header.ELF_PHOff != 0:
     380            Elf_Info.GetProgramList(Whole_Data[Elf_Info.Header.ELF_PHOff:])
     381        if Elf_Info.Header.ELF_SHOff != 0:
     382            Elf_Info.GetSectionList(Whole_Data[Elf_Info.Header.ELF_SHOff:])
     383            Elf_Info.FindUPLDSection(Whole_Data)
     384        Elf_Tree = BIOSTREE(Elf_Info.Name)
     385        Elf_Tree.type = ELF_TREE
     386        Elf_Info.Data = Whole_Data[Elf_Info.HeaderLength:]
     387        Elf_Tree.Data = Elf_Info
     388        ParTree.insertChild(Elf_Tree)
     389
    357390class ParserEntry():
    358391    FactoryTable:dict = {
     
    365398        ROOT_FV_TREE: FdFactory,
    366399        ROOT_TREE: FdFactory,
     400        ROOT_ELF_TREE: ElfFactory,
    367401    }
    368402
  • trunk/src/VBox/Devices/EFI/FirmwareNew/BaseTools/Source/Python/FMMT/core/BiosTree.py

    r99404 r105670  
    1313ROOT_FFS_TREE = 'ROOT_FFS_TREE'
    1414ROOT_SECTION_TREE = 'ROOT_SECTION_TREE'
     15ROOT_ELF_TREE = 'ROOT_ELF_TREE'
    1516
    1617FV_TREE = 'FV'
     
    2223SEC_FV_TREE = 'SEC_FV_IMAGE'
    2324BINARY_DATA = 'BINARY'
     25ELF_TREE = 'ELF'
    2426
    2527RootType = [ROOT_TREE, ROOT_FV_TREE, ROOT_FFS_TREE, ROOT_SECTION_TREE]
     
    2729FfsType = FFS_TREE
    2830SecType = SECTION_TREE
     31ElfType = [ROOT_ELF_TREE, ELF_TREE]
    2932
    3033class BIOSTREE:
     
    5760            self.Child.append(newNode)
    5861        else:
    59             if not pos:
     62            if not pos or pos == len(self.Child):
    6063                LastTree = self.Child[-1]
    6164                self.Child.append(newNode)
     
    119122            Info.append("FilesNum: {}".format(TargetDict.get(Key).get('FilesNum')))
    120123            Info.append("\n")
     124        elif TargetDict[Key]["Type"] == ROOT_ELF_TREE:
     125            Info.append("ELF File: {}\n".format(Key))
     126        elif TargetDict[Key]["Type"] == ELF_TREE:
     127            ProducerId = ""
     128            ImageId = ""
     129            if TargetDict.get(Key).get('IfExist'):
     130                Identifier = TargetDict.get(Key).get('Identifier')
     131                for item in TargetDict.get(Key).get('ProducerId'):
     132                    ProducerId += chr(item)
     133                for item in TargetDict.get(Key).get('ImageId'):
     134                    ImageId += chr(item)
     135                Info.append("- UNIVERSAL_PAYLOAD_INFO")
     136                Info.append("  - 4 bytes align: {}".format(TargetDict.get(Key).get('Upld_Info_Align')))
     137                Info.append("    - Identifier: {}  # 0x48444c50--PLDH / 0x444c5055--UPLD".format(hex(Identifier)))
     138                Info.append("    - SpecRevision: {}".format(hex(TargetDict.get(Key).get('SpecRevision'))))
     139                Info.append("    - Attribute: {}".format(hex(TargetDict.get(Key).get('Attribute'))))
     140                Info.append("    - Revision: {}".format(hex(TargetDict.get(Key).get('Revision'))))
     141                Info.append("    - Capability: {}".format(hex(TargetDict.get(Key).get('Capability'))))
     142                Info.append("    - ProducerId: {}".format(ProducerId))
     143                Info.append("    - ImageId: {}".format(ImageId))
     144                Info.append("\n")
     145                Info.append("- UPLD buffer")
     146                Info.append("  Buffer: {}".format(TargetDict.get(Key).get('Upld_Buffer')))
     147            else:
     148                print("Do not find the Upld Info section!!!\n")
    121149        elif TargetDict[Key]["Type"] in FvType:
    122150            space += 2
     
    147175            TreeInfo =collections.OrderedDict()
    148176
    149         if self.type == ROOT_TREE or self.type == ROOT_FV_TREE or self.type == ROOT_FFS_TREE or self.type == ROOT_SECTION_TREE:
     177        if self.type == ROOT_TREE or self.type == ROOT_FV_TREE or self.type == ROOT_FFS_TREE or self.type == ROOT_SECTION_TREE or self.type == ROOT_ELF_TREE:
    150178            key = str(self.key)
    151179            TreeInfo[self.key] = collections.OrderedDict()
     
    153181            TreeInfo[self.key]["Type"] = self.type
    154182            TreeInfo[self.key]["FilesNum"] = len(self.Child)
    155         elif self.type == FV_TREE or  self.type == SEC_FV_TREE:
     183        elif self.type == ELF_TREE:
     184            key = str(self.Data.Name)
     185            TreeInfo[key] = collections.OrderedDict()
     186            TreeInfo[key]["Name"] = key
     187            TreeInfo[key]["Type"] = self.type
     188            TreeInfo[key]["IfExist"] = self.Data.UpldInfo
     189            if self.Data.UpldInfo:
     190                TreeInfo[key]["Identifier"] = self.Data.UpldInfo.Identifier
     191                TreeInfo[key]["SpecRevision"] = self.Data.UpldInfo.SpecRevision
     192                TreeInfo[key]["Attribute"] = self.Data.UpldInfo.Attribute
     193                TreeInfo[key]["Revision"] = self.Data.UpldInfo.Revision
     194                TreeInfo[key]["Capability"] = self.Data.UpldInfo.Capability
     195                TreeInfo[key]["ProducerId"] = self.Data.UpldInfo.ProducerId
     196                TreeInfo[key]["ImageId"] = self.Data.UpldInfo.ImageId
     197                TreeInfo[key]["Upld_Info_Align"] = self.Data.Upld_Info_Align
     198                TreeInfo[key]["Upld_Buffer"] = self.Data.UpldBuffer
     199        elif self.type == FV_TREE or self.type == SEC_FV_TREE:
    156200            key = str(self.Data.FvId)
    157201            TreeInfo[key] = collections.OrderedDict()
  • trunk/src/VBox/Devices/EFI/FirmwareNew/BaseTools/Source/Python/FMMT/core/BiosTreeNode.py

    r99404 r105670  
    55# SPDX-License-Identifier: BSD-2-Clause-Patent
    66##
     7from FirmwareStorageFormat.UPLHeader import *
    78from FirmwareStorageFormat.FvHeader import *
    89from FirmwareStorageFormat.FfsFileHeader import *
     
    3738        self.HOffset = 0
    3839        self.Data = b''
     40
     41class ElfNode:
     42    def __init__(self, buffer: bytes) -> None:
     43        self.Header = ELF_HEADER32.from_buffer_copy(buffer)
     44        if self.Header.ELF_Identification[0:4] != b'\x7fELF':
     45            logger.error('Invalid Elf Header! Elf Identification {} is not ".ELF".'.format(self.Header.ELF_Identification))
     46            raise Exception("Process Failed: Invalid ELF Header Identification!")
     47        self.Class = self.Header.ELF_Identification[4]
     48        if self.Class == 0x02:
     49            self.Header = ELF_HEADER64.from_buffer_copy(buffer)
     50        elif self.Class != 0x01:
     51            logger.error('Invalid Elf Class! Elf Class {} is not 0x01 or 0x02.'.format(self.Class))
     52            raise Exception("Process Failed: Invalid ELF Class!")
     53
     54        self.ProList = []
     55        self.SecList = []
     56        self.UpldInfoSection = None
     57        self.UpldInfo = None
     58        self.UpldBuffer = b''
     59        self.Name = "ELF"
     60        self.HeaderLength = len(struct2stream(self.Header))
     61        self.HOffset = 0
     62        self.DOffset = 0
     63        self.ROffset = 0
     64        self.Data = b''
     65        self.PadData = b''
     66        self.Upld_Info_Align = False
     67
     68    def GetProgramList(self, buffer: bytes) -> None:
     69        for i in range(self.Header.ELF_PHNum):
     70            if self.Class == 0x01:
     71                ElfProgramHeader = ELF_PROGRAM_HEADER32.from_buffer_copy(buffer[i*self.Header.ELF_PHEntSize:])
     72            elif self.Class == 0x02:
     73                ElfProgramHeader = ELF_PROGRAM_HEADER64.from_buffer_copy(buffer[i*self.Header.ELF_PHEntSize:])
     74            self.ProList.append(ElfProgramHeader)
     75
     76    def GetSectionList(self, buffer: bytes) -> None:
     77        for i in range(self.Header.ELF_SHNum):
     78            if self.Class == 0x01:
     79                ElfSectionHeader = ELF_SECTION_HEADER32.from_buffer_copy(buffer[i*self.Header.ELF_SHEntSize:])
     80            elif self.Class == 0x02:
     81                ElfSectionHeader = ELF_SECTION_HEADER64.from_buffer_copy(buffer[i*self.Header.ELF_SHEntSize:])
     82            self.SecList.append(ElfSectionHeader)
     83
     84    def FindUPLDSection(self, buffer: bytes) -> None:
     85        for item in self.SecList:
     86            if buffer[item.SH_Offset:item.SH_Offset+4] == b'PLDH' or buffer[item.SH_Offset:item.SH_Offset+4] == b'UPLD':
     87                self.UpldInfoSection = item
     88                self.UpldInfo = UNIVERSAL_PAYLOAD_INFO.from_buffer_copy(buffer[item.SH_Offset:item.SH_Offset+item.SH_Size])
     89                self.UpldBuffer = struct2stream(self.UpldInfo)
     90                if (self.UpldInfoSection.SH_Offset) % 4 == 0:
     91                # if (self.UpldInfoSection.SH_Offset - self.Header.ELF_Entry) % 4 == 0:
     92                    self.Upld_Info_Align = True
    3993
    4094class FvNode:
  • trunk/src/VBox/Devices/EFI/FirmwareNew/BaseTools/Source/Python/FMMT/core/FMMTOperation.py

    r99404 r105670  
    189189    if FmmtParser.WholeFvTree.Findlist != []:
    190190        TargetNode = FmmtParser.WholeFvTree.Findlist[0]
    191         if TargetNode.type == FV_TREE or SEC_FV_TREE or DATA_FV_TREE:
     191        if TargetNode.type == FV_TREE or TargetNode.type == SEC_FV_TREE or TargetNode.type == DATA_FV_TREE:
    192192            FinalData = struct2stream(TargetNode.Data.Header) + TargetNode.Data.Data
    193193            with open(outputfile, "wb") as f:
  • trunk/src/VBox/Devices/EFI/FirmwareNew/BaseTools/Source/Python/FMMT/core/FMMTParser.py

    r99404 r105670  
    2121    ## Parser the nodes in WholeTree.
    2222    def ParserFromRoot(self, WholeFvTree=None, whole_data: bytes=b'', Reloffset: int=0) -> None:
    23         if WholeFvTree.type == ROOT_TREE or WholeFvTree.type == ROOT_FV_TREE:
     23        if WholeFvTree.type == ROOT_TREE or WholeFvTree.type == ROOT_FV_TREE or WholeFvTree.type == ROOT_ELF_TREE:
    2424            ParserEntry().DataParser(self.WholeFvTree, whole_data, Reloffset)
    2525        else:
  • trunk/src/VBox/Devices/EFI/FirmwareNew/BaseTools/Source/Python/FMMT/core/FvHandler.py

    r99404 r105670  
    280280                            ParTree.Data.Free_Space = 0
    281281                        ParTree.Data.Size += Needed_Space
    282                         ParTree.Data.Header.Fvlength = ParTree.Data.Size
     282                        ParTree.Data.Header.FvLength = ParTree.Data.Size
    283283                ModifyFvSystemGuid(ParTree)
    284284                for item in ParTree.Child:
     
    388388            Needed_Space = self.NewFfs.Data.Size + len(self.NewFfs.Data.PadData) - self.TargetFfs.Data.Size - len(self.TargetFfs.Data.PadData)
    389389            # If TargetFv have enough free space, just move part of the free space to NewFfs.
    390             if TargetFv.Data.Free_Space >= Needed_Space:
     390            if Needed_Space == 0:
     391                Target_index = TargetFv.Child.index(self.TargetFfs)
     392                TargetFv.Child.remove(self.TargetFfs)
     393                TargetFv.insertChild(self.NewFfs, Target_index)
     394                # Modify TargetFv Header and ExtHeader info.
     395                TargetFv.Data.ModFvExt()
     396                TargetFv.Data.ModFvSize()
     397                TargetFv.Data.ModExtHeaderData()
     398                ModifyFvExtData(TargetFv)
     399                TargetFv.Data.ModCheckSum()
     400                # Recompress from the Fv node to update all the related node data.
     401                self.CompressData(TargetFv)
     402                # return the Status
     403                self.Status = True
     404            elif TargetFv.Data.Free_Space >= Needed_Space:
    391405                # Modify TargetFv Child info and BiosTree.
    392406                TargetFv.Child[-1].Data.Data = b'\xff' * (TargetFv.Data.Free_Space - Needed_Space)
     
    443457                    self.ModifyTest(TargetFv.Parent, Needed_Space)
    444458        else:
    445             New_Free_Space = self.TargetFfs.Data.Size - self.NewFfs.Data.Size
     459            New_Free_Space = self.TargetFfs.Data.Size + len(self.TargetFfs.Data.PadData) - self.NewFfs.Data.Size - len(self.NewFfs.Data.PadData)
    446460            # If TargetFv already have free space, move the new free space into it.
    447461            if TargetFv.Data.Free_Space:
     
    451465                TargetFv.Child.remove(self.TargetFfs)
    452466                TargetFv.insertChild(self.NewFfs, Target_index)
    453                 self.Status = True
    454467            # If TargetFv do not have free space, create free space for Fv.
    455468            else:
     
    462475                TargetFv.Child.remove(self.TargetFfs)
    463476                TargetFv.insertChild(self.NewFfs, Target_index)
    464                 self.Status = True
    465477            # Modify TargetFv Header and ExtHeader info.
    466478            TargetFv.Data.ModFvExt()
     
    471483            # Recompress from the Fv node to update all the related node data.
    472484            self.CompressData(TargetFv)
     485            self.Status = True
    473486        logger.debug('Done!')
    474487        return self.Status
     
    651664            TargetFv.Child[-1].Data.Data = b'\xff' * New_Free_Space
    652665            TargetFv.Data.Size -= Removed_Space
    653             TargetFv.Data.Header.Fvlength = TargetFv.Data.Size
    654             ModifyFvSystemGuid(TargetFv)
     666            TargetFv.Data.Header.FvLength = TargetFv.Data.Size
     667            if struct2stream(TargetFv.Data.Header.FileSystemGuid) == EFI_FIRMWARE_FILE_SYSTEM3_GUID_BYTE:
     668                if TargetFv.Data.Size <= 0xFFFFFF:
     669                    TargetFv.Data.Header.FileSystemGuid = ModifyGuidFormat(
     670                        "8c8ce578-8a3d-4f1c-9935-896185c32dd3")
     671
    655672            for item in TargetFv.Child:
    656673                if item.type == FFS_FREE_SPACE:
  • trunk/src/VBox/Devices/EFI/FirmwareNew/BaseTools/Source/Python/FMMT/core/GuidTools.py

    r99404 r105670  
    111111            self.tooldef_file = os.path.join(os.environ['FmmtConfPath'], 'FmmtConf.ini')
    112112        else:
    113             PathList = os.environ['PATH']
     113            PathList = os.environ['PATH'].split(os.pathsep)
    114114            for CurrentPath in PathList:
    115115                if os.path.exists(os.path.join(CurrentPath, 'FmmtConf.ini')):
  • trunk/src/VBox/Devices/EFI/FirmwareNew/BaseTools/Source/Python/GenFds/Capsule.py

    r80721 r105670  
    22# generate capsule
    33#
     4#  Copyright (C) 2024 Advanced Micro Devices, Inc. All rights reserved.<BR>
    45#  Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>
    56#
     
    7980                elif flag == 'InitiateReset':
    8081                    Flags |= 0x00040000
     82        if 'OEM_CAPSULE_FLAGS' in self.TokensDict:
     83            Flags |= int(self.TokensDict['OEM_CAPSULE_FLAGS'],16)
    8184        Header.write(pack('=I', Flags))
    8285        #
  • trunk/src/VBox/Devices/EFI/FirmwareNew/BaseTools/Source/Python/GenFds/FdfParser.py

    r99404 r105670  
    6666CR_LB_SET = {T_CHAR_CR, TAB_LINE_BREAK}
    6767
    68 RegionSizePattern = compile("\s*(?P<base>(?:0x|0X)?[a-fA-F0-9]+)\s*\|\s*(?P<size>(?:0x|0X)?[a-fA-F0-9]+)\s*")
    69 RegionSizeGuidPattern = compile("\s*(?P<base>\w+\.\w+[\.\w\[\]]*)\s*\|\s*(?P<size>\w+\.\w+[\.\w\[\]]*)\s*")
    70 RegionOffsetPcdPattern = compile("\s*(?P<base>\w+\.\w+[\.\w\[\]]*)\s*$")
    71 ShortcutPcdPattern = compile("\s*\w+\s*=\s*(?P<value>(?:0x|0X)?[a-fA-F0-9]+)\s*\|\s*(?P<name>\w+\.\w+)\s*")
    72 BaseAddrValuePattern = compile('^0[xX][0-9a-fA-F]+')
     68RegionSizePattern = compile(r"\s*(?P<base>(?:0x|0X)?[a-fA-F0-9]+)\s*\|\s*(?P<size>(?:0x|0X)?[a-fA-F0-9]+)\s*")
     69RegionSizeGuidPattern = compile(r"\s*(?P<base>\w+\.\w+[\.\w\[\]]*)\s*\|\s*(?P<size>\w+\.\w+[\.\w\[\]]*)\s*")
     70RegionOffsetPcdPattern = compile(r"\s*(?P<base>\w+\.\w+[\.\w\[\]]*)\s*$")
     71ShortcutPcdPattern = compile(r"\s*\w+\s*=\s*(?P<value>(?:0x|0X)?[a-fA-F0-9]+)\s*\|\s*(?P<name>\w+\.\w+)\s*")
     72BaseAddrValuePattern = compile(r'^0[xX][0-9a-fA-F]+')
    7373FileExtensionPattern = compile(r'([a-zA-Z][a-zA-Z0-9]*)')
    7474TokenFindPattern = compile(r'([a-zA-Z0-9\-]+|\$\(TARGET\)|\*)_([a-zA-Z0-9\-]+|\$\(TOOL_CHAIN_TAG\)|\*)_([a-zA-Z0-9\-]+|\$\(ARCH\)|\*)')
  • trunk/src/VBox/Devices/EFI/FirmwareNew/BaseTools/Source/Python/GenFds/FfsInfStatement.py

    r99404 r105670  
    2020import subprocess
    2121import sys
     22from pathlib import Path
    2223from . import Section
    2324from . import RuleSimpleFile
     
    9394                if ModuleType != SUP_MODULE_USER_DEFINED and ModuleType != SUP_MODULE_HOST_APPLICATION:
    9495                    for LibraryClass in PlatformDataBase.LibraryClasses.GetKeys():
    95                         if LibraryClass.startswith("NULL") and PlatformDataBase.LibraryClasses[LibraryClass, ModuleType]:
     96                        if LibraryClass.startswith("NULL") and LibraryClass[4:].isdigit() and PlatformDataBase.LibraryClasses[LibraryClass, ModuleType]:
    9697                            self.InfModule.LibraryClasses[LibraryClass] = PlatformDataBase.LibraryClasses[LibraryClass, ModuleType]
    9798
     
    101102                    PlatformModule = PlatformDataBase.Modules[StrModule]
    102103                    for LibraryClass in PlatformModule.LibraryClasses:
    103                         if LibraryClass.startswith("NULL"):
     104                        if LibraryClass.startswith("NULL") and LibraryClass[4:].isdigit():
    104105                            self.InfModule.LibraryClasses[LibraryClass] = PlatformModule.LibraryClasses[LibraryClass]
    105106
     
    157158            pass
    158159        elif self.InfFileName[0] == '\\' or self.InfFileName[0] == '/' :
    159             self.InfFileName = self.InfFileName[1:]
     160            ws_path = Path(GenFdsGlobalVariable.WorkSpaceDir)
     161            inf_path = Path(self.InfFileName)
     162            if ws_path in inf_path.parents:
     163                self.InfFileName = str(inf_path.relative_to(ws_path))
     164            else:
     165                self.InfFileName = self.InfFileName[1:]
    160166
    161167        if self.InfFileName.find('$') == -1:
  • trunk/src/VBox/Devices/EFI/FirmwareNew/BaseTools/Source/Python/GenFds/GenFds.py

    r99404 r105670  
    734734                            continue
    735735                        MatchDict = {}
    736                         ReFileEnds = compile('\S+(.ui)$|\S+(fv.sec.txt)$|\S+(.pe32.txt)$|\S+(.te.txt)$|\S+(.pic.txt)$|\S+(.raw.txt)$|\S+(.ffs.txt)$')
     736                        ReFileEnds = compile(r'\S+(.ui)$|\S+(fv.sec.txt)$|\S+(.pe32.txt)$|\S+(.te.txt)$|\S+(.pic.txt)$|\S+(.raw.txt)$|\S+(.ffs.txt)$')
    737737                        FileList = os.listdir(FfsPath[0])
    738738                        for File in FileList:
  • trunk/src/VBox/Devices/EFI/FirmwareNew/BaseTools/Source/Python/GenPatchPcdTable/GenPatchPcdTable.py

    r85718 r105670  
    3232
    3333#============================================== Code ===============================================
    34 symRe = re.compile('^([\da-fA-F]+):([\da-fA-F]+) +([\.\-:\\\\\w\?@\$<>]+) +([\da-fA-F]+)', re.UNICODE)
     34symRe = re.compile(r'^([\da-fA-F]+):([\da-fA-F]+) +([\.\-:\\\\\w\?@\$<>]+) +([\da-fA-F]+)', re.UNICODE)
    3535
    3636def parsePcdInfoFromMapFile(mapfilepath, efifilepath):
     
    5050    if len(lines) == 0: return None
    5151    firstline = lines[0].strip()
    52     if re.match('^\s*Address\s*Size\s*Align\s*Out\s*In\s*Symbol\s*$', firstline):
     52    if re.match(r'^\s*Address\s*Size\s*Align\s*Out\s*In\s*Symbol\s*$', firstline):
    5353        return _parseForXcodeAndClang9(lines, efifilepath)
    5454    if (firstline.startswith("Archive member included ") and
     
    6060
    6161def _parseForXcodeAndClang9(lines, efifilepath):
    62     valuePattern = re.compile('^([\da-fA-FxX]+)([\s\S]*)([_]*_gPcd_BinaryPatch_([\w]+))')
     62    valuePattern = re.compile(r'^([\da-fA-FxX]+)([\s\S]*)([_]*_gPcd_BinaryPatch_([\w]+))')
    6363    status = 0
    6464    pcds = []
    6565    for line in lines:
    6666        line = line.strip()
    67         if status == 0 and (re.match('^\s*Address\s*Size\s*Align\s*Out\s*In\s*Symbol\s*$', line) \
     67        if status == 0 and (re.match(r'^\s*Address\s*Size\s*Align\s*Out\s*In\s*Symbol\s*$', line) \
    6868            or line == "# Symbols:"):
    6969            status = 1
     
    7878def _parseForGCC(lines, efifilepath):
    7979    """ Parse map file generated by GCC linker """
    80     dataPattern = re.compile('^.data._gPcd_BinaryPatch_([\w_\d]+)$')
     80    dataPattern = re.compile(r'^.data._gPcd_BinaryPatch_([\w_\d]+)$')
    8181    status = 0
    8282    imageBase = -1
     
    137137    secs = []    # key = section name
    138138    bPcds = []
    139     symPattern = re.compile('^[_]+gPcd_BinaryPatch_([\w]+)')
     139    symPattern = re.compile(r'^[_]+gPcd_BinaryPatch_([\w]+)')
    140140
    141141    for line in lines:
  • trunk/src/VBox/Devices/EFI/FirmwareNew/BaseTools/Source/Python/Trim/Trim.py

    r89983 r105670  
    2929
    3030## Regular expression for matching Line Control directive like "#line xxx"
    31 gLineControlDirective = re.compile('^\s*#(?:line)?\s+([0-9]+)\s+"*([^"]*)"')
     31gLineControlDirective = re.compile(r'^\s*#(?:line)?\s+([0-9]+)\s+"*([^"]*)"')
    3232## Regular expression for matching "typedef struct"
    33 gTypedefPattern = re.compile("^\s*typedef\s+struct(\s+\w+)?\s*[{]*$", re.MULTILINE)
     33gTypedefPattern = re.compile(r"^\s*typedef\s+struct(\s+\w+)?\s*[{]*$", re.MULTILINE)
    3434## Regular expression for matching "#pragma pack"
    35 gPragmaPattern = re.compile("^\s*#pragma\s+pack", re.MULTILINE)
     35gPragmaPattern = re.compile(r"^\s*#pragma\s+pack", re.MULTILINE)
    3636## Regular expression for matching "typedef"
    37 gTypedef_SinglePattern = re.compile("^\s*typedef", re.MULTILINE)
     37gTypedef_SinglePattern = re.compile(r"^\s*typedef", re.MULTILINE)
    3838## Regular expression for matching "typedef struct, typedef union, struct, union"
    39 gTypedef_MulPattern = re.compile("^\s*(typedef)?\s+(struct|union)(\s+\w+)?\s*[{]*$", re.MULTILINE)
     39gTypedef_MulPattern = re.compile(r"^\s*(typedef)?\s+(struct|union)(\s+\w+)?\s*[{]*$", re.MULTILINE)
    4040
    4141#
     
    4545#
    4646## Regular expression for matching HEX number
    47 gHexNumberPattern = re.compile("(?<=[^a-zA-Z0-9_])(0[xX])([0-9a-fA-F]+)(U(?=$|[^a-zA-Z0-9_]))?")
     47gHexNumberPattern = re.compile(r"(?<=[^a-zA-Z0-9_])(0[xX])([0-9a-fA-F]+)(U(?=$|[^a-zA-Z0-9_]))?")
    4848## Regular expression for matching decimal number with 'U' postfix
    49 gDecNumberPattern = re.compile("(?<=[^a-zA-Z0-9_])([0-9]+)U(?=$|[^a-zA-Z0-9_])")
     49gDecNumberPattern = re.compile(r"(?<=[^a-zA-Z0-9_])([0-9]+)U(?=$|[^a-zA-Z0-9_])")
    5050## Regular expression for matching constant with 'ULL' 'LL' postfix
    51 gLongNumberPattern = re.compile("(?<=[^a-zA-Z0-9_])(0[xX][0-9a-fA-F]+|[0-9]+)U?LL(?=$|[^a-zA-Z0-9_])")
     51gLongNumberPattern = re.compile(r"(?<=[^a-zA-Z0-9_])(0[xX][0-9a-fA-F]+|[0-9]+)U?LL(?=$|[^a-zA-Z0-9_])")
    5252
    5353## Regular expression for matching "Include ()" in asl file
    54 gAslIncludePattern = re.compile("^(\s*)[iI]nclude\s*\(\"?([^\"\(\)]+)\"\)", re.MULTILINE)
     54gAslIncludePattern = re.compile(r"^(\s*)[iI]nclude\s*\(\"?([^\"\(\)]+)\"\)", re.MULTILINE)
    5555## Regular expression for matching C style #include "XXX.asl" in asl file
    5656gAslCIncludePattern = re.compile(r'^(\s*)#include\s*[<"]\s*([-\\/\w.]+)\s*([>"])', re.MULTILINE)
     
    282282                break
    283283        else:
    284             EdkLogger.warn("Trim", "Failed to find include file %s" % Source)
     284            EdkLogger.error("Trim", "Failed to find include file %s" % Source)
    285285            return []
    286286    except:
    287         EdkLogger.warn("Trim", FILE_OPEN_FAILURE, ExtraData=Source)
     287        EdkLogger.error("Trim", FILE_OPEN_FAILURE, ExtraData=Source)
    288288        return []
    289289
  • trunk/src/VBox/Devices/EFI/FirmwareNew/BaseTools/Source/Python/Workspace/DscBuildData.py

    r101291 r105670  
    3838from Workspace.BuildClassObject import PlatformBuildClassObject, StructurePcd, PcdClassObject, ModuleBuildClassObject
    3939from collections import OrderedDict, defaultdict
     40import json
     41import shutil
    4042
    4143def _IsFieldValueAnArray (Value):
     
    5759PcdValueInitName = 'PcdValueInit'
    5860PcdValueCommonName = 'PcdValueCommon'
     61StructuredPcdsDataName = 'StructuredPcdsData.json'
    5962
    6063PcdMainCHeader = '''
     
    9194WindowsCFLAGS = 'CFLAGS = $(CFLAGS) /wd4200 /wd4034 /wd4101 '
    9295LinuxCFLAGS = 'CFLAGS += -Wno-pointer-to-int-cast -Wno-unused-variable '
    93 PcdMakefileEnd = '''
     96PcdMakefileEnd = r'''
    9497!INCLUDE $(BASE_TOOLS_PATH)\Source\C\Makefiles\ms.common
    9598!INCLUDE $(BASE_TOOLS_PATH)\Source\C\Makefiles\ms.app
     
    111114SkuIdPattern = re.compile(r'^[a-zA-Z_][a-zA-Z0-9_]*$')
    112115## regular expressions for finding decimal and hex numbers
    113 Pattern = re.compile('^[1-9]\d*|0$')
     116Pattern = re.compile(r'^[1-9]\d*|0$')
    114117HexPattern = re.compile(r'0[xX][0-9a-fA-F]+$')
    115118## Regular expression for finding header file inclusions
     
    27512754            i +=1
    27522755        return ccflags
    2753     def GenerateByteArrayValue (self, StructuredPcds):
    2754         #
    2755         # Generate/Compile/Run C application to determine if there are any flexible array members
    2756         #
    2757         if not StructuredPcds:
    2758             return
    2759 
    2760         InitByteValue = ""
    2761         CApp = PcdMainCHeader
    2762 
    2763         IncludeFiles = set()
    2764         for PcdName in StructuredPcds:
    2765             Pcd = StructuredPcds[PcdName]
    2766             for IncludeFile in Pcd.StructuredPcdIncludeFile:
    2767                 if IncludeFile not in IncludeFiles:
    2768                     IncludeFiles.add(IncludeFile)
    2769                     CApp = CApp + '#include <%s>\n' % (IncludeFile)
    2770         CApp = CApp + '\n'
    2771         for Pcd in StructuredPcds.values():
    2772             CApp = CApp + self.GenerateArrayAssignment(Pcd)
    2773         for PcdName in sorted(StructuredPcds.keys()):
    2774             Pcd = StructuredPcds[PcdName]
    2775 
    2776             #create void void Cal_tocken_cname_Size functions
    2777             CApp = CApp + self.GenerateSizeFunction(Pcd)
    2778 
    2779             #create void Assign_ functions
    2780 
    2781             # From DEC
    2782             CApp = CApp + self.GenerateDefaultValueAssignFunction(Pcd)
    2783             # From Fdf
    2784             CApp = CApp + self.GenerateFdfValue(Pcd)
    2785             # From CommandLine
    2786             CApp = CApp + self.GenerateCommandLineValue(Pcd)
    2787 
    2788             # From Dsc Global setting
    2789             if self.SkuOverrideValuesEmpty(Pcd.SkuOverrideValues) or Pcd.Type in [self._PCD_TYPE_STRING_[MODEL_PCD_FIXED_AT_BUILD],
    2790                         self._PCD_TYPE_STRING_[MODEL_PCD_PATCHABLE_IN_MODULE]]:
    2791                 CApp = CApp + self.GenerateInitValueFunction(Pcd, self.SkuIdMgr.SystemSkuId, TAB_DEFAULT_STORES_DEFAULT)
    2792             else:
    2793                 for SkuName in self.SkuIdMgr.SkuOverrideOrder():
    2794                     if SkuName not in Pcd.SkuOverrideValues:
    2795                         continue
    2796                     for DefaultStoreName in Pcd.SkuOverrideValues[SkuName]:
    2797                         CApp = CApp + self.GenerateInitValueFunction(Pcd, SkuName, DefaultStoreName)
    2798 
    2799             # From Dsc module scope setting
    2800             CApp = CApp + self.GenerateModuleScopeValue(Pcd)
    2801 
    2802             #create Initialize_ functions
    2803             if self.SkuOverrideValuesEmpty(Pcd.SkuOverrideValues) or Pcd.Type in [self._PCD_TYPE_STRING_[MODEL_PCD_FIXED_AT_BUILD],
    2804                         self._PCD_TYPE_STRING_[MODEL_PCD_PATCHABLE_IN_MODULE]]:
    2805                 InitByteValue, CApp = self.GenerateInitializeFunc(self.SkuIdMgr.SystemSkuId, TAB_DEFAULT_STORES_DEFAULT, Pcd, InitByteValue, CApp)
    2806                 InitByteValue, CApp =  self.GenerateModuleScopeInitializeFunc(self.SkuIdMgr.SystemSkuId,Pcd,InitByteValue,CApp)
    2807             else:
    2808                 for SkuName in self.SkuIdMgr.SkuOverrideOrder():
    2809                     if SkuName not in Pcd.SkuOverrideValues:
    2810                         continue
    2811                     for DefaultStoreName in Pcd.DefaultStoreName:
    2812                         Pcd = StructuredPcds[PcdName]
    2813                         InitByteValue, CApp = self.GenerateInitializeFunc(SkuName, DefaultStoreName, Pcd, InitByteValue, CApp)
    2814 
    2815         CApp = CApp + 'VOID\n'
    2816         CApp = CApp + 'PcdEntryPoint(\n'
    2817         CApp = CApp + '  VOID\n'
    2818         CApp = CApp + '  )\n'
    2819         CApp = CApp + '{\n'
    2820         for Pcd in StructuredPcds.values():
    2821             if self.SkuOverrideValuesEmpty(Pcd.SkuOverrideValues) or Pcd.Type in [self._PCD_TYPE_STRING_[MODEL_PCD_FIXED_AT_BUILD], self._PCD_TYPE_STRING_[MODEL_PCD_PATCHABLE_IN_MODULE]]:
    2822                 CApp = CApp + '  Initialize_%s_%s_%s_%s();\n' % (self.SkuIdMgr.SystemSkuId, TAB_DEFAULT_STORES_DEFAULT, Pcd.TokenSpaceGuidCName, Pcd.TokenCName)
    2823                 for ModuleGuid in Pcd.PcdFiledValueFromDscComponent:
    2824                     CApp += "  Initialize_%s_%s_%s_%s();\n" % (ModuleGuid,TAB_DEFAULT_STORES_DEFAULT ,Pcd.TokenSpaceGuidCName, Pcd.TokenCName)
    2825             else:
    2826                 for SkuName in self.SkuIdMgr.SkuOverrideOrder():
    2827                     if SkuName not in self.SkuIdMgr.AvailableSkuIdSet:
    2828                         continue
    2829                     for DefaultStoreName in Pcd.SkuOverrideValues[SkuName]:
    2830                         CApp = CApp + '  Initialize_%s_%s_%s_%s();\n' % (SkuName, DefaultStoreName, Pcd.TokenSpaceGuidCName, Pcd.TokenCName)
    2831         CApp = CApp + '}\n'
    2832 
    2833         CApp = CApp + PcdMainCEntry + '\n'
    2834 
    2835         if not os.path.exists(self.OutputPath):
    2836             os.makedirs(self.OutputPath)
    2837         CAppBaseFileName = os.path.join(self.OutputPath, PcdValueInitName)
    2838         SaveFileOnChange(CAppBaseFileName + '.c', CApp, False)
    2839 
    2840         # start generating makefile
    2841         MakeApp = PcdMakefileHeader
    2842         if sys.platform == "win32":
    2843             MakeApp = MakeApp + 'APPFILE = %s\%s.exe\n' % (self.OutputPath, PcdValueInitName) + 'APPNAME = %s\n' % (PcdValueInitName) + 'OBJECTS = %s\%s.obj %s.obj\n' % (self.OutputPath, PcdValueInitName, os.path.join(self.OutputPath, PcdValueCommonName)) + 'INC = '
    2844         else:
    2845             MakeApp = MakeApp + PcdGccMakefile
    2846             MakeApp = MakeApp + 'APPFILE = %s/%s\n' % (self.OutputPath, PcdValueInitName) + 'APPNAME = %s\n' % (PcdValueInitName) + 'OBJECTS = %s/%s.o %s.o\n' % (self.OutputPath, PcdValueInitName, os.path.join(self.OutputPath, PcdValueCommonName)) + \
    2847                       'include $(MAKEROOT)/Makefiles/app.makefile\n' + 'TOOL_INCLUDE +='
    2848 
    2849         IncSearchList = []
    2850         PlatformInc = OrderedDict()
    2851         for Cache in self._Bdb._CACHE_.values():
    2852             if Cache.MetaFile.Ext.lower() != '.dec':
    2853                 continue
    2854             if Cache.Includes:
    2855                 if str(Cache.MetaFile.Path) not in PlatformInc:
    2856                     PlatformInc[str(Cache.MetaFile.Path)] = []
    2857                     PlatformInc[str(Cache.MetaFile.Path)].append (os.path.dirname(Cache.MetaFile.Path))
    2858                     PlatformInc[str(Cache.MetaFile.Path)].extend (Cache.CommonIncludes)
    2859 
    2860         PcdDependDEC = []
    2861         for Pcd in StructuredPcds.values():
    2862             for PackageDec in Pcd.PackageDecs:
    2863                 Package = os.path.normpath(mws.join(GlobalData.gWorkspace, PackageDec))
    2864                 if not os.path.exists(Package):
    2865                     EdkLogger.error('Build', RESOURCE_NOT_AVAILABLE, "The dependent Package %s of PCD %s.%s is not exist." % (PackageDec, Pcd.TokenSpaceGuidCName, Pcd.TokenCName))
    2866                 if Package not in PcdDependDEC:
    2867                     PcdDependDEC.append(Package)
    2868 
    2869         if PlatformInc and PcdDependDEC:
    2870             for pkg in PcdDependDEC:
    2871                 if pkg in PlatformInc:
    2872                     for inc in PlatformInc[pkg]:
    2873                         #
    2874                         # Get list of files in potential -I include path
    2875                         #
    2876                         FileList = os.listdir (str(inc))
    2877                         #
    2878                         # Skip -I include path if one of the include files required
    2879                         # by PcdValueInit.c are present in the include paths from
    2880                         # the DEC file.  PcdValueInit.c must use the standard include
    2881                         # files from the host compiler.
    2882                         #
    2883                         if 'stdio.h' in FileList:
    2884                           continue
    2885                         if 'stdlib.h' in FileList:
    2886                           continue
    2887                         if 'string.h' in FileList:
    2888                           continue
    2889                         MakeApp += '-I'  + str(inc) + ' '
    2890                         IncSearchList.append(inc)
    2891         MakeApp = MakeApp + '\n'
    2892 
     2756
     2757    def GetStructurePcdSet (self, OutputValueFile):
     2758        if not os.path.isfile(OutputValueFile):
     2759            EdkLogger.error("GetStructurePcdSet", FILE_NOT_FOUND, "Output.txt doesn't exist", ExtraData=OutputValueFile)
     2760            return []
     2761        File = open (OutputValueFile, 'r')
     2762        FileBuffer = File.readlines()
     2763        File.close()
     2764
     2765        #start update structure pcd final value
     2766        StructurePcdSet = []
     2767        for Pcd in FileBuffer:
     2768            PcdValue = Pcd.split ('|')
     2769            PcdInfo = PcdValue[0].split ('.')
     2770            StructurePcdSet.append((PcdInfo[0], PcdInfo[1], PcdInfo[2], PcdInfo[3], PcdValue[2].strip()))
     2771        return StructurePcdSet
     2772
     2773    def GetBuildOptionsValueList(self):
    28932774        CC_FLAGS = LinuxCFLAGS
    28942775        if sys.platform == "win32":
     
    29272808            ValueList.extend([item for item in BuildOptions['COMMON'] if item.startswith((r"/D", "-D"))])
    29282809            CC_FLAGS += " ".join(ValueList)
     2810        return CC_FLAGS
     2811
     2812
     2813    def GenerateByteArrayValue (self, StructuredPcds):
     2814        #
     2815        # Generate/Compile/Run C application to determine if there are any flexible array members
     2816        #
     2817        if not StructuredPcds:
     2818            return
     2819
     2820        StructuredPcdsData = {}
     2821        StoredStructuredPcdObjectPaths = {}
     2822        SkipPcdValueInit = False
     2823
     2824        CC_FLAGS = self.GetBuildOptionsValueList()
     2825
     2826        for PcdName in StructuredPcds:
     2827            Pcd = StructuredPcds[PcdName]
     2828            TokenSpaceGuidCName = Pcd.TokenSpaceGuidCName
     2829            TokenCName = Pcd.TokenCName
     2830
     2831            # Create a key using TokenSpaceGuidCName and TokenCName
     2832            StructuredPcdsData[f"{TokenSpaceGuidCName}_{TokenCName}"] = {
     2833                "DefaultValueFromDec": Pcd.DefaultValueFromDec,
     2834                "DefaultValues": Pcd.DefaultValues,
     2835                "PcdFieldValueFromComm": Pcd.PcdFieldValueFromComm,
     2836                "PcdFieldValueFromFdf": Pcd.PcdFieldValueFromFdf,
     2837                "DefaultFromDSC": Pcd.DefaultFromDSC,
     2838                "PcdFiledValueFromDscComponent": Pcd.PcdFiledValueFromDscComponent
     2839            }
     2840
     2841        # Store the CC Flags
     2842        StructuredPcdsData["CC_FLAGS"] = CC_FLAGS
     2843        #
     2844        # If the output path doesn't exists then create it
     2845        #
     2846        if not os.path.exists(self.OutputPath):
     2847            os.makedirs(self.OutputPath)
     2848
     2849        StructuredPcdsDataPath = os.path.join(self.OutputPath, self._Arch, StructuredPcdsDataName)
     2850        PcdRecordOutputValueFile = os.path.join(self.OutputPath, self._Arch, 'Output.txt')
     2851
     2852        if not os.path.exists(os.path.dirname(StructuredPcdsDataPath)):
     2853            os.makedirs(os.path.dirname(StructuredPcdsDataPath))
     2854        #
     2855        # Check if the StructuredPcdsData.json exists or not
     2856        # if exits then it might be a incremental build then check if the StructuredPcdsData has been changed or not.
     2857        # if changed then proceed further, if not changed then return the stored data from earlier build
     2858        #
     2859        if os.path.isfile(StructuredPcdsDataPath):
     2860            with open(StructuredPcdsDataPath, 'r') as file:
     2861                StoredStructuredPcdsData = json.load(file)
     2862                # OBJECTS will have the modified time, which needs to be checked later
     2863                StoredStructuredPcdObjectPaths = StoredStructuredPcdsData.pop("OBJECTS", {})
     2864
     2865                if StructuredPcdsData == StoredStructuredPcdsData:
     2866                    SkipPcdValueInit = True
     2867                    for filename, file_mtime in StoredStructuredPcdObjectPaths.items():
     2868                        f_mtime = os.path.getmtime(filename)
     2869                        #
     2870                        # check if the include_file are modified or not,
     2871                        # if modified then generate the PcdValueInit
     2872                        #
     2873                        if f_mtime != file_mtime:
     2874                            SkipPcdValueInit = False
     2875                            break
     2876
     2877        if SkipPcdValueInit:
     2878            return self.GetStructurePcdSet(PcdRecordOutputValueFile)
     2879
     2880        InitByteValue = ""
     2881        CApp = PcdMainCHeader
     2882
     2883        IncludeFiles = set()
     2884        for PcdName in StructuredPcds:
     2885            Pcd = StructuredPcds[PcdName]
     2886            for IncludeFile in Pcd.StructuredPcdIncludeFile:
     2887                if IncludeFile not in IncludeFiles:
     2888                    IncludeFiles.add(IncludeFile)
     2889                    CApp = CApp + '#include <%s>\n' % (IncludeFile)
     2890        CApp = CApp + '\n'
     2891        for Pcd in StructuredPcds.values():
     2892            CApp = CApp + self.GenerateArrayAssignment(Pcd)
     2893        for PcdName in sorted(StructuredPcds.keys()):
     2894            Pcd = StructuredPcds[PcdName]
     2895
     2896            #create void void Cal_tocken_cname_Size functions
     2897            CApp = CApp + self.GenerateSizeFunction(Pcd)
     2898
     2899            #create void Assign_ functions
     2900
     2901            # From DEC
     2902            CApp = CApp + self.GenerateDefaultValueAssignFunction(Pcd)
     2903            # From Fdf
     2904            CApp = CApp + self.GenerateFdfValue(Pcd)
     2905            # From CommandLine
     2906            CApp = CApp + self.GenerateCommandLineValue(Pcd)
     2907
     2908            # From Dsc Global setting
     2909            if self.SkuOverrideValuesEmpty(Pcd.SkuOverrideValues) or Pcd.Type in [self._PCD_TYPE_STRING_[MODEL_PCD_FIXED_AT_BUILD],
     2910                        self._PCD_TYPE_STRING_[MODEL_PCD_PATCHABLE_IN_MODULE]]:
     2911                CApp = CApp + self.GenerateInitValueFunction(Pcd, self.SkuIdMgr.SystemSkuId, TAB_DEFAULT_STORES_DEFAULT)
     2912            else:
     2913                for SkuName in self.SkuIdMgr.SkuOverrideOrder():
     2914                    if SkuName not in Pcd.SkuOverrideValues:
     2915                        continue
     2916                    for DefaultStoreName in Pcd.SkuOverrideValues[SkuName]:
     2917                        CApp = CApp + self.GenerateInitValueFunction(Pcd, SkuName, DefaultStoreName)
     2918
     2919            # From Dsc module scope setting
     2920            CApp = CApp + self.GenerateModuleScopeValue(Pcd)
     2921
     2922            #create Initialize_ functions
     2923            if self.SkuOverrideValuesEmpty(Pcd.SkuOverrideValues) or Pcd.Type in [self._PCD_TYPE_STRING_[MODEL_PCD_FIXED_AT_BUILD],
     2924                        self._PCD_TYPE_STRING_[MODEL_PCD_PATCHABLE_IN_MODULE]]:
     2925                InitByteValue, CApp = self.GenerateInitializeFunc(self.SkuIdMgr.SystemSkuId, TAB_DEFAULT_STORES_DEFAULT, Pcd, InitByteValue, CApp)
     2926                InitByteValue, CApp =  self.GenerateModuleScopeInitializeFunc(self.SkuIdMgr.SystemSkuId,Pcd,InitByteValue,CApp)
     2927            else:
     2928                for SkuName in self.SkuIdMgr.SkuOverrideOrder():
     2929                    if SkuName not in Pcd.SkuOverrideValues:
     2930                        continue
     2931                    for DefaultStoreName in Pcd.DefaultStoreName:
     2932                        Pcd = StructuredPcds[PcdName]
     2933                        InitByteValue, CApp = self.GenerateInitializeFunc(SkuName, DefaultStoreName, Pcd, InitByteValue, CApp)
     2934
     2935        CApp = CApp + 'VOID\n'
     2936        CApp = CApp + 'PcdEntryPoint(\n'
     2937        CApp = CApp + '  VOID\n'
     2938        CApp = CApp + '  )\n'
     2939        CApp = CApp + '{\n'
     2940        for Pcd in StructuredPcds.values():
     2941            if self.SkuOverrideValuesEmpty(Pcd.SkuOverrideValues) or Pcd.Type in [self._PCD_TYPE_STRING_[MODEL_PCD_FIXED_AT_BUILD], self._PCD_TYPE_STRING_[MODEL_PCD_PATCHABLE_IN_MODULE]]:
     2942                CApp = CApp + '  Initialize_%s_%s_%s_%s();\n' % (self.SkuIdMgr.SystemSkuId, TAB_DEFAULT_STORES_DEFAULT, Pcd.TokenSpaceGuidCName, Pcd.TokenCName)
     2943                for ModuleGuid in Pcd.PcdFiledValueFromDscComponent:
     2944                    CApp += "  Initialize_%s_%s_%s_%s();\n" % (ModuleGuid,TAB_DEFAULT_STORES_DEFAULT ,Pcd.TokenSpaceGuidCName, Pcd.TokenCName)
     2945            else:
     2946                for SkuName in self.SkuIdMgr.SkuOverrideOrder():
     2947                    if SkuName not in self.SkuIdMgr.AvailableSkuIdSet:
     2948                        continue
     2949                    for DefaultStoreName in Pcd.SkuOverrideValues[SkuName]:
     2950                        CApp = CApp + '  Initialize_%s_%s_%s_%s();\n' % (SkuName, DefaultStoreName, Pcd.TokenSpaceGuidCName, Pcd.TokenCName)
     2951        CApp = CApp + '}\n'
     2952
     2953        CApp = CApp + PcdMainCEntry + '\n'
     2954
     2955        CAppBaseFileName = os.path.join(self.OutputPath, PcdValueInitName)
     2956        SaveFileOnChange(CAppBaseFileName + '.c', CApp, False)
     2957
     2958        # start generating makefile
     2959        MakeApp = PcdMakefileHeader
     2960        if sys.platform == "win32":
     2961            MakeApp = MakeApp + 'APPFILE = %s\\%s.exe\n' % (self.OutputPath, PcdValueInitName) + 'APPNAME = %s\n' % (PcdValueInitName) + 'OBJECTS = %s\\%s.obj %s.obj\n' % (self.OutputPath, PcdValueInitName, os.path.join(self.OutputPath, PcdValueCommonName)) + 'INC = '
     2962        else:
     2963            MakeApp = MakeApp + PcdGccMakefile
     2964            MakeApp = MakeApp + 'APPFILE = %s/%s\n' % (self.OutputPath, PcdValueInitName) + 'APPNAME = %s\n' % (PcdValueInitName) + 'OBJECTS = %s/%s.o %s.o\n' % (self.OutputPath, PcdValueInitName, os.path.join(self.OutputPath, PcdValueCommonName)) + \
     2965                      'include $(MAKEROOT)/Makefiles/app.makefile\n' + 'TOOL_INCLUDE +='
     2966
     2967        IncSearchList = []
     2968        PlatformInc = OrderedDict()
     2969        for Cache in self._Bdb._CACHE_.values():
     2970            if Cache.MetaFile.Ext.lower() != '.dec':
     2971                continue
     2972            if Cache.Includes:
     2973                if str(Cache.MetaFile.Path) not in PlatformInc:
     2974                    PlatformInc[str(Cache.MetaFile.Path)] = []
     2975                    PlatformInc[str(Cache.MetaFile.Path)].append (os.path.dirname(Cache.MetaFile.Path))
     2976                    PlatformInc[str(Cache.MetaFile.Path)].extend (Cache.CommonIncludes)
     2977
     2978        PcdDependDEC = []
     2979        for Pcd in StructuredPcds.values():
     2980            for PackageDec in Pcd.PackageDecs:
     2981                Package = os.path.normpath(mws.join(GlobalData.gWorkspace, PackageDec))
     2982                if not os.path.exists(Package):
     2983                    EdkLogger.error('Build', RESOURCE_NOT_AVAILABLE, "The dependent Package %s of PCD %s.%s is not exist." % (PackageDec, Pcd.TokenSpaceGuidCName, Pcd.TokenCName))
     2984                if Package not in PcdDependDEC:
     2985                    PcdDependDEC.append(Package)
     2986
     2987        if PlatformInc and PcdDependDEC:
     2988            for pkg in PcdDependDEC:
     2989                if pkg in PlatformInc:
     2990                    for inc in PlatformInc[pkg]:
     2991                        #
     2992                        # Get list of files in potential -I include path
     2993                        #
     2994                        FileList = os.listdir (str(inc))
     2995                        #
     2996                        # Skip -I include path if one of the include files required
     2997                        # by PcdValueInit.c are present in the include paths from
     2998                        # the DEC file.  PcdValueInit.c must use the standard include
     2999                        # files from the host compiler.
     3000                        #
     3001                        if 'stdio.h' in FileList:
     3002                          continue
     3003                        if 'stdlib.h' in FileList:
     3004                          continue
     3005                        if 'string.h' in FileList:
     3006                          continue
     3007                        MakeApp += '-I'  + str(inc) + ' '
     3008                        IncSearchList.append(inc)
     3009        MakeApp = MakeApp + '\n'
     3010
    29293011        MakeApp += CC_FLAGS
    29303012
     
    29473029        SearchPathList.extend(str(item) for item in IncSearchList)
    29483030        IncFileList = GetDependencyList(IncludeFileFullPaths, SearchPathList)
     3031        StructuredPcdsData["OBJECTS"] = {}
    29493032        for include_file in IncFileList:
     3033            StructuredPcdsData["OBJECTS"][include_file] = os.path.getmtime(include_file)
    29503034            MakeApp += "$(OBJECTS) : %s\n" % include_file
    29513035        if sys.platform == "win32":
    2952             PcdValueCommonPath = os.path.normpath(mws.join(GlobalData.gGlobalDefines["EDK_TOOLS_PATH"], "Source\C\Common\PcdValueCommon.c"))
    2953             MakeApp = MakeApp + '%s\PcdValueCommon.c : %s\n' % (self.OutputPath, PcdValueCommonPath)
     3036            PcdValueCommonPath = os.path.normpath(mws.join(GlobalData.gGlobalDefines["EDK_TOOLS_PATH"], "Source\\C\\Common\\PcdValueCommon.c"))
     3037            MakeApp = MakeApp + '%s\\PcdValueCommon.c : %s\n' % (self.OutputPath, PcdValueCommonPath)
    29543038            MakeApp = MakeApp + '\tcopy /y %s $@\n' % (PcdValueCommonPath)
    29553039        else:
     
    30433127                EdkLogger.warn('Build', COMMAND_FAILURE, 'Can not collect output from command: %s\n%s\n%s\n' % (Command, StdOut, StdErr))
    30443128
     3129        #
     3130        # In 1st build create the StructuredPcdsData.json
     3131        # update the record as PCD Input has been changed if its incremental build
     3132        #
     3133        with open(StructuredPcdsDataPath, 'w') as file:
     3134            json.dump(StructuredPcdsData, file, indent=2)
     3135
     3136        # Copy update output file for each Arch
     3137        shutil.copyfile(OutputValueFile, PcdRecordOutputValueFile)
     3138
    30453139        #start update structure pcd final value
    3046         File = open (OutputValueFile, 'r')
    3047         FileBuffer = File.readlines()
    3048         File.close()
    3049 
    3050         StructurePcdSet = []
    3051         for Pcd in FileBuffer:
    3052             PcdValue = Pcd.split ('|')
    3053             PcdInfo = PcdValue[0].split ('.')
    3054             StructurePcdSet.append((PcdInfo[0], PcdInfo[1], PcdInfo[2], PcdInfo[3], PcdValue[2].strip()))
    3055         return StructurePcdSet
     3140        return self.GetStructurePcdSet(OutputValueFile)
    30563141
    30573142    @staticmethod
  • trunk/src/VBox/Devices/EFI/FirmwareNew/BaseTools/Source/Python/Workspace/MetaFileParser.py

    r99404 r105670  
    18981898        ArchList = set()
    18991899        PrivateList = set()
    1900         Line = re.sub(',[\s]*', TAB_COMMA_SPLIT, self._CurrentLine)
     1900        Line = re.sub(r',[\s]*', TAB_COMMA_SPLIT, self._CurrentLine)
    19011901        for Item in Line[1:-1].split(TAB_COMMA_SPLIT):
    19021902            if Item == '':
  • trunk/src/VBox/Devices/EFI/FirmwareNew/BaseTools/Source/Python/Workspace/WorkspaceCommon.py

    r99404 r105670  
    103103    if Module.ModuleType != SUP_MODULE_USER_DEFINED:
    104104        for LibraryClass in Platform.LibraryClasses.GetKeys():
    105             if LibraryClass.startswith("NULL") and Platform.LibraryClasses[LibraryClass, Module.ModuleType]:
     105            if LibraryClass.startswith("NULL") and LibraryClass[4:].isdigit() and Platform.LibraryClasses[LibraryClass, Module.ModuleType]:
    106106                Module.LibraryClasses[LibraryClass] = Platform.LibraryClasses[LibraryClass, Module.ModuleType]
    107107
    108108    # add forced library instances (specified in module overrides)
    109109    for LibraryClass in Platform.Modules[str(Module)].LibraryClasses:
    110         if LibraryClass.startswith("NULL"):
     110        if LibraryClass.startswith("NULL") and LibraryClass[4:].isdigit():
    111111            Module.LibraryClasses[LibraryClass] = Platform.Modules[str(Module)].LibraryClasses[LibraryClass]
    112112
     
    124124        M = LibraryConsumerList.pop()
    125125        for LibraryClassName in M.LibraryClasses:
     126            if LibraryClassName.startswith("NULL") and LibraryClassName[4:].isdigit() and bool(M.LibraryClass):
     127                continue
    126128            if LibraryClassName not in LibraryInstance:
    127129                # override library instance for this module
     
    140142                LibraryModule = BuildDatabase[LibraryPath, Arch, Target, Toolchain]
    141143                # for those forced library instance (NULL library), add a fake library class
    142                 if LibraryClassName.startswith("NULL"):
     144                if LibraryClassName.startswith("NULL") and LibraryClassName[4:].isdigit():
    143145                    LibraryModule.LibraryClass.append(LibraryClassObject(LibraryClassName, [ModuleType]))
    144146                elif LibraryModule.LibraryClass is None \
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette