Grub Dev
Grub Dev
Grub Dev
Yoshinori K. Okuji
Colin D Bennett
Vesa Jskelinen
Colin Watson
Robert Millan
Carles Pina
This developer manual is for GNU GRUB (version 2.06, 10 May 2021).
Copyright
c 1999,2000,2001,2002,2004,2005,2006,2008,2009,2010,2011 Free Software Foun-
dation, Inc.
Permission is granted to copy, distribute and/or modify this document under
the terms of the GNU Free Documentation License, Version 1.2 or any later
version published by the Free Software Foundation; with no Invariant Sections.
i
Table of Contents
2 Coding style . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
2.1 Naming Conventions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
2.2 Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
2.3 Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
2.4 Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
2.5 Macros . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
2.6 Comments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
2.7 Multi-Line Comments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
4 Contributing changes . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
4.1 Getting started. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
4.2 Typical Developer Experience . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
4.3 When you are approved for write access to project’s files . . . . . . . . 9
6 Porting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
7 Error Handling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
10 Video Subsystem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
10.1 Video API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
10.1.1 grub video setup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
10.1.2 grub video restore . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
10.1.3 grub video get info . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
10.1.4 grub video get blit format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
10.1.5 grub video set palette . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
10.1.6 grub video get palette . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
ii GNU GRUB Developers Manual 2.06
13 Verifiers framework . . . . . . . . . . . . . . . . . . . . . . . . . . 45
iii
14 Lockdown framework . . . . . . . . . . . . . . . . . . . . . . . . 47
Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
Chapter 1: Getting the source code 1
2 Coding style
Basically we follow the GNU Coding Standards. We define additional conventions for GRUB
here.
2.2 Functions
If a function is global, its name must be prefixed with grub and must consist of only small
letters. If the function belongs to a specific function module, the name must also be prefixed
with the module name. For example, if a function is for file systems, its name is prefixed
with grub fs . If a function is for FAT file system but not for all file systems, its name is
prefixed with grub fs fat . The hierarchy is noted this way.
After a prefix, a function name must start with a verb (such as get or is). It must
not be a noun. Some kind of abbreviation is permitted, as long as it wouldn’t make code
less readable (e.g. init).
If a function is local, its name may not start with any prefix. It must start with a
verb.
2.3 Variables
The rule is mostly the same as functions, as noted above. If a variable is global, its name
must be prefixed with grub and must consist of only small letters. If the variable belongs
to a specific function module, the name must also be prefixed with the module name. For
example, if a function is for dynamic loading, its name is prefixed with grub dl . If a variable
is for ELF but not for all dynamic loading systems, its name is prefixed with grub dl elf .
After a prefix, a variable name must start with a noun or an adjective (such as name
or long) and it should end with a noun. Some kind of abbreviation is permitted, as long as
it wouldn’t make code less readable (e.g. i18n).
If a variable is global in the scope of a single file (i.e. it is declared with static), its
name may not start with any prefix. It must start with a noun or an adjective.
If a variable is local, you may choose any shorter name, as long as it wouldn’t make
code less readable (e.g. i).
2.4 Types
The name of a type must be prefixed with grub and must consist of only small letters.
If the type belongs to a specific function module, the name must also be prefixed with
the module name. For example, if a type is for OS loaders, its name is prefixed with
grub loader . If a type is for Multiboot but not for all OS loaders, its name is prefixed with
grub loader linux .
The name must be suffixed with t, to emphasize the fact that it is a type but not
a variable or a function.
4 GNU GRUB Developers Manual 2.06
2.5 Macros
If a macro is global, its name must be prefixed with GRUB and must consist of only large
letters. Other rules are the same as functions or variables, depending on whether a macro
is used like a function or a variable.
2.6 Comments
All comments shall be C-style comments, of the form ‘/* ... */’. A comment can be
placed immediately preceding the entity it describes or it can be placed together with code,
variable declarations, or other non-comment entities. However, it is recommended to not
mix various forms especially in types/structs descriptions.
Acceptable:
/* The page # that is the front buffer. */
int displayed_page;
int render_page; /* The page # that is the back buffer. */
4 Contributing changes
Contributing changes to GRUB 2 is welcomed activity. However we have a bit of control
what kind of changes will be accepted to GRUB 2. Therefore it is important to discuss your
changes on grub-devel mailing list (see MailingLists). On this page there are some basic
details on the development process and activities.
First of all you should come up with the idea yourself what you want to contribute.
If you do not have that beforehand you are advised to study this manual and try GRUB 2
out to see what you think is missing from there.
Here are additional pointers:
• https://savannah.gnu.org/task/?group=grub GRUB’s Task Tracker
• https://savannah.gnu.org/bugs/?group=grub GRUB’s Bug Tracker
If you intended to make changes to GRUB Legacy (<=0.97) those are not accepted
anymore.
Also remember that GRUB 2 is licensed under GPLv3 license and that usually means
that you are not allowed to copy pieces of code from other projects. Even if the source
project’s license would be compatible with GPLv3, please discuss it beforehand on
grub-devel mailing list.
• Test your change.
Test that your change works properly. Try it out a couple of times, preferably on
different systems, and try to find problems with it.
• Publish your change.
When you are happy with your change, first make sure it is compilable with latest
development version of GRUB 2. After that please send a patch to grub-devel for
review. Please describe in your email why you made the change, what it changes and
so on. Please be prepared to receive even discouraging comments about your patch.
There is usually at least something that needs to be improved in every patch.
Please use unified diff to make your patch (good match of arguments for diff is ‘-pruN’).
• Respond to received feedback.
If you are asked to modify your patch, please do that and resubmit it for review. If
your change is large you are required to submit a copyright agreement to FSF. Please
keep in mind that if you are asked to submit for copyright agreement, process can take
some time and is mandatory in order to get your changes integrated.
If you are not on grub-devel to respond to questions, most likely your patch will not
be accepted. Also if problems arise from your changes later on, it would be preferable
that you also fix the problem. So stay around for a while.
• Your patch is accepted.
Good job! Your patch will now be integrated into GRUB 2 mainline, and if it didn’t
break anything it will be publicly available in the next release.
Now you are welcome to do further improvements :)
At this point, it is rather annoying that you ought to ask somebody else every change
to be checked in. For efficiency, it is far better, if you can commit it yourself. Therefore,
our policy is to give you the write permission to our official repository, once you have shown
your skill and will, and the FSF clerks have dealt with your copyright assignment.
Chapter 4: Contributing changes 9
4.3 When you are approved for write access to project’s files
As you might know, GRUB is hosted on https://savannah.gnu.org/projects/grub
Savannah, thus the membership is managed by Savannah. This means that, if you want to
be a member of this project:
1. You need to create your own account on Savannah.
2. You can submit “Request for Inclusion” from “My Groups” on Savannah.
Then, one of the admins can approve your request, and you will be a member. If you
don’t want to use the Savannah interface to submit a request, you can simply notify the
admins by email or something else, alternatively. But you still need to create an account
beforehand.
NOTE: we sometimes receive a “Request for Inclusion” from an unknown person. In
this case, the request would be just discarded, since it is too dangerous to allow a stranger
to be a member, which automatically gives him a commit right to the repository, both for
a legal reason and for a technical reason.
If your intention is to just get started, please do not submit a inclusion request.
Instead, please subscribe to the mailing list, and communicate first (e.g. sending a patch,
asking a question, commenting on another message...).
Chapter 5: Updating external code 11
5.1 Gnulib
Gnulib is a source code library that provides basic functionality to programs and libraries.
Many software packages make use of Gnulib to avoid reinventing the portability wheel.
GRUB imports Gnulib using its bootstrap utility, identifying a particular Git com-
mit in ‘bootstrap.conf’. To upgrade to a new Gnulib commit, set GNULIB_REVISION in
‘bootstrap.conf’ to the new commit ID, then run ./bootstrap and whatever else you
need to make sure it works. Check for changes to Gnulib’s ‘NEWS’ file between the old and
new commits; in some cases it will be necessary to adjust GRUB to match. You may also
need to update the patches in ‘grub-core/lib/gnulib-patches/’.
To add a new Gnulib module or remove one that is no longer needed, change gnulib_
modules in ‘bootstrap.conf’. Again, run ./bootstrap and whatever else you need to make
sure it works.
Bootstrapping from an older distribution containing gettext version < 0.18.3, will
require a patch similar to this to be applied first before running the ./bootstrap utility:
diff --git a/bootstrap.conf b/bootstrap.conf
index 988dda0..a3193a9 100644
--- a/bootstrap.conf
+++ b/bootstrap.conf
@ -67,7 +67,7 @ SKIP_PO=t
buildreq="\
autoconf 2.63
automake 1.11
-gettext 0.18.3
+gettext 0.17
git 1.5.5
tar -
"
diff --git a/configure.ac b/configure.ac
index 08b518f..99f5b36 100644
--- a/configure.ac
+++ b/configure.ac
@ -362,7 +362,7 @ AC_CHECK_PROG(HAVE_CXX, $CXX, yes, no)
AC_GNU_SOURCE
AM_GNU_GETTEXT([external])
-AM_GNU_GETTEXT_VERSION([0.18.3])
+AM_GNU_GETTEXT_VERSION([0.17])
AC_SYS_LARGEFILE
5.2 jsmn
jsmn is a minimalistic JSON parser which is implemented in a single header file ‘jsmn.h’.
To import a different version of the jsmn parser, you may simply download the ‘jsmn.h’
header from the desired tag or commit to the target directory:
curl -L https://raw.githubusercontent.com/zserge/jsmn/v1.1.0/jsmn.h \
-o grub-core/lib/json/jsmn.h
5.3 minilzo
miniLZO is a very lightweight subset of the LZO library intended for easy inclusion in other
projects. It is generated automatically from the LZO source code and contains the most
important LZO functions.
To upgrade to a new version of the miniLZO library, download the release tarball
and copy the files into the target directory:
curl -L -O http://www.oberhumer.com/opensource/lzo/download/minilzo-2.08.tar.gz
tar -zxf minilzo-2.08.tar.gz
rm minilzo-2.08/testmini.c
rm -r grub-core/lib/minilzo/*
cp minilzo-2.08/*.[hc] grub-core/lib/minilzo
rm -r minilzo-2.08*
Chapter 6: Porting 13
6 Porting
GRUB2 is designed to be easily portable accross platforms. But because of the nature of
bootloader every new port must be done separately. Here is how I did MIPS (loongson and
ARC) and Xen ports. Note than this is more of suggestions, not absolute truth.
First of all grab any architecture specifications you can find in public (please avoid
NDA).
First stage is “Hello world”. I’ve done it outside of GRUB for simplicity. Your task
is to have a small program which is loadable as bootloader and clearly shows its presence
to you. If you have easily accessible console you can just print a message. If you have a
mapped framebuffer you know address of, you can draw a square. If you have a debug
facility, just hanging without crashing might be enough. For the first stage you can choose
to load the bootloader across the network since format for network image is often easier
than for local boot and it skips the need of small intermediary stages and nvram handling.
Additionally you can often have a good idea of the needed format by running “file” on any
netbootable executable for given platform.
This program should probably have 2 parts: an assembler and C one. Assembler one
handles BSS cleaning and other needed setup (on some platforms you may need to switch
modes or copy the executable to its definitive position). So your code may look like (x86
assembly for illustration purposes)
.globl _start
_start:
movl $_bss_start, %edi
movl $_end, %ecx
subl %edi, %ecx
xorl %eax, %eax
cld
rep
stosb
call main
void
putchar (int c)
{
...
}
void
main (void)
{
const char *ptr = msg;
while (*ptr)
putchar (*ptr++);
while (1);
14 GNU GRUB Developers Manual 2.06
}
Sometimes you need a third file: assembly stubs for ABI-compatibility.
Once this file is functional it’s time to move it into GRUB2. The startup
assembly file goes to grub-core/kern/$cpu/$platform/startup.S. You should also include
grub/symbol.h and replace call to entry point with call to EXT C(grub main). The
C file goes to grub-core/kern/$cpu/$platform/init.c and its entry point is renamed to
void grub machine init (void). Keep final infinite loop for now. Stubs file if any goes
to grub-core/kern/$cpu/$platform/callwrap.S. Sometimes either $cpu or $platform is
dropped if file is used on several cpus respectivelyplatforms. Check those locations if they
already have what you’re looking for.
Then modify in configure.ac the following parts:
CPU names:
case "$target_cpu" in
i[[3456]]86) target_cpu=i386 ;;
amd64) target_cpu=x86_64 ;;
sparc) target_cpu=sparc64 ;;
s390x) target_cpu=s390 ;;
...
esac
Sometimes CPU have additional architecture names which don’t influence booting.
You might want to have some canonical name to avoid having bunch of identical platforms
with different names.
NOTE: it doesn’t influence compile optimisations which depend solely on chosen
compiler and compile options.
if test "x$with_platform" = x; then
case "$target_cpu"-"$target_vendor" in
i386-apple) platform=efi ;;
i386-*) platform=pc ;;
x86_64-apple) platform=efi ;;
x86_64-*) platform=pc ;;
powerpc-*) platform=ieee1275 ;;
...
esac
else
...
fi
This part deals with guessing the platform from CPU and vendor. Sometimes you
need to use 32-bit mode for booting even if OS runs in 64-bit one. If so add your platform
to:
case "$target_cpu"-"$platform" in
x86_64-efi) ;;
x86_64-emu) ;;
x86_64-*) target_cpu=i386 ;;
powerpc64-ieee1275) target_cpu=powerpc ;;
esac
Chapter 6: Porting 15
/* mycpu is big-endian. */
#define GRUB_TARGET_WORDS_BIGENDIAN 1
/* Alternatively: mycpu is little-endian. */
#undef GRUB_TARGET_WORDS_BIGENDIAN
#endif /* ! GRUB_TYPES_CPU_HEADER */
You will also need to add a dummy file to datetime and setjmp modules to avoid
any of it having no files. It can be just completely empty at this stage.
You’ll need to make grub-mkimage.c (util/grub mkimage.c) aware of the needed
format. For most commonly used formats like ELF, PE, aout or raw the support is already
present and you’ll need to make it follow the existant code paths for your platform adding
adjustments if necessary. When done compile:
./bootstrap
./configure --target=$cpu --with-platform=$platform TARGET_CC=.. OBJCOPY=... STRIP=...
make > /dev/null
And create image
./grub-mkimage -d grub-core -O $format_id -o test.img
And it’s time to test your test.img.
If it works next stage is to have heap, console and timer.
To have the heap working you need to determine which regions are suitable
for heap usage, allocate them from firmware and map (if applicable). Then call
grub mm init region (vois *start, grub size t s) for every of this region. As a shortcut
for early port you can allocate right after end or have a big static array for heap.
If you do you’ll probably need to come back to this later. As for output console
you should distinguish between an array of text, terminfo or graphics-based console.
Many of real-world examples don’t fit perfectly into any of these categories but one
of the models is easier to be used as base. In second and third case you should add
your platform to terminfokernel respectively videoinkernel group. A good example of
array of text is i386-pc (kern/i386/pc/init.c and term/i386/pc/console.c). Of terminfo
is ieee1275 (kern/ieee1275/init.c and term/ieee1275/console.c). Of video is loongson
(kern/mips/loongson/init.c). Note that terminfo has to be inited in 2 stages: one before
(to get at least rudimentary console as early as possible) and another after the heap (to
get full-featured console). For the input there are string of keys, terminfo and direct
hardware. For string of keys look at i386-pc (same files), for terminfo ieee1275 (same files)
and for hardware loongson (kern/mips/loongson/init.c and term/at keyboard.c).
For the timer you’ll need to call grub install get time ms (...) with as sole argument
a function returning a grub uint64 t of a number of milliseconds elapsed since arbitrary
point in the past.
Once these steps accomplished you can remove the inifinite loop and you should be
able to get to the minimal console. Next step is to have module loading working. For this
you’ll need to fill kern/$cpu/dl.c and kern/$cpu/cache.S with real handling of relocations
and respectively the real sync of I and D caches. Also you’ll need to decide where in the
Chapter 6: Porting 17
image to store the modules. Usual way is to have it concatenated at the end. In this case
you’ll need to modify startup.S to copy modules out of bss to let’s say ALIGN UP ( end,
8) before cleaning out bss. You’ll probably find useful to add total module size field to
startup.S. In init.c you need to set grub modbase to the address where modules can be
found. You may need grub modules get end () to avoid declaring the space occupied by
modules as usable for heap. You can test modules with:
./grub-mkimage -d grub-core -O $format_id -o test.img hello
and then running “hello” in the shell.
Once this works, you should think of implementing disk access. Look around disk/
for examples.
Then, very importantly, you probably need to implement the actual loader (examples
available in loader/)
Last step to have minimally usable port is to add support to grub-install to put
GRUB in a place where firmware or platform will pick it up.
Next steps are: filling datetime.c, setjmp.S, network (net/drivers), video (video/),
halt (lib/), reboot (lib/).
Please add your platform to Platform limitations and Supported kernels chapter in
user documentation and mention any steps you skipped which result in reduced features
or performance. Here is the quick checklist of features. Some of them are less impor-
tant than others and skipping them is completely ok, just needs to be mentioned in user
documentation.
Checklist:
• Is heap big enough?
• Which charset is supported by console?
• Does platform have disk driver?
• Do you have network card support?
• Are you able to retrieve datetime (with date)?
• Are you able to set datetime (with date)?
• Is serial supported?
• Do you have direct disk support?
• Do you have direct keyboard support?
• Do you have USB support?
• Do you support loading through network?
• Do you support loading from disk?
• Do you support chainloading?
• Do you support network chainloading?
• Does cpuid command supports checking all CPU features that the user might want
conditionalise on (64-bit mode, hypervisor,...)
• Do you support hints? How reliable are they?
• Does platform have ACPI? If so do “acpi” and “lsacpi” modules work?
• Do any of platform-specific operations mentioned in the relevant section of user manual
makes sense on your platform?
18 GNU GRUB Developers Manual 2.06
• Does your platform support PCI? If so is there an appropriate driver for GRUB?
• Do you support badram?
Chapter 7: Error Handling 19
7 Error Handling
Error handling in GRUB 2 is based on exception handling model. As C language doesn’t
directly support exceptions, exception handling behavior is emulated in software.
When exception is raised, function must return to calling function. If calling function
does not provide handling of the exception it must return back to its calling function and
so on, until exception is handled. If exception is not handled before prompt is displayed,
error message will be shown to user.
Exception information is stored on grub_errno global variable. If grub_errno vari-
able contains value GRUB_ERR_NONE, there is no active exception and application can con-
tinue normal processing. When grub_errno has other value, it is required that application
code either handles this error or returns instantly to caller. If function is with return type
grub_err_t is about to return GRUB_ERR_NONE, it should not set grub_errno to that value.
Only set grub_errno in cases where there is error situation.
Simple exception forwarder.
grub_err_t
forwarding_example (void)
{
/* Call function that might cause exception. */
foobar ();
10);
}
If there is a special reason that error code does not need to be taken account, grub_
errno can be zeroed back to GRUB_ERR_NONE. In cases like this all previous error codes
should have been handled correctly. This makes sure that there are no unhandled exceptions.
Example of zeroing grub_errno.
grub_err_t
probe_example ()
{
/* Try to probe device type 1. */
probe_for_device ();
if (grub_errno == GRUB_ERR_NONE)
{
/* Device type 1 was found on system. */
register_device ();
return GRUB_ERR_NONE;
}
/* Zero out error code. */
grub_errno = GRUB_ERR_NONE;
if (grub_errno != GRUB_ERR_NONE)
{
/* Inform rest of the code that there is error (grub_errno
is set). There is no pop here as we want both error states
to be displayed. */
return;
}
10 Video Subsystem
This document contains specification for Video Subsystem for GRUB2. Currently only the
usage interface is described in this document. Internal structure of how video drivers are
registering and how video driver manager works are not included here.
enum grub_video_blit_format
{
/* Follow exactly field & mask information. */
GRUB_VIDEO_BLIT_FORMAT_RGBA,
/* Make optimization assumption. */
GRUB_VIDEO_BLIT_FORMAT_R8G8B8A8,
/* Follow exactly field & mask information. */
GRUB_VIDEO_BLIT_FORMAT_RGB,
/* Make optimization assumption. */
GRUB_VIDEO_BLIT_FORMAT_R8G8B8,
/* When needed, decode color or just use value as is. */
GRUB_VIDEO_BLIT_FORMAT_INDEXCOLOR
};
• Description:
Used to query how data could be optimized to suit specified video mode. Returns exact
video format type, or a generic one if there is no definition for the type. For generic
formats, use grub_video_get_info to query video color coding settings.
• Description:
Map RGB values to compatible screen color data. Values are expected to be in range
0-255 and in RGB modes they will be converted to screen color data. In index color
modes, index color palette will be searched for specified color and then index is returned.
• Description:
Used to blit glyph to viewport in specified coodinates. If glyph is at edge of viewport,
pixels outside of viewport will be clipped out. Software developer should use either
grub_video_map_rgb or grub_video_map_rgba to map requested color to color pa-
rameter.
enum grub_video_blit_operators
{
GRUB_VIDEO_BLIT_REPLACE,
GRUB_VIDEO_BLIT_BLEND
};
• Description:
Used to blit bitmap to viewport in specified coordinates. If part of bitmap is outside
of viewport region, it will be clipped out. Offsets affect bitmap position where data
will be copied from. Negative values for both viewport coordinates and bitmap offset
coordinates are allowed. If data is looked out of bounds of bitmap, color value will be
assumed to be transparent. If viewport coordinates are negative, area of the blitted
rectangle will be shrinken to follow size limits of the viewport and bitmap. Blitting
operator oper specifies should source pixel replace data in screen or blend with pixel
alpha value.
Software developer should use grub_video_bitmap_create or grub_video_bitmap_
load to create or load bitmap data.
enum grub_video_blit_operators
{
GRUB_VIDEO_BLIT_REPLACE,
GRUB_VIDEO_BLIT_BLEND
};
34 GNU GRUB Developers Manual 2.06
• Description:
Used to blit source render target to viewport in specified coordinates. If part of source
render target is outside of viewport region, it will be clipped out. If blitting operator
is specified and source contains alpha values, resulting pixel color components will be
calculated using formula ((src color * src alpha) + (dst color * (255 - src alpha)) /
255, if target buffer has alpha, it will be set to src alpha. Offsets affect render target
position where data will be copied from. If data is looked out of bounds of render
target, color value will be assumed to be transparent. Blitting operator oper specifies
should source pixel replace data in screen or blend with pixel alpha value.
grub_err_t
grub_video_delete_render_target (struct grub_video_render_target *target);
• Description:
Used to delete previously created render target. If target contains NULL pointer,
nothing will be done. If render target is correctly destroyed, GRUB ERR NONE is
returned.
11.1 Introduction
The goal of this format is to provide a bitmap font format that is simple to use, compact,
and cleanly supports Unicode.
12.1 Introduction
The ‘gfxmenu’ module provides a graphical menu interface for GRUB 2. It functions as
an alternative to the menu interface provided by the ‘normal’ module, which uses the grub
terminal interface to display a menu on a character-oriented terminal.
The graphical menu uses the GRUB video API, which is currently for the VESA
BIOS extensions (VBE) 2.0+. This is supported on the i386-pc platform. However, the
graphical menu itself does not depend on using VBE, so if another GRUB video driver were
implemented, the ‘gfxmenu’ graphical menu would work on the new video driver as well.
• canvas
• hbox
• vbox
The GUI component instances are created by the theme loader in
‘gfxmenu/theme_loader.c’ when a theme is loaded. Theme files specify state-
ments such as ‘+vbox{ +label { text="Hello" } +label{ text="World" } }’ to add
components to the component tree root. By nesting the component creation statements in
the theme file, the instantiated components are nested the same way.
When a component is added to a container, that new child is considered owned by
the container. Great care should be taken if the caller retains a reference to the child
component, since it will be destroyed if its parent container is destroyed. A better choice
instead of storing a pointer to the child component is to use the component ID to find the
desired component. Component IDs do not have to be unique (it is often useful to have
multiple components with an ID of " timeout ", for instance).
In order to access and use components in the component tree, there are two functions
(defined in ‘gfxmenu/gui_util.c’) that are particularly useful:
• grub_gui_find_by_id (root, id, callback, userdata):
This function ecursively traverses the component tree rooted at root, and for every
component that has an ID equal to id, calls the function pointed to by callback with
the matching component and the void pointer userdata as arguments. The callback
function can do whatever is desired to use the component passed in.
• grub_gui_iterate_recursively (root, callback, userdata):
This function calls the function pointed to by callback for every component that is a
descendant of root in the component tree. When the callback function is called, the
component and the void pointer userdata as arguments. The callback function can do
whatever is desired to use the component passed in.
13 Verifiers framework
To register your own verifier call ‘grub_verifier_register’ with a structure pointing to
your functions.
The interface is inspired by the hash interface with ‘init’/‘write’/‘fini’.
There are essentially 2 ways of using it, hashing and whole-file verification.
With the hashing approach: During ‘init’ you decide whether you want to check
the given file and init context. In ‘write’ you update your hashing state. In ‘fini’ you
check that the hash matches the expected value/passes some check/...
With whole-file verification: During ‘init’ you decide whether you want to check
the given file and init context. In ‘write’ you verify the file and return an error if it fails.
You don’t have ‘fini’.
Additional ‘verify_string’ receives various strings like kernel parameters to verify.
Returning no error means successful verification and an error stops the current action.
Detailed description of the API:
Every time a file is opened your ‘init’ function is called with file descriptor and file
type. Your function can have the following outcomes:
• returning no error and setting ‘*flags’ to ‘GRUB_VERIFY_FLAGS_DEFER_AUTH’. In this
case verification is deferred to other active verifiers. Verification fails if nobody cares
or selected verifier fails.
• returning no error and setting ‘*flags’ to ‘GRUB_VERIFY_FLAGS_SKIP_VERIFICATION’.
In this case your verifier will not be called anymore and it is assumed to have skipped
verification.
• returning no error and not setting ‘*flags’ to ‘GRUB_VERIFY_FLAGS_SKIP_VERIFICATION’
In this case verification is done as described in the following section.
• returning an error. Then opening of the file will fail due to failed verification.
In the third case your ‘write’ will be called with chunks of the file.
If you need the whole file in a single chunk then during ‘init’ set the bit
‘GRUB_VERIFY_FLAGS_SINGLE_CHUNK’ in ‘*flags’. During ‘init’ you may set ‘*context’
if you need additional context. At every iteration you may return an error and the file will
be considered as having failed the verification. If you return no error then verification
continues.
Optionally at the end of the file ‘fini’, if it exists, is called with just the context. If
you return no error during any of ‘init’, ‘write’ and ‘fini’ then the file is considered as
having succeded verification.
Chapter 14: Lockdown framework 47
14 Lockdown framework
The GRUB can be locked down, which is a restricted mode where some operations are not
allowed. For instance, some commands cannot be used when the GRUB is locked down.
The function grub_lockdown() is used to lockdown GRUB and the function grub_
is_lockdown() function can be used to check whether lockdown is enabled or not. When
enabled, the function returns ‘GRUB_LOCKDOWN_ENABLED’ and ‘GRUB_LOCKDOWN_DISABLED’
when is not enabled.
The following functions can be used to register the commands that can only be used
when lockdown is disabled:
• grub_cmd_lockdown() registers command which should not run when the GRUB is in
lockdown mode.
• grub_cmd_lockdown() registers extended command which should not run when the
GRUB is in lockdown mode.
Appendix A: Copying This Manual 49
The “Invariant Sections” are certain Secondary Sections whose titles are designated, as
being those of Invariant Sections, in the notice that says that the Document is released
under this License. If a section does not fit the above definition of Secondary then it is
not allowed to be designated as Invariant. The Document may contain zero Invariant
Sections. If the Document does not identify any Invariant Sections then there are none.
The “Cover Texts” are certain short passages of text that are listed, as Front-Cover
Texts or Back-Cover Texts, in the notice that says that the Document is released under
this License. A Front-Cover Text may be at most 5 words, and a Back-Cover Text may
be at most 25 words.
A “Transparent” copy of the Document means a machine-readable copy, represented
in a format whose specification is available to the general public, that is suitable for
revising the document straightforwardly with generic text editors or (for images com-
posed of pixels) generic paint programs or (for drawings) some widely available drawing
editor, and that is suitable for input to text formatters or for automatic translation to
a variety of formats suitable for input to text formatters. A copy made in an otherwise
Transparent file format whose markup, or absence of markup, has been arranged to
thwart or discourage subsequent modification by readers is not Transparent. An image
format is not Transparent if used for any substantial amount of text. A copy that is
not “Transparent” is called “Opaque”.
Examples of suitable formats for Transparent copies include plain ascii without
markup, Texinfo input format, LaTEX input format, SGML or XML using a publicly
available DTD, and standard-conforming simple HTML, PostScript or PDF designed
for human modification. Examples of transparent image formats include PNG, XCF
and JPG. Opaque formats include proprietary formats that can be read and edited
only by proprietary word processors, SGML or XML for which the DTD and/or
processing tools are not generally available, and the machine-generated HTML,
PostScript or PDF produced by some word processors for output purposes only.
The “Title Page” means, for a printed book, the title page itself, plus such following
pages as are needed to hold, legibly, the material this License requires to appear in the
title page. For works in formats which do not have any title page as such, “Title Page”
means the text near the most prominent appearance of the work’s title, preceding the
beginning of the body of the text.
A section “Entitled XYZ” means a named subunit of the Document whose title either
is precisely XYZ or contains XYZ in parentheses following text that translates XYZ in
another language. (Here XYZ stands for a specific section name mentioned below, such
as “Acknowledgements”, “Dedications”, “Endorsements”, or “History”.) To “Preserve
the Title” of such a section when you modify the Document means that it remains a
section “Entitled XYZ” according to this definition.
The Document may include Warranty Disclaimers next to the notice which states that
this License applies to the Document. These Warranty Disclaimers are considered to
be included by reference in this License, but only as regards disclaiming warranties:
any other implication that these Warranty Disclaimers may have is void and has no
effect on the meaning of this License.
2. VERBATIM COPYING
Appendix A: Copying This Manual 51
You may copy and distribute the Document in any medium, either commercially or
noncommercially, provided that this License, the copyright notices, and the license
notice saying this License applies to the Document are reproduced in all copies, and
that you add no other conditions whatsoever to those of this License. You may not use
technical measures to obstruct or control the reading or further copying of the copies
you make or distribute. However, you may accept compensation in exchange for copies.
If you distribute a large enough number of copies you must also follow the conditions
in section 3.
You may also lend copies, under the same conditions stated above, and you may publicly
display copies.
3. COPYING IN QUANTITY
If you publish printed copies (or copies in media that commonly have printed covers) of
the Document, numbering more than 100, and the Document’s license notice requires
Cover Texts, you must enclose the copies in covers that carry, clearly and legibly, all
these Cover Texts: Front-Cover Texts on the front cover, and Back-Cover Texts on
the back cover. Both covers must also clearly and legibly identify you as the publisher
of these copies. The front cover must present the full title with all words of the title
equally prominent and visible. You may add other material on the covers in addition.
Copying with changes limited to the covers, as long as they preserve the title of the
Document and satisfy these conditions, can be treated as verbatim copying in other
respects.
If the required texts for either cover are too voluminous to fit legibly, you should put
the first ones listed (as many as fit reasonably) on the actual cover, and continue the
rest onto adjacent pages.
If you publish or distribute Opaque copies of the Document numbering more than 100,
you must either include a machine-readable Transparent copy along with each Opaque
copy, or state in or with each Opaque copy a computer-network location from which
the general network-using public has access to download using public-standard network
protocols a complete Transparent copy of the Document, free of added material. If
you use the latter option, you must take reasonably prudent steps, when you begin
distribution of Opaque copies in quantity, to ensure that this Transparent copy will
remain thus accessible at the stated location until at least one year after the last time
you distribute an Opaque copy (directly or through your agents or retailers) of that
edition to the public.
It is requested, but not required, that you contact the authors of the Document well
before redistributing any large number of copies, to give them a chance to provide you
with an updated version of the Document.
4. MODIFICATIONS
You may copy and distribute a Modified Version of the Document under the conditions
of sections 2 and 3 above, provided that you release the Modified Version under precisely
this License, with the Modified Version filling the role of the Document, thus licensing
distribution and modification of the Modified Version to whoever possesses a copy of
it. In addition, you must do these things in the Modified Version:
A. Use in the Title Page (and on the covers, if any) a title distinct from that of the
Document, and from those of previous versions (which should, if there were any,
52 GNU GRUB Developers Manual 2.06
be listed in the History section of the Document). You may use the same title as
a previous version if the original publisher of that version gives permission.
B. List on the Title Page, as authors, one or more persons or entities responsible for
authorship of the modifications in the Modified Version, together with at least five
of the principal authors of the Document (all of its principal authors, if it has fewer
than five), unless they release you from this requirement.
C. State on the Title page the name of the publisher of the Modified Version, as the
publisher.
D. Preserve all the copyright notices of the Document.
E. Add an appropriate copyright notice for your modifications adjacent to the other
copyright notices.
F. Include, immediately after the copyright notices, a license notice giving the public
permission to use the Modified Version under the terms of this License, in the form
shown in the Addendum below.
G. Preserve in that license notice the full lists of Invariant Sections and required Cover
Texts given in the Document’s license notice.
H. Include an unaltered copy of this License.
I. Preserve the section Entitled “History”, Preserve its Title, and add to it an item
stating at least the title, year, new authors, and publisher of the Modified Version
as given on the Title Page. If there is no section Entitled “History” in the Docu-
ment, create one stating the title, year, authors, and publisher of the Document
as given on its Title Page, then add an item describing the Modified Version as
stated in the previous sentence.
J. Preserve the network location, if any, given in the Document for public access to
a Transparent copy of the Document, and likewise the network locations given in
the Document for previous versions it was based on. These may be placed in the
“History” section. You may omit a network location for a work that was published
at least four years before the Document itself, or if the original publisher of the
version it refers to gives permission.
K. For any section Entitled “Acknowledgements” or “Dedications”, Preserve the Title
of the section, and preserve in the section all the substance and tone of each of the
contributor acknowledgements and/or dedications given therein.
L. Preserve all the Invariant Sections of the Document, unaltered in their text and
in their titles. Section numbers or the equivalent are not considered part of the
section titles.
M. Delete any section Entitled “Endorsements”. Such a section may not be included
in the Modified Version.
N. Do not retitle any existing section to be Entitled “Endorsements” or to conflict in
title with any Invariant Section.
O. Preserve any Warranty Disclaimers.
If the Modified Version includes new front-matter sections or appendices that qualify
as Secondary Sections and contain no material copied from the Document, you may at
your option designate some or all of these sections as invariant. To do this, add their
Appendix A: Copying This Manual 53
titles to the list of Invariant Sections in the Modified Version’s license notice. These
titles must be distinct from any other section titles.
You may add a section Entitled “Endorsements”, provided it contains nothing but
endorsements of your Modified Version by various parties—for example, statements of
peer review or that the text has been approved by an organization as the authoritative
definition of a standard.
You may add a passage of up to five words as a Front-Cover Text, and a passage of up
to 25 words as a Back-Cover Text, to the end of the list of Cover Texts in the Modified
Version. Only one passage of Front-Cover Text and one of Back-Cover Text may be
added by (or through arrangements made by) any one entity. If the Document already
includes a cover text for the same cover, previously added by you or by arrangement
made by the same entity you are acting on behalf of, you may not add another; but
you may replace the old one, on explicit permission from the previous publisher that
added the old one.
The author(s) and publisher(s) of the Document do not by this License give permission
to use their names for publicity for or to assert or imply endorsement of any Modified
Version.
5. COMBINING DOCUMENTS
You may combine the Document with other documents released under this License,
under the terms defined in section 4 above for modified versions, provided that you
include in the combination all of the Invariant Sections of all of the original documents,
unmodified, and list them all as Invariant Sections of your combined work in its license
notice, and that you preserve all their Warranty Disclaimers.
The combined work need only contain one copy of this License, and multiple identical
Invariant Sections may be replaced with a single copy. If there are multiple Invariant
Sections with the same name but different contents, make the title of each such section
unique by adding at the end of it, in parentheses, the name of the original author or
publisher of that section if known, or else a unique number. Make the same adjustment
to the section titles in the list of Invariant Sections in the license notice of the combined
work.
In the combination, you must combine any sections Entitled “History” in the vari-
ous original documents, forming one section Entitled “History”; likewise combine any
sections Entitled “Acknowledgements”, and any sections Entitled “Dedications”. You
must delete all sections Entitled “Endorsements.”
6. COLLECTIONS OF DOCUMENTS
You may make a collection consisting of the Document and other documents released
under this License, and replace the individual copies of this License in the various
documents with a single copy that is included in the collection, provided that you
follow the rules of this License for verbatim copying of each of the documents in all
other respects.
You may extract a single document from such a collection, and distribute it individu-
ally under this License, provided you insert a copy of this License into the extracted
document, and follow this License in all other respects regarding verbatim copying of
that document.
54 GNU GRUB Developers Manual 2.06
Index