Coreboot: Difference between revisions

imported>Milahu
fix nix-shell with mkShellNoCC
Ehmry (talk | contribs)
Coreboot comes with a nix-shell expression.
 
(12 intermediate revisions by 6 users not shown)
Line 1: Line 1:
== Building in nix-shell ==
== Building as Nix Derivation ==
To build your own coreboot bios:


Create a <code>shell.nix</code>, and run <code>nix-shell</code>
There is a commented example of building Coreboot as Nix derivation at [https://github.com/blitz/nix-coreboot blitz/nix-coreboot] on Github.


<syntaxhighlight lang="nix">
== Building in nix-shell ==
# shell.nix
Coreboot as of 24.02 comes with a Nix shell expression for x86 at <code>util/nixshell//devshell-i386.nix</code>.
 
# NOTE we need mkShellNoCC
# mkShell would add the regular gcc, which has no ada (gnat)
# https://github.com/NixOS/nixpkgs/issues/142943
 
with import <nixpkgs> { };
mkShellNoCC {
  buildInputs = [
    gnat11 # gcc with ada
    #gnatboot # gnat1
    ncurses # make menuconfig
    #bison # generate parsers
    #flex
    #clang
    zlib
    #acpica-tools # iasl
    pkgconfig
    qemu # test the image
  ];
  shellHook = ''
    # TODO remove?
    NIX_LDFLAGS="$NIX_LDFLAGS -lncurses"
  '';
}
</syntaxhighlight>
 
Now we can build coreboot:


<syntaxHighlight lang=bash>
<syntaxHighlight lang=bash>
# clone coreboot git repository (latest master)
git clone https://review.coreboot.org/coreboot.git --depth 1
git clone https://review.coreboot.org/coreboot.git --depth 1
# or for a specific coreboot version (I.E. version 4.15)
git clone --branch 4.15 https://review.coreboot.org/coreboot.git --depth 1
# get 3rd party submodules in coreboot repository
cd coreboot
cd coreboot
du -sh . # 200 MByte
du -sh . # ~200 MByte
git submodule update --init --checkout --depth 1
git submodule update --init --checkout --depth 1
du -sh . # 700 MByte
du -sh . # ~700 MByte
 
nix-shell --pure util/nixshell/devshell-i386.nix


# configure
# configure
make menuconfig
# set mainboard model, chip size, ...
 
make menuconfig MENUCONFIG_COLOR=blackbg # blackbg = dark mode
# build toolchain
# this can take some hours
make crossgcc CPUS=$(nproc)


# build firmware
# build firmware
make
make CPUS=$(nproc)


# test firmware
# test firmware
Line 55: Line 31:
</syntaxHighlight>
</syntaxHighlight>


=== Compiler version ===
== Skip building toolchain ==


<code>gcc</code> (provided by <code>clang</code>) and <code>gnat</code> (the GNU Ada compiler) must have the same version
We can use our system toolchain to build coreboot firmware, but this is not recommended per [https://doc.coreboot.org/tutorial/part1.html coreboot docs]:


<syntaxHighlight lang=console>
<blockquote>
gcc --version
you can possibly use your system toolchain, but the results are not reproducible, and may have issues, so this is not recommended
gnat --version
</blockquote>
</syntaxHighlight>


For example, both have version <code>10.3.0</code>
To use the system toolchain, in <code>make menuconfig</code>, enable <code>General Setup > Allow building with any toolchain</code>


== Building as derivation ==
== Building as derivation ==
Line 72: Line 47:
== See also ==
== See also ==


* https://doc.coreboot.org/tutorial/part1.html
* https://www.coreboot.org/Build_HOWTO
* https://www.coreboot.org/Build_HOWTO
* https://www.coreboot.org/Lesson1
* https://www.coreboot.org/Lesson1
* https://wiki.gentoo.org/wiki/Coreboot
* flashing the new bios image
* flashing the new bios image
** https://doc.coreboot.org/flash_tutorial/
** https://doc.coreboot.org/tutorial/flashing_firmware/index.html
** https://libreboot.org/docs/install/spi.html
** https://libreboot.org/docs/install/spi.html
[[Category:Booting]]