[linux project] lichee nano linux burning


lichee_ The nano master chip is Quanzhi FC1001S.

For the time being, this note takes lichee nano as an example, which may be directly adapted to various boards of FC1001S in the future.

Note: when using the lichee nano board and the image provided by lichee, you need to pay attention to the flash chip model of the board and modify the driver if necessary.

Li Zhuming's blog: https://www.cnblogs.com/lizhuming/p/15487208.html

reference resources:

Install cross compilation chain


  • You can install the required version yourself.
  • You can also refer to the following examples:
# Here is to get 7.2 Version 1, you can get other versions or download them directly through the link
wget http://releases.linaro.org/components/toolchain/binaries/7.2-2017.11/arm-linux-gnueabi/gcc-linaro-7.2.1-2017.11-x86_64_arm-linux-gnueabi.tar.xz

tar -vxJf gcc-linaro-7.2.1-2017.11-x86_64_arm-linux-gnueabi.tar.xz
sudo cp -r ./gcc-linaro-7.2.1-2017.11-x86_64_arm-linux-gnueabi /opt/

sudo vim /etc/bash.bashrc

# Add the following at the end of the file
# Add complete

# Make path effective
source /etc/bash.bashrc

After installing the cross compilation chain, you can use the command arm linux gnueabi GCC - V to test whether the installation is successful. Pay attention to your installation users.

Set up SPI FLASH burning environment

After the compilation chain is installed, you also need to install the firmware burning tool. Sunxi tools are used here:

# 0. If Git is not installed, install git first
sudo apt-get install git

# 1. Pull the Sunxi tools library
git clone -b f1c100s-spiflash https://github.com/Icenowy/sunxi-tools.git

# 2. Installation
cd sunxi-tools
make && sudo make install

# 3. Error handling
# 3.1 if fatal error occurs: libusb h: No such file or directory error
sudo apt-get install libusb-1.0-0-dev
# 3.2 fel.c:32:18: fatal error: zlib.h: There is no such file or directory
sudo apt-get install  zlib-devel

# 4. Not surprisingly, it has been installed successfully. You can use this software to burn. Common commands are as follows
# 4.1 check whether the chip has enabled the download mode. If the chip information appears, you can burn it
sudo sunxi-fel ver

# 4.2 burning to flash
sudo xunxi-fel -p spiflash-write [Burning address] [Burned file]

# 4.3 burning into memory
sudo xunxi-fel -p write [Burned memory address] [Burned file]

Put the chip into burn mode

In order to enable the chip to receive the burning firmware, the chip can enter fel mode.

  • Principle: when there is no boot data in flash or the flash chip cannot be found, it will automatically enter fel mode.
  • There are two ways:
    1. Short circuit pins 1 and 4 of flash, power on again, so that the chip can't find flash. Release the short circuit after power on, and then enter fel mode again.
    2. Use U-boot to delete boot data in flash:
# Use the following instructions in u-boot to delete data
# 1. Switch to flash, where 0 is the selected flash and 50000000 is the speed. There is an error in the official document. be careful!
sf probe 0 50000000

# 2. Erase flash. Why erase this address? Please check the spiflash compilation chapter
sf erase 0 0x10000

# 3. Restart

# 4. Use Sunxi FEL ver to find the chip
sudo sunxi-fel ver
AWUSBFEX soc=00001663(F1C100s) 00000001 ver=0001 44 08 scratchpad=00007e00 00000000 00000000

sunxi burn command

  1. Confirm whether to enter fel mode command: sudo Sunxi fel ver
  2. Burning command: sudo Sunxi FEL - P spiflash write [burning address] [burning file]

u-boot clipping

Pull u-boot source code

# 1. Use git to pull u-boot. Here you can use acceleration
git clone https://github.com/Lichee-Pi/u-boot.git

# 2. View the branch and switch to the corresponding branch
git branch -a
git checkout nano-v2018.01

# 3. Configure
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- licheepi_nano_spiflash_defconfig

Configure u-boot

Cut as needed, with the following as a reference:

  • Understand the following bootcmd parameters. Is the command executed before driving the kernel. Generally, it is mainly used to copy data & execute startup, such as copying the device tree and kernel to the memory controller RAM.
# 1. Conduct visual configuration and enter the configuration page
make ARCH=arm menuconfig

# 1.1 how to install the following packages in case of errors
sudo apt-get install libncurses5-dev libncursesw5-dev

# 2. If LCD is used, modify the LCD option
ARM architecture
	Enable graphical uboot console on HDMI, LCD or VGA -> Y
	LCD panel timing details -> x:800,y:480,depth:18,pclk_khz:33000,le:87,ri:40,up:31,lo:13,hs:1,vs:1,sync:3,vmode:0
	# If 480 * 272 screen

	LCD panel backlight pwm pin -> PE6 # See the schematic diagram for details

# 3. Modify boot arguments and transfer parameters to linux
Enable boot arguments -> y
	Boot arguments ->  console=ttyS0,115200 panic=5 rootwait root=/dev/mtdblock3 rw rootfstype=jffs2
# 4. Modify bootcmd and start the linux command. You can specifically understand the meaning of bootcmd code, in which you can copy data to start linux 
Enable a default value for bootcmd -y
	bootcmd -> sf probe 0 50000000; sf read 0x80c00000 0x100000 0x4000; sf read 0x80008000 0x110000 0x400000; bootz 0x80008000 - 0x80C00000

# 5. Save and exit

Check flash drive

  • Add your own FLASH chip driver.
# 1. Open in the code editor/ drivers/mtd/spi/spi_flash_ids.c

# 2. Add the following code in line 170 or so
{"xt25f128b",	   INFO(0x0b4018, 0x0,	64 * 1024,   256, RD_FULL | WR_QPP | SECT_4K) },

# 3. Save and exit

Compiling and writing u-boot


# Compile code
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- -j11

# If the following statement appears at the end, the compilation is successful
 BINMAN  u-boot-sunxi-with-spl.bin

# Error handling, scripts / makefile build:425: recipe for target 'scripts/dtc/pylibfdt' failed
sudo  apt-get install swig python-dev python3-dev

The successfully compiled file is in the u-boot directory, u-boot-sunxi-with-spl bin . Burn them to memory or flash:

# Burn to flash
sudo sunxi-fel -p spiflash-write 0 u-boot-sunxi-with-spl.bin

# Burn it into sram and use it during test (power failure without protection)
sudo sunxi-fel uboot u-boot-sunxi-with-spl.bin


# Test whether flash is successful. If the following code appears, it will be successful
sf probe 0 50000000
SF: Detected xt25f128b with page size 256 Bytes, erase size 4 KiB, total 16 MiB

# Test read 

linux tailoring

Get linux source code

At present, the source code of uboot and linux is recommended by lichee or Quanzhi.

# 1. Because linux is too large, it is recommended to pull only a single branch Acceleration can be used
git clone --depth=1 -b f1c100s-480272lcd-test https://github.com/Icenowy/linux.git

# 2. Download Config file and put it in the directory of the source code. If the file name changes. Replace with config

Replace config file: .config

git pulling is sometimes very slow. It is recommended to configure as follows:

sudo vim /etc/hosts
# Add the following two lines  github.com github.global.ssl.fastly.net
# Add complete
# You can detect GitHub through dns detection website global. ssl. fastly. Net, replace with a faster ip address

Configuring linux

# 1. Graphical configuration
make ARCH=arm menuconfig

# 2. Configure spiflash
Device Drivers
	SPI support
		Allwinner A10 SoCs SPI controller ->n # No choice
		Allwinner A31 SPI Controller -> y

# 3. Configure MTD
Device Drivers
	Memory Technology Device (MTD) support
		Command line partitioning table parsing -> y
		Caching block device access to MTD devices  -> y

# 4. Add File systems
File systems
	Miscellaneous filesystems
		Journalling Flash File System v2 (JFFS2) support -> y
		# Select all below

# 5. Save and exit

# Note that the configuration option should be selected as * instead of M

Configure device tree

  • To add a flash driver, you need to check the flash chip used by the board:

    # 1. Open/ drivers/mtd/spi-nor/spi-nor. C line 1186 Add the following code Support for flash
    { "xt25f128b", INFO(0x0b4018, 0, 64 * 1024, 256, 0) },
  • Configure the device tree. If there is no display, the display part does not need to be configured:

    # 1. Open / arch / arm / boot / DTS / suniv-f1c100s-licheepi-nano DTS file
    # 2. Modify the display driver
    	panel: panel {
    		# Screen modified to 800 * 480
    		compatible = "lg,lb070wv8", "simple-panel";
    		#address-cells = <1>;
    		#size-cells = <0>;
    		enable-gpios = <&pio 4 6 GPIO_ACTIVE_HIGH>;
    		port@0 {
    			reg = <0>;
    			#address-cells = <1>;
    			#size-cells = <0>;
    			panel_input: endpoint@0 {
    				reg = <0>;
    				remote-endpoint = <&tcon0_out_lcd>;
    # 3. Add support for spiflash
    &spi0 {
        pinctrl-names = "default";
        pinctrl-0 = <&spi0_pins_a>;
        status = "okay";
        spi-max-frequency = <50000000>;
        flash: xt25f128b@0 {
            #address-cells = <1>;
            #size-cells = <1>;
            compatible = "winbond,xt25f128b", "jedec,spi-nor";
            reg = <0>;
            spi-max-frequency = <50000000>;
            partitions {
                compatible = "fixed-partitions";
                #address-cells = <1>;
                #size-cells = <1>;
                partition@0 {
                    label = "u-boot";
                    reg = <0x000000 0x100000>;
                partition@100000 {
                    label = "dtb";
                    reg = <0x100000 0x10000>;
                partition@110000 {
                    label = "kernel";
                    reg = <0x110000 0x400000>;
                partition@510000 {
                    label = "rootfs";
                    reg = <0x510000 0xAF0000>;

Compiling and writing linux

Compiling linux:

  • The image file is generated in arch/arm/boot/zImage
  • The device tree file is in arch / arm / boot / DTS / suniv-f1c100s-licheepi-nano dtb
  • Compilation steps:
    # 1. Compilation
    make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- -j11
    # Error handling: fatal error: OpenSSL / bio h:
    sudo apt-get install libssl-dev

Compile the device tree separately:

make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- dtbs -j11


  1. Enter fel mode.
  2. Burning firmware: sudo Sunxi FEL - P spiflash write [burning address] [burning file]

roofs clipping

The collated rootfs uses buildroot.

Get builderoot source code


  1. stay https://buildroot.org/download.html You can download to the latest code package.
  2. Unzip the code package tar -xzvf builderoot-2021.08 tar. gz1.

Configure builderoot

# 1. Open the graphical interface
make menuconfig

# 2. Select the processor
Target options
	Target Architecture (ARM (little endian))
	Target Variant arm926t

# 3. Start soft link, etc
System configuration
	Use syslinks to /usr ....  # Launch link
    Enable root login   		# root login
    Run a getty after boot 		# Input password
    remount root filesystem     # Remount the root file system to read / write

Compile and burn builderoot


# Compilation is slow. You can chat with your wife / girlfriend. If the compilation fails, make clean and start again

The compiled root directory is output / images / rootfs tar . Copy and unzip:

# Copy it
cp output/images/rootfs.tar ../
# Create a directory folder
mkdir rootfs
# Unzip to this folder
tar -xvf rootfs.tar -C rootfs/

# Install jffs2 
sudo apt-get install mtd-utils

# Make a mirror image to get JFFS2 IMG can be burned to the development board
mkfs.jffs2 -s 0x100 -e 0x10000 --pad=0xAF0000 -d rootfs/ -o jffs2.img


  1. Enter fel mode.
  2. Burning firmware: sudo Sunxi FEL - P spiflash write [burning address] [burning file]

SPI FLASH compilation and writing

Partition according to your own configuration

For example:

Partition serial number Partition size Zoning effect Address space and partition name
mtd0 1MB (0x100000) spl+uboot 0x0000000-0x0100000 : "uboot"
mtd1 64KB (0x10000) dtb file 0x0100000-0x0110000 : "dtb"
mtd2 4MB (0x400000) linux kernel 0x0110000-0x0510000 : "kernel"
mtd3 Remaining (0xAF0000) Root file system 0x0510000-0x1000000 : "rootfs"

Single burning

  • Burn the u-boot to the first partition

    sudo sunxi-fel -p spiflash-write 0 u-boot-sunxi-with-spl.bin
  • Burn the dtb file to the second partition

    sudo sunxi-fel -p spiflash-write 0x0100000 suniv-f1c100s-licheepi-nano.dtb
  • Burn the zImage image file to the third partition

    sudo sunxi-fel -p spiflash-write 0x0110000 zImage
  • We burn the root file system to the fourth partition

    sudo sunxi-fel -p spiflash-write 0x0510000 jffs2.img

Package into one file

The above is a firmware burning. We can package it into a firmware for burning through a script:

Create a directory dedicated to firmware, such as my_bin. In this directory, create a folder and store the corresponding firmware in the following format:

  1.  ls
     buildroot  linux  u-boot
  2. Put the following script file into my_ In the bin directory, execute, and output is the last output file.

    #! /bin/bash
    rm -rf ./output
    mkdir ./output
    rm -rf ./rootfs
    mkdir ./rootfs
    dd if=/dev/zero of=flashimg.bin bs=1M count=16 &&\
    dd if=./u-boot/u-boot-sunxi-with-spl.bin of=flashimg.bin bs=1K conv=notrunc &&\
    dd if=./linux/suniv-f1c100s-licheepi-nano.dtb of=flashimg.bin bs=1K seek=1024  conv=notrunc &&\
    dd if=./linux/zImage of=flashimg.bin bs=1K seek=1088  conv=notrunc &&\
    tar -xf ./buildroot/rootfs.tar -C ./rootfs &&\
    mkfs.jffs2 -s 0x100 -e 0x10000 --pad=0xAF0000 -d rootfs/ -o jffs2.img &&\
    dd if=jffs2.img of=flashimg.bin bs=1K seek=5184  conv=notrunc
    mv flashimg.bin ./output
    rm -rf jffs2.img
  3. Execute the command to burn to the development board:

    sudo sunxi-fel -p spiflash-write 0 flashimg.bin

Little knowledge

uboot sf command usage

If spi/qspi flash is supported in uboot, you can use the erase, read and write commands of sf to operate spi flash.

  • sf read is used to read flash data into memory.
  • sf write writes memory data to flash.
  • sf erase erases the flash content at the specified position and length. When writing flash, you must erase it first, otherwise it will fail, because flash can only change from 1 to 0.

Specific reference:

sf - SPI flash sub-system

sf probe [[bus:]cs] [hz] [mode] - init flash device on given SPI bus and chip select

sf read addr offset len - read `len' bytes starting at
                                  `offset' to memory at `addr'

sf write addr offset len        - write `len' bytes from memory
                                  at `addr' to flash at `offset'

sf erase offset [+]len          - erase `len' bytes from `offset'
                                  `+len' round up `len' to block size

sf update addr offset len       - erase and write `len' bytes from memory
                                  at `addr' to flash at `offset'

Usage Note:

  1. Before using other commands of sf, you must use sf probe to connect to flash.
    1. For example: sf probe 0 50000000, initialize FLASH on bus 0, and the speed is 50000000 Hz.

uboot bootz parameter

For ARM, you can use bootz < kernel_ addr> <initrd_ address> <dtb_ Address > to start the kernel.

  • The first parameter is the address of the kernel image.
  • The second parameter is the address of initrd. If initrd does not exist, it can be replaced by -.
  • dtb_address as the last parameter of bootz or bootm.

Keywords: Linux Embedded system SOC

Added by guanche on Tue, 04 Jan 2022 19:59:59 +0200