lbwww/site/docs/linux/grub_cbfs.md

145 lines
5.3 KiB
Markdown
Raw Normal View History

2021-05-18 12:21:48 +00:00
---
title: Modifying grub.cfg in CBFS
x-toc-enable: true
...
NOTE: Libreboot standardises on [flashprog](https://flashprog.org/wiki/Flashprog)
now, as of 27 January 2024, which is a fork of flashrom.
2021-05-18 12:21:48 +00:00
Before you follow this guide, it is advisable that you have the ability to
flash externally, just in case something goes wrong.
Libreboot's own GRUB configuration automatically scans for one provided by
your distro, and this automation will usually work. Sometimes, you might wish
to override it with your own custom menuentry or additional logic in the GRUB
config. You can configure GRUB however you like, and this topic is vast so what
to actually *put in the config* will not be covered here.
This guide will simply teach you how to modify the config, but not what to put.
2021-05-18 12:21:48 +00:00
Compile flashprog and cbfstool
2021-05-18 12:21:48 +00:00
=============================
libreboot does not currently distribute utilities pre-compiled. It only
2021-05-18 12:21:48 +00:00
provides ROM images pre-compiled, where feasible. Therefore, you have to build
the utilities from source.
As for the ROM, there are mainly three methods for obtaining a libreboot ROM
2021-05-18 12:21:48 +00:00
image:
1. Dump the contents of the the main *boot flash* on your system, which already
2023-04-09 21:38:30 +00:00
has libreboot installed (with GRUB as the default payload). Extract the
2021-05-18 12:21:48 +00:00
GRUB configuration from *that* ROM image.
2. Extract it from a libreboot ROM image supplied by the libreboot project, on
the libreboot website or mirrors of the libreboot website.
3. Build the ROM yourself, using the libreboot build system. Instructions for
2021-05-18 12:21:48 +00:00
how to do this are covered in the following article:
[How to build libreboot from source](../build/)
2021-05-18 12:21:48 +00:00
In either case, you will use the `cbfstool` supplied in the libreboot build
2021-05-18 12:21:48 +00:00
system.
This can be found under `coreboot/*/util/cbfstool/` as source code,
where `*` can be any coreboot source code directory for a given mainboard.
The directory named `default` should suffice.
Install the build dependencies. For Debian and similar, you can run
the following command in the libreboot build system, from the root directory
of the libreboot Git repository.
2021-05-18 12:21:48 +00:00
./mk dependencies debian
Determine what coreboot tree you need for your board. For example, if building
for `x200_8mb`, check `config/coreboot/x200_8mb/target.cfg` and it might
say `tree="default"` - in this case, the coreboot tree is named `default`.
2021-05-18 12:21:48 +00:00
Then, download coreboot (we'll assume the `default` tree is correct):
2021-05-18 12:21:48 +00:00
./mk -f coreboot default
2021-05-18 12:21:48 +00:00
Finally, compile the `cbutils` payload (and you will then have the utils):
2021-05-18 12:21:48 +00:00
./mk -b grub
2021-05-18 12:21:48 +00:00
GRUB is multi-tree, but for GRUB utilities that's fine because we don't patch
those in any tree; we only patch the GRUB kernel to add various drivers and
extra crypto such as argon2.
2021-05-18 12:21:48 +00:00
Among other things, this will produce a `cbfstool` executable under any of the
subdirectories in `src/coreboot/` under `util/cbfstool/cbfstool`.
2021-05-18 12:21:48 +00:00
For example: `src/coreboot/default/util/cbfstool/cbfstool`
2021-05-18 12:21:48 +00:00
The `cbfstool` utility is what you shall use. It is used to manipulate CBFS
(coreboot file system) which is a file system contained within the coreboot
ROM image; as a *coreboot distribution*, libreboot inherits this technology.
2021-05-18 12:21:48 +00:00
You can compile cbfstool and ifdtool for the given coreboot tree, e.g.:
./mk -d coreboot default
This will create `elf/cbfstool/default/cbfbstool`
and `elf/ifdtool/default/ifdtool`.
You will also want to build `flashprog` which libreboot recommends for reading
from and/or writing to the boot flash. In the libreboot build system, you can
2021-05-18 12:21:48 +00:00
build it by running this command:
./mk -b flashprog
2021-05-18 12:21:48 +00:00
An executable will be available at `elf/flashprog/flashprog` after you have done
2021-05-18 12:21:48 +00:00
this.
Dump the boot flash
===================
[Learn how to externally reprogram these chips](../install/spi.md) and use
the `-r` option in flashprog; alternatively, for internal flash access,
look at the [main flashing guide](../install/).
Those guides show how to dump the flash contents, which you are advised to do.
Insert new grub.cfg
===================
2021-05-18 12:21:48 +00:00
If you already have a `grub.cfg` in cbfstool, you can extract and modify that
one, e.g.:
2021-05-18 12:21:48 +00:00
cbfstool libreboot.rom extract -n grub.cfg -f grub.cfg
2021-05-18 12:21:48 +00:00
Now remove it:
2021-05-18 12:21:48 +00:00
cbfstool libreboot.rom remove -n grub.cfg
2021-05-18 12:21:48 +00:00
It's important that you re-add `grub.cfg` before flashing:
2021-05-18 12:21:48 +00:00
cbfstool libreboot.rom add -f grub.cfg -n grub.cfg
2021-05-18 12:21:48 +00:00
Repeat this for `grubtest.cfg` if you wish.
2021-05-18 12:21:48 +00:00
If you're using a default Libreboot image, there *is no `grub.cfg` in flash*.
This is because there is also a default one embedded inside the GRUB binary,
which is inside CBFS. So:
2021-05-18 12:21:48 +00:00
The coreboot image has its own filesystem, CBFS, and within CBFS is the GRUB
binary, and within the GRUB binary is another filesystem called memdisk, where
the default GRUB configuration is located.
You can insert a `grub.cfg` into CBFS and it will override the one in memdisk.
2021-05-18 12:21:48 +00:00
Check your board, e.g. `x200_8mb`, look at the file: `config/coreboot/x200_8mb/target.cfg`
and check for `grubtree` - if it's not sot, then it's `default`, otherwise check
what it's set to.
2021-05-18 12:21:48 +00:00
We'll assume it's `default`, so the
file `config/grub/default/config/payload` is your GRUB config; this will be the
same as what yo uhave in memdisk.
2021-05-18 12:21:48 +00:00
Modify *that* file, or the one you extracted if you already inserted a custom
one before, and you will re-insert it when you're done.
2021-05-18 12:21:48 +00:00
Flash the modified ROM image
============================
Check the [Libreboot flashing guide](../install/) which says how to flash the
new image.