Skip to content

Commit

Permalink
add chapter05
Browse files Browse the repository at this point in the history
  • Loading branch information
luffycheung committed Dec 22, 2016
1 parent df79ada commit 8d5bc7f
Show file tree
Hide file tree
Showing 28 changed files with 582 additions and 9 deletions.
Binary file added chapter5/experiment01/4.2.1.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added chapter5/experiment01/4.2.10.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added chapter5/experiment01/4.2.11.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added chapter5/experiment01/4.2.12.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added chapter5/experiment01/4.2.13.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added chapter5/experiment01/4.2.14.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added chapter5/experiment01/4.2.15.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added chapter5/experiment01/4.2.16.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added chapter5/experiment01/4.2.17.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added chapter5/experiment01/4.2.2.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added chapter5/experiment01/4.2.3.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added chapter5/experiment01/4.2.4.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added chapter5/experiment01/4.2.5.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added chapter5/experiment01/4.2.6.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added chapter5/experiment01/4.2.7.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added chapter5/experiment01/4.2.8.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added chapter5/experiment01/4.2.9.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added chapter5/experiment01/4.3.1.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added chapter5/experiment01/4.3.2.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
203 changes: 203 additions & 0 deletions chapter5/experiment01/android_ubuntu_env_setup.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,205 @@
# 实验一. Android Ubuntu编译环境搭建

----------
## 实验目的
- 掌握Ubuntu 12.04 操作系统的安装;
- 掌握交叉编译器的安装;

## 实验环境
* 硬件:CBT-EMB-MIP 实验平台,PC机;
* 软件:VMware;

## 实验内容
* 虚拟机上安装Ubuntu 12.04操作系统;
* 建立Android系统开发环境,安装Android配套的交叉编译器;

## 实验步骤

### 系统镜像下载

Ubuntu12.04 LTS官网下载地址:[http://www.ubuntu.org.cn/download/desktop](http://www.ubuntu.org.cn/download/desktop)

选择64位版本下载(Android光盘\src\chapter05\experiment01目录已经提供,建议用户使用的软硬件环境与本书保持一致,实际硬件差异需要具体灵活设置和下载相应的资源包)。

### 在VMware中安装Ubuntu系统

* 打开VMware,点击File菜单选择New Virtual Machine。在弹出的窗口选择Typical 典型安装,点击下一步,如**图4.2.1**所示

![](/chapter5/experiment01/4.2.1.png)

**图4.2.1**

* 选择ISO镜像的目录,点击下一步,如**图4.2.2**所示

![](/chapter5/experiment01/4.2.2.png)

**图4.2.2**

* 输入Full name,user name,password ,点击下一步,如**图4.2.3**所示

![](/chapter5/experiment01/4.2.3.png)

**图4.2.3**

* 点击Browse选择安装路径,点击下一步,如**图4.2.4**所示

![](/chapter5/experiment01/4.2.4.png)

**图4.2.4**

* Ubuntu需要硬盘空间大约5G,Android源码编译后占硬盘空间大约29G , linux内核编译后约1.9G,因此建议提前为Ubuntu12.04 的安装预留大约40G的空间,点击下一步,如**图4.2.5**所示

![](/chapter5/experiment01/4.2.5.png)

**图4.2.5**

* 点击`Customize Hardware` , 做一些启动基本配置,如图4.2.6和图4.2.7所示

![](/chapter5/experiment01/4.2.6.png)

**图4.2.6**

(注意: 推荐内存大于1G,否则因为内存大小限制将无法编译Android文件系统)

![](/chapter5/experiment01/4.2.7.png)

**图4.2.7**

* 点击`finish`开始安装,如**图4.2.8**所示

![](/chapter5/experiment01/4.2.8.png)

**图4.2.8**

* Ubuntu12.04使用Easy Install工具自动连接互联网安装部分资源包和软件,需一定安装时间。可点击skip跳过,进入系统之后再另外更新安装。如**图4.2.9**所示

![](/chapter5/experiment01/4.2.9.png)

**图4.2.9**

* 安装完成之后虚拟机会自动重启,进入`VMware Easy Install`命令行登录界面,如**图4.2.10**所示

![](/chapter5/experiment01/4.2.10.png)

**图4.2.10**

* 点击VMware中的Power Off按键强制关闭AndroidDev虚拟机,如**图4.2.11**所示

![](/chapter5/experiment01/4.2.11.png)

**图4.2.11**

* 点击`Edit virtual machine settings`,在弹出来的设置窗口中remove掉CD/DVD(IDE)设备。把Floppy中的Connection方式选择为Use physical drive:-> Auto detect。之后点击Power on启动虚拟机。如图4.2.12所示

![](/chapter5/experiment01/4.2.12.png)

**图4.2.12**

*[ubuntu login:]处输入用户名cbt,回车后输入之前步骤中设置的密码进行登录。在cbt@ubuntu:~$后输入startx命令进入系统图像界面,如**图4.2.13**所示

![](/chapter5/experiment01/4.2.13.png)

**图4.2.13**

* 进入系统后,点击VMware菜单中的VM -> Install VMware Tools选项。弹出对话框选择yes,如**图4.2.14**所示

![](/chapter5/experiment01/4.2.14.png)

**图4.2.14**

* 点击右上角的图标选择Log out 退出系统,如**图4.2.15**所示

![](/chapter5/experiment01/4.2.15.png)

**图4.2.15**


* 执行如下命令:
```
$ sudo mv /etc/issue.backup /etc/issue
$ sudo mv /etc/rc.local.backup /etc/rc.local
$ sudo mv /opt/vmware-tools-installer/lightdm.conf /etc/init
```

之后再执行```sudo reboot``` 命令重启或者执行```sudo start lightdm```命令便可以进入图形登录界面。如**图4.2.16**所示

![](/chapter5/experiment01/4.2.16.png)

**图4.2.16**

* 进入系统后,按照下面提示继续安装VMware Tools工具。打开Terminal终端,进入VMware Tools光盘目录将其解压到本地目录/tmp下。命令如下:
```
$ cd /media/VMware Tools
$ tar xvf VMwareTools-8.8.0*.tar.gz -C /tmp
$ cd /tmp/VMware-tools-distrib/
```
执行:

```
$sudo ./VMware-install.pl
```

* 接下来的安装步骤中,一直按回车键确认安装即可。此步骤可能需要一定时间,如**图4.2.17**所示

![](/chapter5/experiment01/4.2.17.png)

**图4.2.17**

* 在Terminal命令行终端中中连接互联网更新之前skip过的内容,执行如下命令:
```
$ sudo apt-get upgrade
$ sudo apt-get update
```

* 安装vim编辑器:
```
$ sudo apt-get install vim-gtk
```

### 安装Android 配套的交叉编译器

* 打开Terminal,输入cp 之后把Android光盘\src\chapter05\experiment01中的arm-linux-gcc-4.5.1.tar.gz压缩包拖拽拷贝到 ~/目录下,如**图4.3.1**所示

![](/chapter5/experiment01/4.3.1.png)

**图4.3.1**

* 执行解压命令
```
$ tar xvf arm-linux-gcc-4.5.1.tar.gz
```

执行该命令,将把arm-linux-gcc 安装到~/toolschain/4.5.1目录下。

* 把编译器的路径加入到系统环境变量,运行命令
```
$ sudo gedit ~/.bashrc
```
编辑~/.bashrc文件,修改最后一行为
```
export PATH=$PATH:~/toolschain/4.5.1/bin
```

注意路径一定要依据上面解压步骤更改正确,否则将不会有效,如**图4.3.2**所示,保存退出。

![](/chapter5/experiment01/4.3.2.png)

**图4.3.2**

* 执行命令:
```
source ~/.bashrc
```

* 在命令行输入```arm-linux-gcc -v ```,出现如下打印信息,则说明交叉编译环境已经成功搭建。
```
gcc version 4.5.1 (ctng-1.8.1-FA)
```

注:若由于切换root用户无法在终端中输入或找到arm-linux-gcc命令,可手动执行
source ~/.bashrc命令导入环境变量,之后即可输入上述命令查看。





125 changes: 125 additions & 0 deletions chapter5/experiment02/android_kernel.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,127 @@
# 实验二. Android 内核移植与编译实验

----------
## 实验目的
- 掌握Android 内核裁减与定制的基本方法;

## 实验环境
* 硬件:CBT-EMB-MIP 实验平台,PC机;
* 软件:VMware Workstation + Ubuntu 12.04 + ARM-LINUX 交叉编译开发环境;

## 实验内容

* 学习Android 内核裁减定制的基本配置方法,利用Android 设备配套Android 内核进行自定义功能(如 helloword 显示)的添加。并重新编译内核源码,生成内核压缩文件uImage ,下载到Android 设备中测试;

## 实验步骤

### 复制内核源码至实验目录

* 将Android光盘\src\chapter04\experiment01下的内核源码包“linux-3.5.tar.gz”复制到Ubuntu 12.04 相应目录下并解压
```
$ sudo -s //输入普通用户密码切换到超级用户
#tar xvf linux-3.5.tar.gz
#cd linux-3.5/
```

### 编译内核

在宿主机端为Android 平台设备 linux-3.5内核编写简单的测试驱动(内核)程序`helloworld.c`,并修改内核目录中相关文件,添加对测试驱动程序的支持。

* 使用vim 编译器手动编写实验代码`helloworld.c`(Android光盘\src\chapter05\experiment02已经存在,可以参考)
```
# vim helloworld.c
```
`helloworld.c` 内容如下:
```
#include<linux/init.h>
#include<linux/module.h>
// 驱动程序的入口函数
static int hello_init(void)
{
printk(KERN_ALERT”#########Hello, workd ! Cyb-Bot ##############\n”);
return 0;
}
//驱动程序的出口函数
static void hello_exit(void)
{
printk(KERN_ALERT”#############Goodbye , world ########\n”);
}
module_init(hello_init);
module_exit(hello_exit);
MODULE_LICENSE(“Dual BSD/GPL”);
```

有关驱动程序的编写规范,请参考后续驱动实验内容,本实验只在编写简单的驱动(内核)程序并加入到Linux 内核目录树中,使用户熟悉编译内核的过程。该驱动程序是向终端输出相关程序信息。
编写好`helloworld.c` 后将其拷贝到内核源码的`drivers/char/`目录下。
```
#cp helloworld.c linux-3.5/drivers/char/
```

* 进入实验内核源码目录修改drivers/char目录下的Kconfig 文件,按照Kconfig 语法添加helloworld程序的菜单支持
```
#cd linux-3.5/drivers/char/
#vim Kconfig
```

在Kconfig文件中添加如下代码:
```
config HELLO_WORLD //驱动名称
bool “Hello World Test” //内核编译是bool类型
depends on ARCH_EXYNOS4 //HELLO_WORLD只有ARCH_EXYNOS4板子上有效
default y //y表示默认运行
help //提示说明,无实际意义
This is a demo to test kernel experiment On Android .
```

注意`config HELLO_MODULE` 段要与前后段有空格隔开,且`bool``tristate`等变量要与行开头有TAB符号位隔开。注意`Konfig` 的格式(用户可以拷贝原有内容进行修改)。

* 进入实验内核源码目录修改`driver/char/`目录下的`Makefile` 文件,按照内核中`Makefile`语法添加`helloworld`程序的编译支持
```
#vim Makefile
```

在Makefile 中添加下面一行:
```
obj-$(CONFIG_HELLO_WORLD) += helloworld.o
```

* 在内核源码目录运行```make menuconfig``` 配置内核对`helloword`程序的支持
* 执行```make menuconfig```(注:执行之前确保开发环境当中有`ncurses`库,执行```sudo apt-get insatll ncurses-dev```下载)
* 配置`helloword`,静态编译。

> │ -&gt; Device Drivers │
> │ -&gt; Character devices
> │ -&gt; Hello World Test
* 退出保存内核配置。
* 在内核源码的顶层目录下编译内核
```
# make
HOSTLD scripts/kconfig/conf
scripts/kconfig/conf -s arch/arm/Kconfig
*
* Restart config...
*
*
* Character devices
*
Virtual terminal (VT) [Y/n/?] y
Enable character translations in console (CONSOLE_TRANSLATIONS) [Y/n/?] y
Support for console on virtual terminal (VT_CONSOLE) [Y/n/?] y
Support for binding and unbinding console drivers (VT_HW_CONSOLE_BINDING) [N/y/?] n
Memory device driver (DEVMEM) [Y/n/?] y
/dev/kmem virtual device support (DEVKMEM) [Y/n/?] y
Hello World Test (HELLO_WORLD) [Y/n/?] (NEW) //输入“y”
```

初次编译内核源码,由于内核源码代码庞大,所需较长时间。编译成功后会在内核源码目录的`arch/arm/boot/`目录下生成内核压缩文件`zImage`

* 按照Android光盘配套烧写文档将新生成的内核镜像文件zImage 烧写到Android平台设备中(Android系统如何安装详见Android光盘\IMG\Cortex-A9系统烧写说明.pdf)

新内核烧写成功后启动Android 实验平台,可以在串口终端中查看到Linux内核在加载过程中打印出来的信息,如**图5.2.1**所示(内核加载只需要2-3秒,为了方便观察现象,可以在内核加载2-3秒后关闭电源来查看打印出来的信息)

```
#########Hello , world ! Cyb-Bot !###########
```

0 comments on commit 8d5bc7f

Please sign in to comment.