Changed crosscompiler-buildscript

Did some groundwork on FAT
This commit is contained in:
Morten Delenk 2016-07-26 20:13:20 +02:00
parent e3b55b6fb2
commit ceb7d0d743
No known key found for this signature in database
GPG key ID: 3F818D0F65DCB490
12 changed files with 206 additions and 21 deletions

BIN
binutils.patch.xz Normal file

Binary file not shown.

View file

@ -1,5 +1,5 @@
CROSSPATH=$HOME/opt # You can change it to whatever you want CROSSPATH=$HOME/opt # You can change it to whatever you want
export PATH=$CROSSPATH/bin:$PATH export PATH=${CROSSPATH}-tools/bin:$CROSSPATH/bin:$PATH
mkdir $CROSSPATH mkdir $CROSSPATH
set -o errexit set -o errexit
function buildscript() { function buildscript() {
@ -24,22 +24,30 @@ function buildscript() {
echo "[$(date +%c)] Building gdb for $1." | tee -a buildlog echo "[$(date +%c)] Building gdb for $1." | tee -a buildlog
mkdir build-gdb mkdir build-gdb
cd build-gdb cd build-gdb
../gdb-7.11/configure --prefix=$CROSSPATH --target=$1 --disable-nls 2>&1 > /dev/null ../gdb-7.11/configure --prefix=$CROSSPATH --target=$2 --disable-nls 2>&1 > /dev/null
gmake -j8 2>&1 > /dev/null gmake -j8 2>&1 > /dev/null
gmake install 2>&1 > /dev/null gmake install 2>&1 > /dev/null
cd .. cd ..
rm -rf build-gdb rm -rf build-gdb
echo "[$(date +%c)] Cross-compiler for $1 was built." | tee -a buildlog echo "[$(date +%c)] Cross-compiler for $1 was built." | tee -a buildlog
} }
srcdir=`pwd`
tempdir=$(mktemp -d) tempdir=$(mktemp -d)
cd $tempdir cd $tempdir
echo "Temponary files are in $tempdir. Build log can be found under $tempdir/buildlog" | tee -a buildlog echo "Temponary files are in $tempdir. Build log can be found under $tempdir/buildlog" | tee -a buildlog
echo "Downloading GCC, Binutils, MPC, MPFR, GMP, isl, cloog and gdb" | tee -a buildlog echo "Downloading Autoconf, Automake, gawk, GCC, Binutils, MPC, MPFR, GMP, isl, cloog and gdb" | tee -a buildlog
wget ftp://ftp.gnu.org/gnu/gcc/gcc-6.1.0/gcc-6.1.0.tar.bz2 ftp://ftp.gnu.org/gnu/binutils/binutils-2.26.tar.bz2 ftp://ftp.gnu.org/gnu/mpc/mpc-1.0.3.tar.gz ftp://ftp.gnu.org/gnu/mpfr/mpfr-3.1.3.tar.xz ftp://ftp.gnu.org/gnu/gmp/gmp-6.1.0.tar.xz http://isl.gforge.inria.fr/isl-0.16.tar.xz http://www.bastoul.net/cloog/pages/download/cloog-0.18.4.tar.gz http://ftp.gnu.org/gnu/gdb/gdb-7.11.tar.xz wget http://ftp.gnu.org/gnu/autoconf/autoconf-2.64.tar.xz http://ftp.gnu.org/gnu/automake/automake-1.11.1.tar.bz2 ftp://ftp.gnu.org/gnu/gcc/gcc-6.1.0/gcc-6.1.0.tar.bz2 ftp://ftp.gnu.org/gnu/binutils/binutils-2.26.tar.bz2 ftp://ftp.gnu.org/gnu/mpc/mpc-1.0.3.tar.gz ftp://ftp.gnu.org/gnu/mpfr/mpfr-3.1.3.tar.xz ftp://ftp.gnu.org/gnu/gmp/gmp-6.1.0.tar.xz http://isl.gforge.inria.fr/isl-0.16.tar.xz http://www.bastoul.net/cloog/pages/download/cloog-0.18.4.tar.gz http://ftp.gnu.org/gnu/gdb/gdb-7.11.tar.xz http://ftp.gnu.org/gnu/gawk/gawk-4.1.3.tar.xz
echo "Untaring..." 2>&1 | tee -a buildlog echo "Untaring..." 2>&1 | tee -a buildlog
tar -xf autoconf-2.64.tar.xz
tar -xf automake-1.11.1.tar.bz2
tar -xf gawk-4.1.3.tar.xz
tar -xf gcc-6.1.0.tar.bz2 tar -xf gcc-6.1.0.tar.bz2
tar -xf binutils-2.26.tar.bz2 tar -xf binutils-2.26.tar.bz2
cd binutils-2.26
xzcat $srcdir/binutils.patch.xz | patch -Np1
cd ..
cd gcc-6.1.0 cd gcc-6.1.0
xzcat $srcdir/gcc.patch.xz | patch -Np1
tar -xf ../mpc-1.0.3.tar.gz tar -xf ../mpc-1.0.3.tar.gz
mv mpc-1.0.3 mpc mv mpc-1.0.3 mpc
tar -xf ../mpfr-3.1.3.tar.xz tar -xf ../mpfr-3.1.3.tar.xz
@ -52,12 +60,34 @@ tar -xf ../cloog-0.18.4.tar.gz
mv cloog-0.18.4 cloog mv cloog-0.18.4 cloog
cd .. cd ..
tar -xf gdb-7.11.tar.xz tar -xf gdb-7.11.tar.xz
echo "Creating tools for building the cross compiler..." 2>&1 | tee -a buildlog
echo "[$(date +%c)] Building native GNU awk." | tee -a buildlog
cd gawk-4.1.3
./configure --prefix=${CROSSPATH}-tools > /dev/null
gmake -j8 > /dev/null
gmake install > /dev/null
cd ..
rm -rf gawk-4.1.3
echo "[$(date +%c)] Building native autoconf." | tee -a buildlog
cd autoconf-2.64
./configure --prefix=${CROSSPATH}-tools > /dev/null
gmake -j8 > /dev/null
gmake install > /dev/null
cd ..
rm -rf autoconf-2.64
echo "[$(date +%c)] Building native automake." | tee -a buildlog
cd automake-1.11.1
./configure --prefix=${CROSSPATH}-tools > /dev/null
gmake -j8 > /dev/null
gmake install > /dev/null
cd ..
rm -rf automake-1.11.1
echo "Preperation done. Beginning the compilation now." 2>&1 | tee -a buildlog echo "Preperation done. Beginning the compilation now." 2>&1 | tee -a buildlog
buildscript i686-elf #x86 port buildscript i686-mtgos i386-elf #x86 port
buildscript arm-none-eabi #Little endian ARM ports (GBA (v4), DS(i) (v4, v5), 3DS/2DS (v4, v5, v6), pi (v6), pi2 (v7)) buildscript arm-none-eabi arm-none-eabi #Little endian ARM ports (GBA (v4), DS(i) (v4, v5), 3DS/2DS (v4, v5, v6), pi (v6), pi2 (v7))
buildscript armeb-eabi #Wii port buildscript armeb-eabi armeb-eabi #Wii port
buildscript ppc-elf #Wii port buildscript ppc-elf ppc-elf #Wii port
buildscript aarch64-none-elf #AArch64 ports (pi3 (v8)) buildscript aarch64-none-elf aarch64-none-elf #AArch64 ports (pi3 (v8))
buildscript x86_64-elf #x86_64 port buildscript x86_64-mtgos i386-elf #x86_64 port
rm -rf gcc* binutils* mpc* mpfr* gmp* rm -rf gcc* binutils* mpc* mpfr* gmp* $crosspath-tools
echo "Done! Have fun with your cross compilers!" 2>&1 | tee -a buildlog echo "Done! Have fun with your cross compilers!" 2>&1 | tee -a buildlog

44
config Normal file
View file

@ -0,0 +1,44 @@
# configuration file generated by Bochs
plugin_ctrl: unmapped=1, biosdev=1, speaker=1, extfpuirq=1, parallel=1, serial=1
config_interface: textconfig
display_library: x
memory: host=32, guest=32
romimage: file="/usr/local/share/bochs/BIOS-bochs-latest"
vgaromimage: file="/usr/local/share/bochs/VGABIOS-lgpl-latest"
boot: floppy
floppy_bootsig_check: disabled=1
floppya: type=1_44, 1_44="mtgos.img", status=inserted, write_protected=0
# no floppyb
ata0: enabled=1, ioaddr1=0x1f0, ioaddr2=0x3f0, irq=14
ata0-master: type=none
ata0-slave: type=none
ata1: enabled=1, ioaddr1=0x170, ioaddr2=0x370, irq=15
ata1-master: type=none
ata1-slave: type=none
ata2: enabled=0
ata3: enabled=0
pci: enabled=1, chipset=i440fx
vga: extension=vbe, update_freq=5, realtime=1
cpu: count=1, ips=16000000, model=atom_n270, reset_on_triple_fault=1, cpuid_limit_winnt=0, ignore_bad_msrs=1
print_timestamps: enabled=0
port_e9_hack: enabled=0
private_colormap: enabled=0
clock: sync=both, time0=local, rtc_sync=0
# no cmosimage
# no loader
log: -
logprefix: %t%e%d
debug: action=ignore
info: action=report
error: action=report
panic: action=ask
keyboard: type=mf, serial_delay=250, paste_delay=100000, user_shortcut=none
mouse: type=ps2, enabled=0, toggle=ctrl+mbutton
sound: waveoutdrv=dummy, waveout=none, waveindrv=dummy, wavein=none, midioutdrv=dummy, midiout=none
speaker: enabled=1, mode=sound
parport1: enabled=1, file=none
parport2: enabled=0
com1: enabled=1, mode=null
com2: enabled=0
com3: enabled=0
com4: enabled=0

BIN
gcc.patch.xz Normal file

Binary file not shown.

View file

@ -4,8 +4,8 @@ MODE = debug
export PATH := $(HOME)/opt/bin:$(PATH) export PATH := $(HOME)/opt/bin:$(PATH)
ifeq ($(arch),x86) ifeq ($(arch),x86)
PREFIX = i686-elf- PREFIX = i686-mtgos-
libpath = i686-elf libpath = i686-mtgos
else else
ifeq ($(arch),x86_64) ifeq ($(arch),x86_64)
PREFIX = x86_64-elf- PREFIX = x86_64-elf-

View file

@ -0,0 +1,90 @@
#include <stdint.h>
#include <base.hpp>
#include <blockdev.hpp>
#include <textDISP.hpp>
#include <partitions.hpp>
using namespace MTGosHAL;
union EBPB {
struct {
uint8_t drivenum;
uint8_t ntflags;
uint8_t signature;
uint32_t volID;
uint8_t label[11];
uint8_t sysident[8];
uint8_t bootcode[448];
uint16_t magic;
}__attribute__((packed)) fat;
struct {
uint32_t sectorsPerFAT;
uint16_t flags;
uint16_t version;
uint32_t rootdirClusterNum;
uint16_t FSInfoSector;
uint16_t backupSector;
uint8_t reserved[12];
uint8_t drivenum;
uint8_t ntflags;
uint8_t signature;
uint32_t volumeID;
uint8_t label[11];
uint8_t sysident[8];
uint8_t bootcode[420];
uint16_t magic;
}__attribute__((packed)) fat32;
};
struct BPB {
uint8_t jmp[3];
uint8_t OEM[8];
uint16_t bytesPerSector;
uint8_t sectorsPerCluster;
uint16_t reservedSectors;
uint8_t numberFAT;
uint16_t numDirent;
uint16_t totalSectors_s;
uint8_t mdt;
uint16_t sectorsPerFAT;
uint16_t sectorsPerTrack;
uint16_t noHeads;
uint32_t noHiddenSectors;
uint32_t totalSectors_b;
EBPB ebpb;
}__attribute__((packed));
void readFAT() {
BPB bpb;
MBR::MBR part(disk.getDriveNumByName("ATA0m"));
disk.readSector(disk.getDriveNumByName("ATA0m"),part.getPartBeg(0),(uint8_t*)&bpb);
out << "Bytes Per Sector: " << (int) bpb.bytesPerSector << "\n";
out << "Sectors per Cluster: " << (int) bpb.sectorsPerCluster << "\n";
out << "Reserved Sectors: " << (int) bpb.reservedSectors << "\n";
out << "Number of FATs: " << (int) bpb.numberFAT << "\n";
out << "Number of root directory entries: " << (int) bpb.reservedSectors << "\n";
uint32_t totalSectors=(bpb.totalSectors_s)?bpb.totalSectors_s:bpb.totalSectors_b;
out << "Total sectors: " << (int) totalSectors << "\n";
uint32_t sectorsPerFAT = (bpb.sectorsPerFAT)?bpb.sectorsPerFAT:bpb.ebpb.fat32.sectorsPerFAT;
out << "Sectors per FAT: " << (int) sectorsPerFAT << "\n";
uint32_t sizeRootDir = ((bpb.numDirent * 32) + (bpb.bytesPerSector-1)) / bpb.bytesPerSector;
out << "Size of root dir: " << (int) sizeRootDir << "\n";
uint32_t firstDataSector = bpb.reservedSectors + (bpb.numberFAT * sectorsPerFAT) + sizeRootDir;
out << "First data sector: " << (int) firstDataSector << "\n";
uint32_t dataSectors = totalSectors - (bpb.reservedSectors + (bpb.numberFAT * sectorsPerFAT) + sizeRootDir);
out << "Data Sectors: " << (int) dataSectors << "\n";
uint32_t totalClusters = totalSectors / bpb.sectorsPerCluster;
out << "Cluster count: " << (int) totalClusters << "\n";
int fatVer;
if(totalClusters < 4085)
fatVer=12;
else if(totalClusters < 65525)
fatVer=16;
else if(totalClusters < 268435445)
fatVer=28;
else
fatVer=32;
out << "Detected file system type: FAT" << fatVer << "\n";
if(fatVer==12)
out << "Congratulations! You are running the worst version of FAT!\n";
if(fatVer>28) {
out << "Not implemented\n";
return;
}
}

View file

@ -1,11 +1,14 @@
/*#include <filesystem.hpp> /*#include <filesystem.hpp>
File::File(Filesystem &fs, String fname): fs(fs), fname(fname) { File::File(Filesystem &fs, String fname): fs(fs), fname(fname) {
size=getFileSize(fname); size=fs.getFileSize(fname);
}; };
auto Fileread(uint64_t offset, uint64_t length) -> uint8_t*; { auto File::read(uint64_t offset, uint64_t length) -> uint8_t*; {
uint8_t *buf=new uint8_t[length]; uint8_t *buf=new uint8_t[length];
if(offset+length>size) if(offset+length>size)
return nullptr; return nullptr;
fs.readFile(fname, offset, offset+length) fs.readFile(fname, offset, offset+length)
}
Directory::Directory(Filesystem &fs, String dname): fs(fs), fname(fname) {
}*/ }*/

View file

@ -1,13 +1,16 @@
#pragma once #pragma once
#include <string.hpp> #include <string.hpp>
#include <partitions.hpp> #include <partitions.hpp>
class File;
class Directory;
class Filesystem { class Filesystem {
protected: protected:
Partitions parts; Partitions &parts;
int part; int part;
virtual auto readSector(uint64_t num, uint8_t* buf) -> void = 0; virtual auto readSector(uint64_t num, uint8_t* buf) -> void = 0;
virtual auto readFile(String &name, uint64_t start, uint64_t end, uint8_t buf) -> void = 0; virtual auto readFile(String &name, uint64_t start, uint64_t end, uint8_t buf) -> void = 0;
virtual auto getFileSize(String &name) -> uint64_t = 0; virtual auto getFileSize(String &name) -> uint64_t = 0;
virtual auto countDirectory(String &name) -> uint32_t =0;
public: public:
friend class File; friend class File;
friend class Directory; friend class Directory;
@ -24,7 +27,19 @@ class File {
uint64_t size; uint64_t size;
File() {} File() {}
public: public:
File(Filesystem &fs, String fname) File(Filesystem &fs, String fname);
auto read(uint64_t offset, uint64_t length) -> uint8_t*; auto read(uint64_t offset, uint64_t length) -> uint8_t*;
} };
class Directory {
private:
String name;
Filesystem &fs;
uint32_t noFiles;
File* contents;
Directory();
public:
Directory(Filesystem &fs, String dname);
auto getCount() -> uint32_t;
auto operator[](uint32_t) -> File&;
};

View file

@ -32,6 +32,7 @@ void task_d() {
while(true) while(true)
out << "d"; out << "d";
} }
void readFAT();
void main(void ** files, MTGosHAL::Serial &debug, MTGosHAL::PMM &mm, MTGosHAL::Screen &out, void main(void ** files, MTGosHAL::Serial &debug, MTGosHAL::PMM &mm, MTGosHAL::Screen &out,
MTGosHAL::Screen &err, MTGosHAL::Keyboard &in, MTGosHAL::Multitasking &tasks, MTGosHAL::BlockDevice &disk) { MTGosHAL::Screen &err, MTGosHAL::Keyboard &in, MTGosHAL::Multitasking &tasks, MTGosHAL::BlockDevice &disk) {
out << "Initializing Kernel!\n"; out << "Initializing Kernel!\n";
@ -49,4 +50,5 @@ void main(void ** files, MTGosHAL::Serial &debug, MTGosHAL::PMM &mm, MTGosHAL::S
out << "Partition 2: beg=" << (int32_t)part.getPartBeg(1) << " end=" << (int32_t)part.getPartEnd(1) << "\n"; out << "Partition 2: beg=" << (int32_t)part.getPartBeg(1) << " end=" << (int32_t)part.getPartEnd(1) << "\n";
out << "Partition 3: beg=" << (int32_t)part.getPartBeg(2) << " end=" << (int32_t)part.getPartEnd(2) << "\n"; out << "Partition 3: beg=" << (int32_t)part.getPartBeg(2) << " end=" << (int32_t)part.getPartEnd(2) << "\n";
out << "Partition 4: beg=" << (int32_t)part.getPartBeg(3) << " end=" << (int32_t)part.getPartEnd(3) << "\n"; out << "Partition 4: beg=" << (int32_t)part.getPartBeg(3) << " end=" << (int32_t)part.getPartEnd(3) << "\n";
readFAT();
} }

Binary file not shown.

View file

@ -27,12 +27,12 @@ echo "Partitioning image..."
sudo gpart create -s MBR $dev sudo gpart create -s MBR $dev
sudo gpart add -t freebsd -b 512 ${dev} sudo gpart add -t freebsd -b 512 ${dev}
echo "Formatting partition..." echo "Formatting partition..."
sudo mkfs.ext2 /dev/${dev}s1 sudo newfs_msdos /dev/${dev}s1
echo "Mounting image..." echo "Mounting image..."
mkdir mount mkdir mount
sudo mount -t ext2fs /dev/${dev}s1 mount sudo mount -t msdosfs /dev/${dev}s1 mount
echo "Installing grub... (May take some time)" echo "Installing grub... (May take some time)"
sudo grub-install --target=i386-pc --boot-directory=mount /dev/$dev --compress=xz --install-modules="normal part_msdos ext2 multiboot biosdisk xzio" --modules="normal part_msdos ext2 multiboot biosdisk xzio" --locales="" --force sudo grub-install --target=i386-pc --boot-directory=mount /dev/$dev --compress=xz --install-modules="normal part_msdos fat multiboot biosdisk xzio" --modules="normal part_msdos fat multiboot biosdisk xzio" --locales="" --force
echo "Copying files..." echo "Copying files..."
sudo mv mtgos.xz mtgos.fnt.xz test.elf.xz mount sudo mv mtgos.xz mtgos.fnt.xz test.elf.xz mount
echo "Creating grub.cfg" echo "Creating grub.cfg"
@ -47,6 +47,7 @@ sudo mv grub.cfg mount/grub
echo "Unmounting everything" echo "Unmounting everything"
sync sync
sleep 0.5 sleep 0.5
df -h mount
sudo umount mount sudo umount mount
sudo mdconfig -d -u ${dev#md} sudo mdconfig -d -u ${dev#md}
echo "Finalizing..." echo "Finalizing..."

BIN
test.elf Executable file

Binary file not shown.