linux修改内核logo和增加开机进度条

修改内核logo 

1.将我们准备好的 logo-linux.png 图片拷贝到drivers/video/logo 这个目录下

2.我们需要把 png 格式的图片转换成 ppm 格式,安装sudo apt-get install netpbm这个工具

3.创建linux_logo_png_to_ppm.sh脚本将png图片转换成ppm格式,脚本内容如下:

#!/bin/sh
rm logo_linux_clut224.c
rm logo_linux_clut224.o

pngtopnm logo-linux.png > logo-linux.pnm
pnmquant 224 logo-linux.pnm > logo-linux224.pnm
pnmtoplainpnm logo-linux224.pnm > logo_linux_clut224.ppm

chmod 777 linux_logo_png_to_ppm.sh

./linux_logo_png_to_ppm.sh

回到linux源码的根目录重新编译源码

make zImgae -j8

如果重新跑内核没有显示Logo:

1.图片尺寸超过了屏幕的分辨

2.检查设备树的LCD

增加开机进度条

        linux内核启动的时候首先显示开机Logo,当"init"进程创建完成后,Linux从内核态切换到用户态,init程序通过/etc/inittab文件进行配置,进而执行/etc/init.d/rcS脚本,然后执行/etc/init.d/下的所有脚本开启相应的服务与功能。在执行执行/etc/init.d/下脚本开启服务的时候可能会比较耗时,因此在此阶段增加一个进度条可提示当前服务的开启情况。

1.下载 psplash 源码并解压

下载psplash:gitclone git://git.yoctoproject.org/psplash
tar -vxf psplash.tar.gz

 psplash-poky.png和psplash-bar.png分别是显示的Logo和进度条

2.安装下面的库,否则编译会报错

sudo apt-get install libgdk-pixbuf2.0-dev

3.制作 autogen.sh 脚本,用于生成 Makefile,autogen.sh脚本内容如下

    #!/bin/bash
    aclocal
    autoheader
    automake --add-missing
    autoconf

chmod 777 autogen.sh

4.将logo-linux.png图片复制到psplash目录下

5.编写auto_generate.sh脚本一键自动生成paplash和psplash-write可执行文件,auto_generate.sh脚本内容如下

#!/bin/sh
rm psplash
rm psplash-write
cp logo-linux.png psplash-poky.png -f
./make-image-header.sh psplash-poky.png POKY
./make-image-header.sh psplash-bar.png BAR
./autogen.sh
./configure --host=arm-linux-gnueabihf
make

1.首先是删除psplash和psplash-write

2.将logo-linux.png重命名为psplash-poky.png

3../configure是配置交叉编译工具链

chmod 777 auto_generate.sh

./auto_generate.sh

最后 将编译生成的 psplash 和 psplash-write 文件拷贝到开发板文件系统/usr/bin 目录下。

6.新建psplash.sh 脚本,并将其拷贝到开发板文件系统的/etc/init.d/目录下,psplash.sh 脚本内容如下

#!/bin/sh

### BEGIN INIT INFO

# Provides: psplash

# Required-Start:

# Required-Stop:

# Default-Start: S

# Default-Stop:

### END INIT INFO

read CMDLINE < /proc/cmdline

for x in $CMDLINE; do

case $x in

psplash=false)

echo "Boot splashscreen disabled"

exit 0;

;;

esac

done

export TMPDIR=/mnt/.psplash

mount tmpfs -t tmpfs $TMPDIR -o,size=40k

rotation=0

if [ -e /etc/rotation ]; then

read rotation < /etc/rotation

fi

/usr/bin/psplash --angle $rotation &

chmod 777 psplash.sh

脚本最后执行psplash程序,传参当前屏幕的角度,psplash运行起来后刷Logo图片,创建管道文件阻塞等待psplash-write程序向管道文件中写入进度条更新命令参数

7.linux启动顺序执行/etc/inittab-->/etc/init.d/rcS。rcS内容如下

#!/bin/sh
#
# rcS		Call all S??* scripts in /etc/rcS.d in
#		numerical/alphabetical order.
#
# Version:	@(#)/etc/init.d/rcS  2.76  19-Apr-1999  miquels@cistron.nl
#

PATH=/sbin:/bin:/usr/sbin:/usr/bin
runlevel=S
prevlevel=N
umask 022
export PATH runlevel prevlevel

#	Make sure proc is mounted
#
[ -d "/proc/1" ] || mount /proc

#
#	Source defaults.
#
. /etc/default/rcS

#
#	Trap CTRL-C &c only in this shell so we can interrupt subprocesses.
#
trap ":" INT QUIT TSTP

#
#	Call all parts in order.
#
exec /etc/init.d/rc S

最后执行了/etc/init.d/下的rc脚本文件,传参S,rc文件内容如下

#!/bin/sh
#
# rc		This file is responsible for starting/stopping
#		services when the runlevel changes.
#
#		Optimization feature:
#		A startup script is _not_ run when the service was
#		running in the previous runlevel and it wasn't stopped
#		in the runlevel transition (most Debian services don't
#		have K?? links in rc{1,2,3,4,5} )
#
# Author:	Miquel van Smoorenburg <miquels@cistron.nl>
#		Bruce Perens <Bruce@Pixar.com>
#
# Version:	@(#)rc  2.78  07-Nov-1999  miquels@cistron.nl
#

. /etc/default/rcS
export VERBOSE

startup_progress() {
    step=$(($step + $step_change))
    if [ "$num_steps" != "0" ]; then
        progress=$((($step * $progress_size / $num_steps) + $first_step))
    else
        progress=$progress_size
    fi
    echo "PROGRESS is $progress $runlevel $first_step + ($step of $num_steps) $step_change $progress_size"
    if type psplash-write >/dev/null 2>&1; then
        TMPDIR=/mnt/.psplash psplash-write "PROGRESS $progress" || true
    fi
    #if [ -e /mnt/.psplash/psplash_fifo ]; then
    #    echo "PROGRESS $progress" > /mnt/.psplash/psplash_fifo
    #fi
}


#
# Start script or program.
#
startup() {
  # Handle verbosity
  [ "$VERBOSE" = very ] && echo "INIT: Running $@..."

  case "$1" in
	*.sh)
		# Source shell script for speed.
		(
			trap - INT QUIT TSTP
			scriptname=$1
			shift
			. $scriptname
		)
		;;
	*)
		"$@"
		;;
  esac
  startup_progress
}

  # Ignore CTRL-C only in this shell, so we can interrupt subprocesses.
  trap ":" INT QUIT TSTP

  # Set onlcr to avoid staircase effect.
  stty onlcr 0>&1

  # Limit stack size for startup scripts
  [ "$STACK_SIZE" == "" ] || ulimit -S -s $STACK_SIZE

  # Now find out what the current and what the previous runlevel are.

  runlevel=$RUNLEVEL
  # Get first argument. Set new runlevel to this argument.
  [ "$1" != "" ] && runlevel=$1
  if [ "$runlevel" = "" ]
  then
	echo "Usage: $0 <runlevel>" >&2
	exit 1
  fi
  previous=$PREVLEVEL
  [ "$previous" = "" ] && previous=N

  export runlevel previous

  # Is there an rc directory for this new runlevel?
  if [ -d /etc/rc$runlevel.d ]
  then
	# Find out where in the progress bar the initramfs got to.
	PROGRESS_STATE=0
	#if [ -f /dev/.initramfs/progress_state ]; then
	#    . /dev/.initramfs/progress_state
	#fi

	# Split the remaining portion of the progress bar into thirds
	progress_size=$(((100 - $PROGRESS_STATE) / 3))

	case "$runlevel" in
		0|6)
			# Count down from -100 to 0 and use the entire bar
			first_step=-100
			progress_size=100
			step_change=1
			;;
	        S)
			# Begin where the initramfs left off and use 2/3
			# of the remaining space
			first_step=progress_size
			progress_size=$(($progress_size * 3))
			step_change=1
			;;
		*)
			# Begin where rcS left off and use the final 1/3 of
			# the space (by leaving progress_size unchanged)
			first_step=$(($progress_size * 2 + $PROGRESS_STATE))
			step_change=1
			;;
	esac

	num_steps=0
	for s in /etc/rc$runlevel.d/[SK]*; do
            case "${s##/etc/rc$runlevel.d/S??}" in
                gdm|xdm|kdm|reboot|halt)
                    break
                    ;;
            esac
            #遍历脚本的数量
            num_steps=$(($num_steps + 1))
        done
        step=0

	# First, run the KILL scripts.
	if [ $previous != N ]
	then
		for i in /etc/rc$runlevel.d/K[0-9][0-9]*
		do
			# Check if the script is there.
			[ ! -f $i ] && continue

			# Stop the service.
			startup $i stop
		done
	fi

	# Now run the START scripts for this runlevel.
	for i in /etc/rc$runlevel.d/S*
	do
		[ ! -f $i ] && continue

		if [ $previous != N ] && [ $previous != S ]
		then
			#
			# Find start script in previous runlevel and
			# stop script in this runlevel.
			#
			suffix=${i#/etc/rc$runlevel.d/S[0-9][0-9]}
			stop=/etc/rc$runlevel.d/K[0-9][0-9]$suffix
			previous_start=/etc/rc$previous.d/S[0-9][0-9]$suffix
			#
			# If there is a start script in the previous level
			# and _no_ stop script in this level, we don't
			# have to re-start the service.
			#
			[ -f $previous_start ] && [ ! -f $stop ] && continue
		fi
		case "$runlevel" in
			0|6)
				startup $i stop
				;;
			*)
				startup $i start
				;;
		esac
	done
  fi

#Uncomment to cause psplash to exit manually, otherwise it exits when it sees a VC switch
if [ "x$runlevel" != "xS" ] && [ ! -x /etc/rc${runlevel}.d/S??xserver-nodm ]; then
    if type psplash-write >/dev/null 2>&1; then
        TMPDIR=/mnt/.psplash psplash-write "QUIT" || true
    	umount -l /mnt/.psplash
    fi
fi

chmod 777 rc

rc脚本启动/etc/rcS.d下的所有脚本文件并更新进度条显示

1.将进度条分成3份

2.遍历/etc/rcS.d/目录下的Sxx脚本文件数量

3.从三分之一的地方开始走进度条,留三分之二来提示脚本的执行进度,每执行完一个脚本步进1,所有脚本执行完毕进度条走到尽头100%。

num_steps=10    脚本文件的数量
first_step=100/3=33   从三分之一的地方开始递增
progress_size=100/3*2=66 将三分之二的进度条分割为num_steps来走进度

progress=$((($step * $progress_size / $num_steps) + $first_step))
progress=$((($step * 66 / 10) + 33))

每执行一个脚本step++

如果需要从0%开始走进度到100%,修改first_step=0,progress_size=100

/etc/rcS.d/目录下的Sxx脚本其实都是/etc/init.d/目录下的软链接

 按照Sxx文件的xx由小到大顺序执行脚本开启相应的服务

总结:psplash.sh脚本把psplash程序运行起来后,创建一个管道文件,阻塞等待rc脚本中通过psplash-write程序向管道中写入更新进度条的命令参数。

关于psplash是否显示提示文字和logo显示的位置可在psplash-config.h中配置

/*
 *  pslash - a lightweight framebuffer splashscreen for embedded devices.
 *
 *  Copyright (c) 2014 MenloSystems GmbH
 *  Author: Olaf Mandel <o.mandel@menlosystems.com>
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2, or (at your option)
 *  any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 */

#ifndef _HAVE_PSPLASH_CONFIG_H
#define _HAVE_PSPLASH_CONFIG_H

/* Text to output on program start; if undefined, output nothing */
#define PSPLASH_STARTUP_MSG ""

/* Bool indicating if the image is fullscreen, as opposed to split screen */
#define PSPLASH_IMG_FULLSCREEN 0

/* Position of the image split from top edge, numerator of fraction */
#define PSPLASH_IMG_SPLIT_NUMERATOR 5

/* Position of the image split from top edge, denominator of fraction */
#define PSPLASH_IMG_SPLIT_DENOMINATOR 6

#endif

关于psplash进度条的颜色可在psplash-colors.h中配置

/*
 *  pslash - a lightweight framebuffer splashscreen for embedded devices.
 *
 *  Copyright (c) 2012 sleep(5) ltd
 *  Author: Tomas Frydrych <tomas@sleepfive.com>
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2, or (at your option)
 *  any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 */

#ifndef _HAVE_PSPLASH_COLORS_H
#define _HAVE_PSPLASH_COLORS_H

/* This is the overall background color */
#define PSPLASH_BACKGROUND_COLOR 0xec,0xec,0xe1

/* This is the color of any text output */
#define PSPLASH_TEXT_COLOR 0x6d,0x6d,0x70

/* This is the color of the progress bar indicator */
#define PSPLASH_BAR_COLOR 0x6d,0x6d,0x70

/* This is the color of the progress bar background */
#define PSPLASH_BAR_BACKGROUND_COLOR 0xec,0xec,0xe1

#endif

  • 1
    点赞
  • 20
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值