]> git.proxmox.com Git - mirror_edk2.git/blob - EmbeddedPkg/Scripts/LauterbachT32/EfiLoadFv.cmm
EmbeddedPkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / EmbeddedPkg / Scripts / LauterbachT32 / EfiLoadFv.cmm
1 ;
2 ; Copyright (c) 2011, Hewlett-Packard Company. All rights reserved.<BR>
3 ;
4 ; SPDX-License-Identifier: BSD-2-Clause-Patent
5 ;
6
7 LOCAL &fvbase &fvsig &fvsig &ffsoffset &ffsfilesize &ffsfileaddr
8 ENTRY &fvbase
9
10 &fvsig=Data.Long(a:&fvbase+0x28)
11 if &fvsig!=0x4856465F
12 (
13 print "FV does not have proper signature, exiting"
14 return
15 )
16
17 print "FV signature found"
18
19 &fvlen=Data.Long(a:&fvbase+0x20)
20
21 ; first ffs file is after fv header, use headerlength field
22 &ffsoffset=(Data.Long(a:&fvbase+0x30)&0xffff)
23
24 ; loop through ffs files
25 &ffsfilesize=1
26 while (&ffsfilesize!=0)&&(&ffsoffset<(&fvlen))
27 (
28 &ffsfileaddr=&fvbase+&ffsoffset
29 ;print "found ffs file at &ffsfileaddr"
30
31 ; process ffs file and increment by ffs file size field
32 gosub ProcessFfsFile &ffsfileaddr
33
34 &ffsfilesize=(Data.Long(a:&ffsfileaddr+0x14)&0x00ffffff)
35 ;print "ffsfilesize is &ffsfilesize"
36
37 &ffsoffset=&ffsoffset+&ffsfilesize
38
39 &ffsfilesize=(Data.Long(a:&fvbase+&ffsoffset+0x14)&0x00ffffff)
40 ;print "ffsfilesize now is &ffsfilesize"
41 if &ffsfilesize==0xffffff
42 (
43 enddo
44 )
45
46 ; align to next 8 byte boundary
47 if (&ffsoffset&0x7)!=0
48 (
49 &ffsoffset=&ffsoffset+(0x8-(&ffsoffset&0x7))
50 )
51
52 ) ; end fv ffs loop
53
54 enddo
55
56 ProcessFfsFile:
57 LOCAL &ffsfilestart &ffsfilesize &ffsfiletype &secoffset &secsize
58 ENTRY &ffsfilestart
59
60 ;print "processing ffs file at &ffsfilestart"
61 &ffsfilesize=Data.Long(a:&ffsfilestart+0x14)
62 &ffsfiletype=(&ffsfilesize&0xff000000)>>24.
63 &ffsfilesize=&ffsfilesize&0x00ffffff
64
65 if &ffsfiletype==0
66 (
67 return
68 )
69
70 print "ffs file at &ffsfilestart size &ffsfilesize type &ffsfiletype"
71
72 &secoffset=&ffsfilestart+0x18
73
74 ; loop through sections in file
75 while &secoffset<(&ffsfilestart+&ffsfilesize)
76 (
77 print "secoffset at &secoffset"
78
79 ; process fv section and increment section offset by size
80 &secsize=(Data.Long(a:&secoffset)&0x00ffffff)
81
82 gosub ProcessFvSection &secoffset
83
84
85 &secoffset=(&secoffset+&secsize)
86
87 ;print "secsize is &secsize"
88 ;print "secoffset at &secoffset"
89
90 ; align to next 4 byte boundary
91 if (&secoffset&0x3)!=0
92 (
93 &secoffset=&secoffset+(0x4-(&secoffset&0x3))
94 )
95 ) ; end section loop
96 return
97
98
99 ProcessFvSection:
100 LOCAL &secstart &sectionsize &sectiontype &secoffset &secsize
101 ENTRY &secstart
102
103 &sectionsize=Data.Long(a:&secstart)
104 &sectiontype=((&sectionsize&0xff000000)>>24.)
105 &sectionsize=&sectionsize&0x00ffffff;
106
107 print "fv section at &secstart size &sectionsize type &sectiontype"
108
109 if &sectiontype==0x10 ; PE32
110 (
111 do EfiProcessPeImage (&secstart+0x4)
112 )
113 else
114 (
115 if &sectiontype==0x12 ; TE
116 (
117 do EfiProcessTeImage (&secstart+0x4)
118 )
119 else
120 (
121 print "unknown section type"
122 )
123 )
124
125 return