]> code.delx.au - refind/blob - BUILDING.txt
Time support in default_selection; enables different default based on
[refind] / BUILDING.txt
1 Requirements
2 ============
3
4 To compile rEFInd, you'll need the following:
5
6 * A Linux installation. Note that this installation does NOT need to be
7 EFI-based. It can be 32- or 64-bit, but unless you use a cross-compiler
8 (which I've not tested), it must be the appropriate bit width for your
9 EFI implementation. (Normally that means 64-bit.) If you don't normally
10 run Linux, you can run it in a VirtualBox or similar virtual machine. (I
11 describe some unsupported non-Linux build options shortly.)
12
13 * A standard set of Linux development tools, based on GCC.
14
15 * One of the following:
16
17 * The TianoCore EDK2 package
18 (http://sourceforge.net/projects/tianocore/). I've tested using the
19 UDK2010.SR1 and UDK2010.SR1.UP1 variants
20 (http://sourceforge.net/apps/mediawiki/tianocore/index.php?title=UDK2010),
21 which are "frozen," rather than the main EDK2 development branch, which
22 is changing as the developers add features, fix bugs, and so on. Using
23 TianoCore EDK2 is supported in rEFInd version 0.4.3 and later (0.4.0
24 and later for the filesystem drivers only). See below for TianoCore
25 setup instructions.
26
27 * The GNU-EFI package (http://sourceforge.net/projects/gnu-efi/). You can
28 install this from a package called "gnu-efi"; however, rEFInd relies on
29 features that were added in (I think) 3.0l to provide driver-loading
30 capabilities. The versions I've used and that work are 3.0p, 3.0q,
31 3.0r, 3.0s, and 3.0u, with a caveat: The new time-sensitive
32 default_selection feature causes rEFInd to hang when using 3.0s and
33 earlier. 3.0u works fine for this (tested with compilation on three
34 computers). I don't know if 3.0t would work. Through mid-to-late 2012,
35 most Linux distributions delivered rather elderly versions of GNU-EFI,
36 but many are catching up by late 2012. You should check your GNU-EFI
37 version number; you may need to download the latest source code,
38 compile it, and install it locally. Between rEFInd version 0.2.7 and
39 0.6.1, the Makefiles assumed a locally-compiled GNU-EFI package, but
40 older and more recent versions assume GNU-EFI installation in typical
41 locations for distribution-provided packages. The legacy BIOS boot
42 support on UEFI-based PCs doesn't work when rEFInd is compiled under
43 GNU-EFI, so as of rEFInd 0.4.6, GNU-EFI is no longer the primary build
44 environment, although it's easier to set up on a Linux system.
45
46 Of the two toolkits, I prefer to use TianoCore because it produces binaries
47 that can boot BIOS/legacy-mode OSes and because the TianoCore-produced
48 binaries are about 20-30KiB smaller than those made by GNU-EFI. Also, I've
49 had problems on a 32-bit Mac Mini with the drivers produced by GNU-EFI
50 hanging the system if I try to load more than one of them. (I haven't
51 encountered this problem on UEFI-based PCs.) That said, the TianoCore EDK2
52 package is much harder to install, so if you don't need the ability to boot
53 BIOS/legacy OSes from rEFInd, GNU-EFI can work as well.
54
55 It's possible to use a non-Linux platform to compile rEFInd. To the best of
56 my knowledge, the rEFInd code doesn't rely on anything Linux-specific in
57 its build requirements, and GNU-EFI's Sourceforge page indicates that it
58 works under Windows and OS X, too; however, my one attempt to compile
59 GNU-EFI under OS X failed. I've received one report that rEFInd compiles
60 successfully with Clang and the TianoCore toolkit under OS X by adding the
61 refind.inf file to a .dsc file that you use for your own projects. You can
62 find brief instructions here (note that this is not my documentation):
63
64 https://github.com/snarez/refind-edk2
65
66 Under Windows, you would need to either create a project or Makefile for
67 your non-GCC compiler or use a GCC port, such as MinGW
68 (http://www.mingw.org). You'd probably need to adjust the Makefiles in the
69 latter case. A procedure similar to that used under OS X might work using
70 GCC or Microsoft's C compiler, but I haven't tested this.
71
72
73 Preparing Your Development Kit
74 ==============================
75
76 If you don't care about booting BIOS-based OSes on UEFI PCs and if you're
77 using Linux, GNU-EFI is the easiest way to compile rEFInd. I don't describe
78 GNU-EFI's setup here because it's likely to be fairly easy. If your
79 distribution provides a recent enough version, you should be able to
80 install a package called gnu-efi and be done with it. If not, you'll need
81 to download the source code tarball, build it, and install it. This process
82 is fairly typical of Linux packages. Read the GNU-EFI documentation if you
83 need help. If you're using GNU-EFI, you can skip the rest of this section.
84
85 If you need support for booting BIOS-based OSes on UEFI PCs, the TianoCore
86 toolkit is required. You might also want to use it if you have problems
87 with GNU-EFI or if you want to build rEFInd on a non-Linux platform.
88 Unfortunately, the TianoCore toolkit is weird by Linux programming
89 standards. It's also quite large -- it's intended as a means to develop a
90 complete EFI firmware implementation, so it contains much more code than is
91 needed to develop standalone EFI applications. I don't know of any Linux
92 distribution packages for it in RPM, Debian package file, or other formats;
93 you MUST install the kit from source code using its own unusual compilation
94 procedure. The installation documentation also omits at least one step and
95 is a bit unclear about others. Here's how I installed the toolkit:
96
97 1) Download UDK2010.SR1.UP1.P1 from
98 https://sourceforge.net/apps/mediawiki/tianocore/index.php?title=UDK2010.
99
100 2) Type "mkdir /usr/local/UDK2010". You can use another directory, but the
101 Makefile for rEFInd's EFI drivers assumes this location. You'll need to
102 edit the EDK2BASE line in the Make.tiano file if you install somewhere
103 else.
104
105 3) Type "cd /usr/local/UDK2010".
106
107 4) Unzip the downloaded file (UDK2010.SR1.UP1.P1.Complete.MyWorkSpace.zip)
108 in the current directory (/usr/local/UDK2010). This creates a handful of
109 files, including a tarball and a couple of .zip files.
110
111 5) Type "unzip UDK2010.SR1.UP1.MyWorkSpace.zip". This extracts the
112 platform-neutral portion of the development kit.
113
114 6) Type "cd MyWorkSpace".
115
116 7) Type "tar xvf ../BaseTools\(Unix\).tar". This extracts the
117 Linux/Unix-specific portions of the toolkit.
118
119 8) Follow the build instructions at
120 https://sourceforge.net/apps/mediawiki/tianocore/index.php?title=Using_EDK_II_with_Native_GCC_4.4;
121 however, a few changes are required, as detailed below....
122
123 9) Type "source edksetup.sh BaseTools". This sets up some environment
124 variables, so subsequent steps (NOT including compiling the rEFInd EFI
125 drivers) must be typed in the shell you use for this step.
126
127 10) Edit Conf/target.txt and change the following:
128 - ACTIVE_PLATFORM = MdePkg/MdePkg.dsc
129 - TARGET = RELEASE (DEBUG might work, but I've not tested it).
130 - TARGET_ARCH = X64 (on x86-64; leave this as IA32 on x86). If you plan
131 to build both architectures on an x86-64 system, you can set this to
132 "IA32 X64".
133 - TOOL_CHAIN_TAG = GCC46 (or other value depending on your GCC version;
134 type "gcc -v" to learn your GCC version number). Note that GCC 4.7
135 and 4.8 don't have their own entries, so use GCC46 for them.
136 The TianoCore Makefiles read some of these variables from this file
137 and use them when accessing directories, so be sure to type these
138 entries in the case specified.
139
140 11) The documentation refers to editing Conf/tools_def.txt in addition to
141 Conf/target.txt, but doesn't specify what to change in
142 Conf/tools_def.txt. I haven't found it necessary to make any changes in
143 Conf/tools_def.txt EXCEPT when using GCC 4.7 on a Fedora 17 system.
144 (I haven't used GCC 4.7 on other platforms, so this may well be
145 necessary on other systems, too.) With that setup, I found it
146 necessary to change the following line:
147 *_GCC46_X64_ASM_FLAGS = DEF(GCC46_ASM_FLAGS) -m64 -melf_x86_64
148 to:
149 *_GCC46_X64_ASM_FLAGS = DEF(GCC46_ASM_FLAGS) -m64
150
151 12) Type "make -C /usr/local/UDK2010/MyWorkSpace/BaseTools/Source/C".
152 (This step is not documented on the EDK Web page.) Note that this
153 requires the g++ compiler and UUID development libraries.
154
155 13) Type "build" to build the main set of EDK2 files. This process is
156 likely to take a few minutes.
157
158 If you installed in a location other than the one I've specified, you must
159 edit the EDK2BASE variable in the Make.tiano and filesystems/Make.tiano
160 files in the rEFInd source package. Once the toolkit is installed, you can
161 build the filesystem drivers or rEFInd, as described below.
162
163
164 Compiling rEFInd
165 ================
166
167 With your development system set up, you can compile rEFInd as follows:
168
169 1) Download and uncompress the rEFInd source code archive. (If you're
170 reading this file, you've probably already done this task.)
171
172 2) Open a Linux shell prompt
173
174 3) Change into the archive's main directory. You should see several files
175 including this BUILDING.txt file and several subdirectories such as
176 "refind", "libeg", "mok", "filesystems", and "include".
177
178 4) Type "make gnuefi" to build with GNU-EFI, or either "make" alone or
179 "make tiano" to build with TianoCore EDK2. With any luck, rEFInd will
180 compile without error, leaving the "refind_ia32.efi" or "refind_x64.efi"
181 file, depending on your platform, in the "refind" subdirectory. This same
182 step builds the "gptsync_x64.efi" or "gptsync_ia32.efi" program file, in
183 the "gptsync" subdirectory. If you want to build IA32 binaries on an
184 x86-64 (X64) system, type "ARCH=ia32 make". This works only if you're
185 using the TianoCore build kit, and only if you set TARGET_ARCH to either
186 "IA32" or "IA32 X64" in target.txt when you set up the TianoCore toolkit.
187 If you plan to build both architectures, be sure to copy the .efi file
188 for the first build out of the refind subdirectory before building the
189 second architecture.
190
191 5) The default build process does NOT build the filesystem drivers. If you
192 want to build them, you must type "make fs" in the main rEFInd source
193 directory to build with the TianoCore EDK2, or "make fs_gnuefi" to build
194 with GNU-EFI. (Typing "ARCH=ia32 make fs" builds IA32 filesystem drivers
195 on an x86-64 system, provided TianoCore is properly configured, as
196 described earlier.) The result is filesystem drivers in the filesystems
197 subdirectory, and also copies placed in the drivers_{arch} subdirectory.
198
199 If rEFInd doesn't compile correctly, you'll need to track down the source
200 of the problem. Double-check that you've got all the necessary development
201 tools installed, including GCC, make, and either GNU-EFI or TianoCore EDK2.
202 You may also need to adjust the Makefile, Make.common file, or Make.tiano
203 file for your system. (The main Makefile controls the process for both
204 toolkits, while Make.common holds GNU-EFI options and Make.tiano holds
205 TianoCore options.) The most likely thing you'll need to change is the path
206 to the various GNU-EFI include files and libraries. Since rEFInd 0.6.2, the
207 default Make.common file includes the following definitions:
208
209 EFIINC = /usr/include/efi
210 GNUEFILIB = /usr/lib64
211 EFILIB = /usr/lib64
212 EFICRT0 = /usr/lib64
213
214 If you've installed GNU-EFI from source code, you may need to add "local"
215 to those paths, as in "/usr/local/include/efi". You might need to change
216 references to "lib64" to "lib32" or "lib" on some systems. Recall that you
217 need at least GNU-EFI version 3.0l to build rEFInd, and until very
218 recently, most distributions provided out-of-date versions of this package.
219
220 If you're using TianoCore's EDK2, as noted earlier, you may need to adjust
221 the EDK2BASE variable in Make.tiano and filesystems/Make.tiano.
222
223 When I tried to compile rEFInd under Ubuntu 12.04 (i386) using GNU-EFI,
224 even with a locally-compiled GNU-EFI 3.0p or 3.0q, I got errors like this:
225
226 main.o: In function `StartLegacy.isra.0':
227 main.c:(.text+0x8b1): undefined reference to `__stack_chk_fail_local'
228 lib.o: In function `ScanVolumeBootcode.part.3':
229 lib.c:(.text+0xf2f): undefined reference to `__stack_chk_fail_local'
230 lib.o: In function `ScanExtendedPartition.isra.4':
231
232 The solution was to recompile GNU-EFI with the -fno-stack-protector GCC
233 flag. In GNU-EFI, this can be added to the CFLAGS line in Make.defaults.
234
235
236 Installing rEFInd
237 =================
238
239 With rEFInd compiled, you can install it. The easiest way to do this is
240 with the install.sh script, which works on both Linux and Mac OS X.
241 Alternatively, you can type "make install" to install using this script.
242 Note that this script copies files to the ESP and uses "efibootmgr" (on
243 Linux) or "bless" (on OS X) to add rEFInd to the firmware's boot loader
244 list. The docs/refind/installing.html file provides more details on this
245 script and its use.
246
247 If install.sh doesn't work for you or if you prefer to do the job manually,
248 you may. On a UEFI-based system, you'll want to copy files on the ESP as
249 follows:
250
251 * Create a directory for rEFInd, such as EFI/refind.
252 * Copy refind/refind_ia32.efi or refind_x64.efi to the ESP's EFI/refind
253 directory.
254 * Copy refind.conf-sample to the EFI/refind directory as refind.conf.
255 * Copy the icons subdirectory, including all its files, to EFI/refind.
256
257 You'll then need to activate rEFInd in your EFI. This can be done with
258 tools such as "efibootmgr" under Linux or "bless" under OS X. See the
259 docs/refind/installing.html file for details.
260
261
262 Note to Distribution Maintainers
263 ================================
264
265 The install.sh script, and therefore the "install" target in the Makefile,
266 installs the program directly to the ESP and it modifies the *CURRENT
267 COMPUTER's* NVRAM. Thus, you should *NOT* use this target as part of the
268 build process for your binary packages (RPMs, Debian packages, etc.).
269 (Gentoo could use it in an ebuild, though....) You COULD, however, install
270 the files to a directory somewhere (/usr/share/refind or whatever) and then
271 call install.sh as part of the binary package installation process. Placing
272 the files directly in /boot/efi/EFI/{distname}/refind and then having a
273 post-install script call efibootmgr is probably the better way to go,
274 but this assumes that the ESP is mounted at /boot/efi.
275
276
277 Compiling the EFI Filesystem Drivers
278 ====================================
279
280 To build all the drivers, you can type "make fs" or "make fs_gnuefi" from
281 the main directory, which builds the drivers and places copies in both the
282 filesystems and drivers_{arch} subdirectories. If you want to build just
283 one driver, you can change into the "filesystems" directory and type "make
284 {fsname}" or "make {fsname}_gnuefi", where {fsname} is a filesystem name --
285 "ext2", "ext4", "reiserfs", "iso9660", or "hfs". In all cases, the build
286 target that appends "_gnuefi" builds with GNU-EFI and the one that doesn't
287 builds with TianoCore.
288
289 To install drivers, you can type "make install" in the "filesystems"
290 directory. This copies all the drivers to the
291 "/boot/efi/EFI/refind/drivers" directory. Alternatively, you can copy the
292 files you want manually. As of version 0.4.8, the install.sh script
293 includes an optional "--drivers" option that will install the drivers along
294 with the main rEFInd program, but to the drivers_{arch} subdirectory of the
295 main rEFInd installation directory.
296
297 *CAUTION:* Install drivers for your system's architecture *ONLY*.
298 Installing drivers for the wrong architecture causes some systems to hang
299 at boot time. This risk can be minimized by including the architecture code
300 in the drivers subdirectory name (drivers_x64 or drivers_ia32).
301
302 The drivers all rely on filesystem wrapper code created by rEFIt's author,
303 Christoph Pfisterer. Most of the drivers seem to have passed through
304 Oracle's VirtualBox project (https://www.virtualbox.org) and the Clover
305 boot loader project (https://sourceforge.net/projects/cloverefiboot/),
306 which I used as the source for this build.