How To Make Efi Bootloader |
|
|

Mar 4 2011, 12:14 PM




- Advanced Member
- Group: Developer
- Posts: 5,555
May be it's a time to think about EFI-based boot loader?
---------------
November 2012
Using git
http://www.projectosx.com/forum/index.php?...ost&p=21635----------------
26.07.2012
Creating GCC46 toolset starting with Xcode 4.3.3-------------------------------------------
31.03.2012
Automatic script by STVNUB to create Clover from zero.-------------------------------------------
29.02.2012
Step by step instructions "How to make Clover from zero"------------------------------------------
26.01.2012
Now Lion compilation method from jadran using recent gcc compiler.
http://www.projectosx.com/forum/index.php?...ost&p=16669------------------------------------------
11.10.2011
New instructions how to make the bootloader
http://www.projectosx.com/forum/index.php?...ost&p=16010One needed tool
mtoc can be found here
http://www.projectosx.com/forum/index.php?...ost&p=15498Instruction below are obsolete.
-------------------------------------------
posts #2,3 now can be performed automatically by
jadran's scriptNote; There is no more needed in the script to download CpuDxe from UDK2010. Now native UefiCpuDxe is working.
post#1 will be obsolete.
-------------------------------------------
Prepare tools:
Follow
this guide.
1. Download prebuild tools from the site
http://www.osxbook.com/book/bonus/chapter4...0-2.3.6.tar.bz2 Copy to system
CODE
sudo cp -r ~/Downloads/usr/local/osxbook /usr/local/
These utilities will be also usefull to compile bootsectors.
2. Set PATH variable
CODE
PATH=/usr/local/osxbook/efi/gcc-4.1.0-glibc-2.3.6/i686-osxbook-linux-gnu/bin:$PATH
3. Download gnu-efi-3.x. There are many download locations found by google. May be you will find more recent sources then at the osxbook. Unpack.
4. EFI definitions in the package is too old. I want to modify them.
gnu_efi.diff.zip ( 11.33K )
Number of downloads: 94Briefly: I applied EFI definitions from Intel to file efiapi.h and some related files.
5. Correct Make.defaults for our tools
CODE
#ARCH = $(shell uname -m | sed s,i[3456789]86,ia32,)
ARCH = ia32
.......
#
# gcc-3.x is required
#
prefix = i686-osxbook-linux-gnu-
6. Compile and install headers
CODE
cd gnu-efi-3.0s
make
sudo make install
Now we can compile EFI applications using these tools. To do that we need to edit makefile and correct headers in the sources.
For example rEFIt.
http://refit.sourceforge.net/1. Download sources. Unpack.
2. Correct make.common as follows
CODE
# this must be /usr/local
EFIINC = /usr/local/include/efi
GNUEFILIB = /usr/local/lib
EFILIB = /usr/local/lib
EFICRT0 = /usr/local/lib
.......
#ARCH = $(shell uname -m | sed s,i[3456789]86,ia32,)
ARCH = ia32
.....
CFLAGS = $(OPTIMFLAGS) -mtune=pentium3 -march=pentium3 -fpic -fshort-wchar $(DEBUGFLAGS)
......
#prefix = /usr/bin/
prefix = i686-osxbook-linux-gnu-
3. First go to libeg folder
CODE
cd ~/refit-0.14-src/libeg
make
4. Next goto refit folder
CODE
cd ~/refit-0.14-src/refit
make
There is refit.efi here!
Any more proposition?
Is there any way to do with UDK2010.UP3?

Mar 5 2011, 08:02 AM




- Advanced Member
- Group: Developer
- Posts: 5,555
Lets continue with EDK2. Thank to Kabyl for providing guide how to.
But... as usual some steps should be revised.
http://sourceforge.net/apps/mediawiki/tian...s#Mac_OS_X_10.51. gmp library
CODE
mkdir ~/src
cd ~/src
curl --remote-name ftp://ftp.gnu.org/gnu/gmp/gmp-4.2.2.tar.bz2
tar jxvf gmp-4.2.2.tar.bz2
cd gmp-4.2.2
./configure --prefix=/usr/local
make
make check
sudo make install
Success!
2. mpfr library. It changed and this guide no more works! Do the follow.
EDITED: goto step 2a.
Goto
http://www.mpfr.org/mpfr-current/#fixedDownload
mpfr-3.0.0.tar.gz into
~/srcUnpack.
CODE
cd ~/src
svn co svn://scm.gforge.inria.fr/svn/mpfr/branches/3.0 mpfr-3.0
Now copy all files from
mpfr-3.0 to
mpfr-3.0.0 because mpfr-3.0 have no some files.
Copy
Makefile.in into
tests folder. (it is a bug that later sould be corrected by authors)
CODE
cd mpfr-3.0.0
./configure --with-gmp-build=../gmp-4.2.2 --prefix=/usr/local
Then stop.
make is not working while with mpfr-2.4.2 there was success.
2a. So return to
http://www.mpfr.org/mpfr-2.4.2/Download the package, unpack.
CODE
cd ~/src/mpfr-2.4.2
./configure --with-gmp-build=../gmp-4.2.2 --prefix=/usr/local
make
sudo make install
Success!
3.
efitool.
Now new Guide.Old guide
http://sourceforge.net/apps/mediawiki/tian...php?title=XcodeGoto Apple.
http://opensource.apple.com/release/mac-os-x-1066/Download latest cctools. Now it is 750. Why SF told about 782? Unpack.
Goto
http://llvm.org/releases/download.html#2.7. Namely version 2.7! We can't use recent version! Download and unpack
LLVM source code.
Copy the
include/llvm-c directory from LLVM into the cctools include directory.
CODE
cd ~/Downloads/cctools-750
make
It stops with error after strip.c. It is normal!

Continue
CODE
cd efitools
make
sudo cp mtoc.NEW /usr/local/bin/mtoc
4.
EDK2 ToolsCODE
cd ~/src
svn checkout https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2 edk2
cd edk2/BaseTools/gcc
./mingw-gcc-build.py --arch=ia32 --prefix=~/programs/gcc/ia32
it takes a time. Even an hour is CPU is not fast enough. Or you can use binay package @post28 by Kabyl.
http://www.projectosx.com/forum/index.php?...ost&p=13179At this point i can't understand why gcc-4.3.0 is not compiled. So the previous step may be
CODE
./mingw-gcc-build.py --arch=ia32 --prefix=~/programs/gcc/ia32 --skip-gcc
Or
this guide.Continue
CODE
cd ~/src/edk2
export EDK_TOOLS_PATH=~/src/edk2/BaseTools
./edksetup.sh BaseTools
Now edit
Conf/tools_def.txtCODE
DEFINE ELFGCC_BIN = /usr/local/bin
...
# Option 1: Hard coded full path to compiler suite
#DEFINE UNIXGCC_IA32_PETOOLS_PREFIX = /opt/tiano/i386-tiano-pe/i386-tiano-pe/bin/
#DEFINE UNIXGCC_X64_PETOOLS_PREFIX = /opt/tiano/x86_64-pc-mingw64/x86_64-pc-mingw64/bin/
#DEFINE UNIXGCC_IPF_PETOOLS_PREFIX = /opt/tiano/ia64-pc-elf/ia64-pc-elf/bin/
...
# Option 5: Install programs under user's home directory
DEFINE UNIXGCC_IA32_PETOOLS_PREFIX = ENV(HOME)/programs/gcc/ia32/bin/i686-pc-mingw32-
DEFINE UNIXGCC_X64_PETOOLS_PREFIX = ENV(HOME)/programs/gcc/x64/bin/x86_64-pc-mingw32-
DEFINE UNIXGCC_IPF_PETOOLS_PREFIX = /usr/local/arm-elf/bin/
#
Find the TARGET_ARCH definition in
Conf/target.txt and change the corresponding line to match this
CODE
TARGET_ARCH = IA32
now build
CODE
cd ~/src/edk2/UnixPkg
./build_sh
Success!
5.
Boot sectors files. They are present as binary ready to use. If you want to recompile look
here.

Mar 5 2011, 10:37 AM




- Advanced Member
- Group: Developer
- Posts: 5,555
Now attempt to build Duet
CODE
cd ~/src/edk2/DuetPkg
./build32.sh
CODE
make: *** [/Users/slice/src/edk2/Build/DuetPkgIA32/DEBUG_XCODE32/IA32/UefiCpuPkg/CpuDxe/CpuDxe/OUTPUT/Ia32/IvtAsm.obj] Error 1
build.py...
: error 7000: Failed to execute command
make tbuild [/Users/slice/src/edk2/Build/DuetPkgIA32/DEBUG_XCODE32/IA32/UefiCpuPkg/CpuDxe/CpuDxe]
build.py...
: error F002: Failed to build module
/Users/slice/src/edk2/UefiCpuPkg/CpuDxe/CpuDxe.inf [IA32, XCODE32, DEBUG]
- Failed -
Build end time: 13:31:28, Mar.05 2011
Build total time: 00:43
Look into CpuDxe. It is empty!
Download UDK2010.UP3
There is another DuetPkg but without build.sh scripts. Join projects. Namely take CpuDxe from UDK and replace in the project
CpuDxe.zip ( 31.21K )
Number of downloads: 34Some correction in project files DuetPkgIa32.dsc:
CODE
#UefiCpuPkg/CpuDxe/CpuDxe.inf
DuetPkg/CpuDxe/Cpu.inf
and in DuetPkg.fdf
CODE
#INF UefiCpuPkg/CpuDxe/CpuDxe.inf
INF DuetPkg/CpuDxe/Cpu.inf
Now repeat ./build.sh and see success.
Now postbuild
CODE
export WORKSPACE=~/src/edk2
Then rename folder edk2/Build/DuetPkgIA32/DEBUG_XCODE32 to edk2/Build/DuetPkgIA32/DEBUG_UNIXGCC
EDITED.
It seems to be better to correct build.sh NOCorrections to postbuild.sh
CODE
export BASETOOLS_DIR=$WORKSPACE/BaseTools/Source/C/bin
...
export BUILD_DIR=$WORKSPACE/Build/DuetPkg$PROCESSOR/DEBUG_XCODE32
Go!
CODE
./PostBuild.sh IA32 UNIXGCC
Success!
Create bootable USB stick. The script CreateBootDisk is not working. Do manually
CODE
sudo -s
cd ~/src/edk2/BaseTools/Source/C/bin
dd if=/dev/rdisk1s1 of=UsbBs32.com bs=512 count=4
./BootSectImage -g UsbBs32.com ~/src/edk2/DuetPkg/BootSector/bin/bs32.com -f
dd if=~/src/edk2/DuetPkg/BootSector/bin/bs32.com of=/dev/rdisk1s1
fdisk -f ~/src/edk2/DuetPkg/BootSector/bin/Mbr.com -u -y /dev/rdisk1
mkdir /Volumes/UsbDuet/efi
Copy Efildr20 and
Efivar.bin into UsbDuet root and some bootloader and support files into efi.
For example:
Place
Shell_Full.efi into /efi/boot/ and rename it to
bootIA32.efi. It will be autostart.
EDITED:
Now we have a method to boot from HFS+ partition. Credits to Kabyl.
bootHFS.zip ( 3.53K )
Number of downloads: 88Copy files to
~/src/edk2/Build/DuetPkgIA32/DEBUG_XCODE32/FVCODE
cd ~/src/edk2/Build/DuetPkgIA32/DEBUG_XCODE32/FV
cat StartHFS.com efi32.com2 Efildr32 >boot
sudo -s
fdisk -f boot0 -u -y /dev/rdisk1
dd if=boot1h of=/dev/rdisk1s2
cp boot /Volumes/Duet
These files differ from Chameleon's!
Be sure about
rdisk1s2 - installation drive, /Volumes/Duet
No matter MBR or GPT.
I checked. These
boot0 and
boot1h works fine with Chameleon.

Mar 5 2011, 06:47 PM




- Advanced Member
- Group: Developer
- Posts: 367
slice,
I can't compile cctools under Lion: it needs mach/ppc/thread_status.h (why does it need PowerPC headers???).
Or do I need to compile all that prerequisites for kernel compilation from the near thread?
This post has been edited by гык-sse2: Mar 5 2011, 06:49 PM
UEFI is a great way to get the best of the best in the world of imagination and creativity. ©Google Scribe

Mar 5 2011, 07:05 PM

- Advanced Member
- Group: Staff
- Posts: 109
QUOTE (гык-sse2 @ Mar 5 2011, 07:47 PM)

slice,
I can't compile cctools under Lion: it needs mach/ppc/thread_status.h (why does it need PowerPC headers???).
Or do I need to compile all that prerequisites for kernel compilation from the near thread?
because it's for Leopard, Lion doesn't have ppc in its SDK, maybe if you get cctools for Lion

Did you try removing ppc flags from Makefile(s)?

Mar 5 2011, 08:37 PM




- Advanced Member
- Group: Developer
- Posts: 5,555
QUOTE (гык-sse2 @ Mar 5 2011, 10:47 PM)

slice,
I can't compile cctools under Lion: it needs mach/ppc/thread_status.h (why does it need PowerPC headers???).
Or do I need to compile all that prerequisites for kernel compilation from the near thread?
Dunno about Lion. We still have no headers for it. Just use Snow for development.
I think kernel prerequisites are desirable although not obligatory.
For Duet I need HFS+ drivers and patches. Any help?

Mar 5 2011, 09:21 PM

- Advanced Member
- Group: Staff
- Posts: 109
QUOTE (Slice @ Mar 5 2011, 09:37 PM)

Dunno about Lion. We still have no headers for it. Just use Snow for development.
I think kernel prerequisites are desirable although not obligatory.
For Duet I need HFS+ drivers and patches. Any help?
HFS+ EFI drivers:
http://www.mediafire.com/?0q96g6ujx9t61r2

Mar 6 2011, 06:49 AM




- Advanced Member
- Group: Developer
- Posts: 5,555
QUOTE (Kabyl @ Mar 6 2011, 01:21 AM)

Thank you, but what about opensource? I know
libsaio folder from Chameleon.
What do you think about creating new svn project? We dont need EDK2 as a hole just minimum sources from it. DuetForMac.
EDITED.
There are EDK2 patches including HFS+ driver in VBox by Oracle. Applying to our sources with precautions!

Mar 6 2011, 07:15 AM

- Advanced Member
- Group: Staff
- Posts: 109
QUOTE (Slice @ Mar 6 2011, 07:49 AM)

Thank you, but what about opensource? I know libsaio folder from Chameleon.
The files I posted were extracted from a VMWare firmware, so no sources, but I did find a good source for HFS+ and and did some work on it, back when I was playing with DUET.
QUOTE
What do you think about creating new svn project? We dont need EDK2 as a hole just minimum sources from it. DuetForMac.
I've done some work on this, I have boot.efi loading and booting the kernel; the minimum required is:
- Fat binary support.
- setting the
IODeviceTree:/efi/platform/FSBFrequency property.
This is done in a module, works under QEMU, but not tested on real HW.
I need to find sometime to get my EDKII work environment set up, and I might create a new project on github or something.

Mar 6 2011, 08:33 AM




- Advanced Member
- Group: Developer
- Posts: 5,555
VMWare no sources but VirtualBox by Oracle - yes! Including HFS+.

Mar 6 2011, 09:15 AM

- Advanced Member
- Group: Staff
- Posts: 109
QUOTE (Slice @ Mar 6 2011, 09:33 AM)

VMWare no sources but VirtualBox by Oracle - yes! Including HFS+.
And you have most of what you need here:
http://www.virtualbox.org/svn/vbox/trunk/s...kg/VBoxAppleSim

Mar 6 2011, 11:16 AM




- Advanced Member
- Group: Developer
- Posts: 5,555
QUOTE (Kabyl @ Mar 6 2011, 01:15 PM)

Done!
Now next questions.
1. I want to start from HFS+ so Start32.asm should be rewritten as for example boot1h or boot2.s. What do you think?
2. FAT binary. I need bootloader for IA32 because of hardware. But others want to have x64. Two builds? Or we can join both? As I think EfiRuntime should be the same arch as kernel. Or it is possible to make Efildr as IA32 but put *efi modules for both arch, for example DxeIpl.efi+DxeIpl64.efi?
3. Do we propose to use Shell.efi or Refit.efi or just start Apple's boot.efi?

Mar 6 2011, 01:13 PM

- Advanced Member
- Group: Staff
- Posts: 109
QUOTE (Slice @ Mar 6 2011, 12:16 PM)

Done!
Now next questions.
1. I want to start from HFS+ so Start32.asm should be rewritten as for example boot1h or boot2.s. What do you think?
We could probably adapt boot1h to load Efldr and jump to it, but it needs to be of a limited size.
QUOTE
2. FAT binary. I need bootloader for IA32 because of hardware. But others want to have x64. Two builds? Or we can join both? As I think EfiRuntime should be the same arch as kernel. Or it is possible to make Efildr as IA32 but put *efi modules for both arch, for example DxeIpl.efi+DxeIpl64.efi?
Two builds, we don't have a choice since boot.efi doesn't include an EBC binary.
QUOTE
3. Do we propose to use Shell.efi or Refit.efi or just start Apple's boot.efi?
Shell is a necessity, especially at this stage, rEFIt could be used for its UI.

Mar 6 2011, 01:44 PM




- Advanced Member
- Group: Developer
- Posts: 5,555
What do you think about differencies between DUET from EDK106 and EDK2. usr-sse2 and A.Woland told then EDK1 is better for us, more stable and USB works better.
QUOTE
We could probably adapt boot1h to load Efldr and jump to it, but it needs to be of a limited size.
Just rename Efildr20 to boot

But no. Start32.S uses FAT32 to work.

Mar 6 2011, 02:14 PM

- Advanced Member
- Group: Staff
- Posts: 714
QUOTE (Slice @ Mar 6 2011, 01:16 PM)

2. FAT binary. I need bootloader for IA32 because of hardware.
Same here, main problem from my tests is AHCI.
I couldn't find one for 32 bit build that works on this MCP79 crap that I have

Funny thing, this netbook use Insyde EFI BIOS, but even I took the BIOS in pieces I didn't found so far any AHCI driver, only IDE., must be somewhere hidden or no idea how it switch to AHCI mode, only AHCI string I found is in setup module...

Mar 6 2011, 02:15 PM

- Advanced Member
- Group: Staff
- Posts: 109
QUOTE (Slice @ Mar 6 2011, 02:44 PM)

What do you think about differencies between DUET from EDK106 and EDK2. usr-sse2 and A.Woland told then EDK1 is better for us, more stable and USB works better.
Yes, ATM EDKI is more stable and even faster than EDKII, but it's not actively developed anymore.
This isn't a problem though, because you're going to write a module and it can be used on either.
QUOTE
Just rename Efildr20 to boot

But no. Start32.S uses FAT32 to work.
Check the load and jump address of Efildr and change them to what is found in Start32.

Mar 6 2011, 04:33 PM




- Advanced Member
- Group: Developer
- Posts: 5,555
QUOTE (Kabyl @ Mar 6 2011, 06:15 PM)

Check the load and jump address of Efildr and change them to what is found in Start32.
You didn't understand me. I mean that Start32 is a part of Efildr
CODE
cat $BOOTSECTOR_BIN_DIR/Start32.com $BOOTSECTOR_BIN_DIR/efi32.com2 $BUILD_DIR/FV/Efildr32 > $BUILD_DIR/FV/Efildr20
and Start32.com uses FAT32, so Efildr20 can't be installed into HFS+ partition as I wish.

Mar 6 2011, 04:49 PM




- Advanced Member
- Group: Developer
- Posts: 5,555
QUOTE (THe KiNG @ Mar 6 2011, 06:14 PM)

Same here, main problem from my tests is AHCI.
I couldn't find one for 32 bit build that works on this MCP79 crap that I have

Funny thing, this netbook use Insyde EFI BIOS, but even I took the BIOS in pieces I didn't found so far any AHCI driver, only IDE., must be somewhere hidden or no idea how it switch to AHCI mode, only AHCI string I found is in setup module...
What about
CODE
# Binary INF file to support toggle among different CPU architectures.
INF RuleOverride=BINARY FatBinPkg/EnhancedFatDxe/Fat.inf
We can use IA32 and X64 simultaneously?

Mar 6 2011, 04:57 PM

- Advanced Member
- Group: Staff
- Posts: 109
QUOTE (Slice @ Mar 6 2011, 05:33 PM)

You didn't understand me. I mean that Start32 is a part of Efildr
CODE
cat $BOOTSECTOR_BIN_DIR/Start32.com $BOOTSECTOR_BIN_DIR/efi32.com2 $BUILD_DIR/FV/Efildr32 > $BUILD_DIR/FV/Efildr20
and Start32.com uses FAT32, so Efildr20 can't be installed into HFS+ partition as I wish.
Actually I did, it's the other way around

I was talking about boot1h which can be used on HFS+.
You can skip Start32 in this case.
QUOTE (Slice @ Mar 6 2011, 05:49 PM)

What about
CODE
# Binary INF file to support toggle among different CPU architectures.
INF RuleOverride=BINARY FatBinPkg/EnhancedFatDxe/Fat.inf
We can use IA32 and X64 simultaneously?
erm... that's for FAT filesystem.

Mar 6 2011, 07:53 PM




- Advanced Member
- Group: Developer
- Posts: 5,555
QUOTE (Kabyl @ Mar 6 2011, 08:57 PM)

Actually I did, it's the other way around

I was talking about boot1h which can be used on HFS+.
You can skip Start32 in this case.
Just jump over Start32? Fine! Thank for trick.
QUOTE
erm... that's for FAT filesystem.
but
CODE
toggle among different CPU architectures
???