一、安装交叉编译环境
交叉编译环境跟uboot使用的一样。
参考:arm-linux-gnueabihf 交叉编译工具链安装
二、下载linux源码
# 默认是zero-4.10.y分支:
git clone https://github.com/Lichee-Pi/linux.git# 或者`zero-4.13.y`对网卡的支持更好
git clone -b zero-4.13.y https://github.com/Lichee-Pi/linux.git# 或者使用最新的内核:
git clone -b zero-5.2.y https://github.com/Lichee-Pi/linux.git
三、修改顶层Makefile
在内核根目录下的Makefile
364行修改默认编译器,可以直接用make
编译:
# ARCH ?= $(SUBARCH)
ARCH ?= arm
CROSS_COMPILE ?= arm-linux-gnueabihf-
四、编译
配置文件在arch/arm/configs
文件夹内。
编译命令:
cd linux
make licheepi_zero_defconfig
make menuconfig #add bluethooth, etc.
make -j16
make -j16 INSTALL_MOD_PATH=out modules
make -j16 INSTALL_MOD_PATH=out modules_install
# 修改了设备树文件后编译
make dtbs
- 编译完成后,
zImage
在arch/arm/boot/
下,驱动模块在out/
下。 - 设备树文件在
arch/arm/boot/dts/
下。 - 普通板的设备树:
sun8i-v3s-licheepi-zero.dtb
- dock板的设备树:
sun8i-v3s-licheepi-zero-dock.dtb
- LCD_480x272的设备树:
sun8i-v3s-licheepi-zero-with-480x272-lcd.dtb
- LCD_800x480的设备树:
sun8i-v3s-licheepi-zero-with-800x480-lcd.dtb
zero-5.2.y 编译LOG:
pjw@pjw-virtual-machine:~/Allwinner/V3S/linux_main/linux-zero-5.2.y$ make -j16 INSTALL_MOD_PATH=out modulesCALL scripts/atomic/check-atomics.shCALL scripts/checksyscalls.shBuilding modules, stage 2.MODPOST 42 modules
pjw@pjw-virtual-machine:~/Allwinner/V3S/linux_main/linux-zero-5.2.y$ make -j16 INSTALL_MOD_PATH=out modules_installINSTALL drivers/input/mousedev.koINSTALL drivers/media/common/tveeprom.koINSTALL drivers/media/common/videobuf2/videobuf2-dma-contig.koINSTALL drivers/media/common/videobuf2/videobuf2-common.koINSTALL drivers/media/common/videobuf2/videobuf2-v4l2.koINSTALL drivers/media/common/videobuf2/videobuf2-vmalloc.koINSTALL drivers/media/common/videobuf2/videobuf2-memops.koINSTALL drivers/media/i2c/msp3400.koINSTALL drivers/media/i2c/saa7115.koINSTALL drivers/media/i2c/ov2640.koINSTALL drivers/media/platform/sunxi/sun6i-csi/sun6i-csi.koINSTALL drivers/media/i2c/mt9v011.koINSTALL drivers/media/platform/video-mux.koINSTALL drivers/media/i2c/tvp5150.koINSTALL drivers/media/usb/uvc/uvcvideo.koINSTALL drivers/media/usb/em28xx/em28xx-v4l.koINSTALL drivers/media/usb/em28xx/em28xx.koINSTALL drivers/media/usb/gspca/gspca_main.koINSTALL drivers/of/of_mdio.koINSTALL drivers/media/v4l2-core/tuner.koINSTALL drivers/media/v4l2-core/v4l2-fwnode.koINSTALL drivers/net/phy/libphy.koINSTALL drivers/mux/mux-core.koINSTALL drivers/net/ethernet/allwinner/sun4i-emac.koINSTALL drivers/net/mii.koINSTALL drivers/net/ethernet/davicom/dm9000.koINSTALL drivers/net/phy/fixed_phy.koINSTALL drivers/net/phy/mdio-sun4i.koINSTALL drivers/staging/rtl8723bs/r8723bs.koINSTALL drivers/usb/class/cdc-wdm.koINSTALL drivers/usb/common/usb-otg-fsm.koINSTALL drivers/usb/serial/usbserial.koINSTALL drivers/usb/serial/usb-serial-simple.koINSTALL drivers/video/backlight/lcd.koINSTALL lib/crypto/libarc4.koINSTALL drivers/usb/serial/cp210x.koINSTALL net/ipv4/udp_diag.koINSTALL net/ipv4/tcp_westwood.koINSTALL net/ipv4/tcp_htcp.koINSTALL net/wireless/cfg80211.koINSTALL net/ipv4/tcp_bic.koINSTALL net/mac80211/mac80211.koDEPMOD 5.2.0-licheepi-zero
zero-4.13.y 编译LOG:
pjw@pjw-virtual-machine:~/Allwinner/V3S/linux$ make -j16 INSTALL_MOD_PATH=out modulesCHK include/config/kernel.releaseCHK include/generated/uapi/linux/version.hCHK include/generated/utsrelease.hCHK scripts/mod/devicetable-offsets.hCHK include/generated/timeconst.hCHK include/generated/bounds.hCHK include/generated/asm-offsets.hCALL scripts/checksyscalls.shBuilding modules, stage 2.MODPOST 3 modulespjw@pjw-virtual-machine:~/Allwinner/V3S/linux$ make -j16 INSTALL_MOD_PATH=out modules_installINSTALL crypto/echainiv.koINSTALL drivers/staging/rtl8723bs/r8723bs.koINSTALL drivers/video/backlight/lcd.koDEPMOD 4.13.16-licheepi-zero+
pjw@pjw-virtual-machine:~/Allwinner/V3S/linux$
五、烧录
准备:
boot.scr
(主线llinux),参考:u-boot传参(boot.scr)和参数配置(script.bin)文件- 设备树
sun8i-v3s-licheepi-zero.dtb
或者sun8i-v3s-licheepi-zero-with-480x272-lcd.dtb
等。 - 刚生成的
zImage
一起放到TF卡第一分区。
# 查询挂载名
df -h
# 拷贝到第一分区(32M卷)
cp zImage boot.scr sun8i-v3s-licheepi-zero-with-480x272-lcd.dtb /挂载的tf卡第一个分区目录(例:/media/pjw/43EE-E439)
六、启动LOG:
这里没有烧录文件系统Buildroot
,所以最后内核会崩溃。
U-Boot SPL 2017.01-rc2-00057-g32ab1804cd-dirty (Feb 22 2021 - 13:37:47)
DRAM: 64 MiB
Trying to boot from MMC1U-Boot 2017.01-rc2-00057-g32ab1804cd-dirty (Feb 22 2021 - 13:37:47 +0800) Allwinner TechnologyCPU: Allwinner V3s (SUN8I 1681)
Model: Lichee Pi Zero
DRAM: 64 MiB
MMC: SUNXI SD/MMC: 0
*** Warning - bad CRC, using default environmentSetting up a 480x272 lcd console (overscan 0x0)
dotclock: 10000kHz = 10000kHz: (1 * 3MHz * 20) / 6
In: serial@01c28000
Out: serial@01c28000
Err: serial@01c28000U-Boot 2017.01-rc2-00057-g32ab1804cd-dirty (Feb 22 2021 - 13:37:47 +0800) Allwinner TechnologyCPU: Allwinner V3s (SUN8I 1681)
Model: Lichee Pi Zero
DRAM: 64 MiB
MMC: SUNXI SD/MMC: 0
*** Warning - bad CRC, using default environmentSetting up a 480x272 lcd console (overscan 0x0)
dotclock: 10000kHz = 10000kHz: (1 * 3MHz * 20) / 6
In: serial@01c28000
Out: serial@01c28000
Err: serial@01c28000
Net: No ethernet found.
starting USB...
No controllers found
Hit any key to stop autoboot: 0
switch to partitions #0, OK
mmc0 is current device
Scanning mmc 0:1...
Found U-Boot script /boot.scr
reading /boot.scr
292 bytes read in 15 ms (18.6 KiB/s)
## Executing script at 41900000
reading zImage
4168040 bytes read in 216 ms (18.4 MiB/s)
reading sun8i-v3s-licheepi-zero-with-480x272-lcd.dtb
11761 bytes read in 28 ms (410.2 KiB/s)
## Flattened Device Tree blob at 41800000Booting using the fdt blob at 0x41800000Loading Device Tree to 42dfa000, end 42dffdf0 ... OKStarting kernel ...[ 0.000000] Booting Linux on physical CPU 0x0
[ 0.000000] Linux version 5.2.0-licheepi-zero (pjw@pjw-virtual-machine) (gcc version 4.9.4 (Linaro GCC 4.9-2017.01)) #1 SMP Mon Mar 22 13:04:18 CST 2021
[ 0.000000] CPU: ARMv7 Processor [410fc075] revision 5 (ARMv7), cr=10c5387d
[ 0.000000] CPU: div instructions available: patching division code
[ 0.000000] CPU: PIPT / VIPT nonaliasing data cache, VIPT aliasing instruction cache
[ 0.000000] OF: fdt: Machine model: Lichee Pi Zero
[ 0.000000] Memory policy: Data cache writealloc
[ 0.000000] percpu: Embedded 16 pages/cpu s34560 r8192 d22784 u65536
[ 0.000000] Built 1 zonelists, mobility grouping on. Total pages: 16129
[ 0.000000] Kernel command line: console=ttyS0,115200 root=/dev/mmcblk0p2 rootwait panic=10 earlyprintk rw
[ 0.000000] Dentry cache hash table entries: 8192 (order: 3, 32768 bytes, linear)
[ 0.000000] Inode-cache hash table entries: 4096 (order: 2, 16384 bytes, linear)
[ 0.000000] mem auto-init: stack:off, heap alloc:off, heap free:off
[ 0.000000] Memory: 54536K/65024K available (6144K kernel code, 301K rwdata, 1676K rodata, 1024K init, 252K bss, 10488K reserved, 0K cma-reserved, 0K highmem)
[ 0.000000] SLUB: HWalign=64, Order=0-3, MinObjects=0, CPUs=1, Nodes=1
[ 0.000000] rcu: Hierarchical RCU implementation.
[ 0.000000] rcu: RCU event tracing is enabled.
[ 0.000000] rcu: RCU restricting CPUs from NR_CPUS=8 to nr_cpu_ids=1.
[ 0.000000] rcu: RCU calculated value of scheduler-enlistment delay is 10 jiffies.
[ 0.000000] rcu: Adjusting geometry for rcu_fanout_leaf=16, nr_cpu_ids=1
[ 0.000000] NR_IRQS: 16, nr_irqs: 16, preallocated irqs: 16
[ 0.000000] random: get_random_bytes called from start_kernel+0x2f8/0x48c with crng_init=0
[ 0.000000] arch_timer: cp15 timer(s) running at 24.00MHz (virt).
[ 0.000000] clocksource: arch_sys_counter: mask: 0xffffffffffffff max_cycles: 0x588fe9dc0, max_idle_ns: 440795202592 ns
[ 0.000008] sched_clock: 56 bits at 24MHz, resolution 41ns, wraps every 4398046511097ns
[ 0.000020] Switching to timer-based delay loop, resolution 41ns
[ 0.000205] clocksource: timer: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 79635851949 ns
[ 0.000450] Console: colour dummy device 80x30
[ 0.000506] Calibrating delay loop (skipped), value calculated using timer frequency.. 48.00 BogoMIPS (lpj=240000)
[ 0.000520] pid_max: default: 32768 minimum: 301
[ 0.000684] Mount-cache hash table entries: 1024 (order: 0, 4096 bytes, linear)
[ 0.000698] Mountpoint-cache hash table entries: 1024 (order: 0, 4096 bytes, linear)
[ 0.001505] CPU: Testing write buffer coherency: ok
[ 0.002027] /cpus/cpu@0 missing clock-frequency property
[ 0.002055] CPU0: thread -1, cpu 0, socket 0, mpidr 80000000
[ 0.002807] Setting up static identity map for 0x40100000 - 0x40100060
[ 0.003016] rcu: Hierarchical SRCU implementation.
[ 0.003548] smp: Bringing up secondary CPUs ...
[ 0.003569] smp: Brought up 1 node, 1 CPU
[ 0.003578] SMP: Total of 1 processors activated (48.00 BogoMIPS).
[ 0.003586] CPU: All CPU(s) started in SVC mode.
[ 0.004662] devtmpfs: initialized
[ 0.008111] VFP support v0.3: implementor 41 architecture 2 part 30 variant 7 rev 5
[ 0.008417] clocksource: jiffies: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 19112604462750000 ns
[ 0.008452] futex hash table entries: 256 (order: 2, 16384 bytes, linear)
[ 0.008714] pinctrl core: initialized pinctrl subsystem
[ 0.009780] NET: Registered protocol family 16
[ 0.010427] DMA: preallocated 256 KiB pool for atomic coherent allocations
[ 0.011690] hw-breakpoint: found 5 (+1 reserved) breakpoint and 4 watchpoint registers.
[ 0.011709] hw-breakpoint: maximum watchpoint size is 8 bytes.
[ 0.035258] SCSI subsystem initialized
[ 0.035449] usbcore: registered new interface driver usbfs
[ 0.035510] usbcore: registered new interface driver hub
[ 0.035611] usbcore: registered new device driver usb
[ 0.035848] mc: Linux media interface: v0.10
[ 0.035889] videodev: Linux video capture interface: v2.00
[ 0.036118] Advanced Linux Sound Architecture Driver Initialized.
[ 0.037409] clocksource: Switched to clocksource arch_sys_counter
[ 0.050204] NET: Registered protocol family 2
[ 0.051014] tcp_listen_portaddr_hash hash table entries: 512 (order: 0, 6144 bytes, linear)
[ 0.051056] TCP established hash table entries: 1024 (order: 0, 4096 bytes, linear)
[ 0.051083] TCP bind hash table entries: 1024 (order: 1, 8192 bytes, linear)
[ 0.051106] TCP: Hash tables configured (established 1024 bind 1024)
[ 0.051253] UDP hash table entries: 256 (order: 1, 8192 bytes, linear)
[ 0.051305] UDP-Lite hash table entries: 256 (order: 1, 8192 bytes, linear)
[ 0.051604] NET: Registered protocol family 1
[ 0.053490] Initialise system trusted keyrings
[ 0.053869] workingset: timestamp_bits=30 max_order=14 bucket_order=0
[ 0.090078] Key type asymmetric registered
[ 0.090102] Asymmetric key parser 'x509' registered
[ 0.090206] Block layer SCSI generic (bsg) driver version 0.4 loaded (major 250)
[ 0.090221] io scheduler mq-deadline registered
[ 0.090229] io scheduler kyber registered
[ 0.091281] sun4i-usb-phy 1c19400.phy: Couldn't request ID GPIO
[ 0.095163] sun8i-v3s-pinctrl 1c20800.pinctrl: initialized sunXi PIO driver
[ 0.095595] sun8i-v3s-pinctrl 1c20800.pinctrl: 1c20800.pinctrl supply vcc-pb not found, using dummy regulator
[ 0.096354] pwm-backlight backlight: backlight supply power not found, using dummy regulator
[ 0.166194] Serial: 8250/16550 driver, 8 ports, IRQ sharing disabled
[ 0.169796] printk: console [ttyS0] disabled
[ 0.190107] 1c28000.serial: ttyS0 at MMIO 0x1c28000 (irq = 34, base_baud = 1500000) is a U6_16550A
[ 0.705163] printk: console [ttyS0] enabled
[ 0.711109] sun8i-v3s-pinctrl 1c20800.pinctrl: 1c20800.pinctrl supply vcc-pe not found, using dummy regulator
[ 0.744489] panel-simple panel: panel supply power not found, using dummy regulator
[ 0.753856] ehci_hcd: USB 2.0 'Enhanced' Host Controller (EHCI) Driver
[ 0.760534] ehci-platform: EHCI generic platform driver
[ 0.766055] ehci-platform 1c1a000.usb: EHCI Host Controller
[ 0.771738] ehci-platform 1c1a000.usb: new USB bus registered, assigned bus number 1
[ 0.779723] ehci-platform 1c1a000.usb: irq 26, io mem 0x01c1a000
[ 0.807429] ehci-platform 1c1a000.usb: USB 2.0 started, EHCI 1.00
[ 0.814656] hub 1-0:1.0: USB hub found
[ 0.818619] hub 1-0:1.0: 1 port detected
[ 0.823250] ohci_hcd: USB 1.1 'Open' Host Controller (OHCI) Driver
[ 0.829577] ohci-platform: OHCI generic platform driver
[ 0.835133] ohci-platform 1c1a400.usb: Generic Platform OHCI controller
[ 0.841853] ohci-platform 1c1a400.usb: new USB bus registered, assigned bus number 2
[ 0.849838] ohci-platform 1c1a400.usb: irq 27, io mem 0x01c1a400
[ 0.922532] hub 2-0:1.0: USB hub found
[ 0.926377] hub 2-0:1.0: 1 port detected
[ 0.933728] usbcore: registered new interface driver usb-storage
[ 0.941348] sun6i-rtc 1c20400.rtc: registered as rtc0
[ 0.946413] sun6i-rtc 1c20400.rtc: RTC enabled
[ 0.951143] i2c /dev entries driver
[ 0.956105] input: ns2009_ts as /devices/platform/soc/1c2ac00.i2c/i2c-0/0-0048/input/input0
[ 0.965807] sunxi-wdt 1c20ca0.watchdog: Watchdog enabled (timeout=16 sec, nowayout=0)
[ 0.974508] sun8i-v3s-pinctrl 1c20800.pinctrl: 1c20800.pinctrl supply vcc-pf not found, using dummy regulator
[ 1.010069] sunxi-mmc 1c0f000.mmc: initialized, max. request size: 16384 KB
[ 1.017657] sun8i-v3s-pinctrl 1c20800.pinctrl: 1c20800.pinctrl supply vcc-pg not found, using dummy regulator
[ 1.029099] usbcore: registered new interface driver usbhid
[ 1.034678] usbhid: USB HID core driver
[ 1.041313] Initializing XFRM netlink socket
[ 1.045626] NET: Registered protocol family 17
[ 1.050792] Registering SWP/SWPB emulation handler
[ 1.056688] Loading compiled-in X.509 certificates
[ 1.066847] simple-framebuffer 43f80000.framebuffer: framebuffer at 0x43f80000, 0x7f800 bytes, mapped to 0x(ptrval)
[ 1.077441] simple-framebuffer 43f80000.framebuffer: format=x8r8g8b8, mode=480x272x32, linelength=1920
[ 1.089774] Console: switching to colour frame buffer device 60x34
[ 1.098263] simple-framebuffer 43f80000.framebuffer: fb0: simplefb registered!
[ 1.106798] sun8i-v3s-pinctrl 1c20800.pinctrl: 1c20800.pinctrl supply vcc-pe not found, using dummy regulator
[ 1.119398] sun4i-drm display-engine: bound 1100000.mixer (ops 0xc07469b8)
[ 1.126858] sun4i-drm display-engine: bound 1c0c000.lcd-controller (ops 0xc0743cb0)
[ 1.134616] [drm] Supports vblank timestamp caching Rev 2 (21.10.2013).
[ 1.141245] [drm] No driver support for vblank timestamp query.
[ 1.147168] fb0: switching to sun4i-drm-fb from simple
[ 1.153160] Console: switching to colour dummy device 80x30
[ 1.159848] [drm] Initialized sun4i-drm 1.0.0 20150629 for display-engine on minor 0
[ 1.194754] mmc0: host does not support reading read-only switch, assuming write-enable
[ 1.196795] mmc0: new high speed SDHC card at address b368
[ 1.198669] mmcblk0: mmc0:b368 NCard 29.1 GiB
[ 1.200976] mmcblk0: p1 p2
[ 1.206230] Console: switching to colour frame buffer device 60x34
[ 1.250491] sun4i-drm display-engine: fb0: sun4i-drmdrmfb frame buffer device
[ 1.258502] usb_phy_generic usb_phy_generic.0.auto: usb_phy_generic.0.auto supply vcc not found, using dummy regulator
[ 1.270004] musb-hdrc musb-hdrc.1.auto: MUSB HDRC host driver
[ 1.275820] musb-hdrc musb-hdrc.1.auto: new USB bus registered, assigned bus number 3
[ 1.285010] hub 3-0:1.0: USB hub found
[ 1.288982] hub 3-0:1.0: 1 port detected
[ 1.294072] sun6i-rtc 1c20400.rtc: setting system clock to 1970-01-01T00:00:52 UTC (52)
[ 1.302425] vcc3v0: disabling
[ 1.305406] vcc5v0: disabling
[ 1.308473] ALSA device list:
[ 1.311445] No soundcards found.
[ 1.350071] EXT4-fs (mmcblk0p2): recovery complete
[ 1.354902] EXT4-fs (mmcblk0p2): mounted filesystem with ordered data mode. Opts: (null)
[ 1.363222] VFS: Mounted root (ext4 filesystem) on device 179:2.
[ 1.377482] devtmpfs: error mounting -2
[ 1.382681] Freeing unused kernel memory: 1024K
[ 1.387420] Run /sbin/init as init process
[ 1.391628] Run /etc/init as init process
[ 1.395696] Run /bin/init as init process
[ 1.399819] Run /bin/sh as init process
[ 1.403666] Kernel panic - not syncing: No working init found. Try passing init= option to kernel. See Linux Documentation/admin-guide/init.rst for guidance.
[ 1.417817] CPU: 0 PID: 1 Comm: swapper/0 Not tainted 5.2.0-licheepi-zero #1
[ 1.424855] Hardware name: Allwinner sun8i Family
[ 1.429590] [<c010ec34>] (unwind_backtrace) from [<c010b6cc>] (show_stack+0x10/0x14)
[ 1.437334] [<c010b6cc>] (show_stack) from [<c069caa0>] (dump_stack+0x94/0xa8)
[ 1.444556] [<c069caa0>] (dump_stack) from [<c011dbd0>] (panic+0x118/0x30c)
[ 1.451514] [<c011dbd0>] (panic) from [<c06b4f68>] (kernel_init+0x104/0x114)
[ 1.458558] [<c06b4f68>] (kernel_init) from [<c01010e8>] (ret_from_fork+0x14/0x2c)
[ 1.466115] Exception stack(0xc3833fb0 to 0xc3833ff8)
[ 1.471162] 3fa0: 00000000 00000000 00000000 00000000
[ 1.479329] 3fc0: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
[ 1.487494] 3fe0: 00000000 00000000 00000000 00000000 00000013 00000000
[ 1.494112] Rebooting in 10 seconds..