blob: e6ccc35b927148dd52901c6308593e3d4989ec58 [file] [log] [blame]
Vishal Bhoj82c80712015-12-15 21:13:33 +05301;
2; Copyright (c) 2011, Hewlett-Packard Company. All rights reserved.<BR>
3;
4; This program and the accompanying materials
5; are licensed and made available under the terms and conditions of the BSD License
6; which accompanies this distribution. The full text of the license may be found at
7; http://opensource.org/licenses/bsd-license.php
8;
9; THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10; WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
11;
12
13 LOCAL &fvbase &fvsig &fvsig &ffsoffset &ffsfilesize &ffsfileaddr
14 ENTRY &fvbase
15
16 &fvsig=Data.Long(a:&fvbase+0x28)
17 if &fvsig!=0x4856465F
18 (
19 print "FV does not have proper signature, exiting"
20 return
21 )
22
23 print "FV signature found"
24
25 &fvlen=Data.Long(a:&fvbase+0x20)
26
27 ; first ffs file is after fv header, use headerlength field
28 &ffsoffset=(Data.Long(a:&fvbase+0x30)&0xffff)
29
30 ; loop through ffs files
31 &ffsfilesize=1
32 while (&ffsfilesize!=0)&&(&ffsoffset<(&fvlen))
33 (
34 &ffsfileaddr=&fvbase+&ffsoffset
35 ;print "found ffs file at &ffsfileaddr"
36
37 ; process ffs file and increment by ffs file size field
38 gosub ProcessFfsFile &ffsfileaddr
39
40 &ffsfilesize=(Data.Long(a:&ffsfileaddr+0x14)&0x00ffffff)
41 ;print "ffsfilesize is &ffsfilesize"
42
43 &ffsoffset=&ffsoffset+&ffsfilesize
44
45 &ffsfilesize=(Data.Long(a:&fvbase+&ffsoffset+0x14)&0x00ffffff)
46 ;print "ffsfilesize now is &ffsfilesize"
47 if &ffsfilesize==0xffffff
48 (
49 enddo
50 )
51
52 ; align to next 8 byte boundary
53 if (&ffsoffset&0x7)!=0
54 (
55 &ffsoffset=&ffsoffset+(0x8-(&ffsoffset&0x7))
56 )
57
58 ) ; end fv ffs loop
59
60enddo
61
62ProcessFfsFile:
63 LOCAL &ffsfilestart &ffsfilesize &ffsfiletype &secoffset &secsize
64 ENTRY &ffsfilestart
65
66 ;print "processing ffs file at &ffsfilestart"
67 &ffsfilesize=Data.Long(a:&ffsfilestart+0x14)
68 &ffsfiletype=(&ffsfilesize&0xff000000)>>24.
69 &ffsfilesize=&ffsfilesize&0x00ffffff
70
71 if &ffsfiletype==0
72 (
73 return
74 )
75
76 print "ffs file at &ffsfilestart size &ffsfilesize type &ffsfiletype"
77
78 &secoffset=&ffsfilestart+0x18
79
80 ; loop through sections in file
81 while &secoffset<(&ffsfilestart+&ffsfilesize)
82 (
83 print "secoffset at &secoffset"
84
85 ; process fv section and increment section offset by size
86 &secsize=(Data.Long(a:&secoffset)&0x00ffffff)
87
88 gosub ProcessFvSection &secoffset
89
90
91 &secoffset=(&secoffset+&secsize)
92
93 ;print "secsize is &secsize"
94 ;print "secoffset at &secoffset"
95
96 ; align to next 4 byte boundary
97 if (&secoffset&0x3)!=0
98 (
99 &secoffset=&secoffset+(0x4-(&secoffset&0x3))
100 )
101 ) ; end section loop
102 return
103
104
105ProcessFvSection:
106 LOCAL &secstart &sectionsize &sectiontype &secoffset &secsize
107 ENTRY &secstart
108
109 &sectionsize=Data.Long(a:&secstart)
110 &sectiontype=((&sectionsize&0xff000000)>>24.)
111 &sectionsize=&sectionsize&0x00ffffff;
112
113 print "fv section at &secstart size &sectionsize type &sectiontype"
114
115 if &sectiontype==0x10 ; PE32
116 (
117 do EfiProcessPeImage (&secstart+0x4)
118 )
119 else
120 (
121 if &sectiontype==0x12 ; TE
122 (
123 do EfiProcessTeImage (&secstart+0x4)
124 )
125 else
126 (
127 print "unknown section type"
128 )
129 )
130
131 return