您的位置:首页 > 编程语言

github上Fuchsia项目相关文章翻译 - Getting Started(fuchsia-mirror/magenta/getting_started.md)

2016-08-17 11:12 519 查看
版权声明:本文为博主原创文章,未经博主允许不得转载。

Quick Start Recipes - 快速入门

For the purpose of this document, we will assume that Magenta is checked out in $SRC/magenta and that we will build toolchains, qemu, etc alongside that. Various make invocations are presented with a “-j32” option for parallel make. If that’s excessive for the machine you’re building on, try -j16 or -j8.

  本文将介绍Magenta及相关工具的编译过程:首先下载Magenta源码,并放在$SRC/magenta目录下;然后逐个编译Toolchains,Qemu和Magenta的源码。

  编译过程中,在make命令后添加-j32选项能让机器通过并行编译的方式加快速度,如果你使用的机器不支持-j32选项,可以尝试一下-j16或者-j8。

Preparing the build environment- 准备编译环境

On Ubuntu this should obtain the necessary pre-reqs:

Ubuntu环境运行如下命令:

sudo apt-get install texinfo libglib2.0-dev autoconf libtool libsdl-dev build-essential


On Mac with homebrew:

装有Homebrew的Mac系统中运行如下命令:

brew install wget pkg-config glib autoconf automake libtool


On Mac with MacPorts:

装有MacPorts的Mac系统中运行如下命令:

port install autoconf automake libtool libpixman pkgconfig glib2


Install Toolchains - 安装Toolchains

If you’re developing on Linux or OSX, there are prebuilt toolchain binaries avaiable. Just run this script from your Magenta working directory:

  如果你在Linux或OSX系统上做开发,操作系统一般会自带预编译的toochain,只需在Magenta目录下运行以下命令即可完成:

./scripts/download-toolchain


Build Toolchains (Optional) - 编译Toolchain(可选)

If the prebuilt toolchain binaries do not work for you, there are a set of scripts which will download and build suitable gcc toolchains for building Magenta for ARM32, ARM64, and x86-64 rchitectures:

  如果上述命令无效,则下载编译适用的GCC toolchain工具,命令如下:

cd $SRC
git clone https://fuchsia.googlesource.com/third_party/gcc_none_toolchains cd toolchains
./doit -a 'arm aarch64 x86_64' -f -j32


Build Qemu - 编译Qemu

You can skip this if you’re only testing on actual hardware, but the emulator is handy for quick local tests and generally worth having around.

  如果你只想在真实硬件环境上做测试的话,你可以跳过该步骤。不过在做一些局部测试的时候,模拟器还是会表现的更方便快捷一些,值得安装。

If you don’t want to install in /usr/local (the default), which will require you to be root, add –prefix=/path/to/install (perhaps $HOME/qemu) and then you’ll need to add /path/to/install/bin to your PATH.

  如果你想把Qemu安装到默认的/usr/local目录,那么你需要root权限,并直接运行以下命令;如果你想指定安装路径,只需要在./configure命令后添加参数–prefix=/path/to/install (其中path代表你想安装的路径,可能是 $HOME/qemu),安装完成后记得修改PATH环境变量,将安装路径加入到PATH中。

cd $SRC
git clone https://fuchsia.googlesource.com/third_party/qemu cd qemu
git checkout fuchsia
./configure --target-list=arm-softmmu,aarch64-softmmu,x86_64-softmmu
make -j32
sudo make install


Configure PATH – 配置PATH环境变量

If you’re using the prebuilt toolchains, you can skip this step, since the build will find them automatically.

  如果你的操作系统自带预编译的toochain(见“Install Toolchains - 安装Toolchains”)则可以跳过该步骤,因为PATH会自动配置好。否则,就需要运行如下命令。

# on Linux
export PATH=$PATH:$SRC/toolchains/aarch64-elf-5.3.0-Linux-x86_64/bin
export PATH=$PATH:$SRC/toolchains/x86_64-elf-5.3.0-Linux-x86_64/bin

# on Mac
export PATH=$PATH:$SRC/toolchains/aarch64-elf-5.3.0-Darwin-x86_64/bin
export PATH=$PATH:$SRC/toolchains/x86_64-elf-5.3.0-Darwin-x86_64/bin


Build Magenta – 编译Magenta

Build results will be in $SRC/magenta/build-{qemu-arm64,pc-x86-64}

The variable $BUILDDIR in examples below refers to the build output directory for the particular build in question.

  执行以下命令后,编译结果将保存在SRC/magenta/build-{qemu-arm64,pc-x86-64}位置下。而命令中的$SRC/magenta指的就是编译后的输出目录。

cd $SRC/magenta

# for aarch64
make -j32 magenta-qemu-arm64

# for x86-64
make -j32 magenta-pc-x86-64


Run Magenta under Qemu – Qemu下运行Magenta

# for aarch64
./scripts/run-magenta-arm64

# for i686
./scripts/run-magenta-x86-64


The -h flag will list a number of options, including things like -b to rebuild first if necessary and -g to run with a graphical framebuffer.

To exit qemu, enter Ctrl-a x. Use Ctrl-a h to see other commands.

  在运行命令时加上-h参数,系统会显示该命令对应的可选参数列表,比如-b参数表示在运行前会根据需要重新编译项目,而-g参数会在图形界面下运行。

  如果要退出Qemu,可以键入Ctrl-a x。如果要查看其它命令,键入Ctrl-a h。

Building Magenta for all targets – 编译所有目标

# The -r enables release builds as well
./scripts/buildall -r


Please build for all targets before submitting to ensure builds work on all architectures.

  要想让Magenta能在所有架构下编译,需要先运行以上命令,编译所有目标。

Enabling Networking under Qemu (x86-64 only) – Qemu下激活网络模块

The run-magenta-x86-64 script, when given the -N argument will attempt to create a network interface using the Linux tun/tap network device named “qemu”. Qemu does not need to be run with any special privileges for this, but you need to create a persistent tun/tap device ahead of time (which does require you be root):

  运行run-magenta-x86-64脚本时(见“Build Magenta – 编译Magenta”),在命令后加上-N参数,系统则会创建一个名为“qemu”的tun/tap虚拟网络设备的接口。Qemu并不需要特殊权限来运行它,但是你需要在root权限下提前为该接口创建一个tun/tap虚拟网络设备。

  下边的命令第一行安装tunctl用到的工具包,第二行是用来创建一个名为qemu的tun/tap虚拟网络设备,该设备拥有者是$USER,第三行启用该设备。

sudo apt-get install uml-utilities
sudo tunctl -u $USER -t qemu
sudo ifconfig qemu up


This is sufficient to enable link local IPv6 (as the loglistener tool uses).

  该命令对IPv6协议有效。

Including Additional Userspace Files – 包含用户空间文件

The Magenta build creates a bootfs image containing necessary userspace components for the system to boot (the device manager, some device drivers, etc). The kernel is capable of including a second bootfs image which is provided by Qemu or the bootloader as a ramdisk image.

  编译Magenta会创建一个bootfs镜像文件,它包含系统启动所必须的用户空间组件,如设备管理器、设备驱动等(什么是bootfs和rootfs百度一下便知)。除此之外,内核还可以包含另一个由Qemu或是bootloader创建的bootfs的内存镜像。

To create such a bootfs image, use the mkbootfs tool that’s generated as part of the build. It can assemble a bootfs image for either source directories (in which case every file in the specified directory and its subdirectories are included) or via a manifest file which specifies on a file-by-file basis which files to include.

  创建bootfs镜像所使用的工具正是在Magenta编译后生成的mkbootfs。mkbootfs可以通过指定源文件夹目录或指定manifest文件的方式来完成bootfs镜像文件的创建。不论使用哪种方式,都要保证创建镜像所需的所有文件都包含其中。

  见如下命令,第一行和第四行分别为指定目录和manifest的创建过程。

$BUILDDIR/tools/mkbootfs -o extra.bootfs @/path/to/directory

echo "issue.txt=/etc/issue" > manifest
echo "etc/hosts=/etc/hosts" >> manifest
$BUILDDIR/tools/mkbootfs -o extra.bootfs manifest


On the booted Magenta system, the files in the bootfs will appear under /boot, so in the above manifest example, the “hosts” file would appear at /boot/etc/hosts.

  Magenta启动后,bootfs文件保存在/boot目录下。例如上述命令中的hosts文件,在启动后的系统中,它的目录位置应该是/boot/etc/hosts。

  

For Qemu, use the -x option to specify an extra bootfs image.

  如果是Qemu,则在命令中加入-x参数,来指定第二个bootfs内存镜像。

Network Booting

The GigaBoot20x6 bootloader speaks a simple network boot protocol (over IPV6 UDP) which does not require any special host configuration or privileged access to use.

  本文中,我们使用的bootloader是GigaBoot20x6,它会启用一个基于IPV6 UDP的网络启动协议,而且使用这个协议不需要特别的配置和权限。

It does this by taking advantage of IPV6 Link Local Addressing and Multicast, allowing the device being booted to advertise its bootability and the host to find it and send a system image to it.

  这样做的目的是利用IPV6的本地链路地址和组播地址,让host能自动获知并找到bootloader所在的待启动设备(可能是个迷你电脑主机),并将系统镜像传输给它。

If you have a device (for example a Broadwell or Skylake Intel NUC) running GigaBoot20x6, you can boot Magenta on it like so:

  如果你有一个运行GigaBoot20x6的设备(比如Broadwell或者Skylake Intel NUC,一种迷你电脑主机,不知道是什么可以百度),运行以下命令就可以在该设备上启用Magenta。

$BUILDDIR/tools/bootserver $BUILDDIR/magenta.bin

# if you have an extra bootfs image (see above):
$BUILDDIR/tools/bootserver $BUILDDIR/magenta.bin /path/to/extra.bootfs


By default bootserver will continue to run and every time it obsveres a netboot beacon it will send the kernel (and bootfs if provided) to that device. If you pass the -1 option, bootserver will exit after a successful boot instead.

  以上命令中的bootserver是Magenta编译后产生的工具,它的作用是找到待启动设备(怎么找到的?本部分前两段文字有说明),并将Magenta镜像文件拷贝给它。Bootserver是一个会持续运行的程序,每当它发现一个网络启动请求,它都会将内核镜像文件发送给待启动设备。在命令后加上-1参数,bootserver就会在发送完成一次镜像后自动退出。

Network Log Viewing

The default build of Magenta includes a network log service that multicasts the system log over the link local IPv6 UDP. Please note that this is a quick hack and the protocol will certainly change at some point.

  Magenta编译的时候,会默认自带一个网络日志服务,它会通过IPV6 UDP本地链路组播系统日志。

For now, if you’re running Magenta on Qemu with the -N flag or running on hardware with a supported ethernet interface (ASIX USB Dongle or Intel Ethernet on NUC), the loglistener tool will observe logs broadcast over the local link:

  不管你是在Qemu上(运行命令待-N参数),还是在联网的硬件设备上运行Magenta系统,loglistener工具都能监听到系统日志的广播行为。

  命令如下:

$BUILDDIR/tools/loglistener
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息