Skip to content

Commit 66e7241

Browse files
committed
Toolchains and getting started guide: remove duplication, other fixes
Fix the CMake example, it has been broken since defconfig change thesofproject/sof#3821 Fix the default target when building tools. Replace a lot of the massive copy/paste with "for platform" loops. Move PATH changes to newlib section and explain that they don't need to be permanent. Signed-off-by: Marc Herbert <marc.herbert@intel.com>
1 parent 84c5ca5 commit 66e7241

1 file changed

Lines changed: 52 additions & 161 deletions

File tree

getting_started/build-guide/build-from-scratch.rst

Lines changed: 52 additions & 161 deletions
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,13 @@ Create or append to the ``LD_LIBRARY_PATH`` environment variable.
152152
Step 2 Build toolchains from source
153153
===================================
154154

155-
Build the xtensa cross-compilation toolchains with crosstool-ng for Intel |BYT|,
156-
|CHT|, |HSW|, |BDW|, |APL|, |CNL|, |ICL|, |JSL|, |TGL| platforms and NXP i.MX8/i.MX8X/i.MX8M
157-
platforms.
155+
Build the xtensa cross-compilation toolchains with crosstool-ng for
156+
Intel |BYT|, |CHT|, |HSW|, |BDW|, |APL|, |CNL|, |ICL|, |JSL|, |TGL|
157+
platforms and NXP i.MX8/i.MX8X/i.MX8M platforms. Building the toolchains
158+
may take about an hour but only once and it removes the dependency on
159+
the Docker image.
160+
161+
For more details go to https://crosstool-ng.github.io/
158162

159163
crosstool-ng
160164
------------
@@ -184,7 +188,7 @@ Toolchains
184188
----------
185189

186190
The config files provided refer to ``../xtensa-overlay/`` and point at
187-
different ``./build/xtensa-*-elf`` subdirectories. Copy the ones you
191+
different ``./builds/xtensa-*-elf`` subdirectories. Copy the ones you
188192
want to ``.config`` and build the cross-compiler(s) for your target
189193
platform(s). ``./ct-ng build`` requires an network connection to
190194
download gcc components.
@@ -221,13 +225,26 @@ default values missing from it:
221225
./ct-ng oldconfig V=1
222226
diff -u config-apl-gcc10.2-gdb9 .config
223227
224-
"Install" toolchains by copying them to ``$SOF_WORKSPACE``.
228+
While other steps take minutes at most, building all toolchains may last
229+
about an hour depending on the performance of your system. Run this loop
230+
to build all toolchains without interruption:
231+
232+
.. code-block:: bash
233+
234+
time for i in config*gcc10*; do
235+
cp "$i" .config && ../ct-install/bin/ct-ng build || break ;
236+
done
237+
238+
239+
"Install" toolchains in the expected location by linking
240+
from ``$SOF_WORKSPACE`` to them:
225241

226242
.. code-block:: bash
227243
228244
ls builds/
229245
# xtensa-apl-elf xtensa-byt-elf xtensa-cnl-elf xtensa-hsw-elf xtensa-imx-elf xtensa-imx8m-elf
230-
cp -r builds/* "$SOF_WORKSPACE"
246+
cd "$SOF_WORKSPACE"
247+
for i in crosstool-ng/builds/xtensa-*; do ln -s "$i"; done
231248
232249
.. note::
233250

@@ -239,16 +256,6 @@ default values missing from it:
239256

240257
i.MX8 and i.MX8X share the same toolchain: xtensa-imx-elf
241258

242-
Add your toolchains to your PATH variable.
243-
244-
.. code-block:: bash
245-
246-
PATH="${SOF_WORKSPACE}"/xtensa-byt-elf/bin/:$PATH
247-
PATH="${SOF_WORKSPACE}"/xtensa-hsw-elf/bin/:$PATH
248-
PATH="${SOF_WORKSPACE}"/xtensa-apl-elf/bin/:$PATH
249-
PATH="${SOF_WORKSPACE}"/xtensa-cnl-elf/bin/:$PATH
250-
PATH="${SOF_WORKSPACE}"/xtensa-imx-elf/bin/:$PATH
251-
PATH="${SOF_WORKSPACE}"/xtensa-imx8m-elf/bin/:$PATH
252259

253260
Additional headers
254261
------------------
@@ -263,40 +270,29 @@ switch to the `xtensa` branch.
263270
cd newlib-xtensa
264271
git checkout -b xtensa origin/xtensa
265272
266-
Build and install for each platform.
273+
Temporarily add toolchains to your PATH variable. This is *not* required
274+
when using high-level scripts described below, only this time here or
275+
when invoking CMake manually. In other words you don't need to adjust
276+
your PATH permanently; no risk to interfere with non-SOF tasks.
277+
278+
.. code-block:: bash
279+
280+
for i in "${SOF_WORKSPACE}"/xtensa-*-elf; do PATH="$PATH:$i"/bin; done
281+
282+
Build and install the newlib headers for each toolchain:
267283

268284
.. code-block:: bash
269285
270286
XTENSA_ROOT="${SOF_WORKSPACE}"/xtensa-root
271-
# Baytrail/Cherrytrail
272-
./configure --target=xtensa-byt-elf --prefix="${XTENSA_ROOT}"
273-
make
274-
make install
275-
rm -fr rm etc/config.cache
276-
# Haswell/Broadwell
277-
./configure --target=xtensa-hsw-elf --prefix="${XTENSA_ROOT}"
278-
make
279-
make install
280-
rm -fr rm etc/config.cache
281-
# Apollo Lake
282-
./configure --target=xtensa-apl-elf --prefix="${XTENSA_ROOT}"
283-
make
284-
make install
285-
rm -fr rm etc/config.cache
286-
# Cannon Lake, Ice Lake, Jasper Lake and Tiger Lake
287-
./configure --target=xtensa-cnl-elf --prefix="${XTENSA_ROOT}"
288-
make
289-
make install
290-
rm -fr rm etc/config.cache
291-
# i.MX8/i.MX8X
292-
./configure --target=xtensa-imx-elf --prefix="${XTENSA_ROOT}"
293-
make
294-
make install
295-
rm -fr rm etc/config.cache
296-
# i.MX8M
297-
./configure --target=xtensa-imx8m-elf --prefix="${XTENSA_ROOT}"
298-
make
299-
make install
287+
time for toolchain in ../xtensa-*-elf; do
288+
./configure --target="${toolchain#../}" --prefix="$XTENSA_ROOT" &&
289+
make && make install || break;
290+
rm etc/config.cache
291+
done
292+
ls "$XTENSA_ROOT"
293+
=> share xtensa-apl-elf xtensa-byt-elf xtensa-cnl-elf xtensa-hsw-elf ...
294+
295+
This should take a few minutes.
300296

301297
.. note::
302298

@@ -332,8 +328,8 @@ Build the firmware for all platforms.
332328
333329
.. note::
334330

335-
This script will only work if the PATH includes both the cross-compiler and
336-
``xtensa-root`` and if they are siblings in the same ``sof`` directory.
331+
This script works only if the cross-compiler and ``xtensa-root`` are
332+
siblings in the same ``sof`` directory, as instructed above.
337333

338334
As of May 2021, you may specify one or more of the following platform
339335
arguments: ``byt``, ``cht``, ``bdw``, ``hsw``, ``apl``, ``skl``, ``kbl``, ``cnl``,
@@ -389,122 +385,18 @@ for |BYT|:
389385
.. code-block:: bash
390386
391387
mkdir build_byt && cd build_byt
392-
cmake -DTOOLCHAIN=xtensa-byt-elf -DROOT_DIR="$XTENSA_ROOT"/xtensa-byt-elf ..
388+
cmake -DTOOLCHAIN=xtensa-byt-elf -DROOT_DIR="$XTENSA_ROOT"/xtensa-byt-elf -DINIT_CONFIG=baytrail_defconfig ..
393389
make help # lists all available targets
394-
make baytrail_defconfig
395390
make bin -j4 VERBOSE=1
396391
397-
for |CHT|:
398-
399-
.. code-block:: bash
392+
You can replace ``byt`` above with any other platform listed in the help
393+
output of the ``sof/scripts/xtensa-build-all.sh``. Find the toolchain
394+
matching each platform in the same script or above.
400395

401-
mkdir build_cht && cd build_cht
402-
cmake -DTOOLCHAIN=xtensa-byt-elf -DROOT_DIR="$XTENSA_ROOT"/xtensa-byt-elf ..
403-
make cherrytrail_defconfig
404-
make bin -j4
405-
406-
for |HSW|:
407-
408-
.. code-block:: bash
409-
410-
mkdir build_hsw && cd build_hsw
411-
cmake -DTOOLCHAIN=xtensa-hsw-elf -DROOT_DIR="$XTENSA_ROOT"/xtensa-hsw-elf ..
412-
make haswell_defconfig
413-
make bin -j4
414-
415-
for |BDW|:
416-
417-
.. code-block:: bash
418-
419-
mkdir build_bdw && cd build_bdw
420-
cmake -DTOOLCHAIN=xtensa-hsw-elf -DROOT_DIR="$XTENSA_ROOT"/xtensa-hsw-elf ..
421-
make broadwell_defconfig
422-
make bin -j4
423-
424-
for |APL|:
425-
426-
.. code-block:: bash
427-
428-
mkdir build_apl && cd build_apl
429-
cmake -DTOOLCHAIN=xtensa-apl-elf -DROOT_DIR="$XTENSA_ROOT"/xtensa-apl-elf ..
430-
make apollolake_defconfig
431-
make bin -j4
432-
433-
for |CNL|:
434-
435-
.. code-block:: bash
436-
437-
mkdir build_cnl && cd build_cnl
438-
cmake -DTOOLCHAIN=xtensa-cnl-elf -DROOT_DIR="$XTENSA_ROOT"/xtensa-cnl-elf ..
439-
make cannonlake_defconfig
440-
make bin -j4
441-
442-
for |ICL|:
443-
444-
.. code-block:: bash
445-
446-
mkdir build_icl && cd build_icl
447-
cmake -DTOOLCHAIN=xtensa-cnl-elf -DROOT_DIR="$XTENSA_ROOT"/xtensa-cnl-elf ..
448-
make icelake_defconfig
449-
make bin -j4
450-
451-
for |JSL|:
452-
453-
.. code-block:: bash
454-
455-
mkdir build_jsl && cd build_jsl
456-
cmake -DTOOLCHAIN=xtensa-cnl-elf -DROOT_DIR="$XTENSA_ROOT"/xtensa-cnl-elf ..
457-
make jasperlake_defconfig
458-
make bin -j4
459-
460-
for |TGL|:
461-
462-
.. code-block:: bash
463-
464-
mkdir build_tgl && cd build_tgl
465-
cmake -DTOOLCHAIN=xtensa-cnl-elf -DROOT_DIR="$XTENSA_ROOT"/xtensa-cnl-elf ..
466-
make tgplp_defconfig
467-
make bin -j4
468-
469-
for |TGL| H:
470-
471-
.. code-block:: bash
472-
473-
mkdir build_tgl-h && cd build_tgl-h
474-
cmake -DTOOLCHAIN=xtensa-cnl-elf -DROOT_DIR="$XTENSA_ROOT"/xtensa-cnl-elf ..
475-
make tgph_defconfig
476-
make bin -j4
477-
478-
for i.MX8:
479-
480-
.. code-block:: bash
481-
482-
mkdir build_imx8 && cd build_imx8
483-
cmake -DTOOLCHAIN=xtensa-imx-elf -DROOT_DIR="$XTENSA_ROOT"/xtensa-imx-elf ..
484-
make imx8_defconfig
485-
make bin -j4
486-
487-
for i.MX8X:
488-
489-
.. code-block:: bash
490-
491-
mkdir build_imx8x && cd build_imx8x
492-
cmake -DTOOLCHAIN=xtensa-imx-elf -DROOT_DIR="$XTENSA_ROOT"/xtensa-imx-elf ..
493-
make imx8x_defconfig
494-
make bin -j4
495-
496-
for i.MX8M:
497-
498-
.. code-block:: bash
499-
500-
mkdir build_imx8m && cd build_imx8m
501-
cmake -DTOOLCHAIN=xtensa-imx8m-elf -DROOT_DIR="$XTENSA_ROOT"/xtensa-imx8m-elf ..
502-
make imx8m_defconfig
503-
make bin -j4
504396

505397
.. note::
506398

507-
After the 'make \*_defconfig' step, you can customize your build with
399+
After the cmake step, you can customize your build with
508400
'make menuconfig'.
509401

510402
DEBUG and ROM options are available for the FW binary build. Enable them
@@ -513,8 +405,7 @@ for i.MX8M:
513405
.. code-block:: bash
514406
515407
mkdir build_cnl_custom && cd build_cnl_custom
516-
cmake -DTOOLCHAIN=xtensa-cnl-elf -DROOT_DIR="$XTENSA_ROOT"/xtensa-cnl-elf ..
517-
make cannonlake_defconfig
408+
cmake -DTOOLCHAIN=xtensa-cnl-elf -DROOT_DIR="$XTENSA_ROOT"/xtensa-cnl-elf -DINIT_CONFIG=cannonlake_defconfig ..
518409
make menuconfig # select/deselect options and save
519410
make bin -j4
520411
@@ -542,8 +433,8 @@ Step 4 Build topology and tools
542433
One-step rebuild from scratch
543434
-----------------------------
544435

545-
Without any argument :git-sof-mainline:`scripts/build-tools.sh` rebuilds
546-
only the minimum subset of :git-sof-mainline:`tools/`.
436+
Without any argument :git-sof-mainline:`scripts/build-tools.sh` builds
437+
the default CMake target "ALL" of :git-sof-mainline:`tools/`.
547438

548439
.. code-block:: bash
549440

0 commit comments

Comments
 (0)