Linux Kernel Build for DE10nano

Introduction

For low-priced board Terasic DE10 nano with FPGA integrated ARM CPU I will write about how to build and update the Linux Kernel.

Multiple Linux SD card images for this board have been uploaded to the Terasic site, and if you register as a user, you can download and start Linux immediately. While playing with this board, if you try to add the Kernel Driver or configure the FPGA with Debye Tree Overlay, you will want to build the Kernel yourself.

wrap up

If you are accustomed to building embedded Linux, this information should be sufficient.

--Kernel souce - https://github.com/altera-opensource/linux-socfpga --What is the required build process? - make socfpga_defconfig; make zImage; make dtbs - make modules; make modules_install ... ――Where to write the created binaries on the SD card --zImage, socfpga_cyclone5_de0_sockit.dtb-> Replace with the corresponding file in Fat Partition --lib / modules / * directory-> copy under "/" on Linux Partition --Reference: Linux portal site for Intel SoC FPGA RocketBoards.org

Things necessary

--PC for development. The OS is Ubuntu Linux. It will be OK even if it is operating under the following environment. - Virtual Machine - Windows SubSystem for Linux(WSL) - Docker container --Internet access is open. To download Kernel Source etc.

Contents of work

The contents of the SD Card required to operate Linux can be divided into two types: Kernel related and Root File System. Only Kernel related files are built here, and the files of the Root File System are used as they are.

procedure

Refer to the documentation on the Linux portal site RocketBoards.org for Intel SoC FPGAs. https://rocketboards.org/foswiki/Documentation/GSRDCompilingLinux You will be running the Building Linux Kernel part of "5. Building Kernel and U-Boot Separately From Git Trees" in.

Environmental preparation

First, download the cross-compiler and prepare the commands required for Kernel build. For example, if the development PC is Ubuntu 18.04 (64bit) in its original state, the following packages are required at a minimum.

$ sudo apt update
$ sudo apt install -y wget git build-essential bc kmod libncursesw5-dev
$ sudo apt install -y lib32stdc++6 lib32ncurses5 lib32z1 

Cross-compiler download

Download the cross-compiler and set the CROSS_COMPILE environment variable. I'm working under my home directory here, but you can go in any directory you like (in that case, change the PATH set in CROSS_COMPILE accordingly).

$ cd ~
$ wget https://releases.linaro.org/archive/14.04/components/toolchain/binaries/gcc-linaro-arm-linux-gnueabihf-4.8-2014.04_linux.tar.bz2 --no-check-certificate
$ tar xjf gcc-linaro-arm-linux-gnueabihf-4.8-2014.04_linux.tar.bz2
$ export CROSS_COMPILE=~/gcc-linaro-arm-linux-gnueabihf-4.8-2014.04_linux/bin/arm-linux-gnueabihf-

Download Kernel Source

Clone the Kernel Source from the Git repository. Then check out your favorite branch or tag. The example checks out the socfpga-4.14.130-ltsi branch. Again, I'm starting work under my home directory, but do it wherever you like. You can change the "test_branch" after -b to any name you like.

$ cd ~
$ git clone https://github.com/altera-opensource/linux-socfpga
$ cd linux-socfpga
$ git checkout -b test_branch origin/socfpga-4.14.130-ltsi 

build zImage, .dtb

Finally, build the final target Kernel body, zImage, and the device tree. (Assuming that export CROSS_COMPILE = ... is already set)

$ export ARCH=arm 
$ make socfpga_defconfig
$ make zImage
$ make socfpga_cyclone5_de0_sockit.dtb

The above will generate zImage under arch / arm / boot / and socfpga_cyclone5_de0_sockit.dtb under arch / arm / boot / dts /. By the way, socfpga_cyclone5_de0_sockit.dtb is a device tree file for DE10nano. Replace these with the zImage, .dtb files in the FAT partition of your SD card.

Example of writing to SD card

First, you need to check the partition contents of the SD card to be rewritten (a card that can boot DE10nano for Linux). Insert the SD card into the development PC and display the partition information. If the SD card device name on your PC is / dev / mmcblk0 The command is sudo fdisk -l / dev / mmcblk0.

$ sudo fdisk -l /dev/mmcblk0
...Abbreviation...
Device         Boot  Start     End Sectors  Size Id Type
/dev/mmcblk0p1        2048  206848  204801  100M  b W95 FAT32
/dev/mmcblk0p2      227331 7395332 7168002  3.4G 83 Linux
/dev/mmcblk0p3      206849  227330   20482   10M a2 unknown

From this information, you can see that the FAT partition is Partition1 (/ dev / mmcblk0p1) and the Linux partition is Partition2 (/ dev / mmcblk0p2).

Rewrite zImage and .dtb in Partition1 (/ dev / mmcblk0p1) of FAT partition with your own. For example, on the Terasic site DE10-Nano Kit Resources Page If you are using the MicroSD Card Image from "Linux LXDE Desktop (kernel 4.5)", replace the corresponding files in the FAT parttition as they are named zImage, soc_system.dtb.

$ sudo mount /dev/mmcblk0p1 /mnt
$ cp /mnt/zImage /mnt/zImage.org
$ cp /mnt/soc_system.dtb /mnt/soc_system.dtb.org
$ cp arch/arm/boot/zImage /mnt 
$ cp arch/arm/boot/dts/socfpga_cyclone5_de0_sockit.dtb /mnt/soc_system.dtb
$ sudo umount /mnt

(Assuming that the device name of the SD card is / dev / mmcblk0 and the empty directory / mnt already exists)

Kernel modules too

The Kernel parameters are set at once with the above-mentioned make socfpga_defconfig, but the module set here is not included in zImage and is set to a separate file (.ko) as a module [M]. There are several. Since these are also Kernel related files, write them to the specified location on the SD card. This is also necessary if you want to use the module selected as [M] in the Kernel Parameter (although I don't think it is necessary in the range where DE10 nano is normally used).

$ make modules
$ mkdir /tmp/kmod
$ make modules_install INSTALL_MOD_PATH=/tmp/kmod
$ cd /tmp/kmod
$ tar cvzf /tmp/mod.tgz *
$ sudo mount /dev/mmcblk0p2 /mnt
$ sudo tar xf /tmp/mod.tgz -C /mnt
$ sudo umount /mnt
$ rm -rf /tmp/mod.tgz /tmp/kmod

(This is an example when the device name of the SD card is / dev / mmcblk0 and the Linux partition of the SD card is / dev / mmcblk0p2) (In this example, / tmp / kmod / lib / modules / \ * / build, / tmp / kmod / lib / modules / \ * / source is a Symbolic Link to the Kernel Source directory on your development PC. In this case, copy to another environment with )

Bonus FrameBuffer driver added

The SD card image provided by Terasic has an image that allows you to use the GUI from the HDMI monitor (such as the "Linux LXDE Desktop" image above), but if you rewrite it to the Kernel created in the above procedure, There is no monitor output. The driver for monitor output (frame buffer driver) is not included in the default socfpga_defconfig. In order to enable monitor output, it is necessary to make a Kernel that contains a frame buffer driver. Between make socfpga_defconfig and make zImage mentioned above

$ make menuconfig 

Please run the. This will launch the GUI? For setting Kernel parameters, so make full use of the cursor keys and Enter key. Go to the line Device Drivers-> Graphics support-> Frame buffer Devices-> Altera VIP Frame Reader framebuffer support and mark it as <*> (with the Spacebar). Select save from the menu at the bottom and save to .config to exit. Then you also need to add the device tree file to start the framebuffer you just enabled. Copy socfpga_cyclone5_de0_sockit.dts as socfpga_cyclone5_de10nano_FB.dts and use your favorite editor to modify socfpga_cyclone5_de10nano_FB.dts.

$ cd arch/arm/boot/dts
$ cp socfpga_cyclone5_de0_sockit.dts socfpga_cyclone5_de10nano_FB.dts
$ vi socfpga_cyclone5_de10nano_FB.dts #Edit
$ cd ../../../..

The modification is to add the following to the end of the file.

&base_fpga_region {
        ranges =  <0x00000000 0xff200000 0x00200000>;

        alt_vip_vfr_hdmi: [email protected] {
		compatible = "ALTR,vip-frame-reader-14.0", "ALTR,vip-frame-reader-9.1";
		reg = <0x00031000 0x00000080>;
		max-width = <1024>;
		max-height = <768>;
		bits-per-color = <8>;
		colors-per-beat = <4>;
		beats-per-pixel = <1>;
		mem-word-width = <128>;
	};
};

Then create a device tree .dtb with the renamed zImage and replace them with the SD card files.

$ make zImage
$ make socfpga_cyclone5_de10nano_FB.dtb

Summary

I wrote a method to build & update only the Linux kernel of the Linux SD card of DE10nano. Actually, there is an aspect that I wrote this content because it was necessary in "FPGA Config with Device Tree Overlay" written in another article. In the above work command example, the SD card of DE10nano is inserted into the development PC, mounted and the contents are rewritten, but I connected the DE10nano and the development PC via Ethernet and generated it on the development PC. I work by sending the binary to DE10nano with scp and rewriting the file with DE10nano (because it is troublesome to insert and remove the SD card).

Reference material

Reference: Compiling Linux on the Linux portal site for Intel SoC FPGAs.

Recommended Posts

Linux Kernel Build for DE10nano
Linux kernel build time
pyenv for linux
Build a mruby development environment for ESP32 (Linux)
About Linux kernel parameters
Linux kernel release 5.x (2/4)
[For memo] Linux Part 2
Check Linux kernel version
Linux kernel release 5.x (3/4)
What is Linux for?
Linux command for self-collection
Linux kernel release 5.x (4/4)
Linux kernel release 5.x (1/4)
[Linux] [kernel module] Build and load a simple loadable kernel module
[Linux] WSL2 Build an environment for laravel7 with Ubuntu 20.04
Self-build linux kernel with clang
What is the Linux kernel?
Linux distribution recommended for beginners
Flutter platform channels for Linux
Linux Command Dictionary (for myself)
Linux command memorandum [for beginners]
[LINUX kernel rebuild] Version upgrade (4.18.0 → 5.8.8)
Convenient Linux shortcuts (for beginners)
Until various crypt implementations in Linux Kernel for ARM are called
Linux kernel memory model related documentation
[For memo] Linux Part 1 vi editor
Try the Linux kernel lockdown mechanism
Create Scratch Offline Editor for Linux
[Note] WSL2 kernel build and use
[Linux] [kernel module] Create kthread in kernel module
Convenient shortcut keys for Linux commands! !! !!
Frequently used Linux commands (for beginners)
[Must-see for beginners] Basics of Linux
linux (kernel) source analysis: system call call
Teamviewer for Linux installation procedure (CentOS)
pykintone on Windows Subsystem for Linux
Linux Basic Education for Front-end Engineer
Use Azure AD for Linux authentication
A memo for utilizing the unit test mechanism KUnit of the Linux kernel
Run XRT (Xilinx Runtime) on Debian GNU / Linux for Ultra96 / Ultra96-V2 (Build)