-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.c
83 lines (71 loc) · 1.45 KB
/
build.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// Copyright (c) 2023 Wang Baisheng <[email protected]>, Wang Shenghan. All Rights Reserved.
#include <unistd.h>
#include <fcntl.h>
#define BASE (0x100000 - 0x4200)
int main() {
int fd, fd_kernel;
int c;
char buf[512];
fd_kernel = open("kernel.bin", O_WRONLY | O_CREAT, 0666);
// boot16.bin
fd = open("boot16.bin", O_RDONLY);
while (1) {
c = read(fd, buf, 512);
if (c > 0) {
write(fd_kernel, buf, c);
} else {
break;
}
};
close(fd);
// boot32.bin
lseek(fd_kernel, 0x100000 - BASE, SEEK_SET);
fd = open("boot32.bin", O_RDONLY);
while (1) {
c = read(fd, buf, 512);
if (c > 0) {
write(fd_kernel, buf, c);
} else {
break;
}
};
close(fd);
// system.bin
lseek(fd_kernel, 0x200000 - BASE, SEEK_SET);
fd = open("system.bin", O_RDONLY);
while (1) {
c = read(fd, buf, 512);
if (c > 0) {
write(fd_kernel, buf, c);
} else {
break;
}
};
close(fd);
// app1
lseek(fd_kernel, 0x1000000 - BASE, SEEK_SET);
fd = open("app/app1.bin", O_RDONLY);
while (1) {
c = read(fd, buf, 512);
if (c > 0) {
write(fd_kernel, buf, c);
} else {
break;
}
};
close(fd);
// app2
lseek(fd_kernel, 0x2000000 - BASE, SEEK_SET);
fd = open("app/app2.bin", O_RDONLY);
while (1) {
c = read(fd, buf, 512);
if (c > 0) {
write(fd_kernel, buf, c);
} else {
break;
}
};
close(fd);
close(fd_kernel);
return 0;
}