1.  软件结构组成


机顶盒修改bios设置 boot 机顶盒_启动脚本



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开始运行。 

 
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] 
 
 
 
 
  
 //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 

 
 
 
 
//读取kernel镜像
 

   3145728 bytes read: OK 

 
<--------
 

     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 

 
 解压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 

 
 
 
 
//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进程





机顶盒修改bios设置 boot 机顶盒_机顶盒修改bios设置_02



启动脚本

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的脚本