当前位置:   article > 正文

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

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格式,脚本内容如下:

  1. #!/bin/sh
  2. rm logo_linux_clut224.c
  3. rm logo_linux_clut224.o
  4. pngtopnm logo-linux.png > logo-linux.pnm
  5. pnmquant 224 logo-linux.pnm > logo-linux224.pnm
  6. 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 源码并解压

  1. 下载psplash:gitclone git://git.yoctoproject.org/psplash
  2. 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脚本内容如下

  1. #!/bin/bash
  2. aclocal
  3. autoheader
  4. automake --add-missing
  5. autoconf

chmod 777 autogen.sh

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

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

  1. #!/bin/sh
  2. rm psplash
  3. rm psplash-write
  4. cp logo-linux.png psplash-poky.png -f
  5. ./make-image-header.sh psplash-poky.png POKY
  6. ./make-image-header.sh psplash-bar.png BAR
  7. ./autogen.sh
  8. ./configure --host=arm-linux-gnueabihf
  9. 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 脚本内容如下

  1. #!/bin/sh
  2. ### BEGIN INIT INFO
  3. # Provides: psplash
  4. # Required-Start:
  5. # Required-Stop:
  6. # Default-Start: S
  7. # Default-Stop:
  8. ### END INIT INFO
  9. read CMDLINE < /proc/cmdline
  10. for x in $CMDLINE; do
  11. case $x in
  12. psplash=false)
  13. echo "Boot splashscreen disabled"
  14. exit 0;
  15. ;;
  16. esac
  17. done
  18. export TMPDIR=/mnt/.psplash
  19. mount tmpfs -t tmpfs $TMPDIR -o,size=40k
  20. rotation=0
  21. if [ -e /etc/rotation ]; then
  22. read rotation < /etc/rotation
  23. fi
  24. /usr/bin/psplash --angle $rotation &

chmod 777 psplash.sh

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

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

  1. #!/bin/sh
  2. #
  3. # rcS Call all S??* scripts in /etc/rcS.d in
  4. # numerical/alphabetical order.
  5. #
  6. # Version: @(#)/etc/init.d/rcS 2.76 19-Apr-1999 miquels@cistron.nl
  7. #
  8. PATH=/sbin:/bin:/usr/sbin:/usr/bin
  9. runlevel=S
  10. prevlevel=N
  11. umask 022
  12. export PATH runlevel prevlevel
  13. # Make sure proc is mounted
  14. #
  15. [ -d "/proc/1" ] || mount /proc
  16. #
  17. # Source defaults.
  18. #
  19. . /etc/default/rcS
  20. #
  21. # Trap CTRL-C &c only in this shell so we can interrupt subprocesses.
  22. #
  23. trap ":" INT QUIT TSTP
  24. #
  25. # Call all parts in order.
  26. #
  27. exec /etc/init.d/rc S

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

  1. #!/bin/sh
  2. #
  3. # rc This file is responsible for starting/stopping
  4. # services when the runlevel changes.
  5. #
  6. # Optimization feature:
  7. # A startup script is _not_ run when the service was
  8. # running in the previous runlevel and it wasn't stopped
  9. # in the runlevel transition (most Debian services don't
  10. # have K?? links in rc{1,2,3,4,5} )
  11. #
  12. # Author: Miquel van Smoorenburg <miquels@cistron.nl>
  13. # Bruce Perens <Bruce@Pixar.com>
  14. #
  15. # Version: @(#)rc 2.78 07-Nov-1999 miquels@cistron.nl
  16. #
  17. . /etc/default/rcS
  18. export VERBOSE
  19. startup_progress() {
  20. step=$(($step + $step_change))
  21. if [ "$num_steps" != "0" ]; then
  22. progress=$((($step * $progress_size / $num_steps) + $first_step))
  23. else
  24. progress=$progress_size
  25. fi
  26. echo "PROGRESS is $progress $runlevel $first_step + ($step of $num_steps) $step_change $progress_size"
  27. if type psplash-write >/dev/null 2>&1; then
  28. TMPDIR=/mnt/.psplash psplash-write "PROGRESS $progress" || true
  29. fi
  30. #if [ -e /mnt/.psplash/psplash_fifo ]; then
  31. # echo "PROGRESS $progress" > /mnt/.psplash/psplash_fifo
  32. #fi
  33. }
  34. #
  35. # Start script or program.
  36. #
  37. startup() {
  38. # Handle verbosity
  39. [ "$VERBOSE" = very ] && echo "INIT: Running $@..."
  40. case "$1" in
  41. *.sh)
  42. # Source shell script for speed.
  43. (
  44. trap - INT QUIT TSTP
  45. scriptname=$1
  46. shift
  47. . $scriptname
  48. )
  49. ;;
  50. *)
  51. "$@"
  52. ;;
  53. esac
  54. startup_progress
  55. }
  56. # Ignore CTRL-C only in this shell, so we can interrupt subprocesses.
  57. trap ":" INT QUIT TSTP
  58. # Set onlcr to avoid staircase effect.
  59. stty onlcr 0>&1
  60. # Limit stack size for startup scripts
  61. [ "$STACK_SIZE" == "" ] || ulimit -S -s $STACK_SIZE
  62. # Now find out what the current and what the previous runlevel are.
  63. runlevel=$RUNLEVEL
  64. # Get first argument. Set new runlevel to this argument.
  65. [ "$1" != "" ] && runlevel=$1
  66. if [ "$runlevel" = "" ]
  67. then
  68. echo "Usage: $0 <runlevel>" >&2
  69. exit 1
  70. fi
  71. previous=$PREVLEVEL
  72. [ "$previous" = "" ] && previous=N
  73. export runlevel previous
  74. # Is there an rc directory for this new runlevel?
  75. if [ -d /etc/rc$runlevel.d ]
  76. then
  77. # Find out where in the progress bar the initramfs got to.
  78. PROGRESS_STATE=0
  79. #if [ -f /dev/.initramfs/progress_state ]; then
  80. # . /dev/.initramfs/progress_state
  81. #fi
  82. # Split the remaining portion of the progress bar into thirds
  83. progress_size=$(((100 - $PROGRESS_STATE) / 3))
  84. case "$runlevel" in
  85. 0|6)
  86. # Count down from -100 to 0 and use the entire bar
  87. first_step=-100
  88. progress_size=100
  89. step_change=1
  90. ;;
  91. S)
  92. # Begin where the initramfs left off and use 2/3
  93. # of the remaining space
  94. first_step=progress_size
  95. progress_size=$(($progress_size * 3))
  96. step_change=1
  97. ;;
  98. *)
  99. # Begin where rcS left off and use the final 1/3 of
  100. # the space (by leaving progress_size unchanged)
  101. first_step=$(($progress_size * 2 + $PROGRESS_STATE))
  102. step_change=1
  103. ;;
  104. esac
  105. num_steps=0
  106. for s in /etc/rc$runlevel.d/[SK]*; do
  107. case "${s##/etc/rc$runlevel.d/S??}" in
  108. gdm|xdm|kdm|reboot|halt)
  109. break
  110. ;;
  111. esac
  112. #遍历脚本的数量
  113. num_steps=$(($num_steps + 1))
  114. done
  115. step=0
  116. # First, run the KILL scripts.
  117. if [ $previous != N ]
  118. then
  119. for i in /etc/rc$runlevel.d/K[0-9][0-9]*
  120. do
  121. # Check if the script is there.
  122. [ ! -f $i ] && continue
  123. # Stop the service.
  124. startup $i stop
  125. done
  126. fi
  127. # Now run the START scripts for this runlevel.
  128. for i in /etc/rc$runlevel.d/S*
  129. do
  130. [ ! -f $i ] && continue
  131. if [ $previous != N ] && [ $previous != S ]
  132. then
  133. #
  134. # Find start script in previous runlevel and
  135. # stop script in this runlevel.
  136. #
  137. suffix=${i#/etc/rc$runlevel.d/S[0-9][0-9]}
  138. stop=/etc/rc$runlevel.d/K[0-9][0-9]$suffix
  139. previous_start=/etc/rc$previous.d/S[0-9][0-9]$suffix
  140. #
  141. # If there is a start script in the previous level
  142. # and _no_ stop script in this level, we don't
  143. # have to re-start the service.
  144. #
  145. [ -f $previous_start ] && [ ! -f $stop ] && continue
  146. fi
  147. case "$runlevel" in
  148. 0|6)
  149. startup $i stop
  150. ;;
  151. *)
  152. startup $i start
  153. ;;
  154. esac
  155. done
  156. fi
  157. #Uncomment to cause psplash to exit manually, otherwise it exits when it sees a VC switch
  158. if [ "x$runlevel" != "xS" ] && [ ! -x /etc/rc${runlevel}.d/S??xserver-nodm ]; then
  159. if type psplash-write >/dev/null 2>&1; then
  160. TMPDIR=/mnt/.psplash psplash-write "QUIT" || true
  161. umount -l /mnt/.psplash
  162. fi
  163. 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中配置

  1. /*
  2. * pslash - a lightweight framebuffer splashscreen for embedded devices.
  3. *
  4. * Copyright (c) 2014 MenloSystems GmbH
  5. * Author: Olaf Mandel <o.mandel@menlosystems.com>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2, or (at your option)
  10. * any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. */
  18. #ifndef _HAVE_PSPLASH_CONFIG_H
  19. #define _HAVE_PSPLASH_CONFIG_H
  20. /* Text to output on program start; if undefined, output nothing */
  21. #define PSPLASH_STARTUP_MSG ""
  22. /* Bool indicating if the image is fullscreen, as opposed to split screen */
  23. #define PSPLASH_IMG_FULLSCREEN 0
  24. /* Position of the image split from top edge, numerator of fraction */
  25. #define PSPLASH_IMG_SPLIT_NUMERATOR 5
  26. /* Position of the image split from top edge, denominator of fraction */
  27. #define PSPLASH_IMG_SPLIT_DENOMINATOR 6
  28. #endif

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

  1. /*
  2. * pslash - a lightweight framebuffer splashscreen for embedded devices.
  3. *
  4. * Copyright (c) 2012 sleep(5) ltd
  5. * Author: Tomas Frydrych <tomas@sleepfive.com>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2, or (at your option)
  10. * any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. */
  18. #ifndef _HAVE_PSPLASH_COLORS_H
  19. #define _HAVE_PSPLASH_COLORS_H
  20. /* This is the overall background color */
  21. #define PSPLASH_BACKGROUND_COLOR 0xec,0xec,0xe1
  22. /* This is the color of any text output */
  23. #define PSPLASH_TEXT_COLOR 0x6d,0x6d,0x70
  24. /* This is the color of the progress bar indicator */
  25. #define PSPLASH_BAR_COLOR 0x6d,0x6d,0x70
  26. /* This is the color of the progress bar background */
  27. #define PSPLASH_BAR_BACKGROUND_COLOR 0xec,0xec,0xe1
  28. #endif

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/菜鸟追梦旅行/article/detail/334940
推荐阅读
相关标签
  

闽ICP备14008679号