获取源代码

见《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文件系统。
    [外链图片转存中…(img-JFTBlOLZ-1607175452720)]
  • 勾选 Device Drivers ‣ Memory Technology Device (MTD) support ‣ Caching block device access to MTD devices,以支持MTD设备,否则启动时会停留在日志 Waiting for root device /dev/mtdblock3… 上,无法进入系统
    [外链图片转存中…(img-3Rvth0SI-1607175452721)]

添加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/bashcurPath=$(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/modulesif [ -f $_IMG_FILE ] ; thenecho "Image exist,rename it to .old"mv $_IMG_FILE $_IMG_FILE.old -fecho "Creating new an Image"
firm -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 SPIU-Boot 2018.01-05679-g013ca457fd-dirty (Sep 20 2020 - 21:41:21 +0800) AllwinneryCPU:   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 environmentIn:    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 80c00000Booting using the fdt blob at 0x80c00000Loading Device Tree to 816fb000, end 816fff3e ... OKStarting 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: OKWelcome to Buildroot
nano login:

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

lichee nano 荔枝派入门——linux内核相关推荐

  1. lichee nano 荔枝派入门——u-boot

    获取源代码 见上一篇文章<lichee nano 荔枝派入门--搭建环境> 切换分支 切换到lichee nano的代码分支,在u-boot目录下操作: # 查看分支 git branch ...

  2. lichee nano 荔枝派入门——buildroot构建文件系统

    lichee nano 荔枝派入门–buildroot构建文件系统 获取buildroot源代码 可以从lichee官方给的链接地址或者从GitHub下载最新的buildroot源代码,具体如下: 从 ...

  3. lichee nano 荔枝派入门——搭建环境

    概述 lichee nano开发大致需要如下环境: linux系统 交叉编译工具链 固件烧录工具 源代码 linux系统 一般使用虚拟机安装linux发行版,具体安装步骤网上很多,这里不再赘述. 另外 ...

  4. lichee nano 荔枝派入门——上手

    前言 最近上手一块lichee nano,主要看中它的小巧精制,最小系统只需要供电电路.SPI Flash.主芯片F1C100S即可,无需外部RAM芯片,因此硬件简单,后续做项目如果有用到简单的lin ...

  5. Lichee Zero 荔枝派 零 入坑记录

    Lichee Zero 荔枝派 零 入坑记录 参考官方网站 http://zero.lichee.pro buildroot-2019.08-rc1 busybox-1.31.0 重编译 修改gett ...

  6. 换种方法学操作系统,轻松入门Linux内核

    计算机已成为现代人日常工作.学习和生活中必不可少的工具.操作系统是计算机之魂,作为用户使用计算机的接口,它负责调度执行各个用户程序,使计算机完成特定的任务:作为计算机硬件资源的管理者,它负责协调计算机 ...

  7. 一叶知秋,一个 LED 就能入门 Linux 内核

    简单点灯 最近项目上需要用到 LED 子系统,在嵌入式 Linux 里面点个灯还是比较简单的,只要在某个灯对应的目录里,向相应文件写入特定值,就可以让 LED 亮/灭/闪烁. # echo 1 > ...

  8. Linux内核源码分析方法

    说明:这是一个刚接触内核三个月的同学,通过对一个内核特性的分析,总结出一套分析内核的方法. 一.内核源码之我见 Linux内核代码的庞大令不少人"望而生畏",也正因为如此,使得人们 ...

  9. linux内核开发_Linux 内核的代码仓库管理与开发流程简介

    作者简介:老 U,致力于开源自由软件推广. 原创雄文:由泰晓读者投递的各类社区原创好文. 版权声明:本文最先发表于 "泰晓科技" 微信公众号,欢迎转载,转载时请在文章的开头保留本声 ...

最新文章

  1. webpack增量打包多页应用
  2. 树莓派:在ubuntu20-server安装和卸载桌面
  3. 深入理解Aho-Corasick自动机算法
  4. loadrunner脚本运行时设置:Run Logic设置运行次数
  5. Linux块设备驱动程序原理
  6. 交大计算机基础知识第一次作业,上海交大计算机第一次作业
  7. 云服务器,Linux上安装xampp,搭建node服务,云服务器Firewalld、iptables,nginx反向代理
  8. aspnetcore的中间件
  9. libevent源码深度剖析四
  10. .NET Windows编程系列笔记(一)
  11. ADS 2013 momentum仿真出错
  12. 李开复给大学生的第7封信:21世纪最需要的7种人才
  13. 波束成形技术原理解析
  14. 【VB+数控原理与系统】数控原理与系统课程设计刀具半径补偿直线-直线VB模拟软件实现
  15. 什么是url,herf和src的区别
  16. 来了!2020云栖大会 蚂蚁金融科技产品能力再升级
  17. 都挺好 苏大强C位出道的不只表情包 还有大眼袋
  18. 百度收购PPS敲定 与爱奇艺整合将成难点
  19. 理想职业计算机程序英语作文,理想职业英文作文120词左右,作为演讲用,要求演讲2到3分钟....
  20. 圣诞节购物软件测试,圣诞节心理测试-鑫海软件

热门文章

  1. vscode蓝色波浪线消除办法
  2. 太素---亿级大规模中文视觉语言预训练数据集
  3. Windows Server 2016 打印机转接
  4. WindowsAPI函数 FILETIME、SYSTEMTIME、GetFileAttributesEx、FileTimeToLocalFileTime、FileTimeToSystemTile
  5. LeetCode 708. 循环有序列表的插入*
  6. 项目阶段六:查看我的订单模块
  7. MATLAB画长草颜团子
  8. Unity Game Optimization 笔记
  9. jupyterlab教程
  10. 体验讯飞星火认知大模型,据说中文能力超越ChatGPT