2021-05-18 12:21:48 +00:00
|
|
|
---
|
|
|
|
title: Modifying grub.cfg in CBFS
|
|
|
|
x-toc-enable: true
|
|
|
|
...
|
|
|
|
|
2024-01-27 22:35:38 +00:00
|
|
|
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.
|
|
|
|
|
2024-08-26 21:36:21 +00:00
|
|
|
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
|
|
|
|
2024-01-27 22:35:38 +00:00
|
|
|
Compile flashprog and cbfstool
|
2021-05-18 12:21:48 +00:00
|
|
|
=============================
|
|
|
|
|
2022-11-14 02:31:12 +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.
|
|
|
|
|
2022-11-14 02:31:12 +00:00
|
|
|
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.
|
2022-11-14 02:31:12 +00:00
|
|
|
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:
|
2022-11-14 02:31:12 +00:00
|
|
|
[How to build libreboot from source](../build/)
|
2021-05-18 12:21:48 +00:00
|
|
|
|
2022-11-14 02:31:12 +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.
|
|
|
|
|
2024-08-26 21:36:21 +00:00
|
|
|
Install the build dependencies. For Debian and similar, you can run
|
2022-11-14 02:31:12 +00:00
|
|
|
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
|
|
|
|
2024-08-26 21:36:21 +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
|
|
|
|
2024-08-26 21:36:21 +00:00
|
|
|
Then, download coreboot (we'll assume the `default` tree is correct):
|
2021-05-18 12:21:48 +00:00
|
|
|
|
2024-08-26 21:36:21 +00:00
|
|
|
./mk -f coreboot default
|
2021-05-18 12:21:48 +00:00
|
|
|
|
2023-10-10 16:58:18 +00:00
|
|
|
Finally, compile the `cbutils` payload (and you will then have the utils):
|
2021-05-18 12:21:48 +00:00
|
|
|
|
2024-08-23 00:28:08 +00:00
|
|
|
./mk -b grub
|
2021-05-18 12:21:48 +00:00
|
|
|
|
2024-08-26 21:36:21 +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
|
2023-10-10 17:31:56 +00:00
|
|
|
subdirectories in `src/coreboot/` under `util/cbfstool/cbfstool`.
|
2021-05-18 12:21:48 +00:00
|
|
|
|
2023-10-10 17:31:56 +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
|
2022-11-14 02:31:12 +00:00
|
|
|
ROM image; as a *coreboot distribution*, libreboot inherits this technology.
|
2021-05-18 12:21:48 +00:00
|
|
|
|
2024-08-26 21:36:21 +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`.
|
|
|
|
|
2024-01-27 22:35:38 +00:00
|
|
|
You will also want to build `flashprog` which libreboot recommends for reading
|
2022-11-14 02:31:12 +00:00
|
|
|
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:
|
|
|
|
|
2024-08-23 00:28:08 +00:00
|
|
|
./mk -b flashprog
|
2021-05-18 12:21:48 +00:00
|
|
|
|
2024-08-23 00:28:08 +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
|
|
|
|
===================
|
|
|
|
|
2024-08-26 21:36:21 +00:00
|
|
|
[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/).
|
2023-09-03 15:07:34 +00:00
|
|
|
|
2024-08-26 21:36:21 +00:00
|
|
|
Those guides show how to dump the flash contents, which you are advised to do.
|
2023-09-03 15:07:34 +00:00
|
|
|
|
2024-08-26 21:36:21 +00:00
|
|
|
Insert new grub.cfg
|
|
|
|
===================
|
2021-05-18 12:21:48 +00:00
|
|
|
|
2024-08-26 21:36:21 +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
|
|
|
|
2024-08-26 21:36:21 +00:00
|
|
|
cbfstool libreboot.rom extract -n grub.cfg -f grub.cfg
|
2021-05-18 12:21:48 +00:00
|
|
|
|
2024-08-26 21:36:21 +00:00
|
|
|
Now remove it:
|
2021-05-18 12:21:48 +00:00
|
|
|
|
2024-08-26 21:36:21 +00:00
|
|
|
cbfstool libreboot.rom remove -n grub.cfg
|
2021-05-18 12:21:48 +00:00
|
|
|
|
2024-08-26 21:36:21 +00:00
|
|
|
It's important that you re-add `grub.cfg` before flashing:
|
2021-05-18 12:21:48 +00:00
|
|
|
|
2024-08-26 21:36:21 +00:00
|
|
|
cbfstool libreboot.rom add -f grub.cfg -n grub.cfg
|
2021-05-18 12:21:48 +00:00
|
|
|
|
2024-08-26 21:36:21 +00:00
|
|
|
Repeat this for `grubtest.cfg` if you wish.
|
2021-05-18 12:21:48 +00:00
|
|
|
|
2024-08-26 21:36:21 +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
|
|
|
|
2024-08-26 21:36:21 +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.
|
2023-09-03 15:07:34 +00:00
|
|
|
|
2024-08-26 21:36:21 +00:00
|
|
|
You can insert a `grub.cfg` into CBFS and it will override the one in memdisk.
|
2021-05-18 12:21:48 +00:00
|
|
|
|
2024-08-26 21:36:21 +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
|
|
|
|
2024-08-26 21:36:21 +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
|
|
|
|
2024-08-26 21:36:21 +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
|
|
|
|
============================
|
|
|
|
|
2024-08-26 21:36:21 +00:00
|
|
|
Check the [Libreboot flashing guide](../install/) which says how to flash the
|
|
|
|
new image.
|