]>
git.proxmox.com Git - mirror_edk2.git/blob - IntelFspWrapperPkg/FspWrapperSecCore/Vtf0/Tools/FixupForRawSection.py
2 # Apply fixup to VTF binary image for FFS Raw section
4 # Copyright (c) 2014, Intel Corporation. All rights reserved.<BR>
6 # SPDX-License-Identifier: BSD-2-Clause-Patent
11 filename
= sys
.argv
[1]
13 if filename
.lower().find('ia32') >= 0:
14 d
= open(sys
.argv
[1], 'rb').read()
15 c
= ((len(d
) + 4 + 7) & ~
7) - 4
18 f
= open(sys
.argv
[1], 'wb')
23 from struct
import pack
26 PAGE_READ_WRITE
= 0x02
27 PAGE_USER_SUPERVISOR
= 0x04
28 PAGE_WRITE_THROUGH
= 0x08
29 PAGE_CACHE_DISABLE
= 0x010
38 c
= ((len(s
) + 0xfff) & ~
0xfff) - len(s
)
39 return ('\x90' * c
) + s
41 def PageDirectoryEntries4GbOf2MbPages(baseAddress
):
44 for i
in range(0x800):
46 baseAddress
+ long(i
<< 21) +
57 def PageDirectoryPointerTable4GbOf2MbPages(pdeBase
):
59 for i
in range(0x200):
71 def PageMapLevel4Table4GbOf2MbPages(pdptBase
):
73 for i
in range(0x200):
85 def First4GbPageEntries(topAddress
):
86 PDE
= PageDirectoryEntries4GbOf2MbPages(0L)
87 pml4tBase
= topAddress
- 0x1000
88 pdptBase
= pml4tBase
- 0x1000
89 pdeBase
= pdptBase
- len(PDE
)
90 PDPT
= PageDirectoryPointerTable4GbOf2MbPages(pdeBase
)
91 PML4T
= PageMapLevel4Table4GbOf2MbPages(pdptBase
)
92 return PDE
+ PDPT
+ PML4T
94 def AlignAndAddPageTables():
95 d
= open(sys
.argv
[1], 'rb').read()
97 topAddress
= 0x100000000 - len(code
)
98 d
= ('\x90' * 4) + First4GbPageEntries(topAddress
) + code
99 f
= open(sys
.argv
[1], 'wb')
103 AlignAndAddPageTables()