-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild_os.sh
More file actions
executable file
·128 lines (104 loc) · 3.31 KB
/
build_os.sh
File metadata and controls
executable file
·128 lines (104 loc) · 3.31 KB
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#!/usr/bin/env bash
#
# Build ThunderOS kernel and filesystem
#
# Compiles the kernel for RISC-V 64-bit architecture and creates
# an ext2 filesystem image for testing.
# Output: build/thunderos.elf, build/fs.img
set -euo pipefail
readonly KERNEL_ELF="build/thunderos.elf"
readonly FS_IMG="build/fs.img"
readonly FS_SIZE="10M"
print_usage() {
echo "Usage: ./build_os.sh [--clean]"
}
require_command() {
local command_name="$1"
local install_hint="$2"
if ! command -v "$command_name" >/dev/null 2>&1; then
echo "✗ Required command not found: ${command_name}" >&2
echo " ${install_hint}" >&2
exit 1
fi
}
main() {
local clean_build=false
if [[ $# -gt 1 ]]; then
print_usage >&2
exit 1
fi
if [[ $# -eq 1 ]]; then
case "$1" in
--clean)
clean_build=true
;;
-h|--help)
print_usage
exit 0
;;
*)
print_usage >&2
exit 1
;;
esac
fi
echo "Building ThunderOS kernel..."
require_command mkfs.ext2 "Install e2fsprogs: sudo apt-get install e2fsprogs"
if [[ "${clean_build}" == true ]]; then
make clean
fi
make all
if [[ ! -f "${KERNEL_ELF}" ]]; then
echo "✗ Build failed" >&2
exit 1
fi
echo ""
echo "✓ Kernel built successfully"
echo " Binary: ${KERNEL_ELF}"
# Create ext2 filesystem image
echo ""
echo "Creating ext2 filesystem image (${FS_SIZE})..."
# Create temporary directory for filesystem contents (force clean)
rm -rf build/testfs
mkdir -m 755 build/testfs
mkdir -m 755 build/testfs/bin
# Add test files
echo "Hello from ThunderOS ext2 filesystem!" > build/testfs/test.txt
echo "This is a sample file for testing." > build/testfs/README.txt
# Build userland programs if available
if [[ -f "build_userland.sh" ]]; then
echo "Building userland programs..."
chmod +x build_userland.sh
./build_userland.sh
# Copy userland binaries if they exist
for prog in cat ls hello clock pwd mkdir rmdir touch rm clear sleep ush ps uname uptime whoami tty kill poweroff reboot; do
if [[ -f "external/userland/build/${prog}" ]]; then
cp "external/userland/build/${prog}" build/testfs/bin/
echo " Added /bin/${prog}"
fi
done
else
echo "✗ build_userland.sh not found" >&2
exit 1
fi
# Create ext2 filesystem
mkfs.ext2 -F -q -d build/testfs "${FS_IMG}" "${FS_SIZE}"
rm -rf build/testfs
if [[ ! -f "${FS_IMG}" ]]; then
echo "✗ Filesystem image was not created" >&2
exit 1
fi
echo "✓ Filesystem created: ${FS_IMG}"
echo " Size: $(du -h "${FS_IMG}" | cut -f1)"
echo ""
echo "Build complete! Run with:"
echo " ./run_os.sh"
echo ""
echo "Or manually with QEMU:"
echo " qemu-system-riscv64 -M virt -m 128M -nographic -serial mon:stdio \\"
echo " -bios none -kernel ${KERNEL_ELF} \\"
echo " -drive file=${FS_IMG},if=none,format=raw,id=hd0 \\"
echo " -device virtio-blk-device,drive=hd0 \\"
echo " -global virtio-mmio.force-legacy=false"
}
main "$@"