-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
82 lines (65 loc) · 2.7 KB
/
Makefile
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
ARCH = $(shell uname -m | sed s,i[3456789]86,ia32,)
OBJS = boot_loader.o boot_page_table.o
TARGET = boot_loader.efi
LIB = /usr/lib
EFILIB = /usr/lib
EFI_CRT_OBJS = $(EFILIB)/crt0-efi-$(ARCH).o
EFI_LDS = $(EFILIB)/elf_$(ARCH)_efi.lds
ifeq ($(origin KERNEL_BUILD),undefined)
KERNEL_BUILD = cmake-build-debug
endif
ifeq ($(origin EFI_SHELL),undefined)
EFI_SHELL = /usr/share/edk2-shell/x64/Shell_Full.efi
endif
CFLAGS += -Iinclude -fno-stack-protector -fpic \
-fshort-wchar -mno-red-zone -Wall
ifeq ($(ARCH),x86_64)
CFLAGS += -DEFI_FUNCTION_WRAPPER
endif
LDFLAGS += -nostdlib -znocombreloc -T $(EFI_LDS) -shared \
-Bsymbolic -L $(EFILIB) -L $(LIB) $(EFI_CRT_OBJS)
all: $(TARGET)
boot_loader.so: $(OBJS)
ld $(LDFLAGS) $(OBJS) -o $@ -lefi -lgnuefi
.FORCE:
# use cmake to enable IDE
kernel: .FORCE
make -C $(KERNEL_BUILD) kernel
ln -sf $(KERNEL_BUILD)/kernel kernel
# g++ -nostdlib -c -o kernel.o kernel.cpp
# ld -static -T kernel.ld -o kernel kernel.o
boot_loader.efi: boot_loader.so
objcopy -j .text -j .sdata -j .data -j .dynamic \
-j .dynsym -j .rel -j .rela -j .reloc \
--target=efi-app-$(ARCH) boot_loader.so boot_loader.efi
setup:
echo "uncomment me to run because this is potentially dangerous"
# dd if=/dev/zero of=.disk.raw.source bs=1M count=128
# parted -s .disk.raw.source -- mktable gpt mkpart primary fat32 1MiB 64MiB
# udisksctl loop-setup -f .disk.raw.source
# sudo mkfs.vfat -F 32 /dev/loop0p1
# udisksctl loop-delete /dev/loop0
# cp .disk.raw.source disk.raw
# a gpt partition table and create an fat32 partion(esp) and 1 ext4 partition
disk.raw: boot_loader.efi startup.nsh kernel
# to remake to .disk.raw.source
# dd if=/dev/zero of=.disk.raw.source bs=1M count=128
# parted -s .disk.raw.source -- mktable gpt mkpart primary fat32 1MiB 64MiB
# udisksctl loop-setup -f .disk.raw.source
# mkfs.vfat -F 32 /dev/loopXp1
# udiskctl loop-delete /dev/loopX
# cp .disk.raw.source disk.raw
./build_disk_image.sh $(EFI_SHELL)
# disk-linux.raw:
# $(eval loop_device := $(shell udisksctl loop-setup -f disk-linux.raw | python3 -c "import sys; print(sys.stdin.read().split()[-1][:-1])"))
# $(info loop device ${loop_device})
# $(eval mount_path := $(shell udisksctl mount -b $(loop_device)p1 | python3 -c "import sys; print(sys.stdin.read().split()[-1])"))
# rm -rf ${mount_path}/EFI ${mount_path}/boot_loader.efi ${mount_path}/startup.nsh
# cp -r linux-efi/EFI ${mount_path}/EFI
# udisksctl unmount -b ${loop_device}p1
# udisksctl loop-delete -b ${loop_device}
sda.vdi: disk.raw startup.nsh kernel
rm -f sda.vdi
VBoxManage convertdd disk.raw sda.vdi --format VDI
clean:
rm *.o *.so *.efi sdb.vdi