limine-install: Embed limine.bin inside limine-install
This commit is contained in:
parent
18bfa311de
commit
5197205697
39
Makefile
39
Makefile
|
@ -1,20 +1,40 @@
|
||||||
CC = cc
|
CC = cc
|
||||||
|
OBJCOPY = objcopy
|
||||||
CFLAGS = -O2 -pipe -Wall -Wextra
|
CFLAGS = -O2 -pipe -Wall -Wextra
|
||||||
|
PREFIX = /usr/local
|
||||||
|
DESTDIR =
|
||||||
|
|
||||||
PATH := $(shell pwd)/toolchain/bin:$(PATH)
|
PATH := $(shell pwd)/toolchain/bin:$(PATH)
|
||||||
|
|
||||||
.PHONY: all clean stage2 stage2-clean decompressor decompressor-clean toolchain test.hdd echfs-test ext2-test fat32-test
|
.PHONY: all clean install bootloader bootloader-clean distclean stage2 stage2-clean decompressor decompressor-clean toolchain test.hdd echfs-test ext2-test fat32-test
|
||||||
|
|
||||||
all: stage2 decompressor
|
all: limine-install
|
||||||
|
|
||||||
|
limine-install: limine-install.c limine.o
|
||||||
|
$(CC) $(CFLAGS) limine.o limine-install.c -o limine-install
|
||||||
|
|
||||||
|
limine.o: limine.bin
|
||||||
|
$(OBJCOPY) -I binary -O default limine.bin limine.o
|
||||||
|
|
||||||
|
limine.bin: bootloader
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -f limine.o limine-install
|
||||||
|
|
||||||
|
install: all
|
||||||
|
install -d $(DESTDIR)$(PREFIX)/bin
|
||||||
|
install -s limine-install $(DESTDIR)$(PREFIX)/bin/
|
||||||
|
|
||||||
|
bootloader: stage2 decompressor
|
||||||
gzip -n -9 < stage2/stage2.bin > stage2/stage2.bin.gz
|
gzip -n -9 < stage2/stage2.bin > stage2/stage2.bin.gz
|
||||||
cd bootsect && nasm bootsect.asm -fbin -o ../limine.bin
|
cd bootsect && nasm bootsect.asm -fbin -o ../limine.bin
|
||||||
cd pxeboot && nasm bootsect.asm -fbin -o ../limine-pxe.bin
|
cd pxeboot && nasm bootsect.asm -fbin -o ../limine-pxe.bin
|
||||||
cp stage2/stage2.map ./
|
cp stage2/stage2.map ./
|
||||||
|
|
||||||
clean: stage2-clean decompressor-clean test-clean
|
bootloader-clean: stage2-clean decompressor-clean test-clean
|
||||||
rm -f stage2/stage2.bin.gz test/stage2.map test.hdd
|
rm -f stage2/stage2.bin.gz test/stage2.map test.hdd
|
||||||
|
|
||||||
distclean: clean
|
distclean: clean bootloader-clean
|
||||||
rm -f limine-install
|
|
||||||
|
|
||||||
stage2:
|
stage2:
|
||||||
$(MAKE) -C stage2 all
|
$(MAKE) -C stage2 all
|
||||||
|
@ -34,16 +54,13 @@ test-clean:
|
||||||
toolchain:
|
toolchain:
|
||||||
cd toolchain && ./make_toolchain.sh -j`nproc`
|
cd toolchain && ./make_toolchain.sh -j`nproc`
|
||||||
|
|
||||||
limine-install: limine-install.c
|
|
||||||
$(CC) $(CFLAGS) limine-install.c -o limine-install
|
|
||||||
|
|
||||||
test.hdd:
|
test.hdd:
|
||||||
rm -f test.hdd
|
rm -f test.hdd
|
||||||
dd if=/dev/zero bs=1M count=0 seek=64 of=test.hdd
|
dd if=/dev/zero bs=1M count=0 seek=64 of=test.hdd
|
||||||
parted -s test.hdd mklabel gpt
|
parted -s test.hdd mklabel gpt
|
||||||
parted -s test.hdd mkpart primary 2048s 100%
|
parted -s test.hdd mkpart primary 2048s 100%
|
||||||
|
|
||||||
echfs-test: all limine-install test.hdd
|
echfs-test: all test.hdd
|
||||||
$(MAKE) -C test
|
$(MAKE) -C test
|
||||||
echfs-utils -g -p0 test.hdd quick-format 512 > part_guid
|
echfs-utils -g -p0 test.hdd quick-format 512 > part_guid
|
||||||
sed "s/@GUID@/`cat part_guid`/g" < test/limine.cfg > limine.cfg.tmp
|
sed "s/@GUID@/`cat part_guid`/g" < test/limine.cfg > limine.cfg.tmp
|
||||||
|
@ -56,7 +73,7 @@ echfs-test: all limine-install test.hdd
|
||||||
./limine-install limine.bin test.hdd
|
./limine-install limine.bin test.hdd
|
||||||
qemu-system-x86_64 -net none -smp 4 -enable-kvm -cpu host -hda test.hdd -debugcon stdio
|
qemu-system-x86_64 -net none -smp 4 -enable-kvm -cpu host -hda test.hdd -debugcon stdio
|
||||||
|
|
||||||
ext2-test: all limine-install test.hdd
|
ext2-test: all test.hdd
|
||||||
$(MAKE) -C test
|
$(MAKE) -C test
|
||||||
cp stage2.map test/
|
cp stage2.map test/
|
||||||
rm -rf test_image/
|
rm -rf test_image/
|
||||||
|
@ -74,7 +91,7 @@ ext2-test: all limine-install test.hdd
|
||||||
./limine-install limine.bin test.hdd
|
./limine-install limine.bin test.hdd
|
||||||
qemu-system-x86_64 -net none -smp 4 -enable-kvm -cpu host -hda test.hdd -debugcon stdio
|
qemu-system-x86_64 -net none -smp 4 -enable-kvm -cpu host -hda test.hdd -debugcon stdio
|
||||||
|
|
||||||
fat32-test: all limine-install test.hdd
|
fat32-test: all test.hdd
|
||||||
$(MAKE) -C test
|
$(MAKE) -C test
|
||||||
cp stage2.map test/
|
cp stage2.map test/
|
||||||
rm -rf test_image/
|
rm -rf test_image/
|
||||||
|
|
|
@ -230,39 +230,32 @@ static bool device_write(const void *buffer, uint64_t loc, size_t count) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extern uint8_t _binary_limine_bin_start[], _binary_limine_bin_end[];
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
int ok = 1;
|
int ok = 1;
|
||||||
FILE *bootloader_file = NULL;
|
uint8_t *bootloader_img = _binary_limine_bin_start;
|
||||||
uint8_t *bootloader_img = NULL;
|
size_t bootloader_file_size =
|
||||||
|
(size_t)_binary_limine_bin_end - (size_t)_binary_limine_bin_start;
|
||||||
uint8_t orig_mbr[70], timestamp[6];
|
uint8_t orig_mbr[70], timestamp[6];
|
||||||
|
|
||||||
if (argc < 3) {
|
if (argc > 1 && strstr("limine.bin", argv[1]) != NULL) {
|
||||||
printf("Usage: %s <bootloader image> <device> [GPT partition index]\n", argv[0]);
|
fprintf(stderr,
|
||||||
|
"WARNING: Passing the bootloader binary as a file argument is\n"
|
||||||
|
" deprecated and should be avoided in the future.\n");
|
||||||
|
argc--;
|
||||||
|
argv[1] = argv[0];
|
||||||
|
argv++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (argc < 2) {
|
||||||
|
printf("Usage: %s <device> [GPT partition index]\n", argv[0]);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
bootloader_file = fopen(argv[1], "rb");
|
device = open(argv[1], O_RDWR);
|
||||||
if (bootloader_file == NULL) {
|
|
||||||
perror("Error: ");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
fseek(bootloader_file, 0, SEEK_END);
|
|
||||||
size_t bootloader_file_size = ftell(bootloader_file);
|
|
||||||
|
|
||||||
bootloader_img = malloc(bootloader_file_size);
|
|
||||||
if (bootloader_img == NULL) {
|
|
||||||
perror("Error: ");
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Load in bootloader image
|
|
||||||
fseek(bootloader_file, 0, SEEK_SET);
|
|
||||||
fread(bootloader_img, 1, bootloader_file_size, bootloader_file);
|
|
||||||
|
|
||||||
device = open(argv[2], O_RDWR);
|
|
||||||
if (device == -1) {
|
if (device == -1) {
|
||||||
perror("Error: ");
|
perror("Error");
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -454,10 +447,6 @@ cleanup:
|
||||||
free(cache);
|
free(cache);
|
||||||
if (device != -1)
|
if (device != -1)
|
||||||
close(device);
|
close(device);
|
||||||
if (bootloader_file)
|
|
||||||
fclose(bootloader_file);
|
|
||||||
if (bootloader_img)
|
|
||||||
free(bootloader_img);
|
|
||||||
|
|
||||||
return ok;
|
return ok;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue