]> code.delx.au - refind/blob - BUILDING.txt
Version 0.4.0 release.
[refind] / BUILDING.txt
1 From rEFIt to rEFInd
2 ====================
3
4 rEFInd is derived from rEFIt (http://refit.sourceforge.net), but the two
5 programs support different build environments. rEFIt was created with
6 Intel's EFI Application Toolkit
7 (http://www.intel.com/technology/efi/toolkit_overview.htm) or TianoCore's
8 EFI Toolkit (https://efi-toolkit.tianocore.org), along with Microsoft's
9 Visual C compiler.
10
11 Compiling the source code provided on the rEFIt site under Linux never
12 worked for me, although the documentation claimed it would. Apparently
13 other Linux developers have run into the same problem; Debian provides a
14 rEFIt package (http://packages.debian.org/sid/refit) that includes
15 extensive patches to enable the program to compile under Linux using the
16 GNU-EFI package (http://sourceforge.net/projects/gnu-efi/). Although
17 GNU-EFI is less sophisticated than recent versions of TianoCore's toolkit,
18 GNU-EFI is my preferred environment because versions of TianoCore that can
19 build under Linux use a very different set of include files and support a
20 somewhat different set of system calls than are used by rEFIt/rEFInd. Thus,
21 converting to a new TianoCore toolkit would entail a lot of work. Using an
22 older version would require building under Windows and using old versions
23 of Microsoft's Visual C. I neither have this toolchain nor do I want to use
24 it. For this reason, I used Debian's patched version of rEFIt as a starting
25 point in forking rEFInd.
26
27 Note that the drivers, added with rEFInd 0.4.0, require use of the
28 TianoCore tool kit. Driver compilation is described in more detail later.
29
30 I've dropped ancillary programs, such as the gptsync program, from rEFInd.
31 You can still use these tools with rEFInd, but you'll need to install them
32 separately.
33
34 The patched version of rEFIt that I used as a starting point disabled the
35 program's ability to load EFI drivers because of limitations in the GNU-EFI
36 library. A combination of improvements in recent versions of the library
37 and implementing a (now apparently abandoned) EFI function directly in
38 rEFInd has enabled me to add this support back to rEFInd 0.2.7 and later.
39
40
41 Requirements
42 ============
43
44 To compile rEFInd, you'll need the following:
45
46 * A Linux installation. Note that this installation does NOT need to be
47 EFI-based. It can be 32- or 64-bit, but unless you use a cross-compiler
48 (which I've not tested), it must be the appropriate bit width for your
49 EFI implementation. (Normally that means 64-bit.) If you don't normally
50 run Linux, you can run it in a VirtualBox or similar virtual machine.
51
52 * A standard set of Linux development tools, based on GCC.
53
54 * The GNU-EFI package (http://sourceforge.net/projects/gnu-efi/). You can
55 install this from a package called "gnu-efi"; however, rEFInd relies on
56 features that were added in (I think) 3.0l to provide driver-loading
57 capabilities. The versions I've used and that work are 3.0p and 3.0q. As
58 of 5/2012, most Linux distributions seem to deliver rather elderly
59 versions of GNU-EFI, so you may need to download the latest source code,
60 compile it, and install it locally. Since rEFInd version 0.2.7, the
61 Makefiles assume this (see below).
62
63 It's possible that you could use a non-Linux platform to compile rEFInd. To
64 the best of my knowledge, the rEFInd code doesn't rely on anything
65 Linux-specific in its build requirements, and GNU-EFI's Sourceforge page
66 indicates that it works under Windows and OS X, too. Thus, you may be able
67 to compile it on these platforms, but I've not tested it in this way. Under
68 Windows, you would need to either create a project or Makefile for your
69 non-GCC compiler or use a GCC port, such as MinGW (http://www.mingw.org).
70 You'd probably need to adjust the Makefile in the latter case.
71
72
73 Compiling rEFInd
74 ================
75
76 With your development system set up, you can compile rEFInd as follows:
77
78 1) Download and uncompress the rEFInd source code archive. (If you're
79 reading this file, you've probably already done this task.)
80
81 2) Open a Linux shell prompt
82
83 3) Change into the archive's main directory. You should see several files
84 including this BUILDING.txt file and several subdirectories such as
85 "refind", "libeg", and "include".
86
87 4) Type "make". With any luck, rEFInd will compile without error, leaving
88 the "refind_ia32.efi" or "refind_x64.efi" file, depending on your
89 platform, in the "refind" subdirectory.
90
91 If rEFInd doesn't compile correctly, you'll need to track down the source
92 of the problem. Double-check that you've got all the necessary development
93 tools installed, including GCC, make, and GNU-EFI. You may also need to
94 adjust the Makefile or Make.common file for your system. The most likely
95 thing you'll need to change is the path to the various GNU-EFI include
96 files and libraries. Since rEFInd 0.2.7, the default Make.common file
97 includes the following definitions:
98
99 EFIINC = /usr/local/include/efi
100 GNUEFILIB = /usr/local/lib
101 EFILIB = /usr/local/lib
102 EFICRT0 = /usr/local/lib
103
104 If you've installed GNU-EFI from a distribution's package, you may need to
105 remove "local" from those paths, and perhaps change references to "lib" to
106 "lib64". As noted earlier, though, as of 5/2012, most distributions provide
107 out-of-date GNU-EFI implementations that will not work with rEFInd 0.2.7
108 and later.
109
110 When I tried to compile rEFInd under Ubuntu 12.04 (i386), even with a
111 locally-compiled GNU-EFI 3.0p or 3.0q, I got errors like this:
112
113 main.o: In function `StartLegacy.isra.0':
114 main.c:(.text+0x8b1): undefined reference to `__stack_chk_fail_local'
115 lib.o: In function `ScanVolumeBootcode.part.3':
116 lib.c:(.text+0xf2f): undefined reference to `__stack_chk_fail_local'
117 lib.o: In function `ScanExtendedPartition.isra.4':
118
119 The solution was to recompile GNU-EFI with the -fno-stack-protector GCC
120 flag. In GNU-EFI, this can be added to the CFLAGS line in Make.defaults.
121
122 Installing rEFInd
123 =================
124
125 With rEFInd compiled, you can install it. The easiest way to do this is
126 with the install.sh script, which works on both Linux and Mac OS X.
127 Alternatively, you can type "make install" to install using this script.
128 Note that this installation copies files to the ESP and uses "efibootmgr"
129 (on Linux) or "bless" (on OS X) to add rEFInd to the firmware's boot loader
130 list. The docs/refind/installing.html file provides more details on this
131 script and its use.
132
133 If install.sh doesn't work for you or if you prefer to do the job manually,
134 you may. On a UEFI-based system, you'll want to copy files on the ESP as
135 follows:
136
137 * Create a directory for rEFInd, such as EFI/refind.
138 * Copy refind/refind_ia32.efi or refind_x64.efi to the ESP's EFI/refind
139 directory.
140 * Copy refind.conf-sample to the EFI/refind directory as refind.conf.
141 * Copy the icons subdirectory, including all its files, to EFI/refind.
142
143 You'll then need to activate rEFInd in your EFI. This can be done with
144 tools such as "efibootmgr" under Linux or "bless" under OS X. See the
145 docs/refind/installing.html file for details.
146
147 Note to Distribution Maintainers
148 ================================
149
150 The install.sh script, and therefore the "install" target in the Makefile,
151 installs the program directly to the ESP and it modifies the *CURRENT
152 COMPUTER's* NVRAM. Thus, you should *NOT* use this target as part of the
153 build process for your binary packages (RPMs, Debian packages, etc.).
154 (Gentoo could use it in an ebuild, though....) You COULD, however, copy the
155 files to a directory somewhere (/usr/share/refind or whatever) and then
156 call install.sh as part of the binary package installation process.
157 Placing the files in /boot/efi/EFI/{distname}/refind and then having a
158 post-install script call efibootmgr is probably the better way to go,
159 though.
160
161 Compiling the EFI Filesystem Drivers
162 ====================================
163
164 The EFI filesystem drivers in the filesystems subdirectory require the
165 TianoCore UDK2010.SR1 toolkit. The drivers might compile with another
166 version of the TianoCore toolkit, but I've not tested them with anything
167 else. (My attempts to use GNU-EFI have failed; at best, I've gotten drivers
168 that load but hang the computer.)
169
170 Unfortunately, the TianoCore toolkit is bulky and weird by Linux
171 programming standards. I don't know of any Linux distribution packages for
172 it in RPM, Debian package file, or other format; you MUST install the kit
173 from source code using its own unusual compilation procedure. The
174 installation documentation also omits at least one step and is a bit
175 unclear about others. Here's how I installed the toolkit:
176
177 1) Download UDK2010.SR1 from
178 https://sourceforge.net/apps/mediawiki/tianocore/index.php?title=UDK2010.
179
180 2) Type "mkdir /usr/local/UDK2010". You can use another directory, but the
181 Makefile for rEFInd's EFI drivers assumes this location. You'll need to
182 edit the EDK2BASE line in the Make.common file if you install somewhere
183 else.
184
185 3) Type "cd /usr/local/UDK2010".
186
187 3) Unzip the downloaded file (UDK2010.SR1.Complete.MyWorkSpace.zip) in the
188 current directory (/usr/local/UDK2010). This creates a handful of files,
189 including a tarball and a couple of .zip files.
190
191 4) Type "unzip UDK2010.SR1.MyWorkSpace.zip". This extracts the
192 platform-neutral portion of the development kit.
193
194 5) Type "cd MyWorkSpace".
195
196 6) Type "tar xvf ../BaseTools\(Unix\)_UDK2010.SR1.tar". This extracts the
197 Linux/Unix-specific portions of the toolkit.
198
199 7) Follow the build instructions at
200 https://sourceforge.net/apps/mediawiki/tianocore/index.php?title=Using_EDK_II_with_Native_GCC_4.4;
201 however, a few changes are required, as detailed below....
202
203 8) Type ". edksetup.sh BaseTools" (note the leading dot). This sets up some
204 environment variables, so subsequent steps (NOT including compiling the
205 rEFInd EFI drivers) must be typed in the shell you use for this step.
206
207 9) Edit Conf/target.txt and change the following:
208 - ACTIVE_PLATFORM = MdeModulePkg/MdeModulePkg.dsc
209 - TARGET = RELEASE (DEBUG might work, but I've not tested it).
210 - TARGET_ARCH = X64 (on x86-64; leave this as IA32 on x86)
211 - TOOL_CHAIN_TAG = GCC45 (or other value depending on your GCC version;
212 type "gcc -v" to learn your GCC version number)
213 The Makefile for the drivers reads some of these variables from this
214 file and uses them when accessing directories, so be sure to type these
215 entries in the case specified. Note that the documentation refers to
216 editing Conf/tools_def.txt in addition to Conf/target.txt, but doesn't
217 specify what to change in Conf/tools_def.txt. I haven't found it
218 necessary to make any changes in Conf/tools_def.txt.
219
220 11) Type "make -C /usr/local/UDK2010/MyWorkSpace/BaseTools/Source/C".
221 (This step is not documented on the EDK Web page.)
222
223 10) Type "build" to build the main set of EDK2 files. This process is
224 likely to take a few minutes.
225
226 Once the toolkit is installed, you can build the filesystem drivers. If you
227 installed in a location other than the one I've specified, you must edit
228 the EDK2BASE variable in the filesystems/Make.common file in the rEFInd
229 source package.. You can then type "make" in the "filesystems" directory,
230 or "make fs" in the main source directory, to build all the drivers. If you
231 want to build just one driver, you can change into the "filesystems"
232 directory and type "make {fsname}", where {fsname} is a filesystem name --
233 "ext2", "reiserfs", "iso9660", or "hfs". The drivers will appear in the
234 "filesystems" directory, and also be copied to the "drivers" directory.
235
236 To install drivers, you can type "make install" in the "filesystems"
237 directory. This copies all the drivers to the
238 "/boot/efi/EFI/refind/drivers" directory. Alternatively, you can copy the
239 files you want manually.
240
241 *CAUTION:* Install drivers for your system's architecture *ONLY*.
242 Installing drivers for the wrong architecture causes some systems to hang
243 at boot time.
244
245 The drivers all rely on filesystem wrapper code created by rEFIt's author,
246 Christoph Phisterer. Most of the drivers seem to have passed through
247 Oracle's VirtualBox project ((https://www.virtualbox.org) and the Clover
248 boot loader project (https://sourceforge.net/projects/cloverefiboot/),
249 which I used as the source for this build.