lichee nano 荔枝派入门——linux内核

获取源代码

《lichee nano 荔枝派入门——搭建环境》
个人建议使用如下命令克隆内核代码:

# 下载默认带480*272LCD的版本
git clone --depth=1 -b f1c100s-480272lcd-test https://github.com/Icenowy/linux.git
## 或者下载不带LCD驱动的版本
git clone --depth=1 -b f1c100s https://github.com/Icenowy/linux.git

切换分支

如果是使用下列命令直接克隆整个仓库:

git clone https://github.com/Icenowy/linux.git

则在下载完代码之后,需要进入内核目录,使用如下命令将分支切换到f1c100s-480272lcd-test或者f1c100s

# 切换到 f1c100s-480272lcd-test
git checkout -f f1c100s-480272lcd-test
# 或者切换到f1c100s
git checkout -f f1c100s

linux内核修改

dts文件

修改内核源码目录下的 ./arch/arm/boot/dts/suniv-f1c100s-licheepi-nano.dts

&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>;
                read-only;
            };

            partition@100000 {
                label = "dtb";
                reg = <0x100000 0x10000>;
                read-only;
            };

            partition@110000 {
                label = "kernel";
                reg = <0x110000 0x400000>;
                read-only;
            };

            partition@510000 {
                label = "rootfs";
                reg = <0x510000 0xAF0000>;
            };
        };
    };
};

(注意:这里我的板子上的SPI Flash型号是xt25f128b,因此上面的型号填的是xt25f128b,官方默认是w25f128,要根据自己板上的型号修改)

内核配置修改

运行 make ARCH=arm menuconfig

  • 勾选 File systems ‣ Miscellaneous filesystems ‣ Journalling Flash File System v2 (JFFS2) support,以支持jffs2文件系统。
  • 勾选 Device Drivers ‣ Memory Technology Device (MTD) support ‣ Caching block device access to MTD devices,以支持MTD设备,否则启动时会停留在日志 Waiting for root device /dev/mtdblock3… 上,无法进入系统

添加flash型号支持

修改源码下的 ./drivers/mtd/spi-nor/spi-nor.c,增加xt25f128b型号:

// 找到如下数组,并修改
static const struct flash_info spi_nor_ids[] = {
	……
	{ "w25q128", INFO(0xef4018, 0, 64 * 1024, 256, SECT_4K) },
	//新增xt25f128b型号的spi flash支持
	{ "xt25f128b", INFO(0x0b4018, 0, 64 * 1024, 256, 0) },
	……
};

如果是其他型号则将型号和对应的ID加入这个表中即可,如果是默认的w25q128,则需要将后面的SECT_4K改为0,如下:

{ "w25q128", INFO(0xef4018, 0, 64 * 1024, 256, 0) },

编译

建议使用如下命令编译:

# 为了加快编译速度,请自行更改线程数
# 编译内核,生成zImage
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- -j4
# 编译dts,生成dtb文件
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- dtbs -j4
# 编译内核模块,并输出到out目录
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- INSTALL_MOD_PATH=out modules
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- INSTALL_MOD_PATH=out modules_install

编译完成后会生成如下两个文件:
./arch/arm/boot/zImage
./arch/arm/boot/dts/suniv-f1c100s-licheepi-nano.dtb
和如下目录:
./out/lib/modules

烧录

单独烧录dtb和zImage

首先要使lichee nano处于fel模式(如何进入fel模式见《lichee nano 荔枝派入门——上手》),为了不擦除之前烧录的u-boot固件,这里只能使用短接spi flash的1、4引脚后上电的方法。
分别使用如下命令将dtb文件烧录到spi flash中:

# 在linux内核目录下执行!否则修改对应的文件路径
#烧录dtb文件
sudo sunxi-fel -p spiflash-write 0x0100000 ./arch/arm/boot/dts/suniv-f1c100s-licheepi-nano.dtb
#烧录内核文件
sudo sunxi-fel -p spiflash-write 0x0110000 ./arch/arm/boot/zImage

这种方法用于单独调试linux内核和dtb文件时使用。如果要烧录文件系统,建议使用下列《全部打包烧录》的方法。

全部打包烧录

同样要使lichee nano处于fel模式才能烧录。
之前在《lichee nano 荔枝派入门——搭建环境》中介绍使用官方的打包脚本把镜像打包成bin文件,再烧录,文件系统使用rootfs-spi-flash.tar
打包脚本:

#!/bin/bash

curPath=$(readlink -f "$(dirname "$0")")
_IMG_FILE=firmware.bin
_UBOOT_FILE=$curPath/u-boot/u-boot-sunxi-with-spl.bin
_DTB_FILE=$curPath/linux/arch/arm/boot/dts/suniv-f1c100s-licheepi-nano.dtb
_KERNEL_FILE=$curPath/linux/arch/arm/boot/zImage
_ROOTFS_FILE=$curPath/rootfs-spi-flash.tar.gz
_MOD_FILE=$curPath/linux/out/lib/modules

if [ -f $_IMG_FILE ] ; then
    echo "Image exist,rename it to .old"
    mv $_IMG_FILE $_IMG_FILE.old -f
    echo "Creating new an Image"
fi

rm -rf ./_temp 
mkdir _temp &&\
cd _temp &&\
echo "Generate bin..."
dd if=/dev/zero of=flashimg.bin bs=1M count=16 &&\
echo "Packing Uboot..."
dd if=$_UBOOT_FILE of=flashimg.bin bs=1K conv=notrunc &&\
echo "Packing dtb..."
dd if=$_DTB_FILE of=flashimg.bin bs=1K seek=1024  conv=notrunc &&\
echo "Packing zImage..."
cp $_KERNEL_FILE ./zImage &&\
dd if=./zImage of=flashimg.bin bs=1K seek=1088  conv=notrunc &&\
mkdir rootfs
echo "Packing rootfs..."
tar -zxvf $_ROOTFS_FILE -C ./rootfs >/dev/null &&\
cp -r $_MOD_FILE  rootfs/lib/modules/ &&\
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 ../$_IMG_FILE &&\
echo "Bin update done!"
echo $(pwd)
cd .. &&\
rm -rf ./_temp 
exit

烧录后正常启动的日志信息

U-Boot SPL 2018.01-05679-g013ca457fd-dirty (Sep 20 2020 - 21:41:21)
DRAM: 32 MiB
Trying to boot from MMC1
Card did not respond to voltage select!
mmc_init: -95, time 22
spl: mmc init failed with error: -95
Trying to boot from sunxi SPI


U-Boot 2018.01-05679-g013ca457fd-dirty (Sep 20 2020 - 21:41:21 +0800) Allwinnery

CPU:   Allwinner F Series (SUNIV)
Model: Lichee Pi Nano
DRAM:  32 MiB
MMC:   SUNXI SD/MMC: 0
SF: Detected xt25f128b with page size 256 Bytes, erase size 4 KiB, total 16 MiB
*** Warning - bad CRC, using default environment

In:    serial@1c25000
Out:   serial@1c25000
Err:   serial@1c25000
Net:   No ethernet found.
starting USB...
No controllers found
Hit any key to stop autoboot:  0 
SF: Detected xt25f128b with page size 256 Bytes, erase size 4 KiB, total 16 MiB
device 0 offset 0x100000, size 0x4000
SF: 16384 bytes @ 0x100000 Read: OK
device 0 offset 0x110000, size 0x400000
SF: 4194304 bytes @ 0x110000 Read: OK
## Flattened Device Tree blob at 80c00000
   Booting using the fdt blob at 0x80c00000
   Loading Device Tree to 816fb000, end 816fff3e ... OK

Starting kernel ...

[    0.000000] Booting Linux on physical CPU 0x0
[    0.000000] Linux version 4.15.0-rc8-licheepi-nano+ (hwk@ubuntu) (gcc versio0
[    0.000000] CPU: ARM926EJ-S [41069265] revision 5 (ARMv5TEJ), cr=0005317f
[    0.000000] CPU: VIVT data cache, VIVT instruction cache
[    0.000000] OF: fdt: Machine model: Lichee Pi Nano
[    0.000000] Memory policy: Data cache writeback
[    0.000000] random: fast init done
[    0.000000] Built 1 zonelists, mobility grouping on.  Total pages: 8128
[    0.000000] Kernel command line: console=ttyS0,115200 panic=5 rootwait root=2
[    0.000000] Dentry cache hash table entries: 4096 (order: 2, 16384 bytes)
[    0.000000] Inode-cache hash table entries: 2048 (order: 1, 8192 bytes)
[    0.000000] Memory: 22672K/32768K available (6144K kernel code, 237K rwdata,)
[    0.000000] Virtual kernel memory layout:
[    0.000000]     vector  : 0xffff0000 - 0xffff1000   (   4 kB)
[    0.000000]     fixmap  : 0xffc00000 - 0xfff00000   (3072 kB)
[    0.000000]     vmalloc : 0xc2800000 - 0xff800000   ( 976 MB)
[    0.000000]     lowmem  : 0xc0000000 - 0xc2000000   (  32 MB)
[    0.000000]     pkmap   : 0xbfe00000 - 0xc0000000   (   2 MB)
[    0.000000]     modules : 0xbf000000 - 0xbfe00000   (  14 MB)
[    0.000000]       .text : 0x(ptrval) - 0x(ptrval)   (7136 kB)
[    0.000000]       .init : 0x(ptrval) - 0x(ptrval)   (1024 kB)
[    0.000000]       .data : 0x(ptrval) - 0x(ptrval)   ( 238 kB)
[    0.000000]        .bss : 0x(ptrval) - 0x(ptrval)   ( 247 kB)
[    0.000000] SLUB: HWalign=32, Order=0-3, MinObjects=0, CPUs=1, Nodes=1
[    0.000000] NR_IRQS: 16, nr_irqs: 16, preallocated irqs: 16
[    0.000044] sched_clock: 32 bits at 24MHz, resolution 41ns, wraps every 8947s
[    0.000107] clocksource: timer: mask: 0xffffffff max_cycles: 0xffffffff, maxs
[    0.000630] Console: colour dummy device 80x30
[    0.000714] Calibrating delay loop... 203.16 BogoMIPS (lpj=1015808)
[    0.070223] pid_max: default: 32768 minimum: 301
[    0.070526] Mount-cache hash table entries: 1024 (order: 0, 4096 bytes)
[    0.070565] Mountpoint-cache hash table entries: 1024 (order: 0, 4096 bytes)
[    0.071954] CPU: Testing write buffer coherency: ok
[    0.073589] Setting up static identity map for 0x80100000 - 0x80100058
[    0.076083] devtmpfs: initialized
[    0.082548] clocksource: jiffies: mask: 0xffffffff max_cycles: 0xffffffff, ms
[    0.082616] futex hash table entries: 256 (order: -1, 3072 bytes)
[    0.082862] pinctrl core: initialized pinctrl subsystem
[    0.084791] NET: Registered protocol family 16
[    0.086150] DMA: preallocated 256 KiB pool for atomic coherent allocations
[    0.087865] cpuidle: using governor menu
[    0.112700] SCSI subsystem initialized
[    0.113034] usbcore: registered new interface driver usbfs
[    0.113179] usbcore: registered new interface driver hub
[    0.113372] usbcore: registered new device driver usb
[    0.113777] pps_core: LinuxPPS API ver. 1 registered
[    0.113799] pps_core: Software ver. 5.3.6 - Copyright 2005-2007 Rodolfo Giom>
[    0.113856] PTP clock support registered
[    0.114329] Advanced Linux Sound Architecture Driver Initialized.
[    0.115828] clocksource: Switched to clocksource timer
[    0.141330] NET: Registered protocol family 2
[    0.142707] TCP established hash table entries: 1024 (order: 0, 4096 bytes)
[    0.142782] TCP bind hash table entries: 1024 (order: 0, 4096 bytes)
[    0.142832] TCP: Hash tables configured (established 1024 bind 1024)
[    0.143096] UDP hash table entries: 256 (order: 0, 4096 bytes)
[    0.143153] UDP-Lite hash table entries: 256 (order: 0, 4096 bytes)
[    0.143607] NET: Registered protocol family 1
[    0.144786] RPC: Registered named UNIX socket transport module.
[    0.144824] RPC: Registered udp transport module.
[    0.144839] RPC: Registered tcp transport module.
[    0.144854] RPC: Registered tcp NFSv4.1 backchannel transport module.
[    0.147112] NetWinder Floating Point Emulator V0.97 (double precision)
[    0.148893] Initialise system trusted keyrings
[    0.149429] workingset: timestamp_bits=30 max_order=13 bucket_order=0
[    0.166550] NFS: Registering the id_resolver key type
[    0.166646] Key type id_resolver registered
[    0.166666] Key type id_legacy registered
[    0.166776] jffs2: version 2.2. (NAND) ?© 2001-2006 Red Hat, Inc.
[    0.180843] Key type asymmetric registered
[    0.180883] Asymmetric key parser 'x509' registered
[    0.181081] Block layer SCSI generic (bsg) driver version 0.4 loaded (major )
[    0.181110] io scheduler noop registered
[    0.181128] io scheduler deadline registered
[    0.181884] io scheduler cfq registered (default)
[    0.181914] io scheduler mq-deadline registered
[    0.181933] io scheduler kyber registered
[    0.183024] sun4i-usb-phy 1c13400.phy: Couldn't request ID GPIO
[    0.192799] suniv-pinctrl 1c20800.pinctrl: initialized sunXi PIO driver
[    0.356949] Serial: 8250/16550 driver, 8 ports, IRQ sharing disabled
[    0.363429] console [ttyS0] disabled
[    0.383674] 1c25000.serial: ttyS0 at MMIO 0x1c25000 (irq = 23, base_baud = 6A
[    0.856929] console [ttyS0] enabled
[    0.867347] panel-simple panel: panel supply power not found, using dummy rer
[    0.876709] SCSI Media Changer driver v0.25 
[    0.884248] m25p80 spi0.0: xt25f128b (16384 Kbytes)
[    0.890291] 4 ofpart partitions found on MTD device spi0.0
[    0.895789] Creating 4 MTD partitions on "spi0.0":
[    0.900702] 0x000000000000-0x000000100000 : "u-boot"
[    0.908202] 0x000000100000-0x000000110000 : "dtb"
[    0.915283] 0x000000110000-0x000000510000 : "kernel"
[    0.922792] 0x000000510000-0x000001000000 : "rootfs"
[    0.930803] ehci_hcd: USB 2.0 'Enhanced' Host Controller (EHCI) Driver
[    0.937454] ehci-platform: EHCI generic platform driver
[    0.942959] ohci_hcd: USB 1.1 'Open' Host Controller (OHCI) Driver
[    0.949249] ohci-platform: OHCI generic platform driver
[    0.954880] usbcore: registered new interface driver usb-storage
[    0.961885] udc-core: couldn't find an available UDC - added [g_cdc] to lists
[    0.970929] i2c /dev entries driver
[    1.035953] sunxi-mmc 1c0f000.mmc: base:0x38af4207 irq:19
[    1.043326] usbcore: registered new interface driver usbhid
[    1.049017] usbhid: USB HID core driver
[    1.070443] NET: Registered protocol family 17
[    1.075141] Key type dns_resolver registered
[    1.081740] Loading compiled-in X.509 certificates
[    1.096711] sun4i-drm display-engine: bound 1e60000.display-backend (ops 0xc)
[    1.105481] sun4i-drm display-engine: bound 1c0c000.lcd-controller (ops 0xc0)
[    1.113269] [drm] Supports vblank timestamp caching Rev 2 (21.10.2013).
[    1.119924] [drm] No driver support for vblank timestamp query.
[    1.173864] Console: switching to colour frame buffer device 60x34
[    1.197258] sun4i-drm display-engine: fb0:  frame buffer device
[    1.204448] [drm] Initialized sun4i-drm 1.0.0 20150629 for display-engine on0
[    1.213606] usb_phy_generic usb_phy_generic.0.auto: usb_phy_generic.0.auto sr
[    1.225514] musb-hdrc musb-hdrc.1.auto: MUSB HDRC host driver
[    1.231437] musb-hdrc musb-hdrc.1.auto: new USB bus registered, assigned bus1
[    1.241477] hub 1-0:1.0: USB hub found
[    1.245403] hub 1-0:1.0: 1 port detected
[    1.251026] using random self ethernet address
[    1.255555] using random host ethernet address
[    1.261883] usb0: HOST MAC 46:3d:d2:e0:42:e8
[    1.266410] usb0: MAC a6:a4:c6:dd:bf:cd
[    1.270403] g_cdc gadget: CDC Composite Gadget, version: King Kamehameha Day8
[    1.277959] g_cdc gadget: g_cdc ready
[    1.282625] cfg80211: Loading compiled-in X.509 certificates for regulatory e
[    1.299970] cfg80211: Loaded X.509 cert 'sforshee: 00b28ddf47aef9cea7'
[    1.306828] vcc3v3: disabling
[    1.309813] ALSA device list:
[    1.312778]   #0: Loopback 1
[    1.316649] platform regulatory.0: Direct firmware load for regulatory.db fa2
[    1.325318] cfg80211: failed to load regulatory.db
[    1.426019] random: crng init done
[    2.732762] VFS: Mounted root (jffs2 filesystem) on device 31:3.
[    2.740500] devtmpfs: mounted
[    2.748244] Freeing unused kernel memory: 1024K
Starting logging: OK
Initializing random number generator... done.
Starting network: OK

Welcome to Buildroot
nano login: 

可以看到已经可以正常进入系统了。

  • 0
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: 荔枝Lichee Pi)是一款基于Allwinner系列芯片的开发板,而nano buildroot是一款开源的工具链。工具链是一系列用于构建、编译和调试软件的工具的集合。而nano buildroot则是在buildroot基础上移植和优化的版本。 荔枝nano buildroot工具链提供了完整的开发环境,可以方便地进行软件的开发和调试。它支持包括C、C++、Shell脚本等多种编程语言,并且提供了一些常用的软件包和工具,如GCC编译器、调试工具链、网络协议栈等。 使用nano buildroot工具链可以方便地构建自己的应用程序,开发各种基于荔枝嵌入式系统。它可以帮助开发者搭建符合自己需求的嵌入式开发环境,并提供了各种工具和库,简化了软件开发的过程。 此外,nano buildroot还提供了一些官方维护的软件包,可以方便地选择和集成到自己的系统中。通过配置文件,开发者可以自定义系统的各种特性,如文件系统类型、网络协议栈等。同时,nano buildroot还支持远程调试功能,可以方便地进行程序的调试和优化。 总结来说,荔枝nano buildroot工具链提供了一个方便、高效的开发环境,适用于各种嵌入式开发项目。它可以帮助开发者快速构建自己的嵌入式系统,并提供强大的调试和优化能力。无论是初学者还是有经验的开发者,都可以通过使用nano buildroot轻松进行嵌入式开发。 ### 回答2: 荔枝LicheePi)是一款开源的单板电脑,而nano buildroot是一个适用于荔枝的工具链。 nano buildroot工具链是专门为荔枝定制的,它提供了一种简化的方式来构建荔枝嵌入式操作系统。通过使用这个工具链,开发者可以轻松地配置和构建他们想要的系统,以满足特定的需求。 该工具链的主要优势之一是其灵活性。它允许开发者选择要包含在系统中的软件包,以及配置系统的各种设置。这使得开发者能够根据项目的需求定制一个最小、精简的系统,从而减少资源的占用,并提高系统的性能。 此外,nano buildroot工具链还提供了一套完整的开发环境,包括交叉编译器、调试工具和库等。它使开发者能够在本地开发环境中编写、编译和调试他们的代码,然后将最终的可执行文件或完整的系统映像传输到荔枝平台上运行。 总的来说,荔枝nano buildroot工具链为开发者提供了一种方便、灵活和高效的方式来构建和定制荔枝嵌入式系统。它使得开发者能够更好地利用荔枝的硬件资源,并快速实现他们的创意和解决方案。 ### 回答3: 荔枝 Nano是一款基于ARM架构的开发板,它运行了Linux操作系统。而Buildroot是一个能够为嵌入式系统生成精简的Linux根文件系统的工具链。 荔枝Nano可以通过Buildroot工具链进行构建,以定制化地配置和构建Linux根文件系统。Buildroot工具链包括一系列的脚本和配置文件,用来从源代码编译各种软件包,生成适用于荔枝Nano的根文件系统。 通过Buildroot工具链,我们可以选择需要的软件包和功能来构建根文件系统,从而满足我们的特定需求。例如,我们可以选择安装必要的组件,如系统工具、网络协议栈、文件系统和驱动程序,以及其他软件包,如开发工具链、编译器和调试工具。 Buildroot工具链的另一个优点是其具有良好的可定制性。我们可以根据自己的需要进行定制,添加或删除想要的软件包,并进行不同选项的配置。这样,我们可以根据具体项目的要求,定制一个定制化的根文件系统,使荔枝Nano满足我们的需求。 然而,需要注意的是,使用Buildroot工具链进行构建需要一定的Linux系统和软件开发经验。用户需要了解Linux系统和软件包的架构和依赖关系,以及如何正确配置和编译它们。同时,构建出的根文件系统还需要经过测试和验证,以确保其稳定性和兼容性。 总而言之,荔枝Nano和Buildroot工具链是一对强大的组合,可以为我们提供一个定制化的Linux根文件系统。通过合理配置和构建,我们可以充分利用荔枝Nano的性能和功能,满足各种嵌入式系统开发的需求。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值