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