见《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
修改内核源码目录下的 ./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
修改源码下的 ./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
首先要使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:
可以看到已经可以正常进入系统了。