机顶盒软件组成及启动流程

1.  软件结构组成


    uboot        : 一种boot loader,负责机顶盒嵌入式linux的系统引导工作,引导系统启动,已经系统维护(镜像烧写,软件更新)。
    env            :uboot 的环境变量,存储着一些变量及其值,供uboot使用,比较重要的两个变量:bootcmd  bootargs。
    logo          :开机图片。
    loader       :升级程序。
    loaderbak :升级程序备份。
    kernel        :linux 内核。
    rootfs         :linux 根文件系统。
    app            :应用程序。
    ui               :页面文件。
    data           :应用程序数据。
    stbenv       :机顶盒产品信息。

2. 启动流程
   总体流程:
   上电  -->  运行uboot  --> 加载kernel,运行kernel  -->  挂载根文件系统  -->  运行init进程  -->  执行启动脚本  -->  运行app

   1.  uboot存储在flash设备的0地址处,上电后,从uboot开始运行。
   2.  uboot起来后会运行bootcmd变量中的指令,bootcmd会读取kernel镜像,然后用 bootm命令去解压kernel镜像并运行kernel,
        运行kernel时,bootargs变量值会传递给kernel。
   3.  kernel起来后根据 bootargs 中root描述挂载 rootfs 。
   4.  rootfs挂载成功后,会运行 init 进程。
   5.  init 进程起来后,会执行启动脚本。
   6.  启动脚本中运行app。

下面是一段盒子启动打印:
Board: STiH237-HDK (B2141)  [32-bit mode] 

U-Boot 2010.09 (Feb 12 2015 - 14:59:24) - stm24-2013-08-17    //uboot 运行

DRAM:  256 MiB
NAND:  ONFI flash detected
ONFI param page 0 valid
ONFI flash is MT29F4G08ABADAH4, 512 MiB, page size 2048+64, sector size 128 KiB
512 MiB
SPI:  info: found ST N25Q256 (32MiB) device (page=256,erase=65536)
info: BCH controller initializing with ECC of 18-bits per 1KiB sector
Bad block table found at page 262080, version 0x01
Bad block table found at page 262016, version 0x01
In:    serial
Out:   serial
Err:   serial
Net:   stmac-0
   Uncompressing Linux 2.6 ...

### 1843224 ###

xxxxxxxx: enable clk
xxxxxxxx: display hd logo
xxxxxxxx: display sd logo
can not find this value
Hit any key to stop autoboot:  0

NAND read: device 0 offset 0x2200000, size 0x300000      //读取kernel镜像
 3145728 bytes read: OK
## Booting kernel from Legacy Image at 80000000 ...          <--------
   Image Name:   Linux 3.4
   Image Type:   SuperH Linux Kernel Image (gzip compressed)
   Data Size:    2080907 Bytes =   2 MiB
   Load Address: 80800000
   Entry Point:  80801000
   Verifying Checksum ... OK
   Uncompressing Kernel Image ... OK                                     解压kernel镜像的打印 ------>

Starting kernel:                              //运行kernel,bootargs传递给kernel
   start    = 0x80801000
   initrd   = 0x00000000 (0 bytes)
   bootargs = console=ttyAS0,115200 ubi.mtd=5 root=ubi0:rootfs rootfstype=ubifs rw mtdparts=stm-nand-bch:1M(uboot),1M(logo),16M(loader),16M(loader_bak),3M(kernel),32M(rootfs),64M(app),32M(ui),345M(data),1M(stbenv) stmmaceth=msglvl:0,watchdog:5000 M129(000000):eth0:off bigphysarea=3000 elevator=cfq

Welcome to STLinux (busybox)!    //init 进程启动,执行启动脚本,脚本中打印的欢迎标语。
[system background process]

//下面是挂载app  ui  data 分区的打印
UBI device number 1, total 512 LEBs (65011712 bytes, 62.0 MiB), available 0 LEBs (0 bytes), LEB size 126976 bytes (124.0 KiB)
UBI device number 2, total 256 LEBs (32505856 bytes, 31.0 MiB), available 0 LEBs (0 bytes), LEB size 126976 bytes (124.0 KiB)
  STxH205  detected (32BITS)
UBI device number 3, total 2760 LEBs (350453760 bytes, 334.2 MiB), available 0 LEBs (0 bytes), LEB size 126976 bytes (124.0 KiB)

Please press Enter to activate this console.

//应用程序开始运行
 -----------------------------------------------------
 Software  : iPanel 3.0 Advanced
 Platform  : STiH273
 Branch    : Debug Branch
 [BuildTime]-[Sep  7 2015]-[17:59:41]
 -----------------------------------------------------


uboot环境变量
uboot命令行,输入 print 即可打印 uboot 环境变量,环境变量可以配置ip serverip mac 地址等(tftp工具下载镜像需要配置ip)。注意以下两个变量:

bootcmd=nand read 80000000 2200000 300000; bootm 80000000
bootargs=console=ttyAS0,115200 ubi.mtd=5 root=ubi0:rootfs rootfstype=ubifs rw mtdparts=stm-nand-bch:1M(uboot),1M(logo),16M(loader),16M(loader_bak),3M(kernel),32M(rootfs),64M(app),32M(ui),345M(data),1M(stbenv) stmmaceth=msglvl:0,watchdog:5000 M129(000000):eth0:off bigphysarea=3000 elevator=cfq

bootcmd:启动命令,描述kernel启动的命令,从上面变量值可以看到是从nand flash中读取了kernel镜像,并交给bootm命令去解压执行。
bootargs:启动参数描述,这些参数会传递给kernel,kernel启动后需要用到这里的参数,例如 root 描述的根文件系统信息,console 描述的串口信息,以及分区划分信息。

init进程
kernel启动后,会挂载根文件系统,然后执行init进程,shell命令行模式下输入 top 命令查看,即可发现这个init进程,其pid是1,是系统启动后运行的第一个用户态进程。


启动脚本
ST平台启动脚本是 /etc/init.d/rcSBB, 不同平台略有区别,因为使用的不同的根文件系统,根文件系统中的 init 进程不同,init 读取启动脚本并执行的策略会有区别,但都是类似的模式。ST 平台启动脚本内容:

#!/bin/sh
echo "Welcome to STLinux (busybox)!"    //欢迎标语
# mount proc filesystem                            <-------
mount -t proc proc /proc
# mount devpts to allow logging in
mount -t devpts devpts /dev/pts -ogid=5,mode=620
# mount sysfs
mount -t sysfs sysfs /sys
#mount -t fusectl fusectl /sys/fs/fuse/connections      挂载一些文件系统 ------>
# start the telnet daemon to allow remote login
#busybox telnetd -l /bin/sh
/sbin/syscall &
/sbin/udevd.sh
/root/ipanel_start.sh          //执行启动app的脚本


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值