Unroot the makefile, enhancements !

This commit is contained in:
Adrien Bourmault 2019-11-11 18:32:22 +01:00
parent 32db8a0a9e
commit afdd7aa4a0
9 changed files with 184 additions and 167 deletions

View File

@ -103,4 +103,6 @@ IDT Overhaul
[...] Time Skip
2019-11-08 @os-k-team <os-k-team@os-k.eu>
* Compilation process : beginning the modernization
* Compilation process : beginning the modernization
2019-11-11 @os-k-team <os-k-team@os-k.eu>
* Compilation process : "unrooting" and enhancing the compilation process scripts

View File

@ -22,7 +22,7 @@
# along with OS/K. If not, see <https://www.gnu.org/licenses/>. #
#=----------------------------------------------------------------------------=#
.PHONY: all test test32 debug gdb install_mbr dust clean OS/K
.PHONY: all test test32 debug gdb install dust clean OS/K
.DELETE_ON_ERROR: $(BINDIR)/kaleid
@ -73,6 +73,9 @@ BINDIR=build/bin
BUILDDIR=build
vpath %.c $(KALEIDDIR)
# Installation parameters
installdisk ?= $(BINDIR)/disk.img
# Color codes
CL='\033[0;32m'
CL2='\033[1;36m'
@ -242,10 +245,9 @@ $(KOBJDIR)/%.o: %.c | $(KOBJDIR)
$(BINDIR)/kaleid: $(LOBJDIR)/kaleid.x86_64
@echo ${CL2}[$@] ${NC}Objcopy...${CL3}
@$(OBJCOPY) -I elf64-x86-64 -O elf32-i386 $(LOBJDIR)/kaleid.x86_64 $(BINDIR)/kaleid
#@make copy_kernel
@echo ${CL2}[$@] ${CL}Success.${CL3}
$(LOBJDIR)/kaleid.x86_64: $(LibCObj) $(KernObj) $(LOBJDIR)/loader.o
$(LOBJDIR)/kaleid.x86_64: $(LibCObj) $(KernObj) $(LOBJDIR)/loader.o $(BUILDDIR)/kernel.ld
@echo ${CL2}[$@] ${NC}Linking kernel objects...${CL3}
@$(LD) $(LDFLAGS) -T $(BUILDDIR)/kernel.ld \
$(LOBJDIR)/loader.o $(KernObj) $(LibCObj) \
@ -263,16 +265,16 @@ OS/K: $(dep) ./ProjectTree $(BINDIR)/kaleid
## QEMU/DEBUG RELATED
test: all
test: all install
@qemu-system-x86_64 -vga std -cpu core2duo -soundhw pcspk -s \
-rtc base=localtime -m $(ram) -hda $(BUILDDIR)/bin/disk.img \
-d cpu_reset,guest_errors,pcall,int 2> $(BUILDDIR)/qemu.log &
test32: all
test32: all install
@qemu-system-i386 -m $(ram) -hda $(BUILDDIR)/bin/disk.img -d \
cpu_reset,guest_errors,pcall,int 2> $(BUILDDIR)/qemu.log &
gdb: all
gdb: all install
@setsid qemu-system-x86_64 -m $(ram) -soundhw pcspk -rtc base=localtime \
-hda $(BUILDDIR)/bin/disk.img -no-reboot -no-shutdown -d \
cpu_reset,guest_errors,pcall,int -s -S 2> $(BUILDDIR)/qemu.log &
@ -282,7 +284,7 @@ gdb: all
-ex "symbol-file $(BINDIR)/kaleid" \
-ex "break BtStartKern" \
ddd: all
ddd: all install_os_k
@setsid qemu-system-x86_64 -m $(ram) -hda $(BUILDDIR)/bin/disk.img -no-reboot -soundhw pcspk \
-no-shutdown -d cpu_reset,guest_errors,pcall,int -s 2> $(BUILDDIR)/qemu.log &
@ddd
@ -290,40 +292,24 @@ ddd: all
## HD IMAGE RELATED ---------------------------------------------------------- #
install_mbr: $(BINDIR)/disk.img $(MBRDIR)/grub.cfg
@mkdir -p $(BINDIR)/disk
install: $(installdisk) $(MBRDIR)/grub.cfg $(BINDIR)/kaleid
@echo ${CL2}[$@] ${NC}Installing MBR on image...${CL3}
@$(MBRDIR)/grub-install.sh $(BINDIR)/disk.img $(BINDIR)/disk $(MBRDIR)/grub.cfg
@rmdir $(BINDIR)/disk
@$(BUILDDIR)/install-os-k.sh $(installdisk) $(MBRDIR)/grub.cfg $(BINDIR)/kaleid
@echo ${CL2}[$@] ${CL}Success.${CL3}
copy_kernel:
@mkdir -p $(BINDIR)/disk
@echo ${CL2}[$@] ${NC}Integrating kernel${CL3}
-@$(MBRDIR)/umount.sh $(BINDIR)/disk || /bin/true
@$(MBRDIR)/mount.sh $(BINDIR)/disk.img $(BINDIR)/disk
@cp $(BINDIR)/kaleid $(BINDIR)/disk/boot/kaleid
@$(MBRDIR)/umount.sh $(BINDIR)/disk
@echo ${CL2}[$@] ${CL}Success.${CL3}
@rmdir $(BINDIR)/disk
$(BINDIR)/disk.img: $(MBRDIR)/create_disk.sh
$(BINDIR)/disk.img: $(BUILDDIR)/create_disk.sh
@echo ${CL2}[$@]${NC} Constructing disk image...${CL3}
-@$(MBRDIR)/umount.sh $(BINDIR)/disk || /bin/true
@$(MBRDIR)/create_disk.sh $(BINDIR)/disk.img
@make install_mbr
@$(BUILDDIR)/create_disk.sh $(BINDIR)/disk.img
@echo ${CL2}[$@]${NC} Constructing disk image...${CL3}
## CLEANUP RELATED ----------------------------------------------------------- #
dust:
-@$(MBRDIR)/umount.sh $(BINDIR)/disk || /bin/true
@rm -Rf $(OBJDIR)/*
@echo ${CL2}[$@] ${CL}Cleaned.${CL3}
clean:
-@$(MBRDIR)/umount.sh $(BINDIR)/disk || /bin/true
@rm -Rvf ./ProjectTree $(BUILDDIR)/*.log
@rm -Rvf $(BINDIR)/* $(OBJDIR)/*
@echo ${CL2}[$@] ${CL}Cleaned.${CL3}

View File

@ -26,12 +26,8 @@
.
├── boot
│   ├── grub
│   │   ├── create_disk.sh
│   │   ├── grub.cfg
│   │   ├── grub-install.sh
│   │   ├── mount.sh
│   │   ├── multiboot.pdf
│   │   └── umount.sh
│   │   └── multiboot.pdf
│   ├── loader
│   │   ├── cpu
│   │   │   ├── cpu32.inc
@ -48,6 +44,122 @@
│   └── folder.desc
├── build
│   ├── bin
│   ├── media
│   │   └── neox
│   │   └── FDD3-0486
│   │   └── boot
│   │   └── grub
│   │   ├── i386-pc
│   │   │   ├── adler32.mod
│   │   │   ├── affs.mod
│   │   │   ├── ata.mod
│   │   │   ├── bitmap.mod
│   │   │   ├── boot.mod
│   │   │   ├── bswap_test.mod
│   │   │   ├── btrfs.mod
│   │   │   ├── cbls.mod
│   │   │   ├── cbmemc.mod
│   │   │   ├── cbtime.mod
│   │   │   ├── cmdline_cat_test.mod
│   │   │   ├── cmp.mod
│   │   │   ├── configfile.mod
│   │   │   ├── cpuid.mod
│   │   │   ├── cs5536.mod
│   │   │   ├── ctz_test.mod
│   │   │   ├── datetime.mod
│   │   │   ├── diskfilter.mod
│   │   │   ├── div.mod
│   │   │   ├── div_test.mod
│   │   │   ├── dm_nv.mod
│   │   │   ├── drivemap.mod
│   │   │   ├── elf.mod
│   │   │   ├── exfat.mod
│   │   │   ├── extcmd.mod
│   │   │   ├── fat.mod
│   │   │   ├── font.mod
│   │   │   ├── gcry_arcfour.mod
│   │   │   ├── gcry_blowfish.mod
│   │   │   ├── gcry_dsa.mod
│   │   │   ├── gcry_idea.mod
│   │   │   ├── gcry_md5.mod
│   │   │   ├── gcry_rijndael.mod
│   │   │   ├── gcry_rmd160.mod
│   │   │   ├── gcry_rsa.mod
│   │   │   ├── gcry_seed.mod
│   │   │   ├── gcry_serpent.mod
│   │   │   ├── gcry_sha256.mod
│   │   │   ├── gcry_whirlpool.mod
│   │   │   ├── gptsync.mod
│   │   │   ├── hashsum.mod
│   │   │   ├── help.mod
│   │   │   ├── hfs.mod
│   │   │   ├── loopback.mod
│   │   │   ├── lsacpi.mod
│   │   │   ├── lsapm.mod
│   │   │   ├── lsmmap.mod
│   │   │   ├── lspci.mod
│   │   │   ├── lvm.mod
│   │   │   ├── lzopio.mod
│   │   │   ├── memrw.mod
│   │   │   ├── minicmd.mod
│   │   │   ├── minix2_be.mod
│   │   │   ├── minix.mod
│   │   │   ├── mpi.mod
│   │   │   ├── multiboot2.mod
│   │   │   ├── multiboot.mod
│   │   │   ├── nilfs2.mod
│   │   │   ├── ntfs.mod
│   │   │   ├── ntldr.mod
│   │   │   ├── odc.mod
│   │   │   ├── part_acorn.mod
│   │   │   ├── part_amiga.mod
│   │   │   ├── part_dfly.mod
│   │   │   ├── part_dvh.mod
│   │   │   ├── part_gpt.mod
│   │   │   ├── part_sun.mod
│   │   │   ├── parttool.mod
│   │   │   ├── pci.mod
│   │   │   ├── play.mod
│   │   │   ├── priority_queue.mod
│   │   │   ├── probe.mod
│   │   │   ├── procfs.mod
│   │   │   ├── progress.mod
│   │   │   ├── pxechain.mod
│   │   │   ├── pxe.mod
│   │   │   ├── random.mod
│   │   │   ├── reboot.mod
│   │   │   ├── regexp.mod
│   │   │   ├── scsi.mod
│   │   │   ├── serial.mod
│   │   │   ├── setpci.mod
│   │   │   ├── signature_test.mod
│   │   │   ├── sleep.mod
│   │   │   ├── sleep_test.mod
│   │   │   ├── syslinuxcfg.mod
│   │   │   ├── tar.mod
│   │   │   ├── terminal.mod
│   │   │   ├── testload.mod
│   │   │   ├── test.mod
│   │   │   ├── testspeed.mod
│   │   │   ├── trig.mod
│   │   │   ├── tr.mod
│   │   │   ├── true.mod
│   │   │   ├── uhci.mod
│   │   │   ├── usbms.mod
│   │   │   ├── usbserial_ftdi.mod
│   │   │   ├── usbserial_pl2303.mod
│   │   │   ├── vbe.mod
│   │   │   ├── verify.mod
│   │   │   ├── vga.mod
│   │   │   ├── video_bochs.mod
│   │   │   ├── video.mod
│   │   │   ├── videotest_checksum.mod
│   │   │   ├── xnu.mod
│   │   │   ├── xnu_uuid.mod
│   │   │   ├── xnu_uuid_test.mod
│   │   │   ├── zfscrypt.mod
│   │   │   └── zfs.mod
│   │   └── locale
│   ├── obj
│   │   └── kaleid
│   │   ├── kernel
@ -103,6 +215,8 @@
│   │   ├── sprintf.d
│   │   ├── string.d
│   │   └── strtol.d
│   ├── create_disk.sh
│   ├── install-os-k.sh
│   └── kernel.ld
├── include
│   ├── ex
@ -211,4 +325,4 @@
├── ProjectTree
└── README.md
41 directories, 145 files
48 directories, 252 files

View File

@ -1,64 +0,0 @@
#=----------------------------------------------------------------------------=#
# GNU GPL OS/K #
# #
# Desc: Grub installation script for the OS/K image #
# #
# #
# Copyright © 2018-2019 The OS/K Team #
# #
# This file is part of OS/K. #
# #
# OS/K is free software: you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by #
# the Free Software Foundation, either version 3 of the License, or #
# any later version. #
# #
# OS/K is distributed in the hope that it will be useful, #
# but WITHOUT ANY WARRANTY# without even the implied warranty of #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
# GNU General Public License for more details. #
# #
# You should have received a copy of the GNU General Public License #
# along with OS/K. If not, see <https://www.gnu.org/licenses/>. #
#=----------------------------------------------------------------------------=#
#Color codes
CL='\033[0;32m'
CL2='\033[1;36m'
CL3='\033[0m'
NC='\033[1;37m'
set -e #exit if error
echo ${CL2}[grub-install.sh]${NC} Mouting image... \(losetup\)${CL3}
## Prepare Mount
sudo losetup -D > /dev/null
sudo losetup /dev/loop0 $1 > /dev/null # mounting the device block
sudo losetup /dev/loop1 $1 -o 1048576 > /dev/null #mounting the logical partition
echo ${CL2}[grub-install.sh]${NC} Mounting volume... \(mount\)${CL3}
## Mount
if [ -e $2/boot ] 
then
sudo umount $2 > /dev/null
fi
sudo mount /dev/loop1 $2 > /dev/null
echo ${CL2}[grub-install.sh]${NC} Installing grub... \(grub-install\)${CL3}
## Install grub
sudo grub-install -V
sudo grub-install --target=i386-pc --debug --root-directory=$2 --boot-directory=$2/boot --no-floppy --modules="part_msdos biosdisk fat multiboot configfile" /dev/loop0 2> build/grub.log
echo ${CL2}[grub-install.sh]${NC} Copying grub.cfg
sudo cp $3 $2/boot/grub/grub.cfg > /dev/null
echo ${CL2}[grub-install.sh]${NC} Sync image... \(sync\)${CL3}
sync
echo ${CL2}[grub-install.sh]${NC} Unmounting volume... \(umount\)${CL3}
sudo umount /dev/loop1 > /dev/null
echo ${CL2}[grub-install.sh]${NC} Unmounting image... \(losetup\)${CL3}
sudo losetup -D > /dev/null
echo ${CL2}[grub-install.sh]${CL} See grub.log for more informations.${CL3}

View File

@ -1,38 +0,0 @@
#=----------------------------------------------------------------------------=#
# GNU GPL OS/K #
# #
# Desc: Simple OS/K image mount script #
# #
# #
# Copyright © 2018-2019 The OS/K Team #
# #
# This file is part of OS/K. #
# #
# OS/K is free software: you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by #
# the Free Software Foundation, either version 3 of the License, or #
# any later version. #
# #
# OS/K is distributed in the hope that it will be useful, #
# but WITHOUT ANY WARRANTY# without even the implied warranty of #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
# GNU General Public License for more details. #
# #
# You should have received a copy of the GNU General Public License #
# along with OS/K. If not, see <https://www.gnu.org/licenses/>. #
#=----------------------------------------------------------------------------=#
#Color codes
CL='\033[0;32m'
CL2='\033[1;36m'
CL3='\033[0m'
NC='\033[1;37m'
set -e #exit if error
echo ${CL2}[mount.sh]${NC} Mouting image... \(losetup\)${CL3}
sudo losetup -D > /dev/null
sudo losetup /dev/loop0 $1 -o 1048576 > /dev/null #mounting the logical partition
echo ${CL2}[mount.sh]${NC} Mouting volume... \(mount\)${CL3}
sudo mount -t vfat /dev/loop0 $2 -o rw,uid=$(id -u),gid=$(id -g) > /dev/null
echo ${CL2}[mount.sh]${CL} Terminated without error.${CL3}

View File

@ -36,8 +36,8 @@ global BtHeader
extern BtStartKern
[BITS 32]
[section .multiboot]
[section .multiboot]
;; MAGNIFICENT MULTIBOOT HEADER FOR GRUB ------------------------------------ ;;
BtHeader:
ALIGN 4
@ -50,8 +50,11 @@ BtHeader:
dd MB_VIDEO_HEIGHT
dd MB_VIDEO_DEPTH
[section .text]
[section .joke]
;; MAGNIFICENT MULTIBOOT HEADER FOR OUR OS BINARY --------------------------- ;;
db "This program cannot be run in Win32 mode, or DOS mode, or in any operating system mode that owns your fantasy. KTHXBYE",0
[section .text]
;;MULTIBOOT POINT ENTRY FOR GRUB -------------------------------------------- ;;
BtStartLoader:
mov esp, KERNEL_STACK ; Setup the stack
@ -180,4 +183,4 @@ AfterInitStack:
mov bl, 0x0c
mov esi, nokernel ; Error 05
call write
jmp Die
jmp Die

View File

@ -33,33 +33,31 @@ set -e #exit if error
## Create the image
echo ${CL2}[create_disk.sh]${NC} Creating image... \(dd\)${CL3}
dd if=/dev/zero of=$1 bs=512 count=131072 status=progress
echo ${CL2}[create_disk.sh]${NC} Partitionning image... \(fdisk\)${CL3}
## Partition the image
# WARNING, DO NOT DELETE SPACES !
sudo fdisk $1 > /dev/null <<EEOF
n
p
1
echo ${CL2}[create_disk.sh]${NC} Partitionning image... \(parted\)${CL3}
/sbin/parted --script $1 mktable msdos mkpart primary 2048s 100% set 1 boot on
a
w
EEOF
# WARNING, YOU CAN NOW DELETE SPACES
echo ${CL2}[create_disk.sh]${NC} Mouting image... \(losetup\)${CL3}
## Map
sudo losetup -D > /dev/null
sudo losetup /dev/loop0 $1 -o 1048576 > /dev/null #mounting the logical partition
echo ${CL2}[create_disk.sh]${NC} Formatting image... \(mkdosfs\)${CL3}
## Format
sudo mkdosfs -F32 -f 2 /dev/loop0 > /dev/null
echo ${CL2}[create_disk.sh]${NC} Formatting image... \(mkdosfs\)${CL3}
/sbin/mkdosfs -F32 -f 2 $1
echo ${CL2}[create_disk.sh]${NC} Mount image... \(udisksctl\)${CL3}
udisksctl loop-setup --no-user-interaction --file $1
lpblock=$(/sbin/losetup -j $1 | cut -d ':' -f 1)
mountpoint=$(udisksctl info -b $lpblock | grep MountPoint | cut -d ':' -f 2 | sed 's/ //g')
echo ${CL2}[create_disk.sh]${NC} Sync image... \(sync\)${CL3}
sync
echo ${CL2}[create_disk.sh]${NC} Unmounting... \(losetup\)${CL3}
sudo losetup -D > /dev/null
echo ${CL2}[create_disk.sh]${NC} Install grub into $lpblock as $mountpoint... \(grub-install\)${CL3}
sudo grub-install --force --target=i386-pc --root-directory=$mountpoint --boot-directory=$mountpoint/boot --no-floppy --modules="part_msdos biosdisk fat multiboot configfile" $lpblock
echo ${CL2}[create_disk.sh]${NC} Sync image... \(sync\)${CL3}
sync
echo ${CL2}[create_disk.sh]${NC} Unmount image... \(udisksctl\)${CL3}
udisksctl unmount --no-user-interaction -b $lpblock
echo ${CL2}[create_disk.sh]${CL} Terminated without error.${CL3}

View File

@ -1,7 +1,7 @@
#=----------------------------------------------------------------------------=#
# GNU GPL OS/K #
# #
# Desc: Simple unmount script #
# Desc: Grub installation script for the OS/K image #
# #
# #
# Copyright © 2018-2019 The OS/K Team #
@ -29,10 +29,22 @@ CL3='\033[0m'
NC='\033[1;37m'
set -e #exit if error
echo ${CL2}[create_disk.sh]${NC} Mount image... \(udisksctl\)${CL3}
udisksctl loop-setup --no-user-interaction --file $1
lpblock=$(/sbin/losetup -j $1 | cut -d ':' -f 1)
echo Block is $lpblock
#udisksctl mount --no-user-interaction -b $lpblock
mountpoint=$(udisksctl info -b $lpblock | grep MountPoint | cut -d ':' -f 2 | sed 's/ //g')
echo ${CL2}[grub-install.sh]${NC} Copying grub.cfg
cp $2 $mountpoint/boot/grub/grub.cfg
echo ${CL2}[grub-install.sh]${NC} Copying kernel
cp $3 $mountpoint/boot/kaleid
echo ${CL2}[grub-install.sh]${NC} Sync image... \(sync\)${CL3}
sync
sleep 1
echo ${CL2}[umount.sh]${NC} Unmounting volume... \(umount\)${CL3}
sudo umount $1
echo ${CL2}[umount.sh]${NC} Unmounting image... \(losetup\)${CL3}
sudo losetup -D
echo ${CL2}[umount.sh]${CL} Terminated without error.${CL3}
echo ${CL2}[create_disk.sh]${NC} Unmount image... \(udisksctl\)${CL3}
udisksctl unmount --no-user-interaction -b $lpblock
#udisksctl loop-delete --no-user-interaction -b $lpblock

View File

@ -27,11 +27,13 @@
ENTRY(BtStartLoader) /* the name of the entry label */
SECTIONS {
. = 0x00100000; /* the code should be loaded at 1 MB */
.boot ALIGN (0x1000) :
{
*(.multiboot)
*(.joke)
}
.text ALIGN (0x1000) :
@ -68,3 +70,5 @@ SECTIONS {
kernelEnd = .;
}