Do not use cat or type.
This commit is contained in:
parent
70cd658ad0
commit
fea8b881af
7
Makefile
7
Makefile
@ -105,9 +105,6 @@ LDFLAGS=-m elf_i386
|
||||
user/%: user/%.o user/crt.o
|
||||
$(LD) $(LDFLAGS) -o $@ -Ttext 0x1000 $^
|
||||
|
||||
image.bin: mbr.bin fs.img
|
||||
$(CAT) $^ >$@
|
||||
|
||||
kernel.bin: $(OBJECTS)
|
||||
$(LD) $(LDFLAGS) $(LDKERNELFLAGS) -o $@ -Ttext 0x9000 $^
|
||||
|
||||
@ -120,9 +117,9 @@ bootmain.o: bootmain.c
|
||||
%.o: %.S
|
||||
$(CC) $(ASMFLAGS) $^ -o $@
|
||||
|
||||
mbr.bin: mbr.elf tools/mbrpad
|
||||
image.bin: mbr.elf tools/mbrpad fs.img
|
||||
$(OBJCOPY) -S -O binary -j .text $< $@
|
||||
tools/mbrpad $@
|
||||
tools/mbrpad $@ fs.img
|
||||
|
||||
mbr.raw: mbr.o bootmain.o
|
||||
$(LD) -N -m elf_i386 -Ttext=0x7c00 --oformat=binary $^ -o $@
|
||||
|
||||
@ -3,20 +3,36 @@
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
|
||||
enum {
|
||||
MBR_END = 510,
|
||||
};
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
if (argc != 2) {
|
||||
fprintf(stderr, "Usage: %s mbr.bin\n", argv[0]);
|
||||
if (argc != 3) {
|
||||
fprintf(stderr, "Usage: %s mbr.bin fs.img\n", argv[0]);
|
||||
return 1;
|
||||
}
|
||||
const char* filename = argv[1];
|
||||
const char* fsimg_path = argv[2];
|
||||
int fd = open(filename, O_RDWR);
|
||||
off_t length = lseek(fd, 0, SEEK_END);
|
||||
if (length > 510) {
|
||||
fprintf(stderr, "file %s is larger than 510 bytes (size: %llu)\n",
|
||||
filename, (unsigned long long)length);
|
||||
if (length > MBR_END) {
|
||||
fprintf(stderr, "file %s is larger than %d bytes (size: %llu)\n",
|
||||
filename, MBR_END, (unsigned long long)length);
|
||||
return 1;
|
||||
}
|
||||
lseek(fd, 510, SEEK_SET);
|
||||
lseek(fd, MBR_END, SEEK_SET);
|
||||
write(fd, "\x55\xaa", 2);
|
||||
|
||||
int fsimg = open(fsimg_path, O_RDONLY);
|
||||
if (fsimg < 0) {
|
||||
perror(fsimg_path);
|
||||
return 1;
|
||||
}
|
||||
char buf[1024];
|
||||
ssize_t bytes;
|
||||
while ((bytes = read(fsimg, buf, sizeof(buf))) > 0) {
|
||||
write(fd, buf, bytes);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user