|
|
1.1 root 1: #include <stdio.h> /* fprintf */
2: #include <stdlib.h> /* contains exit */
3: #include <sys/types.h> /* unistd.h needs this */
4: #include <unistd.h> /* contains read/write */
5: #include <fcntl.h>
1.1.1.3 ! root 6: #include <string.h>
1.1 root 7:
8: #define MINIX_HEADER 32
9: #define GCC_HEADER 1024
10:
11: void die(char * str)
12: {
13: fprintf(stderr,"%s\n",str);
14: exit(1);
15: }
16:
17: void usage(void)
18: {
19: die("Usage: build boot system [> image]");
20: }
21:
22: int main(int argc, char ** argv)
23: {
24: int i,c,id;
25: char buf[1024];
26:
27: if (argc != 3)
28: usage();
29: for (i=0;i<sizeof buf; i++) buf[i]=0;
30: if ((id=open(argv[1],O_RDONLY,0))<0)
31: die("Unable to open 'boot'");
32: if (read(id,buf,MINIX_HEADER) != MINIX_HEADER)
33: die("Unable to read header of 'boot'");
34: if (((long *) buf)[0]!=0x04100301)
35: die("Non-Minix header of 'boot'");
36: if (((long *) buf)[1]!=MINIX_HEADER)
37: die("Non-Minix header of 'boot'");
38: if (((long *) buf)[3]!=0)
39: die("Illegal data segment in 'boot'");
40: if (((long *) buf)[4]!=0)
41: die("Illegal bss in 'boot'");
42: if (((long *) buf)[5] != 0)
43: die("Non-Minix header of 'boot'");
44: if (((long *) buf)[7] != 0)
45: die("Illegal symbol table in 'boot'");
46: i=read(id,buf,sizeof buf);
47: fprintf(stderr,"Boot sector %d bytes.\n",i);
48: if (i>510)
49: die("Boot block may not exceed 510 bytes");
50: buf[510]=0x55;
51: buf[511]=0xAA;
52: i=write(1,buf,512);
53: if (i!=512)
54: die("Write call failed");
55: close (id);
56:
57: if ((id=open(argv[2],O_RDONLY,0))<0)
58: die("Unable to open 'system'");
1.1.1.3 ! root 59: // if (read(id,buf,GCC_HEADER) != GCC_HEADER)
! 60: // die("Unable to read header of 'system'");
! 61: // if (((long *) buf)[5] != 0)
! 62: // die("Non-GCC header of 'system'");
1.1 root 63: for (i=0 ; (c=read(id,buf,sizeof buf))>0 ; i+=c )
64: if (write(1,buf,c)!=c)
65: die("Write call failed");
1.1.1.2 root 66:
67: /* only needed by qemu. ( qemu may not read last sector if
68: * size is < 512 bytes )
69: */
70: memset(buf,0,512);
71: write(1,buf,512);
72:
1.1 root 73: close(id);
74: fprintf(stderr,"System %d bytes.\n",i);
75: return(0);
76: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.