构建Linux笔记v1.0(第一部分)

2014-04-19 20:54:02
构建Linux 编译Linux BeagleBone Black

很久之前的文章,用Makrdown重发布下。

仅供参考,我用Linux的时间较少。
以下很多都是回忆,不一定准了。


我构建的目标平台为BeagleBone Black

交叉编译工具为Sourcery CodeBench Lite

要构建Linux,很简单,只有3个部分,

  1. bootloader,即启动引导程序,我选择U-Boot。
  2. Linux内核。
  3. 应用程序。

我还没研究是什么决定了32位和64位。

我主要的资料:
Running Linux
介绍Linux的书,这才叫入门级,了解下Linux的思想即可,书的内容可能有些过时,
这本书不是介绍怎么使用Linux的。如果想知道怎么使用Linux,
可看看Linux Pocket Guide,很薄。
鸟哥的书也不错,感觉挺详细的,好于大部分书,我没看。
我连shell脚本都不会写呢,很多命令没用过,这与构建Linux关系不大。

Building Embedded Linux Systems
教构建嵌入式Linux的,了解下思想即可。

http://www.linuxfromscratch.org/
教构建各种Linux的网站,最关键的是网站给出了Linux由哪些应用程序构成。
我没有用网站中的方式,sed那种命令不会。也是了解下思想即可。

If you can’t explain it simply, you don’t understand it well enough.
–Albert Einstein

准备SD卡

BeagleBone Black有4种启动方式,我选择用SD卡。
准备SD卡,将SD卡插到电脑中,在我的系统中被识别为/dev/sdb。

分区:

# fdisk /dev/sdb

用法很简单,输入m,就可得到帮助。
第一个分区64M,类型为FAT32 (LBA),加上启动标记。
第二个分区为余下的全部,类型默认为Linux,不必改。

参考过程是这样的,
输入o,新建一个空DOS分区表,这会清除所有分区。
输入p,会列出分区列表,此时应该没有。
输入n来添加新分区,直接enter,接受默认为主分区,enter接受默认为第一分区,
enter接受默认的开始扇区,输入+64M,设置分区大小为64M。
输入t,来改变分区类型,自动选择了第一个分区,输入l可列出所有分区列表的代码,
输入c选择W95 FAT32(LBA)。
输入a,在第一分区设置可启动标记。
输入nenter主分区,enter第二个,enter起始扇区,enter结束扇区。
输入w,将改动写入分区表。

格式化:

# mkfs.vfat -F 32 /dev/sdb1
# mkfs.ext4 /dev/sdb2

第一个分区用来放U-Boot,板子启动后就会找一个叫MLO的文件,
编译U-Boot后,就会生成一个MLO,不必担心。
第二个分区用来放Linux系统。

sdb2被格式化后,里面自动有个lost+found,文件系统的结构中正好有一条:

/lost+found: Filesystem-specific recoverable data

我的文件系统目录结构

/
/bin             --> /usr/bin/
/boot/
/dev/
/etc/
/home/
/home/root
/lib             --> /usr/lib/
/mnt/
/proc/
/run/
/sbin            --> /usr/bin/
/sys/
/tmp
/usr/
/usr/app/
/usr/bin/
/usr/include/
/usr/lib/
/usr/sbin       --> bin/
/usr/share/
/usr/share/man/
/var/
/var/run         --> /run/

便签

编译时的一些配置等,我为了方便调用,放到这里。

$ export PATH=$PATH:/home/spy/Software/arm-2013.11/bin
$ export PATH=$PATH:/home/spy/Work/U-Boot/u-boot/tools
$ export CROSS_COMPILE=arm-none-linux-gnueabi-
# chown -R 0:0 
# chgrp -v tty /usr/app/util-linux/bin/wall
# chown -R spy:users 

找readelf结果中带"Shared library"的行

readelf -ld | grep "Shared library"

以可读写重新挂载根文件系统

mount -n -o remount,rw /

放到交叉编译器搜索库中的程序库
libcap,pam,ncurses,gdbm,db,iptables

coreutils与util-linux重复的命令。
kill

shadow与util-linux重复的命令。
{login,nologin,su}

shadow与coreutils重复的命令。
groups

下面是编译软件的过程

U-Boot

$ export PATH=$PATH:/home/spy/Software/arm-2013.11/bin
$ export CROSS_COMPILE=arm-none-linux-gnueabi-

$ make O=../u-boot distclean
$ make O=../u-boot am335x_boneblack_config
$ make O=../u-boot all

源码中正好有am335x_boneblack这个配置文件,对应我的开发板,想知道可用的配置文件
看README吧,它会告诉你到另一个文件中找。

忘了是编译U-Boot还是Linux内核的时候,提示我的系统中缺少bc,用你的包管理器安上就好了。


摘自TI的wiki,让你了解MLO和u-boot.img是什么。
大概是AM335X芯片中的程序较小,只为了4种启动方式初始化,
然后找到MLO,运行MLO进一步初始化,如DDR3内存。
MLO最后找到u-boot.img,运行之。u-boot.img这个名字应该是在MLO的代码中指定的。
提示:TI的StarterWare中的2个文件叫MLO和app。

Two stage U-Boot design

This section gives an overview of the two stage U-Boot approach adopted for AM335X.

The size of the internal RAM in AM335X is 128KB out of which
18KB at the end is used by the ROM code. Also,
1 KB at the start (0x402f0000 - 0x402f0400) is secure and it cannot be accessed
This places a limit of 109KB on the size of the U-Boot binary which
the ROM code can transfer to the internal RAM and use as an initial stack
before initialization of DRAM.

Since it is not possible to squeeze in all the functionality
that is normally expected from U-Boot in < 110KB (after setting aside some space
for stack, heap etc) a two stage approach has been adopted.
Initial stage initalize only the required boot devices (NAND, MMC, I2C etc);
2nd full stage initall all other devices (ethernet, timers, clocks etc).
The 1st binary is generated MLO and the 2nd stage is generated as u-boot.img.


编译完后,现在就可以找找成就感了,

  1. 将MLO和u-boot.img复制到SD卡的第一个分区里;
  2. 将串口调试用的线与计算机相连,启动串口调试程序,如Putty。
  3. 将SD卡插入开发板,保持按下板子上的启动选择键,插上电源,板子会从SD卡启动,
  4. 可以松开启动选择键了。

Putty的窗口上会打印一些信息,你会看到一个1秒的倒计时,然后U-Boot会运行环境变量中
已经设置好的一些列命令,比如将Linux内核载入内存,但此时还没有内核文件,U-Boot会
停留在它自己的命令行中,你可以输入命令,如reset,这会让板子重启,倒计时的时候
按下计算机上的任意键,U-Boot就不会运行环境变量中的命令了,可玩一玩下面的演示。

给出U-Boot中的一些演示,输入help可显示所有命令。
help后接命令,可显示该命令的帮助。如"help help"。

U-Boot# mmc rescan
U-Boot# mmc list
OMAP SD/MMC: 0
 OMAP SD/MMC: 1
U-Boot# mmc dev
mmc0 is current device
U-Boot# mmc part

Partition Map for MMC device 0  --   Partition Type: DOS

Part    Start Sector    Num Sectors     UUID            Type
  1     2048            131072          29942d7e-01     0c Boot
  2     133120          15390720        29942d7e-02     83
U-Boot# ls mmc 0:1
   100688   mlo
   308232   u-boot.img
      510   uenv.txt

3 file(s), 0 dir(s)

U-Boot# ls mmc 0:2
<DIR>       4096 .
<DIR>       4096 ..
<SYM>          7 bin
<DIR>       4096 boot
<DIR>       4096 dev
<DIR>       4096 etc
<DIR>       4096 home
<SYM>          7 lib
<DIR>       4096 lost+found
<DIR>       4096 mnt
<DIR>       4096 proc
<DIR>       4096 run
<SYM>          7 sbin
<DIR>       4096 sys
<DIR>       4096 tmp
<DIR>       4096 usr
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值