source: trunk/TOOLS/INTERNAL/FIXCODE.C@ 47

Last change on this file since 47 was 47, checked in by Ben Rietbroek, 11 years ago

Fixed Installer to handle packed hideparttable [2012-04-23]

WARNING!!

All commits upto and including the commit of [2012-05-13] contain
a severe bug!! Building from these sources and then disabling
the 'force LBA' feature while also using the drive-letter feature or
editing the label can DESTROY THE MBR on ALL ATTACHED DISKS!!
DO NOT DISABLE 'FORCE LBA USAGE' WHEN BUILT FROM THE THESE COMMITS!!

Changes

o Installer can now handle packed hideparttable
o Implemented upgrading from v1.06 directly to v1.0.8
o Fixed minor stuff when upgrading from v1.06 to v1.07
o Implemented DOS code in C cross-platform installer

There is now one C source for 4 platforms:
DOS,WIN32,OS2 and LINUX (Linux portion not ready yet)
This obsoletes AIRBOOT.ASM/AIRBOOT.COM.
DOS Installer is now AIRBOOTD.EXE.

o This commit is prepairing for v1.0.8-rc2

File size: 6.3 KB
Line 
1// AiR-BOOT (c) Copyright 1998-2008 M. Kiewitz
2//
3// This file is part of AiR-BOOT
4//
5// AiR-BOOT is free software: you can redistribute it and/or modify it under
6// the terms of the GNU General Public License as published by the Free
7// Software Foundation, either version 3 of the License, or (at your option)
8// any later version.
9//
10// AiR-BOOT is distributed in the hope that it will be useful, but WITHOUT ANY
11// WARRANTY: without even the implied warranty of MERCHANTABILITY or FITNESS
12// FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
13// details.
14//
15// You should have received a copy of the GNU General Public License along with
16// AiR-BOOT. If not, see <http://www.gnu.org/licenses/>.
17//
18
19/*
20// FIXCODE.C -- Fix the AiR-BOOT image; include the code-size and MBR prot-img.
21// This reads AIR-BOOT.COM, merges MBR-PROT.BIN and writes AIRBOOT.BIN.
22// It is a quick-and-dirty translation of the original DOS-only ASM file.
23// Of course it's not as small but it's much easier to maintain across
24// multiple platforms. A small change with regard to the old ASM version is
25// that it directly writes AIRBOOT.BIN instead of writing AIR-BOOT.COM.
26// This way the pre and post situations are kept valid.
27*/
28
29
30#include "FIXCODE.H"
31
32
33#ifdef PLATFORM_DOS
34 char welcome[] = "FIXCODE: Hello from DOS !";
35#endif
36
37#ifdef PLATFORM_OS2
38 char welcome[] = "FIXCODE: Hello from OS/2 !";
39#endif
40
41#ifdef PLATFORM_WINNT
42 char welcome[] = "FIXCODE: Hello from Windows NT !";
43#endif
44
45#ifdef PLATFORM_LINUX
46 char welcome[] = "FIXCODE: Hello from Linux !";
47#endif
48
49
50/* File names */
51#define IN_FILE "AIR-BOOT.COM" // Target from assembly.
52#ifdef PLATFORM_LINUX
53#define MERGE_FILE "MBR-PROT/MBR-PROT.BIN" // MBR Protection Image.
54#else
55#define MERGE_FILE "MBR-PROT\\MBR-PROT.BIN" // MBR Protection Image.
56#endif
57#define OUT_FILE "AIRBOOT.BIN" // Generated loader image.
58
59
60/* Copyright message */
61char Copyright[] = "AiR-BOOT Bootcode Image Fix\n"
62 " - (c) Copyright 2009-2012 by M. Kiewitz\n";
63/* Progress messages */
64char LoadCode[] = " - Loading bootcode from file...";
65char LoadMBR[] = " - Loading MBR-protection from file...";
66char MergeMBR[] = " - Merging MBR-protection into bootcode...";
67char CountCode[] = " - Count code in bootcode-image...";
68char WriteCode[] = " - Saving bootcode to file...";
69char Okay[] = "ok\n";
70char Failed[] = "failed\n";
71
72/* Error messages */
73char FailedOpenCode[] = IN_FILE" not found\n";
74char FailedReadCode[] = "Read "IN_FILE" failed\n";
75char FailedInvalidCode[] = "Invalid "IN_FILE"\n";
76char FailedOpenMBR[] = MERGE_FILE" not found\n";
77char FailedReadMBR[] = "Read "MERGE_FILE" failed\n";
78char FailedInvalidMBR[] = "Invalid "MERGE_FILE"\n";
79char FailedWriteCode[] = "Write "OUT_FILE" failed\n";
80
81/* The signature we search for in the AIR-BOOT.COM image */
82char MBRProtectionSignature[] = "AiR-BOOT MBR-Protection Image";
83
84/* File buffers */
85char BootCode[IMAGE_SIZE]; // Buffer for boot-image
86char MBRProtection[1024]; // Buffer for protection-image
87
88
89
90
91/*
92// Main Entrypoint.
93*/
94int main(int argc, char* argv[]) {
95 FILE* ifile = NULL;
96 FILE* mfile = NULL;
97 FILE* ofile = NULL;
98 size_t ibytes = 0;
99 size_t mbytes = 0;
100 size_t obytes = 0;
101 unsigned i = 0;
102 unsigned found = 0;
103
104
105#if DEBUG_LEVEL > 0
106 printf("\n%s\n", welcome);
107 printf("Debug level is: %d\n\n", DEBUG_LEVEL);
108#endif
109
110 /*
111 // Show copyright message.
112 */
113 printf("%s",Copyright);
114
115 /*
116 // Load AIR-BOOT.COM
117 */
118 printf("%s",LoadCode);
119 ifile = fopen(IN_FILE, "rb");
120 if (!ifile) {
121 printf("%s",FailedOpenCode);
122 exit(1);
123 }
124 ibytes = fread(BootCode, 1, IMAGE_SIZE, ifile);
125 if (ferror(ifile)) {
126 printf("%s",FailedReadCode);
127 exit(1);
128 }
129 //printf("ibytes: %d\n", ibytes);
130 fread(BootCode, 1, 1, ifile);
131 if (ibytes != IMAGE_SIZE || !feof(ifile)) {
132 printf("%s", FailedInvalidCode);
133 exit(1);
134 }
135 printf("%s", Okay);
136
137
138 /*
139 // Load MBR-PROT.BIN
140 */
141 printf("%s",LoadMBR);
142 mfile = fopen(MERGE_FILE, "rb");
143 if (!mfile) {
144 printf("%s",FailedOpenMBR);
145 exit(1);
146 }
147 mbytes = fread(MBRProtection, 1, MBRPROT_SIZE, mfile);
148 if (ferror(mfile)) {
149 printf("%s",FailedReadMBR);
150 exit(1);
151 }
152 fread(MBRProtection, 1, 1, mfile);
153 if (mbytes != MBRPROT_SIZE || !feof(mfile)) {
154 printf("%s", FailedInvalidMBR);
155 exit(1);
156 }
157 printf("%s", Okay);
158
159
160 /*
161 // Find Protection Image Signature.
162 // Note that this signature must reside on a sector boundary in the
163 // AIR-BOOT.COM image.
164 */
165 for (i=0; i<55; i++) {
166 if (!memcmp(MBRProtectionSignature, &BootCode[i*SECSIZE], strlen(MBRProtectionSignature))) {
167 found = 1;
168 break;
169 }
170 }
171
172 /*
173 // Abort if not found.
174 */
175 printf("%s",MergeMBR);
176 if (!found) {
177 printf("%s",Failed);
178 exit(2);
179 }
180
181 /*
182 // Merge Protection Image.
183 */
184 memcpy(&BootCode[i*SECSIZE], MBRProtection, MBRPROT_SIZE);
185 printf("%s", Okay);
186
187
188 /*
189 // Count Code Sectors.
190 // Obsolete now because since v1.0.8 the Protection Image has moved just
191 // below the Configuration and the code is always max. size.
192 // Overlap checking is done while assembling AIR-BOOT.ASM.
193 // So we just write the max. code sectors here.
194 */
195 printf("%s", CountCode);
196 BootCode[16] = 53;
197 printf("%s", Okay);
198
199 /*
200 // Write AIRBOOT.BIN
201 */
202 printf("%s", WriteCode);
203 ofile = fopen(OUT_FILE, "wb");
204 if (!ofile) {
205 printf("%s", FailedWriteCode);
206 exit(3);
207 }
208 obytes = fwrite(BootCode, 1, IMAGE_SIZE, ofile);
209 if (obytes != IMAGE_SIZE || ferror(ofile)) {
210 printf("%s", FailedWriteCode);
211 exit(3);
212 }
213 printf("%s", Okay);
214
215
216 /*
217 // Close files.
218 */
219 if (ifile)
220 fclose(ifile);
221 if (mfile)
222 fclose(mfile);
223 if (ofile)
224 fclose(ofile);
225
226
227 return 0L;
228}
229
Note: See TracBrowser for help on using the repository browser.