Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases now! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Mastering Embedded Linux Programming

You're reading from   Mastering Embedded Linux Programming Create fast and reliable embedded solutions with Linux 5.4 and the Yocto Project 3.1 (Dunfell)

Arrow left icon
Product type Paperback
Published in May 2021
Publisher Packt
ISBN-13 9781789530384
Length 758 pages
Edition 3rd Edition
Languages
Tools
Arrow right icon
Authors (2):
Arrow left icon
Frank Vasquez Frank Vasquez
Author Profile Icon Frank Vasquez
Frank Vasquez
Mr. Chris Simmonds Mr. Chris Simmonds
Author Profile Icon Mr. Chris Simmonds
Mr. Chris Simmonds
Arrow right icon
View More author details
Toc

Table of Contents (27) Chapters Close

Preface 1. Section 1: Elements of Embedded Linux
2. Chapter 1: Starting Out FREE CHAPTER 3. Chapter 2: Learning about Toolchains 4. Chapter 3: All about Bootloaders 5. Chapter 4: Configuring and Building the Kernel 6. Chapter 5: Building a Root Filesystem 7. Chapter 6: Selecting a Build System 8. Chapter 7: Developing with Yocto 9. Chapter 8: Yocto Under the Hood 10. Section 2: System Architecture and Design Decisions
11. Chapter 9: Creating a Storage Strategy 12. Chapter 10: Updating Software in the Field 13. Chapter 11: Interfacing with Device Drivers 14. Chapter 12: Prototyping with Breakout Boards 15. Chapter 13: Starting Up – The init Program 16. Chapter 14: Starting with BusyBox runit 17. Chapter 15: Managing Power 18. Section 3: Writing Embedded Applications
19. Chapter 16: Packaging Python 20. Chapter 17: Learning about Processes and Threads 21. Chapter 18: Managing Memory 22. Section 4: Debugging and Optimizing Performance
23. Chapter 19: Debugging with GDB 24. Chapter 20: Profiling and Tracing 25. Chapter 21: Real-Time Programming 26. Other Books You May Enjoy

Obtaining the hardware for this book

The examples in this book are intended to be generic, but to make them relevant and easy to follow, I have had to choose specific hardware. I have chosen three exemplar devices: the Raspberry Pi 4, the BeagleBone Black, and QEMU. The first is by far the most popular Arm-based single board computer on the market. The second is a widely available and cheap development board that can be used in serious embedded hardware. The third is a machine emulator that can be used to create a range of systems that are typical of embedded hardware. It was tempting to use QEMU exclusively, but, like all emulations, it is not quite the same as the real thing. Using the Raspberry Pi 4 and BeagleBone Black, you have the satisfaction of interacting with real hardware and seeing real LEDs flash. While the BeagleBone Black is several years old now, it remains open source hardware (unlike the Raspberry Pi). This means that the board design materials are freely available for anyone to build a BeagleBone Black or derivative into their products.

In any case, I encourage you to try out as many of the examples as you can, using either of these three platforms, or indeed any embedded hardware you may have to hand.

The Raspberry Pi 4

At the time of writing, the Raspberry Pi 4 Model B is the flagship tiny, dual-display, desktop computer produced by the Raspberry Pi Foundation. Their website is
https://raspberrypi.org/. The Pi 4's technical specs include the following:

  • A Broadcom BCM2711 1.5 GHz quad-core Cortex-A72 (Arm® v8) 64-bit SoC
  • 2, 4, or 8 GiB DDR4 RAM
  • 2.4 GHz and 5.0 GHz 802.11ac wireless, Bluetooth 5.0, BLE
  • A serial port for debug and development
  • A MicroSD slot, which can be used as the boot device
  • A USB-C connector that is used to power the board
  • 2 × full size USB 3.0 and 2 × full size USB 2.0 host ports
  • A Gigabit Ethernet port
  • 2 × micro-HDMI ports for video and audio output

In addition, there is a 40-pin expansion header for which there are a great variety of daughter boards, known as HATs (Hardware Attached on Top), that allow you to adapt the board to do many different things. However, you will not need any HATs for the examples in this book. Instead, you will make use of the Pi 4's built-in Wi-Fi and Bluetooth (which the BeagleBone Black lacks).

In addition to the board itself, you will require the following:

  • A 5V USB-C power supply capable of delivering 3 A or more
  • A USB to TTL serial cable with 3.3V logic-level pins like the Adafruit 954
  • A MicroSD card and a means of writing to it from your development PC or laptop, which will be needed to load software onto the board
  • An Ethernet cable and a router to connect it to, as some of the examples require network connectivity

Next is the BeagleBone Black.

The BeagleBone Black

The BeagleBone and the later BeagleBone Black are open hardware designs for a small, credit card-sized development board produced by CircuitCo LLC. The main repository of information is at https://beagleboard.org/. The main points of the specifications are as follows:

  • A TI AM335x 1 GHz Arm® Cortex-A8 Sitara SoC
  • 512 MiB DDR3 RAM
  • 2 or 4 GiB 8-bit eMMC onboard flash storage
  • A serial port for debug and development
  • A MicroSD slot, which can be used as the boot device
  • A Mini-USB OTG client/host port that can also be used to power the board
  • A full size USB 2.0 host port
  • A 10/100 Ethernet port
  • An HDMI port for video and audio output

In addition, there are two 46-pin expansion headers for which there are a great variety of daughter boards, known as capes, which allow you to adapt the board to do many different things. However, you do not need to fit any capes for the examples in this book.

In addition to the board itself, you will require the following:

  • A Mini-USB to USB-A cable (supplied with the board).
  • A serial cable that can interface with the 6-pin 3.3V TTL level signals provided by the board. The BeagleBoard website has links to compatible cables.
  • A MicroSD card and a means of writing to it from your development PC or laptop, which will be needed to load software onto the board.
  • An Ethernet cable and a router to connect it to, as some of the examples require network connectivity.
  • A 5V power supply capable of delivering 1 A or more.

In addition to the above, Chapter 12, Prototyping with Breakout Boards, also requires
the following:

  • A SparkFun model GPS-15193 Breakout board.
  • A Saleae Logic 8 logic analyzer. This apparatus will be used to probe pins for SPI communications between the BeagleBone Black and NEO-M9N.

QEMU

QEMU is a machine emulator. It comes in a number of different flavors, each of which can emulate a processor architecture and a number of boards built using that architecture. For example, we have the following:

  • qemu-system-arm: 32-bit Arm
  • qemu-system-mips: MIPS
  • qemu-system-ppc: PowerPC
  • qemu-system-x86: x86 and x86_64

For each architecture, QEMU emulates a range of hardware, which you can see by using the -machine help option. Each machine emulates most of the hardware that would normally be found on that board. There are options to link hardware to local resources, such as using a local file for the emulated disk drive.

Here is a concrete example:

$ qemu-system-arm -machine vexpress-a9 -m 256M -drive file=rootfs.ext4,sd -net nic -net use -kernel zImage -dtb vexpress- v2p-ca9.dtb -append "console=ttyAMA0,115200 root=/dev/mmcblk0" -serial stdio -net nic,model=lan9118 -net tap,ifname=tap0

The options used in the preceding command line are as follows:

  • -machine vexpress-a9: Creates an emulation of an Arm Versatile Express development board with a Cortex A-9 processor
  • -m 256M: Populates it with 256 MiB of RAM
  • -drive file=rootfs.ext4,sd: Connects the SD interface to the local file rootfs.ext4 (which contains a filesystem image)
  • -kernel zImage: Loads the Linux kernel from the local file named zImage
  • -dtb vexpress-v2p- ca9.dtb: Loads the device tree from the local file vexpress-v2p-ca9.dtb
  • -append "...": Appends this string as the kernel command line
  • -serial stdio: Connects the serial port to the terminal that launched QEMU, usually so that you can log on to the emulated machine via the serial console
  • -net nic,model=lan9118: Creates a network interface
  • -net tap,ifname=tap0: Connects the network interface to the virtual network interface, tap0

To configure the host side of the network, you need the tunctl command from the User Mode Linux (UML) project; on Debian and Ubuntu, the package is named uml-utilites:

$ sudo tunctl -u $(whoami) -t tap0

This creates a network interface named tap0 that is connected to the network controller in the emulated QEMU machine. You configure tap0 in exactly the same way as any other interface.

All of these options are described in detail in the following chapters. I will be using Versatile Express for most of my examples, but it should be easy to use a different machine or architecture.

You have been reading a chapter from
Mastering Embedded Linux Programming - Third Edition
Published in: May 2021
Publisher: Packt
ISBN-13: 9781789530384
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime