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.
|
|
|
|
|
2023-04-09 21:38:30 +00:00
|
|
|
This guide assumes that you use the GRUB bootloader as your default
|
|
|
|
payload. In this configuration, GRUB is flashed alongside coreboot and runs
|
2021-05-18 12:21:48 +00:00
|
|
|
on *bare metal* as a native coreboot payload and does *not* use BIOS or UEFI
|
|
|
|
services (but it *can* load and execute SeaBIOS, in addition to any other
|
|
|
|
coreboot payload, by chainloading it).
|
|
|
|
|
2022-11-14 02:31:12 +00:00
|
|
|
In most circumstances, this guide will not benefit you. libreboot's default
|
2021-05-18 12:21:48 +00:00
|
|
|
GRUB configuration file contains scripting logic within it that intelligently
|
|
|
|
searches for GRUB partitions installed onto a partition on your SSD, HDD or
|
2022-11-14 02:31:12 +00:00
|
|
|
USB drive installed on your computer. If such a file is found, libreboot's
|
2021-05-18 12:21:48 +00:00
|
|
|
default GRUB configuration is configured to switch automatically to that
|
|
|
|
configuration. While not perfect, the logic *does* work with most
|
|
|
|
configurations.
|
|
|
|
|
|
|
|
Therefore, you should only follow *this* guide if the automation (described
|
|
|
|
above) does not work. It goes without saying that modifying the default GRUB
|
|
|
|
configuration is risky, because a misconfiguration could create what's called
|
|
|
|
a *soft brick* where your machine is effectively useless and, in that scenario,
|
|
|
|
may or may not require external flashing equipment for restoring the machine to
|
|
|
|
a known state.
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
Install the build dependencies. For Ubuntu 20.04 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
|
|
|
|
2023-01-08 01:22:04 +00:00
|
|
|
./build dependencies ubuntu2004
|
2021-05-18 12:21:48 +00:00
|
|
|
|
|
|
|
Then, download coreboot:
|
|
|
|
|
2023-10-20 05:07:57 +00:00
|
|
|
./update trees -f coreboot
|
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
|
|
|
|
2023-10-20 05:07:57 +00:00
|
|
|
./build grub
|
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-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-01-27 22:35:38 +00:00
|
|
|
./update trees -b flashprog
|
2021-05-18 12:21:48 +00:00
|
|
|
|
2024-01-27 22:35:38 +00:00
|
|
|
An executable will be available at `src/flashprog/flashprog` after you have done
|
2021-05-18 12:21:48 +00:00
|
|
|
this.
|
|
|
|
|
|
|
|
Dump the boot flash
|
|
|
|
===================
|
|
|
|
|
2022-11-14 02:31:12 +00:00
|
|
|
If you wish to modify your *existing* libreboot ROM, which was installed on
|
2024-01-27 22:35:38 +00:00
|
|
|
your computer, you can use `flashprog` to acquire it.
|
2021-05-18 12:21:48 +00:00
|
|
|
|
2022-11-14 02:31:12 +00:00
|
|
|
Simply run the following, after using libreboot's build system to compile
|
2024-01-27 22:35:38 +00:00
|
|
|
flashprog:
|
2021-05-18 12:21:48 +00:00
|
|
|
|
2024-01-27 22:35:38 +00:00
|
|
|
sudo ./src/flashprog/flashprog -p internal -r dump.bin
|
2021-05-18 12:21:48 +00:00
|
|
|
|
2024-01-27 22:35:38 +00:00
|
|
|
If flashprog complains about multiple flash chip definitions, do what it says to
|
2021-05-18 12:21:48 +00:00
|
|
|
rectify your command and run it again.
|
|
|
|
|
|
|
|
You may want to use the following, instead of `-p internal`:
|
|
|
|
`-p internal:laptop=force_I_want_a_brick,boardmismatch=force`
|
|
|
|
|
|
|
|
Do not let the word *brick* fools you. This merely disables the safety checks
|
2024-01-27 22:35:38 +00:00
|
|
|
in flashprog, which is sometimes necessary depending on what ROM was already
|
2021-05-18 12:21:48 +00:00
|
|
|
flashed, versus the new ROM image.
|
|
|
|
|
|
|
|
The `internal` option assumes that internal read/write is possible; this is
|
|
|
|
when you read from and/or write to the boot flash from an operating systems
|
2023-04-09 21:38:30 +00:00
|
|
|
(usually Linux) that is *running on* the target system.
|
2021-05-18 12:21:48 +00:00
|
|
|
|
|
|
|
In other cases, you may need to connect an SPI programmer externally (with the
|
|
|
|
machine powered down) and read the contents of the boot flash.
|
|
|
|
|
|
|
|
[Learn how to externally reprogram these chips](../install/spi.md)
|
|
|
|
|
|
|
|
Extract grub.cfg
|
|
|
|
================
|
|
|
|
|
2023-10-20 23:00:28 +00:00
|
|
|
Libreboot 20231021 or newer
|
2023-09-03 15:07:34 +00:00
|
|
|
-----------------------------------
|
|
|
|
|
2023-10-20 23:00:28 +00:00
|
|
|
Releases or or after 20231021 contain `grub.cfg` inside the GRUB memdisk,
|
2023-09-03 15:07:34 +00:00
|
|
|
inaccessible directly from CBFS, but the memdisk is inside `grub.elf` which
|
|
|
|
gets put inside CBFS.
|
|
|
|
|
|
|
|
An override is possible, on these Libreboot revisions. If `grub.cfg` is present
|
|
|
|
in CBFS, Libreboot's GRUB will use *that* and not the memdisk one; it will not
|
|
|
|
auto-switch to `grubtest.cfg`, but the test config will be available in the
|
|
|
|
menu to switch to, if present.
|
|
|
|
|
|
|
|
You can find `grub.cfg` under lbmk (for this purpose, it's best to use the
|
2023-10-20 23:00:28 +00:00
|
|
|
lbmk one, not the release one - unless you're using a release image).
|
|
|
|
Find it at path (in current lbmk): `config/grub/config/grub.cfg`.
|
2023-09-03 15:07:34 +00:00
|
|
|
|
|
|
|
So, you can *add* `grubtest.cfg` as normal, test that, and
|
|
|
|
then *add* `grub.cfg` once you're happy, and it will override the default.
|
|
|
|
|
2023-10-20 23:00:28 +00:00
|
|
|
Libreboot 20230625 or older
|
2023-09-03 15:07:34 +00:00
|
|
|
----------------------------
|
|
|
|
|
2023-10-20 23:00:28 +00:00
|
|
|
NOTE: This information will probably be deleted after a certain time has passed.
|
|
|
|
Libreboot changed a lot, as of release 20231021 in reference to 20230625, so it
|
|
|
|
may take a while before people adjust; therefore, this information is provided
|
|
|
|
for reference, but you should consider it to be deprecated:
|
|
|
|
|
2023-04-09 21:38:30 +00:00
|
|
|
libreboot images that use the GRUB bootloader will have *two* configuration
|
2021-05-18 12:21:48 +00:00
|
|
|
files in CBFS:
|
|
|
|
|
|
|
|
* `grub.cfg`
|
|
|
|
* `grubtest.cfg`
|
|
|
|
|
|
|
|
We recommend that you modify `grubtest.cfg` first, and boot. Select the boot
|
|
|
|
menu option for loading `grubtest.cfg` and verify that your new config works
|
|
|
|
correctly. If it doesn't, keep modifying `grubtest.cfg` until it does work.
|
|
|
|
When that it done, copy the changes over to `grub.cfg
|
|
|
|
|
|
|
|
You can use the following commands to modify the contents of CBFS, where
|
|
|
|
GRUB's configuration file is concerned (dump.bin is the ROM that you dumped,
|
2022-11-14 02:31:12 +00:00
|
|
|
or it could refer to the libreboot ROM image that you compiled or otherwise
|
2021-05-18 12:21:48 +00:00
|
|
|
acquired).
|
|
|
|
|
|
|
|
Show the contents of CBFS, in your ROM:
|
|
|
|
|
2023-01-08 01:22:04 +00:00
|
|
|
cbfstool dump.bin print
|
2021-05-18 12:21:48 +00:00
|
|
|
|
|
|
|
Extract `grub.cfg` (substitude with `grubtest.cfg` as desired):
|
|
|
|
|
2023-01-08 01:22:04 +00:00
|
|
|
cbfstool dump.bin extract -n grub.cfg -f grub.cfg
|
2021-05-18 12:21:48 +00:00
|
|
|
|
|
|
|
You will now have a file named `grub.cfg`.
|
|
|
|
|
|
|
|
Make your desired modifications. You should then delete the old `grub.cfg`
|
|
|
|
from your ROM image.
|
|
|
|
|
|
|
|
Insert new grub.cfg
|
|
|
|
===================
|
|
|
|
|
2023-10-20 23:00:28 +00:00
|
|
|
NOTE: As stated above, releases on or after Libreboot 20231021 only default to
|
2023-09-03 15:07:34 +00:00
|
|
|
the config in memdisk, and lack a CBFS config, so you can skip the *remove*
|
|
|
|
step below and just directly add the new `grub.cfg` - unless you already
|
|
|
|
added one before, in which case removal is required first.
|
|
|
|
|
2021-05-18 12:21:48 +00:00
|
|
|
Remove the old `grub.cfg` (substitute with `grubtest.cfg` as desired):
|
|
|
|
|
2023-01-08 01:22:04 +00:00
|
|
|
cbfstool dump.bin remove -n grub.cfg
|
2021-05-18 12:21:48 +00:00
|
|
|
|
|
|
|
Add your modified `grub.cfg` (substitute with `grubtest.cfg` as desired):
|
|
|
|
|
2023-01-08 01:22:04 +00:00
|
|
|
cbfstool dump.bin add -f grub.cfg -n grub.cfg -t raw
|
2021-05-18 12:21:48 +00:00
|
|
|
|
|
|
|
Flash the modified ROM image
|
|
|
|
============================
|
|
|
|
|
2022-11-14 02:31:12 +00:00
|
|
|
Your modified `dump.bin` or other modified libreboot ROM can then be re-flashed
|
2021-05-18 12:21:48 +00:00
|
|
|
using:
|
|
|
|
|
2024-01-27 22:35:38 +00:00
|
|
|
sudo ./flashprog -p internal -w dump.bin
|
2021-05-18 12:21:48 +00:00
|
|
|
|
|
|
|
If a `-c` option is required, use it and specify a flash chip name. This is
|
2024-01-27 22:35:38 +00:00
|
|
|
only useful when `flashprog` complains about multiple flash chips being
|
2021-05-18 12:21:48 +00:00
|
|
|
detected.
|
|
|
|
|
2024-01-27 22:35:38 +00:00
|
|
|
If flashprog complains about wrong chip/board, make sure that your ROM is for
|
2021-05-18 12:21:48 +00:00
|
|
|
the correct system. If you're sure, you can disable the safety checks by running
|
|
|
|
this instead:
|
|
|
|
|
2024-01-27 22:35:38 +00:00
|
|
|
sudo ./flashprog -p internal:laptop=force_I_want_a_brick,boardmismatch=force -w dump.bin
|
2021-05-18 12:21:48 +00:00
|
|
|
|
|
|
|
If you need to use external flashing equipment, see the link above to the
|
|
|
|
Raspberry Pi page.
|