完善内核build系统

This commit is contained in:
pointer-to-bios 2023-12-29 22:54:46 +08:00
parent 35c8548e77
commit 4092d58ede
5 changed files with 125 additions and 29 deletions

1
.gitignore vendored
View File

@ -3,3 +3,4 @@
*.o *.o
*.map *.map
*.elf *.elf
metaverse_kernel

View File

@ -1,13 +1,27 @@
.PHONY: all clear run debug SOURCE := $(shell pwd)/src/scripts
all: .PHONY: all clear run debug config
all: config
@make -C src all --no-print-directory @make -C src all --no-print-directory
clear: clear: config
@make -C src clear --no-print-directory @make -C src clear --no-print-directory
run: run: config
@make -C test run --no-print-directory @make -C test run --no-print-directory
debug: debug: config
@make -C test debug --no-print-directory @make -C test debug --no-print-directory
config:
@if [ "${shell uname -s}" != "Linux" ]; then \
echo -e "\e[1;33mMetaverse\e[0m must build under \e[1;35mLinux\e[0m or itself."; \
exit -1; \
fi
@if [ -f "metaverse_kernel" ]; then \
echo; \
else \
touch metaverse_kernel; \
"${SOURCE}/depcheck"; \
fi

View File

@ -56,8 +56,10 @@ VPATH = memm/ memm/allocator tty/ klog/ arch/${ARCH}
%.32.o: arch/${ARCH}/%.s %.32.o: arch/${ARCH}/%.s
@echo -e "\e[1m\e[33m${ASM}\e[0m \e[32m$<\e[0m \e[34m-->\e[0m \e[1m\e[32m$@\e[0m" @echo -e "\e[1m\e[33m${ASM}\e[0m \e[32m$<\e[0m \e[34m-->\e[0m \e[1m\e[32m$@\e[0m"
@${ASM} ${ASMFLAGS32} -o $@ $< 2>&1 | "${SOURCE}/colorize" "warning:=pink" "error:=red" @${ASM} ${ASMFLAGS32} -o $@ $< 2>&1 \
@objcopy -I elf32-i386 -O elf64-x86-64 $@ $@ 2>&1 | "${SOURCE}/colorize" "warning:=pink" "error:=red" "objcopy=lyellow" | "${SOURCE}/colorize" "warning:=pink" "error:=red"
@objcopy -I elf32-i386 -O elf64-x86-64 $@ $@ 2>&1 \
| "${SOURCE}/colorize" "warning:=pink" "error:=red" "objcopy=lyellow"
%.o: arch/${ARCH}/%.s %.o: arch/${ARCH}/%.s
@echo -e "\e[1m\e[33m${ASM}\e[0m \e[32m$<\e[0m \e[34m-->\e[0m \e[1m\e[32m$@\e[0m" @echo -e "\e[1m\e[33m${ASM}\e[0m \e[32m$<\e[0m \e[34m-->\e[0m \e[1m\e[32m$@\e[0m"

79
src/scripts/depcheck Executable file
View File

@ -0,0 +1,79 @@
#!/usr/bin/python
import subprocess
import os
color = {
'black': '\033[30m',
'red': '\033[31m',
'green': '\033[32m',
'yellow': '\033[33m',
'blue': '\033[34m',
'pink': '\033[35m',
'cyan': '\033[36m',
'white': '\033[37m',
'lblack': '\033[1;30m',
'lred': '\033[1;31m',
'lgreen': '\033[1;32m',
'lyellow': '\033[1;33m',
'lblue': '\033[1;34m',
'lpink': '\033[1;35m',
'lcyan': '\033[1;36m',
'lwhite': '\033[1;37m',
'reset': '\033[0m',
}
arch = subprocess.check_output("uname -m", shell=True).decode().strip()
kernel_modules = [
"nbd",
]
softwares = {
"doas": ["doas"],
"gcc": ["gcc"],
"nasm": ["nasm"],
"rust": ["rustc", "rustdoc", "rust-lldb"],
"qemu": ["qemu-img", "qemu-nbd", "qemu-system-"+arch],
}
# 检查内核模块
lsmodoutput = subprocess.check_output("lsmod", shell=True).decode()
print("Checking kernel modules ...")
for mod in kernel_modules:
mmod = "\n" + mod
mmod += " "
if mmod in lsmodoutput:
print(" " + color['lpink'] + f"{mod}" + color['reset'] + " exists.")
else:
print(" " + color['lred'] + f"{mod}" + color['reset'] + " not found.")
print("Kernel module " +
color['lred'] + f"{mod}" + color['reset'] + " is not installed.")
exit(-1)
# 检查软件依赖
pathsenv = os.environ.get("PATH").split(":")
for software, progs in softwares.items():
print("Checking " + color['lcyan'] +
f"{software}" + color['reset'] + " ...")
for program in progs:
exists = False
for path in pathsenv:
if os.path.isfile(os.path.join(path, program)):
exists = True
break
if exists:
print(" " + color['lyellow'] +
f"{program}" + color['reset'] + " existed.")
else:
print(" " + color['lred'] +
f"{program}" + color['reset'] + " not found.")
print("Software " + color['lred'] + f"{software}" +
color['reset'] + " is not installed or completed.")
exit(-2)
print("All dependencies are " +
color['lgreen'] + "satisfied." + color['reset'])

View File

@ -6,45 +6,45 @@ ARCH := $(shell uname -m)
BIOS = bios/${ARCH}/OVMF_CODE.fd BIOS = bios/${ARCH}/OVMF_CODE.fd
run: run:
@sudo modprobe nbd @doas modprobe nbd
@make load @make load
@qemu-system-x86_64 -m 4G metaverse.img -bios ${BIOS} @qemu-system-${ARCH} -m 4G metaverse.img -bios ${BIOS}
debug: debug:
@echo "在gdb中连接远程目标'localhost:1234'即可" @echo "在gdb中连接远程目标'localhost:1234'即可"
@sudo modprobe nbd @doas modprobe nbd
@make load @make load
@qemu-system-x86_64 -m 4G metaverse.img -bios ${BIOS} -s -S @qemu-system-${ARCH} -m 4G metaverse.img -bios ${BIOS} -s -S
create: create:
@qemu-img create -f qcow2 metaverse.img 512M @qemu-img create -f qcow2 metaverse.img 512M
@sudo modprobe nbd @doas modprobe nbd
@sudo qemu-nbd --connect=/dev/nbd0 metaverse.img @doas qemu-nbd --connect=/dev/nbd0 metaverse.img
@sudo partprobe /dev/nbd0 @doas partprobe /dev/nbd0
@echo "你需要为这个虚拟磁盘写入一个GPT分区表并分出efi分区和根分区。" @echo "你需要为这个虚拟磁盘写入一个GPT分区表并分出efi分区和根分区。"
@sudo fdisk /dev/nbd0 @doas fdisk /dev/nbd0
@sudo mkfs.fat -F 32 /dev/nbd0p1 @doas mkfs.fat -F 32 /dev/nbd0p1
@sudo mkfs.fat -F 32 /dev/nbd0p2 @doas mkfs.fat -F 32 /dev/nbd0p2
@sudo mount /dev/nbd0p2 mnt/ @doas mount /dev/nbd0p2 mnt/
@sudo mount -m /dev/nbd0p1 mnt/boot/ @doas mount -m /dev/nbd0p1 mnt/boot/
@sudo mkdir mnt/boot/EFI/ @doas mkdir mnt/boot/EFI/
@make unmount @make unmount
load: load:
@echo loading kernel ... @echo loading kernel ...
@make mount @make mount
@sudo cp ${TARGET} mnt/boot/ @doas cp ${TARGET} mnt/boot/
@make unmount @make unmount
mount: mount:
@sudo modprobe nbd @doas modprobe nbd
@sudo qemu-nbd --connect=/dev/nbd0 metaverse.img @doas qemu-nbd --connect=/dev/nbd0 metaverse.img
@sudo partprobe /dev/nbd0 @doas partprobe /dev/nbd0
@sudo mount /dev/nbd0p2 mnt/ @doas mount /dev/nbd0p2 mnt/
@sudo mount /dev/nbd0p1 mnt/boot/ @doas mount /dev/nbd0p1 mnt/boot/
unmount: unmount:
@sync @sync
@sudo umount /dev/nbd0p1 @doas umount /dev/nbd0p1
@sudo umount /dev/nbd0p2 @doas umount /dev/nbd0p2
@sudo qemu-nbd --disconnect /dev/nbd0 @doas qemu-nbd --disconnect /dev/nbd0