2011-01-14

Embedded Linux from Scratch on VMWare: (2) Some Make-ups to Shell

1: 电源管理
============

执行halt或poweroff时, linux已 shut down, 系统提示"System halted"但硬件(电源)没有关闭



需要给kernel增加电源管理. 只需要启用电源管理(PM)和ACPI两个基本功能; idle, CPU频率调节, 睡眠等不是必须的
-> Power management and ACPI options
-> Power Management support
ACPI (Advanced Configuration and Power Interface) Support (NEW)
-> Future power /sys interface (NEW)
重建内核, 系统 poweroff 就可关机/断电了; halt 只关闭linux, 不断电, 这是预期的结果

2: 网络支持(TCP/IP)
======================

网络支持要启动的内核配置有: TCP/IP协议栈, Ethern和网卡驱动. 参考: http://tldp.org/HOWTO/NET3-4-HOWTO.html

首先增加TCP/IP协议栈
-> Networking support
-> Networking options
-> TCP/IP networking
以太网支持以及网络接口卡的驱动:
-> Device Drivers
-> Network device support
-> Ethernet (10 or 100Mbit)
-> EISA, VLB, PCI and on board controllers
->AMD PCnet32 PCI support
关于网络接口的硬件信息, 可在host上检查:
v4@elws:~$ lspci
...
02:00.0 Ethernet controller: Advanced Micro Devices [AMD] 79c970 [PCnet32 LANCE] (rev 10)
...
这是PCI网卡. lsmod 列出驱动模块, 可以找到名为 pcnet32 的 module
v4@elws:~$ lsmod | grep pcnet
pcnet32 27396 0
mii 4896 1 pcnet32
然后在menuconfig里搜索(按'/'键)pcnet32即可找到其设备驱动
重新build kernel, 启动 target. 检查以太网接口硬件是否识别
/ # dmesg | grep eth
pcnet32: eth0: registered as PCnet/PCI II 79C970A
设置一下 loop back:
/ # ifconfig lo 127.0.0.1
/ # ping 127.0.0.1
如果能ping通, 表明tcp/ip安装正常. 配置一下eth0(下面的地址是我的虚拟网络设置, 159.19.49.2 为网关)
/ # ifconfig eth0 159.19.49.43 netmask 255.255.255.0 broadcast 159.19.49.255
pcnet32 0000: 02:00.0: eth0: link up
/ # ping 159.19.49.2
如果能够ping通网关, 则表明以太网网络接口的设备驱动安装成功
可以将lo和eth0的配置命令放入/etc/init.d/rcS脚本中, 在系统启动时自动执行

另一种配置网络接口的方式是使用 ifup 命令, 它将设置在 /etc/network/interfaces 脚本中的网络接口 bring up. 该接口定义支持dhcp, 例如
auto lo eth0
iface lo inet loopback
#iface eth0 inet static
#address 159.19.49.43
#netmask 255.255.255.0
#gateway 159.19.49.2
iface eth0 inet dhcp
然后执行
ifdown -a # required to execute this before ifup
ifup -a
如果抱怨有/etc/networ/if-up.d 之类的目录找不到, 则创建对应目录
dhcp 是通过启动 busybox udhcpc 进程来配置的, 如果报错
udhcpc: socket: Address family not supported by protocol
google一下, 需要给内核配置以下几项:
-> Networking support
-> Networking options
-> Packet socket
-> Network packet filtering framework
现在, udhcpc 可以获取到IP地址了, 启动时可看到屏幕打印
udhcpc (v1.18.1) started
Sending discover...
Sending select for 159.19.49.136...
Lease of 159.19.49.136 obtained, lease time 1800
但是, ifconfig eth0 看到eth0起来了, 但还是没有分配ip v4地址. dmesg 可看到
pcnet32 0000:02:00.0: eth0: link up
eth0: no IPv6 routers present
ip v6倒不是问题. 主要是udhcpc 取得IP地址后, 将调用一个脚本, 该脚本进一步调用 ifconfig 来配置eth0. 启动到 host 上将 buildroot-2010.11/output/target/usr/share/udhcpc/default.script 拷贝到 target 的 /usr/share/udhcpc/default.script(注意: man udhcpc 说默认脚本为 /etc/udhcpc/default.script, 实际并非如此), 这样就应该可以正常 ifdown/ifup 来配置lo 和 eth0.

但是在udhcpc 执行 /usr/share/udhcpc/default.script脚本的过程中还有一条错误信息
route: SIOCDELRT: No such process
这是
route del default gw 0.0.0.0 eth0
一行产生的, 我还不清楚为什么会这样, 网上有人说到可以忽略. 现在还需要设置一下 hostname:
echo toy > /etc/hostname
hostname `cat /etc/hostname`
同时, 需要把第2行加入到 /etc/init.d/rcS 中, 让系统启动时自动设置

3: 禁用 console idle timeout
=================================

console 设备默认10分钟没有输入会黑屏, 如果不想要这个特性可以在 /boot/grub/menu.lst 中增加内核启动参数
consoleblank=0
其单位为秒, 0 表示禁用

4: 企鹅logo
=============

启用framebuffer, 获得图形界面的console(以及企鹅logo!)
参考 kernel 文档
  • Documentation/fb/framebuffer.txt
  • Documentation/fb/fbcon.txt
  • Documentation/fb/vesafb.txt
  • Documentation/svga.txt
  • 《Essential Linux Device Drivers》, Chapter 12, Linux-Video Subsystem 一节
需要为内核增加
  • vt(virtual terminal) 驱动 - 工作在 fbcon 或 vgacon 之上
  • fbcon 驱动 - 工作在 vesafb 之上, 对等于 vgacon 的地位
  • vesafb 驱动 - VESA 兼容图形卡的 framebuffer 驱动(framebuffer 对 VESA 的实现), 直接驱动硬件
启用 vesafb:
-> Device Drivers
-> Graphics support
-> Support for frame buffer devices
-> VESA VGA graphics support
启用 fbcon:
-> Device Drivers
-> Graphics support
-> Console display driver support
-> Framebuffer Console support
选择一个比较好的字体:
-> Device Drivers
-> Graphics support
-> Console display driver support
-> Select compiled-in fonts
-> VGA 8x16 font
启用linux企鹅logo:
-> Device Drivers
-> Graphics support
-> Bootup logo
在内核启动参数增加 vga=ask, 启动时将提示回车选择支持的vga模式. 选择340(800x600, 32位), kernel 启动并显示企鹅logo:


我们修改一下 /boot/grub/menu.lst:
kernel /boot/bzImage rw root=/dev/sda1 consoleblank=0 vga=0x341
# 0x341=>1024x768, 32 bit
创建一个 framebuffer 设备节点:
mknod /dev/fb0 c 29 1
Done!

5: NEXT TODO
==============

现在有了网络 + framebuffer, 系统大小 2.9 MB; 后面接下来要安装 GTK+2.0(gtk direct fb), 然后是一个浏览器

No comments:

Post a Comment