1-
2-
3- # Object files grouped by functionality
41FILES = \
52 ./build/kernel.asm.o \
63 ./build/kernel.o \
@@ -72,7 +69,7 @@ prepare_dirs:
7269
7370all : build install
7471
75- build : prepare_dirs fonts ./bin/boot_with_size.bin user_programs ./bin/os.bin
72+ build : prepare_dirs fonts ./bin/boot_with_size.bin ./bin/kernel.bin user_programs ./bin/os.bin
7673 @echo " Build complete! User programs built but not installed to disk image."
7774 @echo " To install user programs to disk image, run: make install"
7875
@@ -82,82 +79,75 @@ fonts:
8279install : ./bin/os.bin
8380ifeq ($(UNAME_S ) ,Linux)
8481 @echo "Installing user programs and assets to disk image (Linux)..."
85- @# Create mount point if it doesn't exist
8682 @sudo mkdir -p /mnt/d
87- @# Unmount if already mounted
8883 @sudo umount /mnt/d 2>/dev/null || true
89- @# Mount the disk image
90- @sudo mount -t vfat ./bin/os.bin /mnt/d
91- @# Copy all assets recursively
92- @sudo cp -r ./assets/* /mnt/d/ 2>/dev/null || true
93- @# Find and copy all .elf files from programs directory
94- @find ./assets/etc/default/user/programs -name '*.elf' -exec sudo cp {} /mnt/d/ \;
95- @# Unmount the disk image
84+ @sudo mount -t vfat ./bin/os.bin /mnt/d || { echo "Failed to mount disk image"; exit 1; }
85+ @if [ -d "./assets" ]; then sudo cp -r ./assets/* /mnt/d/ || { echo "Failed to copy assets"; sudo umount /mnt/d; exit 1; }; fi
86+ @if [ -d "./assets/etc/default/user/programs" ]; then find ./assets/etc/default/user/programs -name '*.elf' -exec sudo cp {} /mnt/d/ \; || { echo "Failed to copy .elf files"; sudo umount /mnt/d; exit 1; }; fi
9687 @sudo umount /mnt/d
9788 @echo "User programs and assets installed to disk image!"
9889else ifeq ($(UNAME_S),Darwin)
99- @echo "Attaching disk image (macOS)..."
100- @bash -c '\
101- DISK_ID=$$(hdiutil attach -imagekey diskimage-class=CRawDiskImage -nomount ./bin/os.bin | awk "/\\/dev\\// {print \$$1}"); \
102- echo "diskutil list output for $$DISK_ID:"; \
103- diskutil list $$DISK_ID; \
104- PART_DEV=$$(ls /dev/$$(basename $$DISK_ID)s1); \
105- echo "Partition device: $$PART_DEV"; \
106- sudo mkdir -p /Volumes/viosmnt; \
107- sudo mount -t msdos $$PART_DEV /Volumes/viosmnt || { echo "Failed to mount $$PART_DEV"; hdiutil detach $$DISK_ID; exit 1; }; \
108- echo "Copying files..."; \
109- sudo cp -r ./assets/* /Volumes/viosmnt/ 2>/dev/null || true; \
110- find ./assets/etc/default/user/programs -name "*.elf" -exec sudo cp {} /Volumes/viosmnt/ \; ; \
90+ @echo "Preparing disk image for macOS..."
91+ @bash -c "\
92+ set -e; \
93+ echo 'Attaching disk image...'; \
94+ ATTACH_OUTPUT=\$$(hdiutil attach -imagekey diskimage-class=CRawDiskImage -nomount ./bin/os.bin 2>/dev/null); \
95+ DISK_ID=\$$(echo \"\$$ATTACH_OUTPUT\" | grep -o '/dev/disk[0-9]*' | head -1); \
96+ PARTITION_ID=\"\$${DISK_ID}s1\"; \
97+ if [ -z \"\$$DISK_ID\" ]; then echo 'Failed to attach disk image'; exit 1; fi; \
98+ echo \"Attached as \$$DISK_ID, partition \$$PARTITION_ID\"; \
99+ echo 'Formatting partition as FAT32...'; \
100+ diskutil eraseVolume MS-DOS VIOSFAT32 \"\$$PARTITION_ID\" >/dev/null 2>&1 || { echo 'Failed to format partition'; hdiutil detach \"\$$DISK_ID\" 2>/dev/null; exit 1; }; \
101+ echo 'Copying files...'; \
102+ if [ -d './assets' ]; then \
103+ echo 'Copying assets...'; \
104+ cp -r ./assets/* /Volumes/VIOSFAT32/ || { echo 'Failed to copy assets'; diskutil unmount \"\$$PARTITION_ID\"; hdiutil detach \"\$$DISK_ID\" 2>/dev/null; exit 1; }; \
105+ else \
106+ echo 'No assets directory found, skipping...'; \
107+ fi; \
108+ if [ -d './assets/etc/default/user/programs' ]; then \
109+ echo 'Copying .elf files...'; \
110+ find ./assets/etc/default/user/programs -name '*.elf' -exec cp {} /Volumes/VIOSFAT32/ \; || { echo 'Failed to copy .elf files'; diskutil unmount \"\$$PARTITION_ID\"; hdiutil detach \"\$$DISK_ID\" 2>/dev/null; exit 1; }; \
111+ else \
112+ echo 'No programs directory found, skipping...'; \
113+ fi; \
111114 sync; \
112- echo "Unmounting..."; \
113- sudo umount /Volumes/viosmnt; \
114- hdiutil detach $$DISK_ID; \
115- echo "User programs and assets installed to disk image!"; \
116- '
115+ echo 'Unmounting for boot sector update...'; \
116+ diskutil unmount \"\$$PARTITION_ID\" >/dev/null 2>&1 || echo 'Unmount failed, continuing...'; \
117+ echo 'Installing custom boot sector...'; \
118+ dd if=./bin/vbr.bin of=\"\$$PARTITION_ID\" bs=512 count=1 conv=notrunc 2>/dev/null || echo 'Warning: Failed to install custom boot sector'; \
119+ hdiutil detach \"\$$DISK_ID\" >/dev/null 2>&1 || echo 'Detach failed, continuing...'; \
120+ echo 'User programs and assets installed to disk image!'; \
121+ "
117122endif
118123
124+
119125./bin/kernel.bin : prepare_dirs $(FILES )
120126 i686-elf-gcc $(FLAGS ) -T ./src/linker.ld -o ./bin/kernel.bin -ffreestanding -O0 -nostdlib $(FILES )
121127
122- ./bin/mbr .bin : prepare_dirs ./src/boot/mbr.asm
128+ ./bin/boot .bin : prepare_dirs ./src/boot/mbr.asm ./src/boot/vbrEntry.asm ./src/boot/vbrMain.asm ./src/boot/fsinfo .asm
123129 nasm -f bin ./src/boot/mbr.asm -o ./bin/mbr.bin
124-
125- ./bin/vbr.bin : prepare_dirs ./src/boot/vbr.asm
126- nasm -f bin ./src/boot/vbr.asm -o ./bin/vbr.bin
130+ nasm -f bin ./src/boot/vbrEntry.asm -o ./bin/vbrEntry.bin
131+ nasm -f bin ./src/boot/vbrMain.asm -o ./bin/vbrMain.bin
132+ nasm -f bin ./src/boot/fsinfo.asm -o ./bin/fsinfo.bin
133+ dd if=./bin/vbrEntry.bin of=./bin/vbr.bin bs=512 count=1 conv=notrunc status=none
134+ dd if=./bin/vbrMain.bin of=./bin/vbr.bin bs=512 seek=1 count=2 conv=notrunc status=none
135+ dd if=./bin/mbr.bin of=$@ bs=512 count=1 conv=notrunc status=none
136+ dd if=./bin/vbr.bin of=$@ bs=512 seek=2050 count=3 conv=notrunc status=none
137+ dd if=./bin/fsinfo.bin of=$@ bs=512 seek=2060 count=1 conv=notrunc status=none
127138
128139# Calculate kernel size and update boot sector
129- ./bin/boot_with_size.bin : ./bin/mbr.bin ./bin/vbr.bin ./bin/kernel.bin
130- @echo " Calculating kernel size and updating VBR..."
131- # ./updateBoot.sh ./bin/vbr.bin ./bin/kernel.bin
132- @echo " Combining MBR + VBR into boot image..."
133- dd if=./bin/mbr.bin of=./bin/boot_with_size.bin bs=512 count=1 conv=notrunc
134- dd if=./bin/vbr.bin of=./bin/boot_with_size.bin bs=512 seek=2048 conv=notrunc
135-
136- ./bin/os.bin :
137- python3 utilities/make_mbr_partition.py ./bin/os.bin --size 128 --start 2048 --type 0x0C
138- @bash -c " \
139- set -e; \
140- ATTACH_OUTPUT=$$(hdiutil attach -imagekey diskimage-class=CRawDiskImage -nomount ./bin/os.bin ) ; \
141- echo ' hdiutil attach output:' ; \
142- echo " $$ ATTACH_OUTPUT" ; \
143- DISK_ID=$$(echo "$$ATTACH_OUTPUT" | awk '/\/dev\// {print $$1; exit}' ) ; \
144- if [ -z " $$ DISK_ID" ]; then \
145- echo ' ERROR: No device found. hdiutil did not recognize the image as a disk.' ; \
146- exit 1; \
147- fi ; \
148- echo " DISK_ID is $$ DISK_ID" ; \
149- PART_DEV=$$(ls /dev/$$(basename $$DISK_ID) s1 2>/dev/null || true ) ; \
150- if [ -z " $$ PART_DEV" ]; then \
151- echo ' ERROR: Partition device not found. Check the image partition table.' ; \
152- hdiutil detach $$ DISK_ID; \
153- exit 1; \
154- fi ; \
155- echo " Formatting partition $$ PART_DEV as FAT32..." ; \
156- sudo newfs_msdos -F 32 -v VIOS_BOOT $$ PART_DEV; \
157- hdiutil detach $$ DISK_ID; \
158- "
159- @sudo dd if=./bin/vbr.bin of=./bin/os.bin bs=512 seek=2048 conv=notrunc
160-
140+ ./bin/boot_with_size.bin : ./bin/boot.bin ./bin/kernel.bin
141+ @echo " Calculating kernel size and updating boot sector..."
142+ cp ./bin/boot.bin ./bin/boot_with_size.bin
143+
144+
145+ ./bin/os.bin : ./bin/boot_with_size.bin
146+ rm -rf ./bin/os.bin
147+ dd if=./bin/boot_with_size.bin of=./bin/os.bin bs=512 conv=notrunc
148+ dd if=./bin/kernel.bin of=./bin/os.bin bs=512 seek=2070 conv=notrunc
149+ dd if=/dev/zero bs=1048576 count=128 >> ./bin/os.bin
150+
161151# Generic C and ASM file rules
162152./build/% .o : ./src/% .c
163153 mkdir -p $(dir $@ )
@@ -168,12 +158,14 @@ endif
168158 nasm -f elf -g $< -o $@
169159
170160user_programs :
171- @{ \
172- for dir in $( shell find ./assets/etc/default/user/programs -mindepth 1 -maxdepth 1 -type d) ; do \
161+ @if [ -d " ./assets/etc/default/user/programs " ] ; then \
162+ for dir in $$ ( find ./assets/etc/default/user/programs -mindepth 1 -maxdepth 1 -type d 2> /dev/null ); do \
173163 echo " Building user program $$ dir..." ; \
174164 $(MAKE ) -C $$ dir all || exit 1; \
175165 done ; \
176- }
166+ else \
167+ echo " No user programs directory found (./assets/etc/default/user/programs), skipping..." ; \
168+ fi
177169
178170user_programs_clean :
179171 @for dir in ./assets/etc/default/user/programs/* / ; do \
0 commit comments