Raspberry Pi 笔记

编译内核

获取Kernel

1
$git clone --depth=1 https://github.com/raspberrypi/linux

获取交叉编译工具

1
$sudo apt-get install gcc-arm-linux-gnueabihf

进入目录设定编译选项

1
2
$cd linux
$make -j4 ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- bcm2709_defconfig

参数bcm2709_defconfig是Raspberry Pi2/3代,1代使用bcmrpi_defconfig
j4是使用4核心来编译,建议改为核心数的1.5倍
然后开始编译

1
$make -j4 ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- zImage modules dtbs

编译需要一段时间
完成之后插入烧写好raspbian系统的TF卡,安装modules

1
$sudo make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- INSTALL_MOD_PATH=/media/dan/7f593562-9f68-4bb9-a7c9-2b70ad620873/ modules_install

INSTALL_MOD_PATH后面的路径改为本机路径
可以选择覆盖掉原来的Kernel或者放置多个kernel以便切换
然后拷贝KernelDevice Tree blobs到TF卡

1
2
3
4
$sudo cp arch/arm/boot/zImage /media/dan/boot/kernel-new.img
$sudo cp arch/arm/boot/dts/*.dtb /media/dan/boot/
$sudo cp arch/arm/boot/dts/overlays/*.dtb* /media/dan/boot/overlays/
$sudo cp arch/arm/boot/dts/overlays/README /media/dan/boot/overlays/

如果没有覆盖Kernel的话,还需要编辑/boot/config.txt加上

1
kernel=kernel-new.img

编译就完成了

更换logo和启动画面

安装图形工具netpbm

1
$sudo apt-get install -y netpbm

准备一张63×80像素用于替换的logo.jpg
然后生成logo_linux_clut224.ppm

1
2
3
4
$cd ~/linux/drivers/video/logo
$jpegtopnm logo.jpg >logo.ppm
$ppmquant 224 logo.ppm >logo_224.tmp
$pnmnoraw logo_224.tmp > logo_linux_clut224.ppm

在交叉编译之前,确保开机logo是224色设置

1
make -j4 ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- menuconfig

位置在

  1. Device Drivers —>
  2. Graphics support —>
  3. [*] Bootup logo —>
  4. — Bootup logo
    [ ] Standard black and white Linux logo
    [ ] Standard 16-color Linux logo
    [*] Standard 224-color Linux logo

后续开始编译,步骤同上

启动画面

安装看图工具fbi

1
$sudo apt-get install fbi

拷贝图片并保存到/etc/splash.jpg
在TF卡的/etc/init.d/下创建新脚本asplashscreen

1
$sudo nano /etc/init.d/asplashscreen

内容

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#! /bin/sh
### BEGIN INIT INFO
# Provides: asplashscreen
# Required-Start:
# Required-Stop:
# Should-Start:
# Default-Start: S
# Default-Stop:
# Short-Description: Show custom splashscreen
# Description: Show custom splashscreen
### END INIT INFO


do_start () {

/usr/bin/fbi -T 1 -noverbose -a /etc/splash.jpg
exit 0
}

case "$1" in
start|"")
do_start
;;
restart|reload|force-reload)
echo "Error: argument '$1' not supported" >&2
exit 3
;;
stop)
# No-op
;;
status)
exit 0
;;
*)
echo "Usage: asplashscreen [start|stop]" >&2
exit 3
;;
esac

:

保存之后,设置文件执行属性

1
$sudo chmod a+x /etc/init.d/asplashscreen

最后将脚本加入服务

1
$sudo insserv /etc/init.d/asplashscreen

结束

屏蔽开机信息

打开/boot/cmdline.txt
修改console=tty1console=tty3
结尾增改为

1
logo.nologo loglevel=3 vt.global_cursor_default=0