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