uClinuxforS3CEV40 English V3.1

download uClinuxforS3CEV40 English V3.1

of 19

Transcript of uClinuxforS3CEV40 English V3.1

  • 8/13/2019 uClinuxforS3CEV40 English V3.1

    1/19

    - 1 -

    About uClinuxs Fast Installation Configuration

    Compilation and Run

    1 Installation and Configuration of Cygwin

    The latest Cygwin can be downloaded from its website http://www.cygwin.com. As

    well as you can find it at the enclosed CD of this book, which version is 1.5.10-3, locates

    at CD2_S3CEV40 Tools\Cygwin 1.5.10. The release date of version 1.5.10 is May,

    2004. You also need to unzip it before installation.

    1) Run setup.exe, choose the Install from Local Directory then click Next Step .

    Please refer to the below fig. 0-1.

    Fig. 0-1 Installation of Cygwin

    2) Choose installation directory. Please note the installation directory must locates at

    the NTFS partition of the hard disk, or it will affect the file attributes thus leads to

    an error.

    If your hard disk is not in the NTFS format, you need to convert it into NTFS under

    DOS. For example you can use this DOS command: convert F: /FS:NTFS. Please

    note this command can only be used under Win2000 or above. After you execute

    the convert command, restart the PC. So the partition can be changed into NTFS.

    Select the Unix Text File Type, then click Next Step. More details please refer to

    the below fig. 0-2.

  • 8/13/2019 uClinuxforS3CEV40 English V3.1

    2/19

    - 2 -

    Fig. 0-2 Choose Installation Directory

    3) Select local package directory for example \cygwin 1.5.1\cygwin. Then click

    Next Step. As fig. 0-3 shows.

    Fig. 0-3 Select Local Package Directory

  • 8/13/2019 uClinuxforS3CEV40 English V3.1

    3/19

    - 3 -

    4) Select Packages. You can adjust the packages by clicking Default which is at the

    left hand side of the dialog window. In order to be able to develop ucLinux, the

    below packages must be selected.

    Admin Includes boot service tools such as cygrunsrv and so

    on. Necessary for booting NFS.

    Archive Compress or decompress files tools

    Base Basic Linux tools

    Devel Development kit, includes gcc, make etc.

    Libs Function Library

    Net Network tools

    Shells General Shell tools

    Utils Tools such as bzip2 etc.

    Fig. 0-4 Select packages

    Do step by step according to the prompt after the packages are installed, then you can

    normally run the Cygwin.

    2 Install the source code of uClinux

    Source code of uClinux can be found at the uClinux Source directory of the

    accompanying CD of this book. That is CD1_S3CEV40 General\Software\uClinux for

  • 8/13/2019 uClinuxforS3CEV40 English V3.1

    4/19

    - 4 -

    S3CEV40\uClinux-s3cev40.tar.gz.Please copy it to directory cygwin/usr/local/src. If the

    folder src is not existing. Please execute the command mkdir /usr/local/src to create it.

    In order to unzip it, please execute the following commands:

    cd /usr/local/src

    tar xzvf uClinux-s3cev40.tar.gz

    After the commands are fully executed, if there is a prompt as:tar: Error exit delayed from previous errors

    Please ignore this prompt due to it is normal.

    Once the decompression is finished, there will be directory named uclinux-s3cev40

    under /usr/local/src, which is used to put the source code. Hereafter all the operation will

    be acted under this directory.

    Please note, the latest ucLinux source code can be downloaded here:

    http://www.uclinux.org/pub/uClinux/dist

    3 Installation of development toolchain

    l Installation of ARM toolchain

    The toolchain installation software can be found at the directory of the accompanying

    CD1 of this book. It is CD1_S3CEV40 General\Software\uClinux for S3CEV40\Cross

    compiler for Cygwin:

    Fig. 0-5 Installation of Cygwin ARM Toolchain for ucLinux

    Fix the installation directory at the above dialog. The Arm toolchain will be installed to

    the directory of /usr/local/armtools.

    l Path configuration of the ARM toolchain

    After the installation was finished, please run the below command at the Cygwin

    console, so that the installation path of ARM toolchain can be regarded as a system default

    path. Please make sure that the path of ARM toolchain has been regarded as the system

    default path before compiling ucLinux.

    export PATH=/usr/local/armtools/bin:$PATH

  • 8/13/2019 uClinuxforS3CEV40 English V3.1

    5/19

    - 5 -

    Another way is to modify the /home/.bash_profile, add the above command to the

    end of the file. After this, this command will be auto-executed when the console boots.

    4 Config the uClinux

    Run the command below to config the ucLinux.

    cd /usr/local/src/ uclinux-s3cev40

    make xconfig

    The configuration dialog window is as the fig. 0-6.

    Fig. 0-6 Embedded Linux Configuration

    Click Vendor/Product Selection, a new dialog window is as fig. 0-7 below:

    Fig. 0-7 Vendor/Product Selection

    Choose Embest at Select the Vendor you wish to target, then click Main Menu

    return to the main configuration interface.

    Click Kernel/Library/Defaults Selection at the main configuration interface, you will

    see a new dialog window as fig. 0-8:

  • 8/13/2019 uClinuxforS3CEV40 English V3.1

    6/19

    - 6 -

    Fig. 0-8 Kernel/Library/Defaults Selection

    Option Meanings Configuration(default)

    Vendor/Product select the Vendor/Product Embest/S3C44B0

    Kernel Select the Kernel Linux-2.4.x

    Libc VersionSelect the version of

    library versionuClibc

    Default all Settings Default all Settings

    Customize Kernel Settings Customize Kernel SettingsCustomized by

    customer

    Customize Vendor/User SettingsCustomize Vendor/User

    Settings

    Customized by

    customer

    Update Default Vendor SettingsUpdate Default Vendor

    Settings

    Diagram 1-1 Target platform option

    Choose linux-2.4.x at the Kernel Version option; And choose uClibc at the Libc

    Version option.

    Please choose n(no) at Customize Kernel Settings and Customize / Vendor/User

    Settings options because uClinux-s3cev40 has been set properly after released. Or you

    can choose to customize it by yourself.

    Then click Main Menu return to the main configuration interface.Click Save and Exit at the main configuration interface, by now the ucLinux

    configuration is finished.

    5 Compile uClinux

    In order to compile ucLinux, please execute the following commands under Cygwin

    orderly:

    make dep

    make clean

    make lib_only

  • 8/13/2019 uClinuxforS3CEV40 English V3.1

    7/19

    - 7 -

    make user_only

    make romfs

    make image

    The above commands comments are as below:

    Make dep Search the relationship between the compile output of ucLinux andsource code, hereby generate the rely files.

    Make clean Delete all the object files, module files and temporary files which are

    generated while creating the kernel.

    Make lib_only To compile the uC-libc function library, then generate function library

    files such as libc.a libm.a and so on.

    Make user_only To compile the applications.

    Make romfs To generate the Romfs file system, using applications which are well

    compiled (romfs directory).

    Make image Use the romfs directory to generate file system image, then compile the

    kernel, thus get the kernel image.

    Finally we get these two files under images directory:

    zImage Executive image file of uClinux, kernel 2.4.x.

    romfs.img Image of file system

    zImage has included the image of file system, so you can use it to burn the Flash chip

    directly.

    6 Burn ucLinux kernel

    1 Config the Embest Online Flash Programmer at first

    Connect the JTAG interface of Embest emulator with JTAG interface of Embest

    S3CEV40, meantime connect the parallel port of Embest emulator with parallel port of PC

    host.

    Run the Embest Online Flash Programmer for ARM, click FileOpen, load the

    CD1_S3CEV40 General\Software\S3CEV40\EmbestS3CEV40.cfg

    Click SettingConfigure, the configuration dialog window is as fig. 0-9:

  • 8/13/2019 uClinuxforS3CEV40 English V3.1

    8/19

    - 8 -

    Fig. 0-9 Flash Programmer configuration

    Select Flash chip SST39LF/VF160 as above fig. 0-9.

    Select S3C44B0X as fig. 0-10:

    Fig. 0-10 Select CPU

  • 8/13/2019 uClinuxforS3CEV40 English V3.1

    9/19

    - 9 -

    2 Program the image file

    First we need to download bootloader, which locates at CD1_S3CEV40

    General\Software\Image\uclinux\blob.s3cev40.bin. Select sector 1-16 of the flash as fig.

    0-11.

    Fig. 0-11 Download the bootloader

    Download zImage to the 17-192 section Flash address, which locates at

    CD1_S3CEV40 General\Software\Image\uclinux\zImage, please refer to fig. 0-12

    Fig. 0-12 Download the zImage

  • 8/13/2019 uClinuxforS3CEV40 English V3.1

    10/19

    - 10 -

    Then download the romfs.img at 193-400 sector of the flash following above the method.

    please refer to following fig

    7 Run uClinux

    Use the accompanying serial cable to connect UART0 of target board with COM1 of PChost.

    Run the HyperTerminal at PC host, set to 115200 baud rate, 8, N/A, 1, N/A. Please

    refer to fig. 0-13:

  • 8/13/2019 uClinuxforS3CEV40 English V3.1

    11/19

    - 11 -

    Fig. 0-13 Configuration of HyperTerminal

    Run the ucLinux, result is as fig. 0-14 shows:

    Fig. 0-14 Interface when running uClinux

  • 8/13/2019 uClinuxforS3CEV40 English V3.1

    12/19

    - 12 -

    8 To develop a simple application under uCLinux

    Here we will introduce the basic steps regarding how to develop applications under

    uCLinux. In this example, we will create a simple application and add it to file system.

    Hardware requirement: EmbestS3CEV40 platform, PC host, Embest

    Emulator/PowerICE/UNetICE JTAG debugger,

    Software requirement: Cygwin under Windows 98/2000/NT/XP, Embest Online Flash

    Programmer

    1 Steps:

    1. Preparation. Use the accompanying serial cable to connect UART0 of target board

    with serial port of PC host. Meantime connect Embest Emulator/PowerICE/UNetICE JTAG

    debugger with Embest S3CEV40 board.

    2. Run the HyperTerminal at PC host, set to 115200 baud rate, 8, N/A, 1, N/A.

    3. Create a new directory app under /usr/local/src/uClinux-s3cev40/user/ so that

    you can put led.c and makefile (under example) into it. Please execute the command

    below:

    $:mkdir p /usr/local/src/uClinux-s3cev40/user/app

    Copy led.c and Makefile, which locates at CD1_S3CEV40 General\Software\uClinux

    for S3CEV40\example to the app directory.

    Makefile is used to manage the application project. By using it, you are able to configthe object file, compiler, parameter, routine, deletion regulation etc.

    4. Edit the configuration file

    Add the application information into the configuration option by editing the

    configuration file, so that the new application can be regarded as the file systems own

    users application. Edit the /usr/local/src/uClinux-s3cev40/config/config.in as the

    diagram below:

    ########################################################################

    mainmenu_option next_comment

    comment 'User Application'

    bool 'Led' CONFIG_USER_LED

    comment "User Application"

    endmenu

    ########################################################################

    After this is done, you will see a menu User Application at the user application

    configuration interface.

    5. Edit the Makefile

    Edit the \cygwin\usr\local\src\uClinux-s3cev40\user\Makefile to add our new

    application. Please add the sentence below to

    \cygwin\usr\local\src\uClinux-s3cev40\user\Makefile.

  • 8/13/2019 uClinuxforS3CEV40 English V3.1

    13/19

    - 13 -

    dir_$(CONFIG_USER_LED) += app

    Usually compiler will visit the new applications automatically to get the necessary

    information.

    6. To compile the ucLinux

    Re-compile the ucLinux, so that the new application will be added to file system.

    Then burn the file system to the corresponding section of Flash, then run it.

    export PATH=/usr/local/armtools/bin:$PATH

    make xconfig

    make dep

    make lib_only

    make user_only

    make romfs

    make image

    Please note: When using the make xconfig, select Kernel/Library/Defaults

    Selection, then click Y at Customize Ventor/User Setting and return and click save

    and exit. Then choose User Application at the pop-up Application Configuration window.

    Then choose led at the User Application. More details please refer to the fig. below.

    (a)

    (b)

    If you amended the application and want to re-compile it, you can just start at the

    command make user_only.

    7. Load EmbestS3CEV40.cfg at the Embest Flash Programmer, then download

    bootloader blob.s3cev40.bin to Flash address 1-16 sector. Download zImage to Flash

    address 17-192 sector and romfs.img to the 193-400 sector.

  • 8/13/2019 uClinuxforS3CEV40 English V3.1

    14/19

    - 14 -

    8. Run ucLinux at the Embest S3CEV40 platform. You can observe the running of

    ucLinux by using HyperTerminal. Once ucLinux is fully booted, you can see the interface as

    below:

    Sash command shell (version 1.1.1)

    />

    Enter directory bin then run led application:/>cd bin

    /bin>led

    Thus you can see LED1 and LED2 turn on and off and the same time .

    2 Example code as reference

    /*******************************************************

    * File Name led.c

    * Description timing interrupt

    * Author * Date

    *******************************************************/

    #include

    #include

    #include

    /*define port configuration register and port data register address*/

    #define PCONB (*(volatile unsigned *)0x01D20008)

    #define PDATB (*(volatile unsigned *)0x01D2000C)

    int i=0;

    /*you may modify the value of PDATB and change the led output.PB9

    and PB10 are corresponding pins to led1 OUTPUT and led2 OUTPUT.

    Howover,each of port B pins is controled by register PDATB.SO you

    may modify the corresponding bit of PDATB to control the led OUTPUT.*/

    static void sig_alarm(int signumber)

    {

    if(i==0)

    {

    PDATB |= 0xFF;

    i = 1;

    }

    else

    {

    PDATB &= 0xCF;

    i = 0;

    }

    alarm(2);

    }

    int main(void){

    if(signal(SIGALRM,sig_alarm) == SIG_ERR)

  • 8/13/2019 uClinuxforS3CEV40 English V3.1

    15/19

    - 15 -

    {

    printf("some error occurs\n");

    return 1;

    }

    alarm(2);

    while(1);

    return 0;}

    9 Add application program fast

    The procedures of adding application programs and its compilation and execution

    are formal, but very complex, it is inconvenient for user while in development and

    debug, user can add application programs fast while in development and debug follo

    wing the instructions below:

    1) Compile and generate executable file

    Enter the following commands to directly compile the source code file of the pro

    gram, for more complex projects, we can use Makefile as described in above part:

    arm-elf-gcc Wall O2 -Wl,-elf2flt o led led.c

    The led generated is in flat format, which can directly run under uClinux.

    2) Copy executable file to file system.

    romfs directory is a generated file system directory, it is generated when execut

    ing make romfs command, if user has executed make romfs command, he can co

    py the generated executable file led to the directory romfs/bin, no need execute t

    he command again. Caution: if user has executed make clean command, all the c

    ontents under romfs will be cleaned.

    3) Generate images of file system

    User can directly execute the following command to generate images of file syst

    em romfs.img in the uclinux-s3cev40 folder:

    genromfs -v -V "ROMdisk" f romfs.img -d /usr/local/src/uclinux-s3cev40/romfs

    Now the images of file system romfs.img includes the new application program l

    -ed.

    10. Methods of debug application program

    In general, there are following three methods to debug the application programs

    in uClinux:

    1) Host debug

    In Linux operating system or PC hosts using Cygwin Windows operating system,

    user can use host (x86)-based development and debug tool, e.g. GCC and GDB to compile and debug application program, when the debug is successful, use cross

  • 8/13/2019 uClinuxforS3CEV40 English V3.1

    16/19

    - 16 -

    compiler arm-elf-gcc to conduct secondary compilation, in the end, transplant it t

    o uClinux system for running.

    This method has wide variety of tools for your choice, and it is fast, especially s

    uitable for prophase debug of large complex applications.

    In this method, user must pay attention to the concerns of implanting from Linu

    x to uClinux, the biggest concerns are the difference between uClinux functions andLinux functions, and using Vfork to substitute fork.

    2) Serial port printing debug

    Serial port printing debug information is an important debug approach for uClinu

    x to develop application program.

    The moment the program directly runs in target board, the target board is conn

    ected with host through serial port, the information output during the running of pro

    gram is displayed in the serial port terminal of the host.

    The programmer adds Printf sentences to source code of program at appropriate

    location, after compilation, when the program runs to specific sentence while runni

    ng on Uclinux, it will print some important variables, parameters onto terminal interf

    ace through serial port at real-time, allow the developer to observe the running stat

    us of the program in timely way, and provide important basis and information for fu

    ture amendment and optimization.

    3) Remote interactive debug

    Run gdbserver on uClinux system, The communication between the target syste

    ms such as GDB of ARM running in host and gdbserver of the target board are reali

    zed through serial port or Ethernet, gbserver controls the running of program and fe

    edback the running status of program with debug instructions of GDB.

    In the above debug methods, codes are frequently modified and recompiled, so

    how to download the application to uClinux fast and conveniently is another concern

    of developer during the debug, we will introduce a the most common approach to

    download and debug application programs in the following section:

    FTP/TFTP method

    11. TFTP transfer debug program

    1) Trivial file transfer protocol

    The Trivial File Transfer Protocol (TFTP) is suitable for the transfer of small files,

    it is small and easy to realize. TFTP also uses customer server, but it uses UDP da

    ta report (UDP 69 port), so TFTP must have its own error-correcting action. TFTP on

    ly supports file transfer, doesnt support interaction, and it has no a big command s

    et. Its advantages: I. It can be used in UDP environment. TFTP is suitable for the c

    ase when program or file need be downloaded to a number of computers concurrent

    ly. II. TFTP codes occupies smaller memory, some equipment doesnt need hard dis

  • 8/13/2019 uClinuxforS3CEV40 English V3.1

    17/19

    - 17 -

    k, small-capacity solidified fixed TFTP, UDP and IP memory is enough; its disadvant

    ages: transfer is less reliable, no password, etc.

    TFTP is usually applied in the development of uClinux.

    2) Establish FTP/TFTP server in PC

    Run tftpd32.exe, the TFTP server program, to setup working status, authority an

    d local tftp directory, in default state, it will directly start working, and current direc

    tory is the default local tftp directory.

    Figure 11-1 Interface of TFTP server

    3) Transfer application program by means of TFTP (take multithreaded

    program for example)

    Prepare experimental environment, use the serial port cable supplied with Embest

    S3CEV40 target board to connect UART0 and PCs serial port COM1 of target board,

    use the net cable supplied with Embest S3CEV40 target board to connect the net

    port of target board and PC.

    Run Windowss own super terminal serial port communication program in PC, set

    Baud Rate of 115200, 1 stop bit, no panty bit, no hardware flow control.

    Run tftpd32.exe in PC, setup the path to point at the binary file evfork.

    Run uClinux embedded system on Embest S3CEV40 target board, you will see the

    following interface in the super terminal screen:

    Sash command shell (version 1.1.1)

    />

  • 8/13/2019 uClinuxforS3CEV40 English V3.1

    18/19

    - 18 -

    Run cygwin in PC, compile the routine evfork.c in routine list, execute the following

    commands, a binary file evfork will be generated:

    arm-elf-gcc o evfork evfork.c elf2flt

    Execute TFTP command in super terminal window to download the program evfork

    to file system of target board, when the command is accomplished, a executable

    file evfork will appear in the var folder under root directory uClinux.

    Notice: 192.192.192.39 is IP address of PC.

    />tftp g l /var/evfork r evfork 192.192.192.39

    Execute the following command in super terminal window, first add executable

    authority for evfork file, then run the program.

    />cd var

    var>chmod 777 evfork

    /var> ./evfork

    i am the child process, my process id is 21end pid is 21

    i am the parent process, my process id is 20

    Figure 11-2

    source code for reference:

    #include

    #include

    #include

    main() {

    int pid;

    //creat the child process.

    pid=vfork();

    //execute process according to the pid returned.

  • 8/13/2019 uClinuxforS3CEV40 English V3.1

    19/19

    - 19 -

    if (pid < 0)

    //creat failed.

    printf("error in fork!\n");

    else if (pid == 0)

    //return 0 ,exec the child.

    printf("i am the child process, my process id is %d\n",getpid());

    else {

    //return the child pid,exec the parent.

    printf("i am the parent process, my process id is %d\n",getpid());

    exit(0);

    }

    printf("end pid is %d\n",getpid());

    }