CLFS Arm
CLFS Arm
Table of Contents
Preface ......................................................................................................................................................................... v
i. Foreword ............................................................................................................................................................ v
ii. Audience ........................................................................................................................................................... v
iii. Prerequisites ................................................................................................................................................... vi
iv. Typography .................................................................................................................................................... vii
v. Structure .......................................................................................................................................................... vii
vi. Open Publication License ............................................................................................................................ viii
vii. Master Changelog .......................................................................................................................................... x
viii. Cross-LFS Acknowledgements .................................................................................................................. xiv
ix. Errata .............................................................................................................................................................. xv
I. Introduction ............................................................................................................................................................. 1
1. Introduction ....................................................................................................................................................... 2
1.1. How to Build a CLFS System ................................................................................................................ 2
1.2. Host System Requirements ..................................................................................................................... 2
1.3. Resources ................................................................................................................................................. 4
1.4. Help .......................................................................................................................................................... 5
II. Preparing for the Build .......................................................................................................................................... 7
2. Build Directory, Packages, and Patches .......................................................................................................... 8
2.1. Introduction .............................................................................................................................................. 8
2.2. Creating Build and Sources Directories .................................................................................................. 8
2.3. All Packages ............................................................................................................................................ 8
2.4. Needed Patches ........................................................................................................................................ 9
3. Final Preparations ........................................................................................................................................... 11
3.1. About $CLFS ......................................................................................................................................... 11
3.2. Adding the CLFS User ......................................................................................................................... 11
3.3. Setting Up the Environment .................................................................................................................. 12
III. Make the Cross-Compile Tools ......................................................................................................................... 14
4. Constructing Cross-Compile Tools ................................................................................................................ 15
4.1. Introduction ............................................................................................................................................ 15
4.2. Build CFLAGS ...................................................................................................................................... 15
4.3. Build Variables ...................................................................................................................................... 15
4.4. Create the Cross Tools Sysroot Directory ............................................................................................ 17
4.5. Linux-Headers-4.9.22 ............................................................................................................................ 18
4.6. Binutils-2.27 ........................................................................................................................................... 19
4.7. GCC-6.2.0 - Static ................................................................................................................................. 21
4.8. musl-1.1.16 ............................................................................................................................................ 24
4.9. GCC-6.2.0 - Final .................................................................................................................................. 25
4.10. Create the Target File System Directory ............................................................................................ 27
4.11. ToolChain Variables ............................................................................................................................ 27
IV. Building the CLFS System ................................................................................................................................ 28
5. Installing Basic System Software .................................................................................................................. 29
5.1. Introduction ............................................................................................................................................ 29
5.2. Creating Directories ............................................................................................................................... 29
5.3. Creating the passwd, group, and lastlog Files ...................................................................................... 29
5.4. libgcc-6.2.0 ............................................................................................................................................ 33
iii
Cross-Compiled Linux From Scratch - Embedded - Version GIT-20190419-arm
iv
Cross-Compiled Linux From Scratch - Embedded - Version GIT-20190419-arm
Preface
Foreword
The Linux From Scratch Project has seen many changes in the few years of its existence. I personally became involved
with the project in 2000, around the time of the 3.x releases. At that time, the build process was to create static binaries
with the host system, then chroot and build the final binaries on top of the static ones.
Later came the use of the /static directory to hold the initial static builds, keeping them separated from the final
system, then the PureLFS process developed by Ryan Oliver and Greg Schafer, introducing a new toolchain build
process that divorces even our initial builds from the host. Finally, LFS 6 bought Linux Kernel 2.6, the udev dynamic
device structure, sanitized kernel headers, and other improvements to the Linux From Scratch system.
The one "flaw" in LFS is that it has always been based on an x86 class processor. With the advent of the Athlon
64 and Intel EM64T processors, the x86-only LFS is no longer ideal. Throughout this time, Ryan Oliver developed
and documented a process by which you could build Linux for any system and from any system, by use of cross-
compilation techniques. Thus, the Cross-Compiled LFS (CLFS) was born.
CLFS Embedded follows the same guiding principles the LFS project has always followed, e.g., knowing your system
inside and out by virtue of having built the system yourself. Additionally, during a CLFS Embedded build, you will
learn advanced techniques such as cross-build toolchains, and how to create a smaller footprint system supporting
architectures such as ARM and MIPS, in addition to x86.
We hope you enjoy building your own CLFS Embedded system, and the benefits that come from a system tailored
to your needs.
--
Jim Gifford, CLFS Project Co-leader (Page Author)
Jeremy Utley, CLFS 1.x Release Manager (Page Author)
Ryan Oliver, CLFS Project Co-leader
Joe Ciccone, Justin Knierim, Chris Staub, Matt Darcy, Ken Moffat,
Maarten Lankhorst, Zack Winkles, Manuel Canales Esparcia,
Nathan Coulson, and Andrew Bradford - CLFS Developers
Audience
There are many reasons why somebody would want to read this book. The principal reason is to install a Linux system
from the source code. A question many people raise is, “why go through all the hassle of manually building a Linux
system from scratch when you can just download and install an existing one?” That is a good question and is the
impetus for this section of the book.
One important reason for the existence of CLFS is to help people understand how a Linux system works. Building
an CLFS system helps demonstrate what makes Linux tick, and how things work together and depend on each other.
One of the best things this learning experience provides is the ability to customize Linux to your own tastes and needs.
A key benefit of CLFS is that it allows users to have more control over their system without any reliance on a Linux
implementation designed by someone else. With CLFS, you are in the driver's seat and dictate every aspect of the
system, such as the directory layout and bootscript setup. You also dictate where, why, and how programs are installed.
v
Cross-Compiled Linux From Scratch - Embedded - Version GIT-20190419-arm
Another benefit of CLFS is the ability to create a very compact Linux system. When installing a regular distribution,
one is often forced to include several programs which are probably never used. These programs waste disk space
or CPU cycles. It is not difficult to build an CLFS Embedded system of less than 10 megabytes (MB), which is
substantially smaller than the majority of existing installations. Try that with a regular distribution!
We could compare Linux distributions to a hamburger purchased at a fast-food restaurant—you have no idea what
might be in what you are eating. CLFS, on the other hand, does not give you a hamburger. Rather, CLFS provides
the recipe to make the exact hamburger desired. This allows users to review the recipe, omit unwanted ingredients,
and add your own ingredients to enhance the flavor of the burger. When you are satisfied with the recipe, move on
to preparing it. It can be made to exact specifications—broil it, bake it, deep-fry it, or barbecue it.
Another analogy that we can use is that of comparing CLFS with a finished house. CLFS provides the skeletal plan of
a house, but it is up to you to build it. CLFS maintains the freedom to adjust plans throughout the process, customizing
it to the needs and preferences of the user.
Security is an additional advantage of a custom built Linux system. By compiling the entire system from source code,
you are empowered to audit everything and apply all the security patches desired. It is no longer necessary to wait
for somebody else to compile binary packages that fix a security hole. Unless you examine the patch and implement
it yourself, you have no guarantee that the new binary package was built correctly and adequately fixes the problem.
The goal of Cross Linux From Scratch is to build a complete and usable foundation-level system. Readers who do not
wish to build their own Linux system from scratch may not benefit from the information in this book. If you only want
to know what happens while the computer boots, we recommend the “From Power Up To Bash Prompt” HOWTO
located at http://axiom.anu.edu.au/~okeefe/p2b/ or on The Linux Documentation Project's (TLDP) website at http://
www.tldp.org/HOWTO/From-PowerUp-To-Bash-Prompt-HOWTO.html. The HOWTO builds a system which is
similar to that of this book, but it focuses strictly on creating a system capable of booting to a shell prompt. Consider
your objective. If you wish to build a Linux system and learn along the way, this book is your best choice.
There are too many good reasons to build your own CLFS system to list them all here. This section is only the tip
of the iceberg. As you continue in your CLFS experience, you will find the power that information and knowledge
truly bring.
Prerequisites
Building a CLFS system is not a simple task. It requires a certain level of existing knowledge of Unix system
administration in order to resolve problems, and correctly execute the commands listed. In particular, as an absolute
minimum, the reader should already have the ability to use the command line (shell) to copy or move files and
directories, list directory and file contents, and change the current directory. It is also expected that the reader has a
reasonable knowledge of using and installing Linux software. A basic knowledge of the architectures being used in
the Cross LFS process and the host operating systems in use is also required.
Because the CLFS book assumes at least this basic level of skill, the various CLFS support forums are unlikely to be
able to provide you with much assistance. Your questions regarding such basic knowledge will likely go unanswered,
or you will be referred to the CLFS essential pre-reading list.
Before building a CLFS system, we recommend reading the following HOWTOs:
• Software-Building-HOWTO
http://www.tldp.org/HOWTO/Software-Building-HOWTO.html
This is a comprehensive guide to building and installing “generic” Unix software distributions under Linux.
• The Essential Pre-Reading Hint
vi
Cross-Compiled Linux From Scratch - Embedded - Version GIT-20190419-arm
http://www.linuxfromscratch.org/hints/downloads/files/essential_prereading.txt
This is a hint written specifically for users new to Linux. It includes a list of links to excellent sources of
information on a wide range of topics. Anyone attempting to install CLFS should have an understanding of many
of the topics in this hint.
Typography
To make things easier to follow, there are a few typographical conventions used throughout this book. This section
contains some examples of the typographical format found throughout Linux From Scratch.
./configure --prefix=/usr
This form of text is designed to be typed exactly as seen unless otherwise noted in the surrounding text. It is also used
in the explanation sections to identify which of the commands is being referenced.
install-info: unknown option '--dir-file=/mnt/clfs/usr/info/dir'
This form of text (fixed-width text) shows screen output, probably as the result of commands issued. This format is
also used to show filenames, such as /etc/ld.so.conf.
Emphasis
This form of text is used for several purposes in the book. Its main purpose is to emphasize important points or items.
http://clfs.org/
This format is used for hyperlinks, both within the CLFS community and to external pages. It includes HOWTOs,
download locations, and websites.
cat > ${CLFS}/etc/group << "EOF"
root:x:0:
bin:x:1:
......
EOF
This format is used when creating configuration files. The first command tells the system to create the file ${CLFS}/
etc/group from whatever is typed on the following lines until the sequence end of file (EOF) is encountered.
Therefore, this entire section is generally typed as seen.
[REPLACED TEXT]
This format is used to encapsulate text that is not to be typed as seen or copied-and-pasted.
passwd(5)
This format is used to refer to a specific manual page (hereinafter referred to simply as a “man” page). The number
inside parentheses indicates a specific section inside of man. For example, passwd has two man pages. man passwd
will print the first man page it finds that matches “passwd”, which will be /usr/share/man/man1/passwd.
1. For this example, you will need to run man 5 passwd in order to read the specific page being referred to. It should
be noted that most man pages do not have duplicate page names in different sections. Therefore, man [program
name] is generally sufficient.
Structure
This book is divided into the following parts.
vii
Cross-Compiled Linux From Scratch - Embedded - Version GIT-20190419-arm
Part I - Introduction
Part I explains a few important notes on how to proceed with the Cross-LFS installation. This section also provides
meta-information about the book.
The reference must be immediately followed with any options elected by the author(s) and/or publisher of the
document (see section VI).
Commercial redistribution of Open Publication-licensed material is permitted.
Any publication in standard (paper) book form shall require the citation of the original publisher and author. The
publisher and author's names shall appear on all outer surfaces of the book. On all outer surfaces of the book the
original publisher's name shall be as large as the bridgehead of the work and cited as possessive with respect to the
bridgehead.
viii
Cross-Compiled Linux From Scratch - Embedded - Version GIT-20190419-arm
II. COPYRIGHT
The copyright to each Open Publication is owned by its author(s) or designee.
V. GOOD-PRACTICE RECOMMENDATIONS
In addition to the requirements of this license, it is requested from and strongly recommended of redistributors that:
1. If you are distributing Open Publication works on hardcopy or CD-ROM, you provide email notification to the
authors of your intent to redistribute at least thirty days before your manuscript or media freeze, to give the authors
time to provide updated documents. This notification should describe modifications, if any, made to the document.
2. All substantive modifications (including deletions) be either clearly marked up in the document or else described
in an attachment to the document.
3. Finally, while it is not mandatory under this license, it is considered good form to offer a free copy of any hardcopy
and CD-ROM expression of an Open Publication-licensed work to its author(s).
ix
Cross-Compiled Linux From Scratch - Embedded - Version GIT-20190419-arm
A. To prohibit distribution of substantively modified versions without the explicit permission of the author(s).
"Substantive modification" is defined as a change to the semantic content of the document, and excludes mere changes
in format or typographical corrections.
To accomplish this, add the phrase `Distribution of substantively modified versions of this document is prohibited
without the explicit permission of the copyright holder.' to the license reference or copy.
B. To prohibit any publication of this work or derivative works in whole or in part in standard (paper) book form for
commercial purposes is prohibited unless prior permission is obtained from the copyright holder.
To accomplish this, add the phrase 'Distribution of the work or derivative of the work in any standard (paper) book
form is prohibited unless prior permission is obtained from the copyright holder.' to the license reference or copy.
Master Changelog
This is version GIT-20190419 of the Cross-Compiled Linux From Scratch book, dated April 19, 2019. If this book
is more than six months old, a newer and better version is probably already available. To find out, please check one
of the mirrors via http://trac.clfs.org/.
Below is a list of detailed changes made since the previous release of the book.
Changelog Entries:
• April 19, 2019
• [abradford] - Fix download links for MPC and bootscripts.
• October 12, 2017
• [abradford] - Many small fixes submitted by "selk" on IRC and "akhiezer" via email.
• [abradford] - Update Linux to v4.9.22.
• [abradford] - Update musl to version 1.1.16.
• [abradford] - Add new concept of "targetfs" directory parallel to the cross-tools which allows easier retaining
of cross-tools across target builds.
• [abradford] - Remove utmp, wtmp, and btmp creation.
• December 28, 2016
• [abradford] - Add apt-get line to INSTALL document.
• [abradford] - Update binutils to version 2.27.
• [abradford] - Update busybox to version 1.24.2.
• [abradford] - Update gmp to version 6.1.1.
• [abradford] - Update Linux to version 4.4.21.
• [abradford] - Update mpc to version 1.0.3.
• [abradford] - Update mpfr to version 3.1.2.
• [abradford] - Update musl to version 1.1.15.
• [abradford] - Update GCC to version 6.2 which removes the need for patching GCC for compatibility with
musl.
• [abradford] - Update host requirements and script for m4 and ncurses5.
• June 13, 2014
x
Cross-Compiled Linux From Scratch - Embedded - Version GIT-20190419-arm
• [abradford] - Created a Beyond section just for extra libraries and moved zlib into it.
• April 19, 2011
• [abradford] - Created a Beyond section just for networking tools.
• [abradford] - Created a Beyond section just for file system tools and moved e2fsprogs into it.
• April 8, 2011
• [jciccone] - Cleaned up the acknowledgements page.
• March 31, 2011
• [abradford] - Updated BusyBox to version 1.18.4.
• [abradford] - Updated GCC to version 4.6.0.
• [abradford] - Updated MPC to version 0.9.
• [abradford] - Updated zlib to version 1.2.5.
• [abradford] - Updated Linux kernel to version 2.6.38.2.
• [abradford] - Require Gawk 3.1 or greater because of Iana-Etc requirements.
• [abradford] - Updated "What Now?" section to include CBLFS link. Thanks go to Adrian Grigo.
• [abradford] - Link ${CLFS}/etc/init.d/rcS to ${CLFS}/etc/rc.d/startup so that BusyBox's init can find the
startup scripts.
• [abradford] - Updated mdev configuration such that video output is disabled by default to ensure no errors if
video is not available.
• March 23, 2011
• [abradford] - Remove mknod commands as mdev takes care of creating all required entries in /dev
automatically.
• [abradford] - Moved change ownership section to be as late in the book as possible and only operate on a copy
of the file system.
• March 18, 2011
• [abradford] - Copy libgcc library to target as it's needed by at least e2fsprogs.
• March 7, 2011
• [abradford] - Added optional information for building C++ compiler.
• [abradford] - Updated bootscripts install target and package contents to match current bootscripts.
• February 24, 2011
• [abradford] - Added --disable-multilib to GCC builds.
• February 10, 2011
• [abradford] - Changed GCC Static and Final to build GCC for ${CLFS_ABI} for ARM and MIPS,
${CLFS_CPU} for x86. This removes the need for using the ${BUILD} variable when building packages.
• [abradford] - Updated Resources section.
• January 30, 2011
• [abradford] - Updated MPFR download link.
• [abradford] - Updated GCC to version 4.5.2.
xiii
Cross-Compiled Linux From Scratch - Embedded - Version GIT-20190419-arm
Cross-LFS Acknowledgements
The CLFS team would like to acknowledge people who have assisted in making the book what it is today.
Our Leaders:
• Ryan Oliver - Build Process Developer.
• Joe Ciccone - Lead Developer.
• Jim Gifford - Lead Developer.
xiv
Cross-Compiled Linux From Scratch - Embedded - Version GIT-20190419-arm
Errata
The software used to create a CLFS system is constantly being updated and enhanced. Security warnings and bug
fixes may become available after the CLFS book has been released. Once a release of the CLFS Embedded book is
made, this page will provide a link to the CLFS Embedded errata page.
xv
Cross-Compiled Linux From Scratch - Embedded - Version GIT-20190419-arm
Part I. Introduction
Cross-Compiled Linux From Scratch - Embedded - Version GIT-20190419-arm
Chapter 1. Introduction
1.1. How to Build a CLFS System
The CLFS system will be built by using a previously installed Linux distribution (such as Debian, Fedora, Mandriva,
SUSE, or Ubuntu). This existing Linux system (the host) will be used as a starting point to provide necessary
programs, including a compiler, linker, and shell, to build the new system. Select the “development” option during
the distribution installation to be able to access these tools.
As an alternative to installing an entire separate distribution onto your machine, you may wish to use the Linux From
Scratch LiveCD. This CD works well as a host system, providing all the tools you need to successfully follow the
instructions in this book. It does also contain source packages and patches for the LFS book, and a copy of the LFS
book, but not the needed packages or book for CLFS. You can still use the CD for building CLFS, but you will need
to download the packages, patches and book separately. You can also look at http://www.linuxfromscratch.org/hints/
downloads/files/lfscd-remastering-howto.txt for infomation on building your own CD, replacing the LFS packages
and book with those for CLFS. Once you have the CD, no network connection or additional downloads are necessary.
For more information about the LFS LiveCD or to download a copy, visit http://www.linuxfromscratch.org/livecd/.
Build Directory, Packages, and Patches of this book describes how to create a temporary build directory and which
packages and patches need to be downloaded to build a CLFS system. Final Preparations discusses the setup for an
appropriate working environment. Please read Final Preparations carefully as it explains several important issues the
developer should be aware of before beginning to work through Constructing Cross-Compile Tools and beyond.
Constructing Cross-Compile Tools explains the installation of cross-compile tools which will be built on the host
but be able to compile programs that run on the target machine. These cross-compile tools will be used to create
the final-system.
The process of building cross-compile tools first involves installing binutils into ${CLFS}/cross-tools, so that we
have an asembler and a linker for our target architecture. GCC is then compiled statically and installed into ${CLFS}/
cross-tools, this cross-compiler is used to build the libc for the final-system. The GCC cross-compiler is then rebuilt
dynamically - this final cross-compiler is what will be used to build the final-system.
In Installing Basic System Software, the full CLFS system is cross-compiled. The system is built using a sysroot
compiler. Sysroot is a parameter passed to binutils and gcc that modifies its default search paths.
To finish the installation, the CLFS-Bootscripts are set up in Setting Up System Bootscripts, and the kernel and
boot loader are set up in Making the CLFS System Bootable. The End contains information on furthering the CLFS
experience beyond this book. After the steps in this book have been implemented, the computer will be ready to
reboot into the new CLFS system.
This is the process in a nutshell. Detailed information on each step is discussed in the following chapters and package
descriptions. Items that may seem complicated will be clarified, and everything will fall into place as the reader
embarks on the CLFS adventure.
2
Cross-Compiled Linux From Scratch - Embedded - Version GIT-20190419-arm
• Bash-4.0
• Binutils-2.20
• Bzip2-1.0.5
• Coreutils-8.1
• Diffutils-3.0
• Findutils-4.4.0
• Gawk-3.1
• GCC-4.4
• Glibc-2.11
• Grep-2.6
• Gzip-1.3
• M4-1.4.16
• Make-3.81
• ncurses5
• Patch-2.6
• Sed-4.2.1
• Sudo-1.7.4p4
• Tar-1.23
• Texinfo-4.13
3
Cross-Compiled Linux From Scratch - Embedded - Version GIT-20190419-arm
To see whether your host system has all the appropriate versions, run the following:
EOF
bash version-check.sh
1.3. Resources
1.3.1. FAQ
If during the building of the CLFS system you encounter any errors, have any questions, or think there is a typo in the
book, please start by consulting the Frequently Asked Questions (FAQ) that is located at http://trac.clfs.org/wiki/faq.
For information on the different lists, how to subscribe, archive locations, and additional information, visit http://
trac.clfs.org/wiki/lists.
4
Cross-Compiled Linux From Scratch - Embedded - Version GIT-20190419-arm
1.3.3. IRC
Several members of the CLFS community offer assistance on our community Internet Relay Chat (IRC) network.
Before using this support, please make sure that your question is not already answered in the CLFS FAQ or the
mailing list archives. You can find the IRC network at chat.freenode.net. The support channel for cross-lfs
is named #cross-lfs. If you need to show people the output of your problems, please use http://pastebin.clfs.org and
reference the pastebin URL when asking your questions.
1.4. Help
If an issue or a question is encountered while working through this book, check the FAQ page at http://trac.clfs.org/
wiki/faq#generalfaq. Questions are often already answered there. If your question is not answered on this page, try
to find the source of the problem. The following hint will give you some guidance for troubleshooting: http://www.
linuxfromscratch.org/hints/downloads/files/errors.txt.
We also have a wonderful CLFS community that is willing to offer assistance through the mailing lists and IRC (see
the Section 1.3, “Resources” section of this book). However, we get several support questions everyday and many
of them can be easily answered by going to the FAQ and by searching the mailing lists first. So for us to offer the
best assistance possible, you need to do some research on your own first. This allows us to focus on the more unusual
support needs. If your searches do not produce a solution, please include all relevant information (mentioned below)
in your request for help.
• The version of the book being used (in this case CLFS Embedded GIT-20190419)
• The host distribution and version being used to create CLFS.
• The architecture of the host and target.
• The value of the ${CLFS_TARGET}, and ${BUILD} environment variables.
• The package or section in which the problem was encountered.
• The exact error message or symptom received. See Section 1.4.3, “Compilation Problems” below for an
example.
• Note whether you have deviated from the book at all. A package version change or even a minor change to any
command is considered deviation.
5
Cross-Compiled Linux From Scratch - Embedded - Version GIT-20190419-arm
Note
Deviating from this book does not mean that we will not help you. After all, the CLFS project is about
personal preference. Be upfront about any changes to the established procedure—this helps us evaluate and
determine possible causes of your problem.
gcc -DALIASPATH=\"/mnt/clfs/usr/share/locale:.\"
-DLOCALEDIR=\"/mnt/clfs/usr/share/locale\"
-DLIBDIR=\"/mnt/clfs/usr/lib\"
-DINCLUDEDIR=\"/mnt/clfs/usr/include\" -DHAVE_CONFIG_H -I. -I.
-g -O2 -c getopt1.c
gcc -g -O2 -static -o make ar.o arscan.o commands.o dir.o
expand.o file.o function.o getopt.o implicit.o job.o main.o
misc.o read.o remake.o rule.o signame.o variable.o vpath.o
default.o remote-stub.o version.o opt1.o
-lutil job.o: In function `load_too_high':
/clfs/tmp/make-3.79.1/job.c:1565: undefined reference
to `getloadavg'
collect2: ld returned 1 exit status
make[2]: *** [make] Error 1
make[2]: Leaving directory `/clfs/tmp/make-3.79.1'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/clfs/tmp/make-3.79.1'
make: *** [all-recursive-am] Error 2
In this case, many people would just include the bottom section:
This is not enough information to properly diagnose the problem because it only notes that something went wrong,
not what went wrong. The entire section, as in the example above, is what should be saved because it includes the
command that was executed and the associated error message(s).
An excellent article about asking for help on the Internet is available online at http://catb.org/~esr/faqs/smart-
questions.html. Read and follow the hints in this document to increase the likelihood of getting the help you need.
6
Cross-Compiled Linux From Scratch - Embedded - Version GIT-20190419-arm
export CLFS=/mnt/clfs
Ensure that this new directory has permissions that are not too restrictive such that you can write to it as a non-root
user. Depending on the location of the CLFS directory, you may need to do this as the root user:
Downloaded packages and patches will need to be stored somewhere that is conveniently available throughout the
entire build. A working directory is also required to unpack the sources and build them. ${CLFS}/sources can
be used both as the place to store the tarballs and patches and as a working directory.
Create a directory to store the sources:
mkdir -v ${CLFS}/sources
8
Cross-Compiled Linux From Scratch - Embedded - Version GIT-20190419-arm
9
Cross-Compiled Linux From Scratch - Embedded - Version GIT-20190419-arm
10
Cross-Compiled Linux From Scratch - Embedded - Version GIT-20190419-arm
11
Cross-Compiled Linux From Scratch - Embedded - Version GIT-20190419-arm
Grant clfs full access to ${CLFS} by making clfs the directory's owner. You may need to do this as the root user:
sudo chown -Rv clfs ${CLFS}
Next, login as user clfs. This can be done via a virtual console, through a display manager, or with the following
substitute user command:
su - clfs
The “-” instructs su to start a login shell as opposed to a non-login shell. The difference between these two types of
shells can be found in detail in bash(1) and info bash.
12
Cross-Compiled Linux From Scratch - Embedded - Version GIT-20190419-arm
The LC_ALL variable controls the localization of certain programs, making their messages follow the conventions
of a specified country. If the host system uses a version of Glibc older than 2.2.4, having LC_ALL set to something
other than “POSIX” or “C” (during this chapter) may cause issues.
By putting ${CLFS}/cross-tools/bin at the beginning of the PATH, the cross-compiler built in Constructing
Cross-Compile Tools will be picked up by the build process for the temp-system packages before anything that may
be installed on the host. This, combined with turning off hashing, helps to ensure that you will be using the cross-
compile tools to build the temp-system in /tools.
Finally, to have the environment fully prepared for building the temporary tools, source the just-created user profile:
source ~/.bash_profile
13
Cross-Compiled Linux From Scratch - Embedded - Version GIT-20190419-arm
Several of the packages are patched before compilation, but only when the patch is needed to circumvent a problem
or supply a default configuration. Warning messages about offset or fuzz may also be encountered when applying a
patch. Do not worry about these warnings, as the patch was still successfully applied.
During the compilation of most packages, there will be several warnings that scroll by on the screen. These are normal
and can safely be ignored. These warnings are as they appear—warnings about deprecated, but not invalid, use of
the C or C++ syntax. C standards change fairly often, and some packages still use the older standard. This is not a
problem, but does prompt the warning.
Important
After installing each package, both in this and the next chapters, delete its source and build directories,
unless specifically instructed otherwise.
15
Cross-Compiled Linux From Scratch - Embedded - Version GIT-20190419-arm
If your target CPU has hardware floating point support (not all ARM CPUs do), then set the following CLFS_FLOAT
variable to either "hard" or "softfp". Use "softfp" if you need to integrate binaries compiled with "soft". Use "hard"
if you don't. If your target CPU does not have hard floating point support, set the following CLFS_FLOAT vairable
to "soft".
If you chose either "hard" or "softfp" for CLFS_FLOAT, you now need to set which floating point hardware is actually
included (see table below) with your ARM CPU:
export CLFS_ARCH=arm
export CLFS_ARM_ARCH="[architecture]"
16
Cross-Compiled Linux From Scratch - Embedded - Version GIT-20190419-arm
Now we will add this to ~/.bashrc, just in case you have to exit and restart building later:
mkdir -p ${CLFS}/cross-tools/${CLFS_TARGET}
ln -sfv . ${CLFS}/cross-tools/${CLFS_TARGET}/usr
17
Cross-Compiled Linux From Scratch - Embedded - Version GIT-20190419-arm
4.5. Linux-Headers-4.9.22
The Linux Kernel contains a make target that installs “sanitized” kernel headers.
make mrproper
make ARCH=${CLFS_ARCH} headers_check
make ARCH=${CLFS_ARCH} INSTALL_HDR_PATH=${CLFS}/cross-tools/${CLFS_TARGET} header
Short Descriptions
${CLFS}/cross-tools/ The Linux API headers
${CLFS_TARGET}/include/{asm,asm-
generic,drm,linux,mtd,rdma,scsi,sound,video,xen}/
*.h
18
Cross-Compiled Linux From Scratch - Embedded - Version GIT-20190419-arm
4.6. Binutils-2.27
The Binutils package contains a linker, an assembler, and other tools for handling object files.
mkdir -v ../binutils-build
cd ../binutils-build
Prepare Binutils for compilation:
../binutils-2.27/configure \
--prefix=${CLFS}/cross-tools \
--target=${CLFS_TARGET} \
--with-sysroot=${CLFS}/cross-tools/${CLFS_TARGET} \
--disable-nls \
--disable-multilib
The meaning of the configure options:
--prefix=${CLFS}/cross-tools
This tells the configure script to prepare to install the package in the ${CLFS}/cross-tools directory.
--target=${CLFS_TARGET}
This creates a cross-architecture executable that creates files for ${CLFS_TARGET} but runs on the host system.
--with-sysroot=${CLFS}/cross-tools/${CLFS_TARGET}
This tells configure that ${CLFS} is going to be the root of our system. It will now use the specified sysroot,
${CLFS}, as a prefix of the default search paths.
--disable-nls
This disables internationalization as i18n is not needed for the cross-compile tools.
--disable-multilib
This option disables the building of a multilib capable binutils.
Compile the package:
make configure-host
make
The meaning of the make options:
configure-host
This checks the host environment and makes sure all the necessary tools are available to compile Binutils.
Install the package:
make install
19
Cross-Compiled Linux From Scratch - Embedded - Version GIT-20190419-arm
Short Descriptions
addr2line Translates program addresses to file names and line numbers; given an address and the name of an
executable, it uses the debugging information in the executable to determine which source file and
line number are associated with the address
ar Creates, modifies, and extracts from archives
as An assembler that assembles the output of gcc into object files
c++filt Used by the linker to de-mangle C++ and Java symbols and to keep overloaded functions from
clashing
elfedit Examine and modify ELF metadata within an ELF object
gprof Displays call graph profile data
ld A linker that combines a number of object and archive files into a single file, relocating their data
and tying up symbol references
nm Lists the symbols occurring in a given object file
objcopy Copy the contents of one object file to another
objdump Displays information about the given object file, with options controlling the particular information
to display; the information shown is useful to programmers who are working on the compilation
tools
ranlib Generates an index of the contents of an archive and stores it in the archive; the index lists all of the
symbols defined by archive members that are relocatable object files
readelf Displays information about ELF type binaries
size Lists the section sizes and the total size for the given object files
strings Outputs, for each given file, the sequences of printable characters that are of at least the specified
length (defaulting to four); for object files, it prints, by default, only the strings from the initializing
and loading sections while for other types of files, it scans the entire file
strip Discards symbols from object files
libiberty Contains routines used by various GNU programs, including getopt, obstack, strerror, strtol, and
strtoul
libbfd The Binary File Descriptor library
libopcodes A library for dealing with opcodes—the “readable text” versions of instructions for the processor;
it is used for building utilities like objdump.
20
Cross-Compiled Linux From Scratch - Embedded - Version GIT-20190419-arm
4.7.1. Installation of Cross GCC Compiler with Static libgcc and no Threads
GCC requires the GMP, MPFR, and MPC packages to either be present on the host or to be present in source form
within the gcc source tree. Unpack these into the GCC directory after unpacking GCC:
tar xf ../mpfr-3.1.4.tar.bz2
mv -v mpfr-3.1.4 mpfr
tar xf ../gmp-6.1.1.tar.bz2
mv -v gmp-6.1.1 gmp
tar xf ../mpc-1.0.3.tar.gz
mv -v mpc-1.0.3 mpc
The GCC documentation recommends building GCC outside of the source directory in a dedicated build directory:
mkdir -v ../gcc-build
cd ../gcc-build
../gcc-6.2.0/configure \
--prefix=${CLFS}/cross-tools \
--build=${CLFS_HOST} \
--host=${CLFS_HOST} \
--target=${CLFS_TARGET} \
--with-sysroot=${CLFS}/cross-tools/${CLFS_TARGET} \
--disable-nls \
--disable-shared \
--without-headers \
--with-newlib \
--disable-decimal-float \
--disable-libgomp \
--disable-libmudflap \
--disable-libssp \
--disable-libatomic \
--disable-libquadmath \
--disable-threads \
--enable-languages=c \
--disable-multilib \
--with-mpfr-include=$(pwd)/../gcc-6.2.0/mpfr/src \
--with-mpfr-lib=$(pwd)/mpfr/src/.libs \
--with-arch=${CLFS_ARM_ARCH} \
--with-float=${CLFS_FLOAT} \
--with-fpu=${CLFS_FPU}
21
Cross-Compiled Linux From Scratch - Embedded - Version GIT-20190419-arm
--prefix=${CLFS}/cross-tools
This tells the configure script to prepare to install the package in the ${CLFS}/cross-tools directory.
--build=${CLFS_HOST}
This tells the configure script the triplet to use to build GCC. It will use ${CLFS_HOST} as that's where it's
being built.
--host=${CLFS_HOST}
This tells the configure script the triplet of the machine GCC will be executed on when actually cross compiling.
It will use ${CLFS_HOST} as that's where GCC will execute when cross compiling software later.
--target=${CLFS_TARGET}
This tells the configure script the triplet of the machine GCC will build executables for. It will use
${CLFS_TARGET} so that software compiled with this version of GCC can be executed on the embedded
machine target.
--with-sysroot=${CLFS}/cross-tools/${CLFS_TARGET}
This tells configure that ${CLFS}/cross-tools/${CLFS_TARGET} is going to be the temporary root of our
system. It will now use the specified sysroot as a prefix of the default search paths.
--disable-nls
This disables internationalization as i18n is not needed for the cross-compile tools.
--disable-shared
Disables the creation of the shared libraries.
--without-headers
Tells configure to not use any headers from any C libraries. This is needed as we haven't yet built the C library
and to prevent influence from the host environment.
--with-newlib
Tells configure to build libgcc without needing any C libraries.
--disable-decimal-float
Tells configure to disable IEEE 754-2008 decimal floating point support. Decimal floating point support isn't
needed yet.
--disable-libgomp
Tells configure to not build the GOMP run-time libraries. GOMP is the GNU implementation of OpenMP, a
API for shared-memory parallel programming.
--disable-libmudflap
Tells configure to not build libmudflap. Mudflap is a library that can be used to help check for proper pointer
usage.
--disable-libssp
Tells configure not to build run-time libraries for stack smashing detection.
--disable-libatomic
Tells configure not to build atomic operations.
--disable-libquadmath
Tells configure not to build quad math operations.
22
Cross-Compiled Linux From Scratch - Embedded - Version GIT-20190419-arm
--disable-threads
This will prevent GCC from looking for the multi-thread include files, since they haven't been created for this
architecture yet. GCC will be able to find the multi-thread information after the glibc headers are created.
--enable-languages=c
This option ensures that only the C compiler is built.
--disable-multilib
This option specifies that multiple target libraries should not be built.
--with-mpfr-include=$(pwd)/../gcc-6.2.0/mpfr/src
Tells configure how to find the mpfr headers.
--with-mpfr-lib=$(pwd)/mpfr/src/.libs
Tells configure to use the mpfr libraries built within the GCC build directory. This happens automatically but is
needed to prevent GCC from searching the host's normal library paths.
--with-arch=${CLFS_ARM_ARCH}
This option sets the ARM architecture selected earlier.
--with-float=${CLFS_FLOAT}
This option sets the floating point mode selected earlier.
--with-fpu=${CLFS_FPU}
This option sets the hardware floating point type selected earlier. If soft floating point was selected, this value
is ignored.
Continue with compiling the package:
23
Cross-Compiled Linux From Scratch - Embedded - Version GIT-20190419-arm
4.8. musl-1.1.16
The musl package contains the main C library. This library provides the basic routines for allocating memory,
searching directories, opening and closing files, reading and writing files, string handling, pattern matching,
arithmetic, and so on.
./configure \
CROSS_COMPILE=${CLFS_TARGET}- \
--prefix=/ \
--target=${CLFS_TARGET}
make
Short Descriptions
ld-musl The musl dynamic linker / loader
libc The C library
libcrypt The cryptographic library
libdl The musl dynamic linker / loader library
libm The math library
libpthread The POSIX thread library
librt The clock and timer library
24
Cross-Compiled Linux From Scratch - Embedded - Version GIT-20190419-arm
Note
If you would like to build a C++ compiler in addition to the C compiler, change the following --enable-
languages=c option to be --enable-languages=c,c++ instead. A C++ compiler is not required for any of the
software included in this book.
../gcc-6.2.0/configure \
--prefix=${CLFS}/cross-tools \
--build=${CLFS_HOST} \
--host=${CLFS_HOST} \
--target=${CLFS_TARGET} \
--with-sysroot=${CLFS}/cross-tools/${CLFS_TARGET} \
--disable-nls \
--enable-languages=c \
--enable-c99 \
--enable-long-long \
--disable-libmudflap \
--disable-multilib \
--with-mpfr-include=$(pwd)/../gcc-6.2.0/mpfr/src \
--with-mpfr-lib=$(pwd)/mpfr/src/.libs \
--with-arch=${CLFS_ARM_ARCH} \
--with-float=${CLFS_FLOAT} \
--with-fpu=${CLFS_FPU}
The meaning of the configure options not used previously:
--enable-c99
Enable C99 support for C programs.
25
Cross-Compiled Linux From Scratch - Embedded - Version GIT-20190419-arm
--enable-long-long
Enables long long support in the compiler.
Continue with compiling the package:
make
make install
Short Descriptions
gcc The C compiler
gcov A coverage testing tool; it is used to analyze programs to determine where optimizations will have the
most effect
libgcc Contains run-time support for gcc
26
Cross-Compiled Linux From Scratch - Embedded - Version GIT-20190419-arm
27
Cross-Compiled Linux From Scratch - Embedded - Version GIT-20190419-arm
29
Cross-Compiled Linux From Scratch - Embedded - Version GIT-20190419-arm
In order for user root to be able to login and for the name “root” to be recognized, there must be relevant entries
in the /etc/passwd and /etc/group files.
The actual password for root (the “::” used here is just a placeholder and allow you to login with no password)
will be set later.
Additional optional users you may want to add:
bin:x:1:1:bin:/bin:/bin/false
Can be useful for compatibility with legacy applications.
daemon:x:2:6:daemon:/sbin:/bin/false
It is often recommended to use an unprivileged User ID/Group ID for daemons in order to limit their access
to the system.
adm:x:3:16:adm:/var/adm:/bin/false
Was used for programs that performed administrative tasks.
lp:x:10:9:lp:/var/spool/lp:/bin/false
Used by programs for printing.
mail:x:30:30:mail:/var/mail:/bin/false
Often used by email programs.
news:x:31:31:news:/var/spool/news:/bin/false
Often used for network news servers.
uucp:x:32:32:uucp:/var/spool/uucp:/bin/false
Often used for Unix-to-Unix Copy of files from one server to the next
operator:x:50:0:operator:/root:/bin/ash
Often used to allow system operators to access the system.
postmaster:x:51:30:postmaster:/var/spool/mail:/bin/false
Generally used as an account that receives all the information of troubles with the mail server.
nobody:x:65534:65534:nobody:/:/bin/false
Used by NFS.
30
Cross-Compiled Linux From Scratch - Embedded - Version GIT-20190419-arm
adm:x:16:root,adm,daemon
All users in this group are allowed to do administrative tasks
console:x:17:
This group has direct access to the console
cdrw:x:18:
This group is allowed to use the CDRW drive
mail:x:30:mail
Used by MTAs (Mail Transport Agents)
news:x:31:news
Used by Network News Servers
uucp:x:32:uucp
Used by the Unix-to-Unix copy users
users:x:100:
The default GID used by shadow for new users
nogroup:x:65533:
This is a default group used by some programs that do not require a group
nobody:x:65534:
This is used by NFS
The created groups are not part of any standard—they are groups decided on in part by the requirements of BusyBox
later in this chapter, and in part by common convention employed by a number of existing Linux distributions. The
Linux Standard Base (LSB, available at http://www.linuxbase.org) recommends only that, besides the group root
31
Cross-Compiled Linux From Scratch - Embedded - Version GIT-20190419-arm
with a Group ID (GID) of 0, a group bin with a GID of 1 be present. All other group names and GIDs can be chosen
freely by the system administrator since well-written programs do not depend on GID numbers, but rather use the
group's name.
The login, agetty, and init programs (and others) use the lastlog file to record information such as who was logged
into the system and when. However, these programs will not write to the lastlog file if it does not already exist.
Initialize the lastlog file and give it proper permissions:
touch ${CLFS}/targetfs/var/log/lastlog
chmod -v 664 ${CLFS}/targetfs/var/log/lastlog
32
Cross-Compiled Linux From Scratch - Embedded - Version GIT-20190419-arm
5.4. libgcc-6.2.0
When compiling dynamically linked software using GCC, GCC requires that libgcc be able to be loaded during
runtime when executing the software. Hence, we must be sure to provide the final system with a copy of the libgcc
we previously built for our cross tools.
cp -v ${CLFS}/cross-tools/${CLFS_TARGET}/lib/libgcc_s.so.1 ${CLFS}/targetfs/lib/
${CLFS_TARGET}-strip ${CLFS}/targetfs/lib/libgcc_s.so.1
33
Cross-Compiled Linux From Scratch - Embedded - Version GIT-20190419-arm
5.5. musl-1.1.16
The musl package contains the main C library. This library provides the basic routines for allocating memory,
searching directories, opening and closing files, reading and writing files, string handling, pattern matching,
arithmetic, and so on. We build it again here so that it can be installed into our targetfs sysroot but this time we only
build the shared object version.
./configure \
CROSS_COMPILE=${CLFS_TARGET}- \
--prefix=/ \
--disable-static \
--target=${CLFS_TARGET}
make
34
Cross-Compiled Linux From Scratch - Embedded - Version GIT-20190419-arm
5.6. BusyBox-1.24.2
BusyBox combines tiny versions of many common UNIX utilities into a single small executable. It provides
replacements for most of the utilities you usually find in GNU fileutils, shellutils, etc. The utilities in BusyBox
generally have fewer options than their full-featured GNU cousins; however, the options that are included provide
the expected functionality and behave very much like their GNU counterparts. BusyBox provides a fairly complete
environment for any small or embedded system.
make distclean
Note
We tell BusyBox to use the generic defconfig. For those who are more adventurous, you can use make
menuconfig, and create a custom or modified configuration for your build.
Disable building both ifplugd and inetd as they both have issues building against musl:
Disable the use of ipsvd for both TCP and UDP as it has issues building against musl (similar to inetd's issues):
If you're going to build your kernel with modules, you will need to make sure depmod.pl is available for your host
to execute:
cp -v examples/depmod.pl ${CLFS}/cross-tools/bin
chmod -v 755 ${CLFS}/cross-tools/bin/depmod.pl
35
Cross-Compiled Linux From Scratch - Embedded - Version GIT-20190419-arm
36
Cross-Compiled Linux From Scratch - Embedded - Version GIT-20190419-arm
5.7. iana-etc-2.30
The iana-etc package provides data for network services and protocols.
make get
The following command converts the raw data provided by IANA into the correct formats for the /etc/protocols
and /etc/services data files:
make STRIP=yes
Short Descriptions
/etc/protocols Describes the various DARPA Internet protocols that are available from the TCP/IP
subsystem
/etc/services Provides a mapping between friendly textual names for internet services, and their underlying
assigned port numbers and protocol types
37
Cross-Compiled Linux From Scratch - Embedded - Version GIT-20190419-arm
You may add any other file systems, such as swap or other partitions or network file systems, to this fstab if you wish.
38
Cross-Compiled Linux From Scratch - Embedded - Version GIT-20190419-arm
6.3. Linux-4.9.22
The Linux package contains the Linux kernel.
Note
Since you are building for an embedded system make sure all key components are built into the kernel
and not as modules. The key components are console/video, disk, and network. Without these built in, the
system will not function properly. It is recommended to configure the kernel without modules in order to
conserve disk space and to reduce the complexity of booting.
Note
If you are using the u-boot bootloader, creating a uImage type kernel is recommended. Install the u-boot
tools (not documented here) and append "uImage" when compiling the kernel.
39
Cross-Compiled Linux From Scratch - Embedded - Version GIT-20190419-arm
The resulting kernel will be located within the arch/${CLFS_ARCH}/boot. There may be more than one
version of the same kernel, simply with different compression or bootloader helpers added. Follow your bootloader's
instructions on how to copy the kernel to the final system.
Short Descriptions
.config Contains all the configuration selections for the kernel
zImage, uImage, bzImage, vmlinux The compiled Linux kernel.
System.map A list of addresses and symbols; it maps the entry points and
addresses of all the functions and data structures in the kernel.
Useful for debugging, sometimes.
40
Cross-Compiled Linux From Scratch - Embedded - Version GIT-20190419-arm
6.4. Bootloaders
There are many different bootloaders. Creating detailed instructions on how to use even the more popular ones is
difficult as each architecture and board often has different levels of support or configuration options within each
bootloader. Often, development kits will ship with a bootloader already configured, if your board comes with a
bootloader pre-configured, it's best to start using that and then venture on to building the bootloader yourself later.
A few of the popular bootloaders include:
Barebox
http://barebox.org/
CoLo
http://www.colonel-panic.org/cobalt-mips/
GNU GRUB
https://www.gnu.org/software/grub/
Syslinux
http://www.syslinux.org/wiki/index.php/The_Syslinux_Project
u-boot
http://www.denx.de/wiki/U-Boot
41
Cross-Compiled Linux From Scratch - Embedded - Version GIT-20190419-arm
42
Cross-Compiled Linux From Scratch - Embedded - Version GIT-20190419-arm
Short Descriptions
functions Contains common functions, such as error and status checking, that are used by several bootscripts
startup Performs all startup script operations
shutdown Performs all shutdown operations
syslog Starts and stops the system log daemons
43
Cross-Compiled Linux From Scratch - Embedded - Version GIT-20190419-arm
# Devices:
# Syntax: %s %d:%d %s
# devices user:group mode
# null does already exist; therefore ownership has to be changed with command
null root:root 0666 @chmod 666 $MDEV
zero root:root 0666
grsec root:root 0660
full root:root 0666
# console does already exist; therefore ownership has to be changed with command
#console root:tty 0600 @chmod 600 $MDEV && mkdir -p vc && ln -sf ../$MDEV vc/0
console root:tty 0600 @mkdir -pm 755 fd && cd fd && for x in 0 1 2 3 ; do ln -sf
# ram.*
ram([0-9]*) root:disk 0660 >rd/%1
loop([0-9]+) root:disk 0660 >loop/%1
sd[a-z].* root:disk 0660 */lib/mdev/usbdisk_link
hd[a-z][0-9]* root:disk 0660 */lib/mdev/ide_links
md[0-9] root:disk 0660
44
Cross-Compiled Linux From Scratch - Embedded - Version GIT-20190419-arm
# dri device
card[0-9] root:video 0660 =dri/
# misc stuff
agpgart root:root 0660 >misc/
psaux root:root 0660 >misc/
rtc root:root 0664 >misc/
# input stuff
event[0-9]+ root:root 0640 =input/
mice root:root 0640 =input/
mouse[0-9] root:root 0640 =input/
ts[0-9] root:root 0600 =input/
# v4l stuff
vbi[0-9] root:video 0660 >v4l/
video[0-9] root:video 0660 >v4l/
# dvb stuff
dvb.* root:video 0660 */lib/mdev/dvbdev
# net devices
45
Cross-Compiled Linux From Scratch - Embedded - Version GIT-20190419-arm
# zaptel devices
zap(.*) root:dialout 0660 =zap/%1
dahdi!(.*) root:dialout 0660 =dahdi/%1
# raid controllers
cciss!(.*) root:disk 0660 =cciss/%1
ida!(.*) root:disk 0660 =ida/%1
rd!(.*) root:disk 0660 =rd/%1
# hpilo
hpilo!(.*) root:root 0660 =hpilo/%1
# xen stuff
xvd[a-z] root:root 0660 */lib/mdev/xvd_links
EOF
46
Cross-Compiled Linux From Scratch - Embedded - Version GIT-20190419-arm
# End /etc/profile
EOF
47
Cross-Compiled Linux From Scratch - Embedded - Version GIT-20190419-arm
Now we will create the inittab file for use with our system, please note that if you'd like a login prompt on a serial
console to uncomment enabling of this and verify the serial port device name as many embedded boards have serial
ports which are not named 'ttyS':
::sysinit:/etc/rc.d/startup
# Put a getty on the serial line (for a terminal). Uncomment this line if
# you're using a serial console on ttyS0, or uncomment and adjust it if using a
# serial console on a different serial port.
#::respawn:/sbin/getty -L ttyS0 115200 vt100
::shutdown:/etc/rc.d/shutdown
::ctrlaltdel:/sbin/reboot
EOF
[clfs] needs to be replaced with the name given to the computer. Do not enter the Fully Qualified Domain Name
(FQDN) here. That information will be put in the /etc/hosts file in the next section.
48
Cross-Compiled Linux From Scratch - Embedded - Version GIT-20190419-arm
Unless the computer is to be visible to the Internet (i.e., there is a registered domain and a valid block of assigned
IP addresses—most users do not have this), make sure that the IP address is in the private network IP address range.
Valid ranges are:
Class Networks
A 10.0.0.0
B 172.16.0.0 through 172.31.0.255
C 192.168.0.0 through 192.168.255.255
A valid IP address could be 192.168.1.1. A valid FQDN for this IP could be www.linuxfromscratch.org (not
recommended because this is a valid registered domain address and could cause domain name server issues).
Even if not using a network card, an FQDN is still required. This is necessary for certain programs to operate correctly.
127.0.0.1 localhost
[192.168.1.1] [<HOSTNAME>.example.org] [HOSTNAME]
The [192.168.1.1] and [<HOSTNAME>.example.org] values need to be changed for specific users or
requirements (if assigned an IP address by a network/system administrator and the machine will be connected to an
existing network).
If a network card is not going to be configured, create the /etc/hosts file by running:
49
Cross-Compiled Linux From Scratch - Embedded - Version GIT-20190419-arm
The following command creates the required directories and the interfaces file, assuming DHCP will be used
for eth0:
50
Cross-Compiled Linux From Scratch - Embedded - Version GIT-20190419-arm
For DHCP to work properly with udhcpc, the BusyBox dhcp client, a configuration script is needed. Create a simple
script to assign the provided DHCP address and update /etc/resolv.conf:
[ -z "$1" ] && echo "Error: should be called from udhcpc" && exit 1
RESOLV_CONF="/etc/resolv.conf"
[ -n "$broadcast" ] && BROADCAST="broadcast $broadcast"
[ -n "$subnet" ] && NETMASK="netmask $subnet"
case "$1" in
deconfig)
/sbin/ifconfig $interface 0.0.0.0
;;
renew|bound)
/sbin/ifconfig $interface $ip $BROADCAST $NETMASK
if [ -n "$router" ] ; then
while route del default gw 0.0.0.0 dev $interface ; do
true
done
for i in $router ; do
route add default gw $i dev $interface
done
fi
exit 0
EOF
chmod +x ${CLFS}/targetfs/usr/share/udhcpc/default.script
51
Cross-Compiled Linux From Scratch - Embedded - Version GIT-20190419-arm
53
Cross-Compiled Linux From Scratch - Embedded - Version GIT-20190419-arm
8.4. Zlib-1.2.8
The Zlib package contains compression and decompression routines used by some programs.
make
Copy only the shared library into the target file system and ensure that its symlink is present so the runtime loader
can find it:
cp -v ${CLFS}/cross-tools/${CLFS_TARGET}/lib/libz.so.1.2.8 ${CLFS}/targetfs/lib/
ln -sv libz.so.1.2.8 ${CLFS}/targetfs/lib/libz.so.1
Short Descriptions
libz Contains compression and decompression functions used by some programs
54
Cross-Compiled Linux From Scratch - Embedded - Version GIT-20190419-arm
8.5. Netplug-1.2.9.2
Netplug is a daemon that detects insertion and removal of network cables and reacts to bring up or take down the
network interface.
make
55
Cross-Compiled Linux From Scratch - Embedded - Version GIT-20190419-arm
8.6. Dropbear-2013.60
Dropbear is a relatively small SSH server and client. Dropbear has a small memory footprint suitable for memory-
constrained environments, while still having the same features as OpenSSH. It does not depend on OpenSSL and it
has a MIT style license.
Dropbear depends on zlib.
Configure dropbear:
Note
We are just telling dropbear to use the default configuration plus scp. For those who are more adventurous,
edit options.h to further configure dropbear.
make MULTI=1 \
PROGRAMS="dropbear dbclient dropbearkey dropbearconvert scp"
make MULTI=1 \
PROGRAMS="dropbear dbclient dropbearkey dropbearconvert scp" \
install DESTDIR=${CLFS}/targetfs
56
Cross-Compiled Linux From Scratch - Embedded - Version GIT-20190419-arm
Note
There are options that can be passed to make and make install that will reduce the size and functionality
of the Wireless Tools. See the Wireless Tools INSTALL file for more information.
make PREFIX=${CLFS}/targetfs/usr
57
Cross-Compiled Linux From Scratch - Embedded - Version GIT-20190419-arm
Important
The commands on this page of the book must be performed while logged in as root. Check that ${CLFS}
is still set:
echo ${CLFS}
The following file should not to belong to the root group, it should belong to the utmp group (group 13):
chgrp -v 13 ${CLFS}/targetfs/var/log/lastlog
Now you can move your compressed tarball to your target system. This will be different on every embedded device.
When uncompressing the tarball, make sure to pass tar the "-p" switch to ensure permissions are preserved.
59
Cross-Compiled Linux From Scratch - Embedded - Version GIT-20190419-arm
60
Cross-Compiled Linux From Scratch - Embedded - Version GIT-20190419-arm
61
Cross-Compiled Linux From Scratch - Embedded - Version GIT-20190419-arm
Libraries
Index
libbfd: 19, 20
libc: 24, 24
Packages libcrypt: 24, 24
libdl: 24, 24
Binutils
libgcc*: 25, 26
cross tools: 19
libiberty: 19, 20
Bootscripts: 43
libm: 24, 24
BusyBox: 35
libopcodes: 19, 20
Dropbear: 56
libpthread: 24, 24
GCC
librt: 24, 24
cross tools, final: 25
libz: 54, 54
cross tools, static: 21
iana-etc: 37
musl Scripts
cross tools: 24 functions: 43, 43
final system: 34 localnet
libgcc /etc/hosts: 48
final system: 33 configuring: 48
Linux: 39 network
Linux-Headers: 18 /etc/hosts: 48
mdev: 44 configuring: 49
Netplug: 55 shutdown: 43, 43
wireless_tools: 57 startup: 43, 43
Zlib: 54 syslog: 43, 43
Programs Others
addr2line: 19, 20 /usr/include/{asm,linux}/*.h: 18, 18
ar: 19, 20 /etc/fstab: 38
as: 19, 20 /etc/group: 29
c++filt: 19, 20 /etc/hosts: 48
elfedit: 19, 20 /etc/inittab: 47
gcc: 25, 26 /etc/mdev.conf: 44
gcov: 25, 26 /etc/passwd: 29
gprof: 19, 20 /etc/profile: 47
ld: 19, 20 /etc/protocols: 37
ld-musl: 24, 24 /etc/services: 37
nm: 19, 20 /var/log/lastlog: 29
objcopy: 19, 20
objdump: 19, 20
ranlib: 19, 20
readelf: 19, 20
size: 19, 20
strings: 19, 20
strip: 19, 20
62