computer system laboratory lab3 - cross tools. lab 3 experimental goal build a development...

15
COMPUTER SYSTEM LABORATORY Lab3 - Cross Tools

Upload: baldric-robbins

Post on 23-Dec-2015

214 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: COMPUTER SYSTEM LABORATORY Lab3 - Cross Tools. Lab 3 Experimental Goal Build a development environment for embedded systems. Cross compiler, assembler,

COMPUTER SYSTEM

LABORATORYLab3 - Cross Tools

Page 2: COMPUTER SYSTEM LABORATORY Lab3 - Cross Tools. Lab 3 Experimental Goal Build a development environment for embedded systems. Cross compiler, assembler,

/ 152Lab 3

Experimental Goal

•Build a development environment for embedded systems.• Cross compiler, assembler, linker

• Cross C standard library

2013/10/1

C program

compiler

Assembly language program

assembler

Transforms the C program into an assembly language program

linker

Object: Machine language moduleObject: Library routine (machine language)

Executable: Machine language program

Page 3: COMPUTER SYSTEM LABORATORY Lab3 - Cross Tools. Lab 3 Experimental Goal Build a development environment for embedded systems. Cross compiler, assembler,

/ 153Lab 3

Environment

• Host System• Windows XP

• Build System• VirtualBox + Ubuntu 8.04

• Target System• Creator XScale PXA270

• Software• GNU Binutils

• GNU Compiler Collection (GCC)

• Red Hat Newlib

• makeinfo_version.patch

• You can download all software from RSWiki CSL Course Software2013/10/1

Page 4: COMPUTER SYSTEM LABORATORY Lab3 - Cross Tools. Lab 3 Experimental Goal Build a development environment for embedded systems. Cross compiler, assembler,

/ 154Lab 3

Change Apt Sources List

•Ubuntu 8.04 is now out of support and no longer receiving updates and security patches. There are repositories available at http://old-releases.ubuntu.com.

•Step1: modify /etc/apt/sources.list.• % sudo sed -i -e 's/tw.archive.ubuntu.com\|security.ubuntu.com/old-releases.ubuntu.com/g' /etc/apt/sources.list

• You have to be careful of the area which was set during the installation. If you chose the area other than Taiwan, you have to modify the command to the correct one.

• You can type “man sed” to see more information.

•Step2: upgrate the sources list.• % sudo apt-get update

2013/10/1

Page 5: COMPUTER SYSTEM LABORATORY Lab3 - Cross Tools. Lab 3 Experimental Goal Build a development environment for embedded systems. Cross compiler, assembler,

/ 155Lab 3

GNU Cross-Binutils Compilation (1/2)

• Prerequisite• % sudo apt-get install libc6-dev texinfo vim patch

• Step1: download the source codes.• % wget http://eraser.csie.ntu.edu.tw/courses/csl/10201/lab3/software/binutils-2.16.1.tar.gz

• Step2: extract the source codes.• % tar zxvf binutils-2.16.1.tar.gz

• Step3: set configuration before you compile the source codes.• % cd binutils-2.16.1

• % ./configure --target=arm-elf --prefix=$HOME/<your path>• configure command is used to automatically create a Makefile according to your

configurations.

• Makefile is used to specify how to build your source codes.2013/10/1

Page 6: COMPUTER SYSTEM LABORATORY Lab3 - Cross Tools. Lab 3 Experimental Goal Build a development environment for embedded systems. Cross compiler, assembler,

/ 156Lab 3

GNU Cross-Binutils Compilation (2/2)

• Step4: compile the cross-binutils.• % make -j4

• Step5: install the cross-binutils.• % make -j4 install

• Step6: append the installation directory to PATH.• % sudo vim /etc/environment

• PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:$HOME/<your path>/bin"

• % source /etc/environment

• If you open another terminal, you need to source again.

• Test your cross-binutils.• % arm-elf-as -version

2013/10/1

Page 7: COMPUTER SYSTEM LABORATORY Lab3 - Cross Tools. Lab 3 Experimental Goal Build a development environment for embedded systems. Cross compiler, assembler,

/ 157Lab 3

GNU Cross-Compiler Compilation (1/2)

•Step1: download the source codes.• % wget http://eraser.csie.ntu.edu.tw/courses/csl/10201/lab3/software/gcc-3.3.6.tar.gz

•Step2: extract the source codes.• % tar zxvf gcc-3.3.6.tar.gz

•Step3: set configuration.• % cd gcc-3.3.6

• % ./configure --target=arm-elf --prefix=$HOME/<the your path previously> --enable-languages=c --with-newlib

•Step4: compile the cross-compiler.• % make -j4

2013/10/1

Page 8: COMPUTER SYSTEM LABORATORY Lab3 - Cross Tools. Lab 3 Experimental Goal Build a development environment for embedded systems. Cross compiler, assembler,

/ 158Lab 3

GNU Cross-Compiler Compilation (2/2)

•Step5: install the cross-compiler.• % make -j4 install

•Test your cross-compiler.• % arm-elf-gcc -v

2013/10/1

Page 9: COMPUTER SYSTEM LABORATORY Lab3 - Cross Tools. Lab 3 Experimental Goal Build a development environment for embedded systems. Cross compiler, assembler,

/ 159Lab 3

GNU Cross-Newlib Compilation (1/3)

•Step1: download the source codes.• % wget http://eraser.csie.ntu.edu.tw/courses/csl/10201/lab3/software/newlib-1.14.0.tar.gz

•Step2: extract the source codes.• % tar zxvf newlib-1.14.0.tar.gz

•Step3: apply the patch.• % cd newlib-1.14.0

• % wget http://eraser.csie.ntu.edu.tw/courses/csl/10201/lab3/software/makeinfo_version.patch

• % patch < makeinfo_version.patch

2013/10/1

Page 10: COMPUTER SYSTEM LABORATORY Lab3 - Cross Tools. Lab 3 Experimental Goal Build a development environment for embedded systems. Cross compiler, assembler,

/ 1510Lab 3

GNU Cross-Newlib Compilation (2/3)

• Step4: set configuration.• % ./configure --target=arm-elf --prefix=$HOME/<the your path

previously>

• Step5: compile the cross-newlib.• % make -j4

• Step6: install the cross-newlib.• % make -j4 install

• Test a assembly code generation. • The test source code, test1.c,

can be downloaded from our course website.

• % arm-elf-gcc -S test1.c

• % vim test1.s2013/10/1

Page 11: COMPUTER SYSTEM LABORATORY Lab3 - Cross Tools. Lab 3 Experimental Goal Build a development environment for embedded systems. Cross compiler, assembler,

/ 1511Lab 3

GNU Cross-Newlib Compilation (3/3)

•Test an executable.• % arm-elf-gcc test1.c -o test1

• % file test1

2013/10/1

Page 12: COMPUTER SYSTEM LABORATORY Lab3 - Cross Tools. Lab 3 Experimental Goal Build a development environment for embedded systems. Cross compiler, assembler,

/ 1512Lab 3

Install PXA270 Cross-Compiler (1/2)

•However, since previous cross-compiler does not contain related PXA270 headers and configurations, it can not compile executable for PXA270.• Actually, it can only be used for U-Boot (bootloader) only.

• If we want to cross compile a program which can be executed on PXA270, we should install the cross-compiler provided by microtime (新華 ).

•Step1: download new cross-compiler.• % wget http://eraser.csie.ntu.edu.tw/courses/csl/10201/lab3/software/arm-linux-toolchain-bin.4.0.2.tar.gz

2013/10/1

Page 13: COMPUTER SYSTEM LABORATORY Lab3 - Cross Tools. Lab 3 Experimental Goal Build a development environment for embedded systems. Cross compiler, assembler,

/ 1513Lab 3

Install PXA270 Cross-Compiler (2/2)

•Step2: extract the tar.gz file to the home directory.• % tar zxvf arm-linux-toolchain-bin.4.0.2.tar.gz -C $HOME

•Step3: append the installation directory (bin) to PATH.• Do not forget to source again to load new PATH.

•Test the new cross-compiler.• % arm-unknown-linux-gnu-gcc -v

2013/10/1

Page 14: COMPUTER SYSTEM LABORATORY Lab3 - Cross Tools. Lab 3 Experimental Goal Build a development environment for embedded systems. Cross compiler, assembler,

/ 1514Lab 3

Compile a PXA270 Executable

•Step1: use the new cross-compiler to compile test1.c.• % arm-unknown-linux-gnu-gcc -static test1.c -o test1

• Please add –static flag to compile an executable with static library.

•Step2: transfer the executable to Linux on PXA270.

•Step3: change the permission of the executable.• $ chmod +x test1

•Step4: try to execute test1.

2013/10/1

Page 15: COMPUTER SYSTEM LABORATORY Lab3 - Cross Tools. Lab 3 Experimental Goal Build a development environment for embedded systems. Cross compiler, assembler,

/ 1515Lab 3

Lab Requirement & Bonus

•Show that you can cross compile a program for PXA270.

•Bonus:Answer the question of lab3 on RSWiki CSL course website.Write it in your report.

•Please send your report to both TAs.• [email protected], [email protected]

• Please use this title format: [CSL] G# Lab# Ver#

• E.g., [CSL] G13 Lab3 Ver1

2013/10/1