Embedded Linux Development - Part 5

dev.to

Until here, I've talked about the embedded Linux development in four stage: toolchain, bootloader, Linux kernel, rootfs. In this tutorial, I will create a SD card image including these and then run it in BeagleBone Black.

Firstly, let's remember that what I've produced from these stages:

  • MLO (second-stage bootloader)

  • u-boot.img (main bootloader)

  • uEnv.txt (commands for the bootloader)

  • zImage (compressed the kernel image)

  • am335x-boneblack.dtb (device tree for the kernel)

  • Debian rootfs (including the kernel modules)

How can I create a SD card image including all of these?

Firstly, I need to create two partitions, one for booting and second for rootfs. So plugin the SD card into the PC (I'm on Ubuntu) and create the partitions:

$ sudo parted -s /dev/sdX mklabel msdos # parition table and partitions

$ sudo parted -s /dev/sdX mkpart primary fat32 1MiB 65MiB # boot partition (FAT32, 64MB)
$ sudo parted -s /dev/sdX set 1 boot on # make it first parititon

$ sudo parted -s /dev/sdX mkpart primary ext4 65MiB 100% # rootfs parititon (ext4, rest of SD card)

$ sudo mkfs.vfat -F 32 -n boot /dev/sdX1 # format the boot partition
$ sudo mkfs.ext4 -L rootfs /dev/sdX2 # format the rootfs partition
Enter fullscreen mode Exit fullscreen mode

In here, I created the "boot" partition which was formatted with FAT32 and "rootfs" partition with ext4. Why did I create two distinct partitions? The first reason is that the kernel loads and runs the rootfs. So the bootloader cannot reside in the rootfs because of the bootloader runs before the kernel. Second reason is that the bootloader works with FAT32 better (even if the FAT32 size is much bigger).

After that, copy the MLO, u-boot.img, uEnv.txt, zImage, am335x-boneblack.dtb into the "boot" partition. Also copy the your rootfs content into the "rootfs" partition.

That's it. The SD card is ready to run the BeagleBone Black. So plugin the SD card and then power up the board. Well how to enter into the Debian rootfs? There is a J1 header besides the P9. It's the serial port. Pin 1 is GND, 4 is RX and 5 is TX. Use FT232R converter to connect these pins to PC.

To see the outputs, open a terminal and the type:

$ screen /dev/ttyUSBX 115200 # or /dev/ttyACMX
Enter fullscreen mode Exit fullscreen mode

Reboot the BeagleBone Black and then you will see the u-boot and the kernel messages. Lastly, you will see the login session:

Type the "root" and the password (you set it in previous tutorial). That's it. You are in the BeagleBone Black terminal.

You can do whatever you want after that 🥳🥳🥳.

In the next tutorial, I will show that how to use ssh command so that you can easily make connection over USB cable, not needing to J1 header.

Resources:

Simmonds C., Mastering Embedded Linux Programming, Packt Publishing, 2015
Embedded Linux system development training, Bootlin, 2024

Source: dev.to

arrow_back Back to News