完善内核build系统
This commit is contained in:
parent
35c8548e77
commit
4092d58ede
|
@ -3,3 +3,4 @@
|
|||
*.o
|
||||
*.map
|
||||
*.elf
|
||||
metaverse_kernel
|
||||
|
|
24
Makefile
24
Makefile
|
@ -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
|
||||
|
||||
clear:
|
||||
clear: config
|
||||
@make -C src clear --no-print-directory
|
||||
|
||||
run:
|
||||
run: config
|
||||
@make -C test run --no-print-directory
|
||||
|
||||
debug:
|
||||
debug: config
|
||||
@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
|
||||
|
|
|
@ -56,8 +56,10 @@ VPATH = memm/ memm/allocator tty/ klog/ arch/${ARCH}
|
|||
|
||||
%.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"
|
||||
@${ASM} ${ASMFLAGS32} -o $@ $< 2>&1 | "${SOURCE}/colorize" "warning:=pink" "error:=red"
|
||||
@objcopy -I elf32-i386 -O elf64-x86-64 $@ $@ 2>&1 | "${SOURCE}/colorize" "warning:=pink" "error:=red" "objcopy=lyellow"
|
||||
@${ASM} ${ASMFLAGS32} -o $@ $< 2>&1 \
|
||||
| "${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
|
||||
@echo -e "\e[1m\e[33m${ASM}\e[0m \e[32m$<\e[0m \e[34m-->\e[0m \e[1m\e[32m$@\e[0m"
|
||||
|
|
|
@ -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'])
|
|
@ -6,45 +6,45 @@ ARCH := $(shell uname -m)
|
|||
BIOS = bios/${ARCH}/OVMF_CODE.fd
|
||||
|
||||
run:
|
||||
@sudo modprobe nbd
|
||||
@doas modprobe nbd
|
||||
@make load
|
||||
@qemu-system-x86_64 -m 4G metaverse.img -bios ${BIOS}
|
||||
@qemu-system-${ARCH} -m 4G metaverse.img -bios ${BIOS}
|
||||
|
||||
debug:
|
||||
@echo "在gdb中连接远程目标'localhost:1234'即可"
|
||||
@sudo modprobe nbd
|
||||
@doas modprobe nbd
|
||||
@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:
|
||||
@qemu-img create -f qcow2 metaverse.img 512M
|
||||
@sudo modprobe nbd
|
||||
@sudo qemu-nbd --connect=/dev/nbd0 metaverse.img
|
||||
@sudo partprobe /dev/nbd0
|
||||
@doas modprobe nbd
|
||||
@doas qemu-nbd --connect=/dev/nbd0 metaverse.img
|
||||
@doas partprobe /dev/nbd0
|
||||
@echo "你需要为这个虚拟磁盘写入一个GPT分区表并分出efi分区和根分区。"
|
||||
@sudo fdisk /dev/nbd0
|
||||
@sudo mkfs.fat -F 32 /dev/nbd0p1
|
||||
@sudo mkfs.fat -F 32 /dev/nbd0p2
|
||||
@sudo mount /dev/nbd0p2 mnt/
|
||||
@sudo mount -m /dev/nbd0p1 mnt/boot/
|
||||
@sudo mkdir mnt/boot/EFI/
|
||||
@doas fdisk /dev/nbd0
|
||||
@doas mkfs.fat -F 32 /dev/nbd0p1
|
||||
@doas mkfs.fat -F 32 /dev/nbd0p2
|
||||
@doas mount /dev/nbd0p2 mnt/
|
||||
@doas mount -m /dev/nbd0p1 mnt/boot/
|
||||
@doas mkdir mnt/boot/EFI/
|
||||
@make unmount
|
||||
|
||||
load:
|
||||
@echo loading kernel ...
|
||||
@make mount
|
||||
@sudo cp ${TARGET} mnt/boot/
|
||||
@doas cp ${TARGET} mnt/boot/
|
||||
@make unmount
|
||||
|
||||
mount:
|
||||
@sudo modprobe nbd
|
||||
@sudo qemu-nbd --connect=/dev/nbd0 metaverse.img
|
||||
@sudo partprobe /dev/nbd0
|
||||
@sudo mount /dev/nbd0p2 mnt/
|
||||
@sudo mount /dev/nbd0p1 mnt/boot/
|
||||
@doas modprobe nbd
|
||||
@doas qemu-nbd --connect=/dev/nbd0 metaverse.img
|
||||
@doas partprobe /dev/nbd0
|
||||
@doas mount /dev/nbd0p2 mnt/
|
||||
@doas mount /dev/nbd0p1 mnt/boot/
|
||||
|
||||
unmount:
|
||||
@sync
|
||||
@sudo umount /dev/nbd0p1
|
||||
@sudo umount /dev/nbd0p2
|
||||
@sudo qemu-nbd --disconnect /dev/nbd0
|
||||
@doas umount /dev/nbd0p1
|
||||
@doas umount /dev/nbd0p2
|
||||
@doas qemu-nbd --disconnect /dev/nbd0
|
||||
|
|
Loading…
Reference in New Issue