| 1 |
Building from source |
| 2 |
==================== |
| 3 |
|
| 4 |
First thing, clone git repository for yourself (if you haven't done it already), |
| 5 |
see :ref:`git repo setup`. |
| 6 |
|
| 7 |
You're going to need the following tools to get started: |
| 8 |
|
| 9 |
* gcc or clang |
| 10 |
* meson |
| 11 |
* ninja |
| 12 |
* pkg-config |
| 13 |
* sphinx-build* |
| 14 |
|
| 15 |
| \* optional, to build man-pages and html documentation |
| 16 |
|
| 17 |
And the following dependencies: |
| 18 |
|
| 19 |
* cmocka [#b1]_ |
| 20 |
* linux-headers [#b2]_ |
| 21 |
* libpci [#b2]_ |
| 22 |
* libusb1 [#b2]_ |
| 23 |
* libftdi1 [#b2]_ |
| 24 |
* libjaylink [#b2]_ |
| 25 |
* NI-845x driver & library package [#b3]_ |
| 26 |
* libcrypto [#b4]_ |
| 27 |
|
| 28 |
.. [#b1] | optional, for building unit testing |
| 29 |
.. [#b2] | optional, depending on the selected programmer |
| 30 |
.. [#b3] | optional, proprietary and Windows only. (See Windows build instructions) |
| 31 |
.. [#b4] | optional, to enable RPMC commands |
| 32 |
|
| 33 |
If you are cross compiling, install the dependencies for your target. |
| 34 |
|
| 35 |
TL;DR |
| 36 |
----- |
| 37 |
:: |
| 38 |
|
| 39 |
meson setup builddir |
| 40 |
meson compile -C builddir |
| 41 |
meson test -C builddir |
| 42 |
meson install -C builddir |
| 43 |
|
| 44 |
|
| 45 |
.. _installing-dependencies: |
| 46 |
|
| 47 |
Installing dependencies |
| 48 |
----------------------- |
| 49 |
|
| 50 |
.. todo:: Move the bullet points to `tabs <https://www.w3schools.com/howto/howto_js_tabs.asp>`_ |
| 51 |
|
| 52 |
* No external dependencies (documentation should be build without fetching all of pypi) |
| 53 |
* No Javascript? |
| 54 |
|
| 55 |
Linux |
| 56 |
""""" |
| 57 |
|
| 58 |
* Debian / Ubuntu |
| 59 |
|
| 60 |
:: |
| 61 |
|
| 62 |
apt-get install -y \ |
| 63 |
gcc meson ninja-build pkg-config python3-sphinx \ |
| 64 |
libcmocka-dev libpci-dev libusb-1.0-0-dev libftdi1-dev libjaylink-dev \ |
| 65 |
libssl-dev |
| 66 |
|
| 67 |
* ArchLinux / Manjaro |
| 68 |
|
| 69 |
:: |
| 70 |
|
| 71 |
pacman -S --noconfirm \ |
| 72 |
gcc meson ninja pkg-config python-sphinx cmocka \ |
| 73 |
pciutils libusb libftdi libjaylink \ |
| 74 |
openssl |
| 75 |
|
| 76 |
* openSUSE / SUSE |
| 77 |
|
| 78 |
:: |
| 79 |
|
| 80 |
zypper install -y \ |
| 81 |
gcc meson ninja pkg-config python3-Sphinx \ |
| 82 |
libcmocka-devel pciutils-devel libusb-1_0-devel libftdi1-devel libjaylink-devel |
| 83 |
|
| 84 |
* NixOS / nixpkgs |
| 85 |
|
| 86 |
* There is a ``shell.nix`` under ``scripts/`` |
| 87 |
|
| 88 |
:: |
| 89 |
|
| 90 |
nix-shell -p \ |
| 91 |
gcc meson ninja pkg-config sphinx \ |
| 92 |
cmocka pciutils libusb1 libftdi1 libjaylink |
| 93 |
|
| 94 |
* Alpine Linux |
| 95 |
|
| 96 |
:: |
| 97 |
|
| 98 |
apk add \ |
| 99 |
build-base meson ninja pkgconf py3-sphinx \ |
| 100 |
cmocka-dev pciutils-dev libusb-dev libjaylink-dev |
| 101 |
|
| 102 |
Windows |
| 103 |
""""""" |
| 104 |
|
| 105 |
* MSYS2 |
| 106 |
|
| 107 |
Install `MSYS2 <https://www.msys2.org/>`_ and ensure it is `fully updated <https://www.msys2.org/docs/updating/>`_. |
| 108 |
|
| 109 |
* ``libpci`` is not available through the package manager and pci based programmer are not supported on Windows. |
| 110 |
* ``ni845x_spi`` is only available with the proprietary library from National Instruments. Download and install the driver |
| 111 |
from `ni.com <https://www.ni.com/en-us/support/downloads/drivers/download.ni-845x-driver-software.html>`_ and build flashrom |
| 112 |
for **32-bit**. Add ``-Dprogrammer=ni845x_spi`` to your meson configuration. |
| 113 |
|
| 114 |
In the MINGW64 shell run:: |
| 115 |
|
| 116 |
pacman -Sy \ |
| 117 |
mingw-w64-x86_64-gcc mingw-w64-x86_64-meson mingw-w64-x86_64-ninja mingw-w64-x86_64-pkg-config mingw-w64-x86_64-python-sphinx \ |
| 118 |
mingw-w64-x86_64-cmocka mingw-w64-x86_64-libusb mingw-w64-x86_64-libftdi mingw-w64-x86_64-libjaylink-git |
| 119 |
|
| 120 |
For building flashrom as 32-bit application, use the MSYS2 MINGW32 shell and run:: |
| 121 |
|
| 122 |
pacman -Sy \ |
| 123 |
mingw-w64-i686-gcc mingw-w64-i686-meson mingw-w64-i686-ninja mingw-w64-i686-pkg-config mingw-w64-i686-python-sphinx \ |
| 124 |
mingw-w64-i686-cmocka mingw-w64-i686-libusb mingw-w64-i686-libftdi mingw-w64-i686-libjaylink-git |
| 125 |
|
| 126 |
MacOS |
| 127 |
""""" |
| 128 |
|
| 129 |
* Homebrew |
| 130 |
|
| 131 |
* ``libpci`` is not available through the package manager |
| 132 |
* ``libjaylink`` is not available through the package manager |
| 133 |
|
| 134 |
:: |
| 135 |
|
| 136 |
brew install \ |
| 137 |
meson ninja pkg-config sphinx-doc \ |
| 138 |
libusb libftdi |
| 139 |
|
| 140 |
BSD |
| 141 |
""" |
| 142 |
|
| 143 |
* FreeBSD / DragonFlyBSD |
| 144 |
|
| 145 |
* ``libusb1`` is part of the system |
| 146 |
* ``libjaylink`` is not available through the package manager |
| 147 |
|
| 148 |
:: |
| 149 |
|
| 150 |
pkg install \ |
| 151 |
meson ninja pkgconf py39-sphinx \ |
| 152 |
cmocka libpci libftdi1 |
| 153 |
|
| 154 |
* OpenBSD |
| 155 |
|
| 156 |
* ``libjaylink`` is not available through the package manager |
| 157 |
|
| 158 |
:: |
| 159 |
|
| 160 |
pkg_add \ |
| 161 |
meson ninja pkg-config py39-sphinx\ |
| 162 |
cmocka pciutils libusb1 libftdi1 |
| 163 |
|
| 164 |
* NetBSD |
| 165 |
|
| 166 |
* ``libjaylink`` is not available through the package manager |
| 167 |
* note: https://www.cambus.net/installing-ca-certificates-on-netbsd/ |
| 168 |
|
| 169 |
:: |
| 170 |
|
| 171 |
pkgin install \ |
| 172 |
meson ninja pkg-config py39-sphinx \ |
| 173 |
cmocka pciutils libusb1 libftdi1 |
| 174 |
|
| 175 |
OpenIndiana (Illumos, Solaris, SunOS) |
| 176 |
""""""""""""""""""""""""""""""""""""" |
| 177 |
|
| 178 |
* ``libpci`` missing, pciutils is build without it |
| 179 |
* ``libftdi1`` & ``libjaylink`` are not available through the package manager |
| 180 |
* TODO: replace ``build-essential`` with the default compiler |
| 181 |
|
| 182 |
:: |
| 183 |
|
| 184 |
pkg install build-essential meson ninja cmocka libusb-1 |
| 185 |
|
| 186 |
DJGPP-DOS |
| 187 |
""""""""" |
| 188 |
|
| 189 |
* Get `DJGPP <https://www.delorie.com/djgpp/>`_ |
| 190 |
* A great build script can be found `here <https://github.com/andrewwutw/build-djgpp>`_ |
| 191 |
* Download the `pciutils <https://mj.ucw.cz/sw/pciutils/>`_ sources |
| 192 |
|
| 193 |
| Run the following commands in the the pciutils directory to build libpci for DOS. |
| 194 |
| Replace ``<DOS_INSTALL_ROOT>`` with your cross-compile install root. |
| 195 |
|
| 196 |
:: |
| 197 |
|
| 198 |
make install-lib \ |
| 199 |
ZLIB=no \ |
| 200 |
DNS=no \ |
| 201 |
HOST=i386-djgpp-djgpp \ |
| 202 |
CROSS_COMPILE=i586-pc-msdosdjgpp- \ |
| 203 |
STRIP="--strip-program=i586-pc-msdosdjgpp-strip -s" \ |
| 204 |
PREFIX=<DOS_INSTALL_ROOT> |
| 205 |
|
| 206 |
Point pkg-config to the ``<DOS_INSTALL_ROOT>`` :: |
| 207 |
|
| 208 |
export PKG_CONFIG_SYSROOT=<DOS_INSTALL_ROOT> |
| 209 |
|
| 210 |
* To compile flashrom use the ``meson_cross/i586_djgpp_dos.txt`` cross-file |
| 211 |
* You will need `CWSDPMI.EXE <https://sandmann.dotster.com/cwsdpmi/>`_ to run flashrom |
| 212 |
|
| 213 |
libpayload |
| 214 |
"""""""""" |
| 215 |
|
| 216 |
.. todo:: Add building instructions for libpayload |
| 217 |
|
| 218 |
|
| 219 |
.. _meson_configuration: |
| 220 |
|
| 221 |
Configuration |
| 222 |
------------- |
| 223 |
|
| 224 |
In the flashrom repository run:: |
| 225 |
|
| 226 |
meson setup [builtin options] [flashrom options] <builddir> |
| 227 |
|
| 228 |
Mesons ``[builtin options]`` can be displayed with ``meson setup --help``. |
| 229 |
The flashrom specific options can be found in ``meson_options.txt`` in the top-level |
| 230 |
directory of flashrom and are used like in cmake with ``-Doption=value`` |
| 231 |
Run ``meson configure`` to display all configuration options. |
| 232 |
|
| 233 |
.. todo:: Write a sphinx extension to render ``meson_options.txt`` here |
| 234 |
|
| 235 |
|
| 236 |
Configuration for Crossbuilds |
| 237 |
----------------------------- |
| 238 |
Flashrom specific cross-files can be found in the ``meson_cross`` folder. |
| 239 |
To use them run:: |
| 240 |
|
| 241 |
meson setup --cross-file <path/to/crossfile> [builtin options] [flashrom options] <builddir> |
| 242 |
|
| 243 |
The options are the same as the normal configuration options. For more information see |
| 244 |
https://mesonbuild.com/Cross-compilation.html |
| 245 |
|
| 246 |
|
| 247 |
Compiling |
| 248 |
--------- |
| 249 |
Run:: |
| 250 |
|
| 251 |
meson compile -C <builddir> |
| 252 |
|
| 253 |
|
| 254 |
Update configuration |
| 255 |
-------------------- |
| 256 |
If you want to change your initial configuration for some reason |
| 257 |
(for example you discovered that a programmer is missing), run:: |
| 258 |
|
| 259 |
meson configure [updated builtin options] [updated flashrom options] <builddir> |
| 260 |
|
| 261 |
.. _unit tests: |
| 262 |
|
| 263 |
Unit Tests |
| 264 |
---------- |
| 265 |
To execute the unit tests run:: |
| 266 |
|
| 267 |
meson test -C <builddir> |
| 268 |
|
| 269 |
You will get a summary of the unit test results at the end. |
| 270 |
|
| 271 |
|
| 272 |
Code coverage |
| 273 |
""""""""""""" |
| 274 |
gcov |
| 275 |
Due to a bug in lcov, the html file will only be correct if lcov is not |
| 276 |
installed and gcovr is installed. See |
| 277 |
https://github.com/linux-test-project/lcov/issues/168 and |
| 278 |
https://github.com/mesonbuild/meson/issues/6747 |
| 279 |
|
| 280 |
To create the coverage target add ``-Db_coverage=true`` to your build configuration. |
| 281 |
After executing the tests, you can run :: |
| 282 |
|
| 283 |
ninja -C <builddir> coverage |
| 284 |
|
| 285 |
to generate the coverage report. |
| 286 |
|
| 287 |
lcov / llvm |
| 288 |
https://clang.llvm.org/docs/SourceBasedCodeCoverage.html |
| 289 |
Make sure that you are using `clang` as compiler, e.g. by setting `CC=clang` during configuration. |
| 290 |
Beside that you need to add ``-Dllvm_cov=enabled`` to your build configuration :: |
| 291 |
|
| 292 |
CC=clang meson setup -Dllvm_cov=enable <builddir> |
| 293 |
meson test -C <builddir> |
| 294 |
ninja -C <builddir> llvm-cov-tests |
| 295 |
|
| 296 |
For additional information see `the meson documentation <https://mesonbuild.com/Unit-tests.html#coverage>`_ |
| 297 |
|
| 298 |
|
| 299 |
Installing |
| 300 |
---------- |
| 301 |
To install flashrom and documentation, run:: |
| 302 |
|
| 303 |
meson install -C <builddir> |
| 304 |
|
| 305 |
This will install flashrom under the PREFIX selected in the configuration phase. Default is ``/usr/local``. |
| 306 |
|
| 307 |
To install into a different directory use DESTDIR, like this:: |
| 308 |
|
| 309 |
DESTDIR=/your/destination/directory meson install -C <your_build_dir> |
| 310 |
|
| 311 |
You can also set the prefix during configuration with:: |
| 312 |
|
| 313 |
meson setup --prefix <DESTDIR> <your_build_dir> |
| 314 |
|
| 315 |
Create distribution package |
| 316 |
--------------------------- |
| 317 |
To create a distribution tarball from your ``builddir``, run:: |
| 318 |
|
| 319 |
meson dist -C <builddir> |
| 320 |
|
| 321 |
This will collect all git tracked files and pack them into an archive. |
| 322 |
|
| 323 |
Current flashrom version is in the VERSION file. To release a new flashrom |
| 324 |
version you need to change VERSION file and tag the changing commit. |