Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2122038
  • 博文数量: 229
  • 博客积分: 7217
  • 博客等级: 上校
  • 技术积分: 3224
  • 用 户 组: 普通用户
  • 注册时间: 2009-02-19 17:23
个人简介

个人主页https://xugaoxiang.com,微信公众号: Dev_Club 或者搜索 程序员Club

文章分类

全部博文(229)

文章存档

2017年(1)

2016年(20)

2015年(23)

2013年(1)

2012年(23)

2011年(68)

2010年(62)

2009年(31)

分类: LINUX

2009-12-25 11:26:29

一、简介

GeeXboX是一个linux多媒体操作系统,是一款开源软件,集成强悍的mplayer播放器,支持大多数的音视频格式,是你身边的open media center。
上图是GeeXboX在虚拟机virtualbox里运行的画面。

GeeXboX的UI不是由X Window上的GTK+实现的,而是MPlayer的OSD。

GeeXboX支持:

- MPEG 1/2 movies (MPG files, VCDs, DVDs ...)
- MPEG 4 movies (DivX, XviD, H.264 ...)
- RealMedia and Windows Media movies.
- OggMedia streams
- Matroska streams
- Audio streams like : MP3, Ogg/Vorbis, WAV (AudioCD), AC3, DTS, MusePack (MPC), FLAC ...
- Network streams : WebRadio and WebTV through SHOUTcast.
- Watching analog TV and digital DVB
- Playing analog Radio streams.
- Playing files from your local network (LAN) through remote NFS, Samba (i.e. Windows) or UPnP shares.

二、启动顺序

This section deals with booting from a CD, but most of the information applies in a similar way to booting from USB stick.

MBR

The BIOS loads the MBR (Master Boot Record) from CD into memory and executes it. The place on the CD where the BIOS looks for the MBR is determined by the ISO9660 standard. Generally speaking the boot loader software provides the binary code for the MBR. This is usually written is assember as it runs in Real mode. In this mode your pc still thinks it's a 286 with only 640k of memory. Once the kernel is booted, the system switches into protected mode where it can address its memory properly using 32 bit addressing, and run to it's full potential (helped by linux of course).

ISOLinux

ISOLinux is the bootloader used when GeeXboX boots from CD. In the ISOLinux configuration (/GEEXBOX/boot/isolinux.cfg) the important parameters are the path to the kernel (vmlinuz), the path to the root file system (initrd.gz) and the file system type (ramfs). Here is where the file system wrappers start to play a part.

The kernel is loaded and uncompressed into memory. The bootloader knows how to uncompress the gzip format of the root file system (initrd.gz) and uncompresses that into memory and mounts it. At this point we can say we have an operating system that can do something useful. As we will see, there is a lot of functionality here already.

initrd

Once the initial file system is mounted, the kernel hands control to a user program. We say we are in user space from now on. In our case the command that is run is:

/bin/sh /linuxrc

This looks simple, but there is quite a lot happening here. The initrd contains a symlink for /bin/sh that sends control to /bin/busybox.

Busybox

Busybox is the swiss army coat hanger of embedded linux and a very powerful tool. It can be compiled to contain any of a long list of standard GNU programs. When invoked, it examines the command used and responds as if it was that command. Eg:

/bin/busybox tar xzf somefile.tar.gz

This will cause busybox to act just like GNU tar and uncompress the specified file. This is why it is called a Multi call binary, it can be called by many names and takes on the role of whatever you call it.

The busybox present in the initrd is quite simplified and it only knows the commands needed to perform the bootstrapping required to get the main file system mounted. It does not know ls, for example, and is not realy suitable for interactive use unless you really know what you are doing. In general this stage will pass transparently as the system boots.

linuxrc

Linuxrc is a shell script that contains the first real user-space logic we have encountered so far. It's job is to deal with the devices that the kernel has discovered, in a sensible way, and to mount the main file system.

To run through quickly what linuxrc does:

  • Mount RAMFS and pivot root to move the current file system into the ram file system
  • Mount the kernel file systems (/proc, /sys) and get busybox to install itself into the RAMFS
  • Start udev the interface to the kernel device messages
  • Figure out what kind of FS we're booting from and locate the /bin.tar.lzma file (another file system wrapper) and uncompress it into the RAMFS

bin.tar.lzma

This is a compressed file system. Basically a tar archive with extra-good compression on it. As it expandes it creates files and directories as necessary. In this file system are all the important binaries and shared libraries needed to use the hardware of your computer. A very wide range of hardware is able to be used. This file system also contains a number of scripts that provide interfaces to various functions like: tvon, tvoff. This way the software is more modular. If you are interested in customising your GeeXboX for specific hardware, this is where your hardware libraries and binary drivers will be stored.

linuxrc continues...

  • Copy important files from the CD into RAMFS
  • Run /sbin/Init

init

We are now at stage II of the bootstrapping and things start to look more like a "normal" linux boot process. Amoung other things, init starts to run the scripts in /GEEXBOX/etc/init.d, very much like a debian style linux.


三、在双系统(winXP+ubuntu9.04)安装运行GeeXbox

1、准备磁盘分区
    我这里是sda7,格式化分区
    mkfs.ext3 /dev/sda7
    文件系统最好是FAT16、FAT32、NTFS或EXT*
    mount /dev/sda7 /media

2、下载GeeXboX ISO
    mount -o loop geexbox-1.2.3-custom-zh_CN.i386.iso /mnt
    cd /mnt

3、拷贝整个文件夹GEEXBOX
    cp -rf * /media

4、vi /boot/grub.menu.lst
    增加如下语句

    title GeeXboX
    root (hd0,6)
    kernel /GEEXBOX/boot/vmlinuz root=/dev/ram0 rw rdinit=linuxrc boot=UUID=$my_uuid      lang=en keymap=qwerty splash ...
    initrd /GEEXBOX/boot/initrd.gz
    quiet

5、reboot
    重启后在GRUB中就可以看到GeeXboX这个启动选项了。


四、添加软件包(译)

什么是GeeXboX软件包

软 件包是GeeXboX发行版的一个组成部分。它可以以库、驱动甚至是软件的形式存在。在GeeXboX代码结构中,它是SHELL的集合,利用 GeeXboX自己的工具链来编译,安装并打上相应的补丁,最后最加入到ISO文件中。工具链支持软件包的依赖关系,这就意味着你可以自己去定义这样的依 赖关系。每个新的软件包都必须放在代码的packages目录下。

包定义文件

以下是工具链用到的简单包定义文件列表:

-unpack:这个文件定义了当软件包被解开之后要做的动作,通常是对配置文件进行的操作,这个文件是可选的。
-build:这个文件的作用是如何编译这个软件包。通常是带参数的./configure和make操作。
-install:这个文件定义了如何将编译文件加到ISO文件中。通常仅仅是将编译出的二进制文件和配置文件拷贝到ISO文件中的正确位置。

请注意这三个文件都必须要有可执行的属性。
每 当上述文件之一被成功执行后,build.arch/.stamps/package/就会产生一个文件,当此文件执行完毕而又被另一脚本文件调用,则被 调用的文件仅执行一次。如unpack执行后,再执行build,而build里调用了unpack,则unpack仅会被执行一次。
为了用户测试的方便,可以手动执行上述这些脚本文件:

./scripts/{get|unpack|build|install} package


另一个需要的文件是url,它是一个文本文件,内容是软件包的http或ftp地址。
除了上述3个文件,软件包还可以包含如下文件夹:

-config:包含软件包的配置文件
-init.d:这个目录的文件会被自动拷贝到ISO里的/etc/init.d目录下。在系统启动时会自动执行这里面的文件,因为每个文件都要有可执行的标记。
-patches:在unpack执行时需要打上的补丁文件都放在这,这些补丁文件必须要有统一的格式,由diff -Naur产生。
-src:这个目录包含在build阶段需要编译的C源代码。

脚本依赖关系

不同的软件包通过脚本依赖关系联系在一起。每个软件包都是通过顺序执行如下文件产生
1、unpack
2、build
3、install

但是,你可能在编译当前软件包时需要先解压另一个软件包,增加如下语句到你的脚本中去

$SCRIPTS/unpack package1


这样工具链就会先去执行package1的unpack操作,完成后再执行脚本余下的操作。

在编译过程中加入软件包

在编译过程中,为了加进新的软件包,你必须修改scripts/gentree,加入对新软件包的操作。

url文件示例

以下是linux软件包的url文件内容

http://ftp.ch.kernel.org/pub/linux/kernel/v2.6/linux-2.6.12.3.tar.bz2
ftp://ftp.alsa-project.org/pub/kernel-patches/alsa-git-2005-06-22.patch.gz

它决定了下载软件包的url地址。

unpack脚本示例

当unpack被执行时,会从软件包源码sources目录下取出包然后将其解压到build.arch/package下,所有packages/package/patches/下的补丁文件都会被调用。
以下是linux软件包的unpack文件内容

#!/bin/sh
. config/options

它是一个shell脚本,包含了config/options文件。
每个软件包脚本都是以这些行命令开始的。

$SCRIPTS/install make
$SCRIPTS/install sed
$SCRIPTS/extract $1 "alsa-git*" $BUILD/$1*
$SCRIPTS/unpack lzma

它定义了软件包安装的需求。在执行其它脚本命令之前,GeeXboX工具链进行make和sed软件包的安装,解压alsa-git到linux的编译树目录下($1代表你所要安装的软件包),然后再unpack lzma包。

LINUX="`ls -d $BUILD/linux*`"
sed "s/CONFIG_BLK_DEV_RAM_SIZE=.*/CONFIG_BLK_DEV_RAM_SIZE=$RAMDISK_SIZE/" $PACKAGES/linux/config/linux.$TARGET_ARCH.conf > $LINUX/.config
cp $BUILD/lzma*/SRC/7zip/Compress/LZMA_C/LzmaDecode.[ch] $LINUX/lib/
sed -i "s%^int Lzma%static int Lzma%g" $LINUX/lib/LzmaDecode.[ch]


我们编辑一些配置文件

yes "" | make config ARCH=$TARGET_ARCH -C $LINUX
make prepare0 ARCH=$TARGET_ARCH -C $LINUX

最后准备下编译的源代码。

build脚本示例

以下是linux软件包的build文件内容

#!/bin/sh
. config/options

包含了GeeXboX工具链属性

$SCRIPTS/build toolchain
$SCRIPTS/build module-init-tools

确认GeeXboX工具链已编译成功,否则就编译之。

DEPMOD="`ls -d $ROOT/$BUILD/module-init-tool*/depmod`"
LINUX="`ls -d $ROOT/$BUILD/linux*`"
MODDIR="$LINUX/modules"
export CROSS_COMPILE=$TARGET_PREFIX
export ARCH=$TARGET_ARCH

导出所有的编译选项

rm -rf $MODDIR
mkdir -p $MODDIR

删除之前的编译模块。

case $TARGET_ARCH in
  i386)
    make bzImage -C "$LINUX"
    ;;
  ppc)
    unset LDFLAGS
    make vmlinux -C "$LINUX"
    ;;
esac
make modules -C "$LINUX"
make INSTALL_MOD_PATH=$MODDIR DEPMOD=$DEPMOD modules_install -C "$LINUX"

最后将linux内核和驱动编译成模块。

rm -f $MODDIR/lib/modules/*/build
rm -f $MODDIR/lib/modules/*/source

删除没用的目录,防止在安装过程中也将它们安装到ISO文件中。

install脚本示例

以下是linux软件包的install文件内容

#!/bin/sh
. config/options

包含GeeXboX工具链属性

case "$2" in
  image)
    test "$3" != installator && INSTALL="$INSTALL/boot"
    mkdir -p $INSTALL
    case $TARGET_ARCH in
      i386)
        cp $BUILD/$1*/arch/$TARGET_ARCH/boot/bzImage $INSTALL/vmlinuz
        ;;
      ppc)
        cp $BUILD/linux*/vmlinux $INSTALL/vmlinux
        $STRIP $INSTALL/vmlinux
        ;;
    esac
    ;;

检查系统架构,拷贝内核文件到ISO文件中的正确位置。

modules)
    cp -r $BUILD/linux*/modules/* $INSTALL
    mkdir -p $INSTALL/etc
    cp $PACKAGES/linux/config/modules $INSTALL/etc
    cp $PACKAGES/linux/config/tvcard $INSTALL/etc
    ;;
esac

最后拷贝所有的内核驱动(模块),将一些运行时配置文件放到/etc目录下(ISO文件中)。
$INSTALL代表安装路径,而ISO文件正是将其压缩而产生的。

djstava


阅读(4118) | 评论(0) | 转发(0) |
0

上一篇:MKV文件格式

下一篇:Mplayer VDPAU

给主人留下些什么吧!~~