Lab 3 Department of Computer Science and Information Engineering National Taiwan University Lab3 -...

20
Lab 3 Department of Computer Science and Information Engineering National Taiwan University Computer System Laboratory Lab3 - Cross Tools 2014/10/7 / 20 1

Transcript of Lab 3 Department of Computer Science and Information Engineering National Taiwan University Lab3 -...

Lab 3 Department of Computer Science and Information EngineeringNational Taiwan University / 201

Computer System Laboratory

Lab3 - Cross Tools

2014/10/7

Lab 3 Department of Computer Science and Information EngineeringNational Taiwan University / 202

Experimental Goal

Build a development environment for embedded systems. Cross compiler, assembler, linker Cross C standard library

2014/10/7

Lab 3 Department of Computer Science and Information EngineeringNational Taiwan University / 203

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 Simple Linux Kernel for PXA270 Simple File System for PXA270 Cross Compiler for PXA270

You can find all software on RSWiki CSL Course Software.

2014/10/7

Lab 3 Department of Computer Science and Information EngineeringNational Taiwan University / 204

GNU Binutils

The GNU Binutils are a collection of binary tools for creating and managing binary programs, libraries, and assembly source code.

The main tools are: ld: the GNU linker as: the GNU assembler

The GNU binutils are typically used in conjunction with compilers such as the GNU Compiler Collection (gcc), build tools like make, and the GNU Debugger (gdb).

2014/10/7

Reference: http://www.gnu.org/software/binutils/

Lab 3 Department of Computer Science and Information EngineeringNational Taiwan University / 205

GNU Cross-Binutils Compilation (1/2)

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

Step 1: download the source codes. % cd ~ % wget http://eraser.csie.ntu.edu.tw/courses/csl/10301/lab3/software/binutils-2.16.1.tar.gz

Step 2: extract the source codes. % tar zxvf binutils-2.16.1.tar.gz

Step 3: set configuration before you compile the source codes. % cd binutils-2.16.1 % ./configure --target=arm-elf --prefix=$HOME/<installation 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.

2014/10/7

Lab 3 Department of Computer Science and Information EngineeringNational Taiwan University / 206

GNU Cross-Binutils Compilation (2/2)

Step 4: compile the cross-binutils. % make

Step 5: install the cross-binutils. % make install

Step 6: append the bin directory to PATH. % nano ~/.bashrc

export PATH="$PATH:$HOME/<installation path>/bin"

% source ~/.bashrc You can also reopen the terminal, and .bashrc will be sourced in the shell startup

process.

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

2014/10/7

Lab 3 Department of Computer Science and Information EngineeringNational Taiwan University / 207

GNU Compiler Collection

The GNU Compiler Collection (GCC) is a compiler system produced by the GNU Project supporting various programming languages.

GCC has been ported to a wide variety of processor architectures, and is widely deployed as a tool in the development of software, and it is also available for most embedded platforms.

The main tool is gcc.

2014/10/7

Reference: Wikipedia http://en.wikipedia.org/wiki/GNU_Compiler_Collection

Lab 3 Department of Computer Science and Information EngineeringNational Taiwan University / 208

GNU Cross-Compiler Compilation (1/2)

Step 1: download the source codes. % cd ~ % wget http://eraser.csie.ntu.edu.tw/courses/csl/10301/lab3/software/gcc-3.3.6.tar.gz

Step 2: extract the source codes. % tar zxvf gcc-3.3.6.tar.gz

Step 3: set configuration. % cd gcc-3.3.6 % ./configure --target=arm-elf --prefix=$HOME/<the installation path

previously> --enable-languages=c --with-newlib

2014/10/7

Lab 3 Department of Computer Science and Information EngineeringNational Taiwan University / 209

GNU Cross-Compiler Compilation (2/2)

Step 4: compile the cross-compiler. % make

Step 5: install the cross-compiler. % make install

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

2014/10/7

Lab 3 Department of Computer Science and Information EngineeringNational Taiwan University / 2010

C Standard Library – Newlib

The C standard library is the standard library for the C programming language, as specified in the ANSI C standard.

There are many implementations of C library. GNU C Library, used in Linux Newlib μClibc, a C standard library for embedded μClinux systems Microsoft C Run-time Library, part of Microsoft Visual C++ Etc.

Newlib is a C standard library implementation intended for use on embedded systems.

2014/10/7

Lab 3 Department of Computer Science and Information EngineeringNational Taiwan University / 2011

GNU Cross-Newlib Compilation (1/2)

Step 1: download the source codes. % cd ~ % wget http://eraser.csie.ntu.edu.tw/courses/csl/10301/lab3/software/newlib-1.14.0.tar.gz

Step 2: extract the source codes. % tar zxvf newlib-1.14.0.tar.gz

Step 3: apply the patch. % cd newlib-1.14.0 % wget http://eraser.csie.ntu.edu.tw/courses/csl/10301/lab3/software/makeinfo_version.patch

% patch < makeinfo_version.patch

2014/10/7

Lab 3 Department of Computer Science and Information EngineeringNational Taiwan University / 2012

GNU Cross-Newlib Compilation (2/2)

Step 4: set configuration. % ./configure --target=arm-elf --prefix=$HOME/<the installation path

previously>

Step 5: compile the cross-newlib. % make

Step 6: install the cross-newlib. % make install

2014/10/7

Lab 3 Department of Computer Science and Information EngineeringNational Taiwan University / 2013

Cross Compile a C program

Write a simple C program. % cd ~ % nano test1.c

#include <stdio.h>

void main() {

printf("hello world\n");

}

Test a assembly code generation. % arm-elf-gcc -S test1.c % nano test1.s

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

2014/10/7

Lab 3 Department of Computer Science and Information EngineeringNational Taiwan University / 2014

Memory Layout of PXA270

2014/10/7

0x00000000

0x00040000

0x00080000

0x02000000

U-Boot

diag

Flash

0xA0000000

0xA1080000

0xA4000000

uImage (TFTP)

RAM

0x00480000

0x01380000

Linux kernel

Root Filesystem

0xA1480000rootfs (TFTP)

Lab 3 Department of Computer Science and Information EngineeringNational Taiwan University / 2015

Install Linux on PXA270 (1/2)

Step 1: download uImage and rootfs into TFTP server.

Step 2: enter U-Boot in PXA270, or use the debugger Domingo.

Step 3: download and copy uImage to flash address 0x80000. You can download to RAM address 0xA1080000 for TFTP. The erased end address is 0x47FFFF (32 sectors). It will take about 3 minutes.

Step 4: download and copy rootfs to flash address 0x480000. You can download to RAM address 0xA1480000 for TFTP. The erased end address is 0x137FFFF (120 sectors). It will take about 3 minutes.

Tips: You can refer to the steps by which you copy U-Boot to flash in lab2.

2014/10/7

Lab 3 Department of Computer Science and Information EngineeringNational Taiwan University / 2016

Install Linux on PXA270 (2/2)

Step 5: change U-Boot environment settings. u-boot$ setenv linux bootm 80000 u-boot$ setenv bootcmd run linux u-boot$ saveenv

Step 6: reset PXA270 and load Linux.

2014/10/7

Lab 3 Department of Computer Science and Information EngineeringNational Taiwan University / 2017

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 (新華 ).

Step 1: download the precompiled cross-compiler. % wget http://eraser.csie.ntu.edu.tw/courses/csl/10301/lab3/software/arm-linux-toolchain-bin.4.0.2.tar.gz

2014/10/7

Lab 3 Department of Computer Science and Information EngineeringNational Taiwan University / 2018

Install PXA270 Cross-Compiler (2/2)

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

Step 3: append the installation directory (bin) to PATH. % nano ~/.bashrc Do not forget to source again for new PATH.

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

2014/10/7

Lab 3 Department of Computer Science and Information EngineeringNational Taiwan University / 2019

Compile a PXA270 Executable

Step 1: 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.

Step 2: transfer the executable to Linux on PXA270 via TFTP. $ tftp -g -r <the path of the file> 192.168.0.10 Note that the command is different from the one in U-Boot.

Step 3: change the permission of the executable. $ chmod +x test1

Step 4: try to execute test1. $ ./test1

2014/10/7

Lab 3 Department of Computer Science and Information EngineeringNational Taiwan University / 2020

Lab Requirement

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

Please hand in your lab report to the FTP. Server: 140.112.90.174 Username: csl2014 Password: csl2014HomeWork Directory: lab3 Please use this format for filename: “G# Ver#”, where G# is your group id and

Ver# is revision version number. E.g., G1 Ver2

2014/10/7