Filesystem part 1: FAT32 image bootstrapping
This commit is contained in:
6
.gitignore
vendored
6
.gitignore
vendored
@@ -1,8 +1,6 @@
|
|||||||
*.o
|
*.o
|
||||||
bochslog.txt
|
|
||||||
build/
|
build/
|
||||||
kernel.elf
|
kernel.elf
|
||||||
os.iso
|
blankos-fat.img
|
||||||
blankos.iso
|
|
||||||
real/
|
|
||||||
i386-elf-7.5.0-Linux-x86_64/
|
i386-elf-7.5.0-Linux-x86_64/
|
||||||
|
i386-elf-7.5.0-Linux-x86_64.tar.xz
|
||||||
|
|||||||
10
bochsrc.txt
10
bochsrc.txt
@@ -1,10 +0,0 @@
|
|||||||
megs: 32
|
|
||||||
display_library: x
|
|
||||||
romimage: file=/usr/share/bochs/BIOS-bochs-legacy
|
|
||||||
vgaromimage: file=/usr/share/bochs/VGABIOS-lgpl-latest
|
|
||||||
ata0-master: type=cdrom, path=os.iso, status=inserted
|
|
||||||
boot: cdrom
|
|
||||||
log: bochslog.txt
|
|
||||||
clock: sync=realtime, time0=local
|
|
||||||
cpu: count=1, ips=1000000
|
|
||||||
com1: enabled=1, mode=file, dev=com1.out
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
default=0
|
|
||||||
timeout=0
|
|
||||||
|
|
||||||
title os
|
|
||||||
kernel /boot/kernel.elf
|
|
||||||
Binary file not shown.
Binary file not shown.
37
makefile
37
makefile
@@ -1,5 +1,5 @@
|
|||||||
CC = i386-elf-7.5.0-Linux-x86_64/bin/i386-elf-gcc
|
CC = i386-elf-7.5.0-Linux-x86_64/bin/i386-elf-gcc
|
||||||
CFLAGS = -Wall -Wextra -Wno-builtin-declaration-mismatch -c -I src/
|
CFLAGS = -g -Wall -Wextra -Wno-builtin-declaration-mismatch -c -I src/
|
||||||
LDFLAGS = -T link.ld -melf_i386
|
LDFLAGS = -T link.ld -melf_i386
|
||||||
AS = nasm
|
AS = nasm
|
||||||
ASFLAGS = -f elf
|
ASFLAGS = -f elf
|
||||||
@@ -16,6 +16,9 @@ ASM_SOURCES = $(wildcard $(KERNEL_DIR)/*.s) $(wildcard $(LIBC_DIR)/*.s) $(wildca
|
|||||||
|
|
||||||
OBJECTS = $(patsubst $(SRC_DIR)/%, $(OBJ_DIR)/%, $(C_SOURCES:.c=.o) $(ASM_SOURCES:.s=.o))
|
OBJECTS = $(patsubst $(SRC_DIR)/%, $(OBJ_DIR)/%, $(C_SOURCES:.c=.o) $(ASM_SOURCES:.s=.o))
|
||||||
|
|
||||||
|
TOOLCHAIN_SRC = https://newos.org/toolchains/i386-elf-7.5.0-Linux-x86_64.tar.xz
|
||||||
|
TOOLCHAIN_FILE = i386-elf-7.5.0-Linux-x86_64.tar.xz
|
||||||
|
|
||||||
all: $(OBJ_DIR) kernel.elf
|
all: $(OBJ_DIR) kernel.elf
|
||||||
|
|
||||||
$(OBJ_DIR):
|
$(OBJ_DIR):
|
||||||
@@ -32,31 +35,17 @@ $(OBJ_DIR)/%.o: $(SRC_DIR)/%.s
|
|||||||
$(AS) $(ASFLAGS) $< -o $@
|
$(AS) $(ASFLAGS) $< -o $@
|
||||||
|
|
||||||
toolchain:
|
toolchain:
|
||||||
wget https://newos.org/toolchains/i386-elf-7.5.0-Linux-x86_64.tar.xz
|
wget $(TOOLCHAIN_SRC)
|
||||||
tar xf i386-elf-7.5.0-Linux-x86_64.tar.xz
|
tar xf $(TOOLCHAIN_FILE)
|
||||||
|
|
||||||
os.iso: kernel.elf
|
blankos-fat.img:
|
||||||
cp kernel.elf iso/boot/kernel.elf
|
sudo ./setup.sh
|
||||||
genisoimage -R \
|
|
||||||
-b boot/grub/stage2_eltorito \
|
|
||||||
-no-emul-boot \
|
|
||||||
-boot-load-size 4 \
|
|
||||||
-A os \
|
|
||||||
-input-charset utf8 \
|
|
||||||
-quiet \
|
|
||||||
-boot-info-table \
|
|
||||||
-o os.iso \
|
|
||||||
iso
|
|
||||||
|
|
||||||
real: kernel.elf
|
run: blankos-fat.img
|
||||||
mkdir -p real/boot/grub
|
qemu-system-i386 -drive file=blankos-fat.img,format=raw
|
||||||
cp kernel.elf real/boot/kernel.elf
|
|
||||||
cp grub.cfg real/boot/grub/grub.cfg
|
|
||||||
grub-mkrescue real -o blankos.iso
|
|
||||||
|
|
||||||
run: os.iso
|
debug:
|
||||||
bochs -f bochsrc.txt -q
|
qemu-system-i386 -s -S -drive file=blankos-fat.img,format=raw
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -rf $(OBJ_DIR) kernel.elf os.iso blankos.iso real
|
rm -rf $(OBJ_DIR) kernel.elf blankos-fat.img $(TOOLCHAIN_FILE)
|
||||||
|
|
||||||
|
|||||||
75
setup.sh
Executable file
75
setup.sh
Executable file
@@ -0,0 +1,75 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# A script to create a FAT32 loopback device, place a kernel onto it, and install GRUB.
|
||||||
|
# Inspired by JakeSteinburger's SpecOS setup script!
|
||||||
|
|
||||||
|
if [ "$EUID" -ne 0 ]; then
|
||||||
|
echo "Please execute this script with root privileges."
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -f "blankos-fat.img" ]; then
|
||||||
|
echo "Deleting previous disk image..."
|
||||||
|
rm blankos-fat.img
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -d "/mnt/blankos" ]; then
|
||||||
|
echo "Deleting previous mountpoint..."
|
||||||
|
rm -rf /mnt/blankos
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Creating new mountpoint..."
|
||||||
|
mkdir /mnt/blankos
|
||||||
|
|
||||||
|
echo "Creating an empty disk image..."
|
||||||
|
dd if=/dev/zero of=blankos-fat.img bs=512 count=131072
|
||||||
|
|
||||||
|
echo "Appending a parition to disk image..."
|
||||||
|
fdisk blankos-fat.img << EOF
|
||||||
|
n
|
||||||
|
p
|
||||||
|
1
|
||||||
|
|
||||||
|
|
||||||
|
a
|
||||||
|
w
|
||||||
|
EOF
|
||||||
|
|
||||||
|
echo "Creating loopback devices..."
|
||||||
|
losetup -fP blankos-fat.img
|
||||||
|
|
||||||
|
# Get first partition loopback
|
||||||
|
LOOP_DEVICE=$(losetup -l | grep blankos-fat.img | awk '{print $1}')
|
||||||
|
PARTITION="${LOOP_DEVICE}p1"
|
||||||
|
|
||||||
|
echo "Creating FAT32 partition..."
|
||||||
|
mkfs.vfat -F 32 $PARTITION
|
||||||
|
|
||||||
|
echo "Mounting partition..."
|
||||||
|
mount $PARTITION /mnt/blankos
|
||||||
|
|
||||||
|
echo "Installing GRUB on $LOOP_DEVICE"
|
||||||
|
grub-install --root-directory=/mnt/blankos --target=i386-pc --no-floppy --modules="normal part_msdos fat multiboot" $LOOP_DEVICE
|
||||||
|
|
||||||
|
echo "Copying kernel file and GRUB configuration file..."
|
||||||
|
|
||||||
|
cp kernel.elf /mnt/blankos/boot/
|
||||||
|
cp grub.cfg /mnt/blankos/boot/grub/
|
||||||
|
|
||||||
|
echo "Appending test files..."
|
||||||
|
mkdir /mnt/blankos/hello
|
||||||
|
echo "Hello, world from FAT32 text file." > /mnt/blankos/hello/testfile.txt
|
||||||
|
|
||||||
|
# cp program.elf /mnt/blankos/programs/
|
||||||
|
# In the future, when the OS can load programs and parse ELF
|
||||||
|
|
||||||
|
echo "Unmounting partition..."
|
||||||
|
umount /mnt/blankos
|
||||||
|
|
||||||
|
echo "Freeing loopback devices..."
|
||||||
|
losetup -d $LOOP_DEVICE
|
||||||
|
|
||||||
|
echo "Fixing disk image permissions..."
|
||||||
|
sudo chmod 666 blankos-fat.img
|
||||||
|
|
||||||
|
echo "The blankos-fat.img disk image is ready for use with QEMU or real hardware."
|
||||||
BIN
stage2_eltorito
BIN
stage2_eltorito
Binary file not shown.
Reference in New Issue
Block a user