Jollen’s Consulting



                      ,
         ,



                                   ,
                        ...
Jollen’s Consulting
                               ta@jollen.org
                                               [
  ]




...
’
Linux                 -                                     Jollen’s Consulting. www.jollen.org/consulting
Linux               -                                                       Jollen’s Consulting. www.jollen.org/consulting
Linux               -                           Jollen’s Consulting. www.jollen.org/consulting
Linux                   -   Jollen’s Consulting. www.jollen.org/consulting
Linux   -         Jollen’s Consulting. www.jollen.org/consulting
# cd /
        # tar zxvf arm-9tdmi-linux-gnu.tar.gz
        (                         )

        # export
        PATH=/o...
– ipaddr                      	
 


  – serverip             	
             	
 




Linux          -                Jollen...
jollen.org # printenv
   bootdelay=3
   ethaddr=10:10:ff:ff:ff:ff
   ipaddr=192.168.1.10
   serverip=192.168.1.1
   netmas...
jollen.org # set ipaddr 192.168.100.15
  jollen.org # set serverip 192.168.100.14
  jollen.org # saveenv
  Saving Environm...
• loadAddress
                   	
          	
 
• bootfilename           	
 




 Linux              -                   ...
jollen.org # tftpboot 30F00000 uimage.img
        jollen.org # tftpboot 32000000 urootfs.img
        jollen.org # bootm 30...
Linux               -                     Jollen’s Consulting. www.jollen.org/consulting
src/cross.mk    TOOL_TOP



TOOL_TOP = /opt/crosstool/gcc-3.4.1-glibc-2.3.3/arm-9tdmi-linux-gnu




 Linux            -   ...
src/hello/                               make               	
 

# make
[ -- Start to compile hello.c to hello.o -- ]
/opt...
• hello


• hello.gdb
                        	
 
              	
 
• hello.o hello.c             	
 

 # arm-9tdmi-linux-...
hello


                                            • hello              copy
# tftp –g –r hello 192.168.100.14           ...
Linux   -   Jollen’s Consulting. www.jollen.org/consulting
Linux         -     Jollen’s Consulting. www.jollen.org/consulting
•                             	
 

                                                            	
 

•                 	
 
...
#export PATH=/opt/crosstool/gcc-3.4.1-glibc-2.3.3/arm-9tdmi-
linux-gnu/bin:$PATH

#arm-9tdmi-linux-gnu-gcc -g -nostdinc 
-...
• -nostdinc

• -I
• -mtune=arm9tdmi

• -march=armv4

• -fomit-frame-pointer                       	
 

•   -fsigned-char
•...
arm-9tdmi-linux-gnu-ld 
-nostdlib 
-L /opt/crosstool/gcc-3.4.1-glibc-2.3.3/arm-9tdmi-linux-gnu/arm-9tdmi-linux-gnu/lib 
-L...
•   -L
•   -o
•   -lc     libc
•   -lgcc      libgcc




    Linux         -       Jollen’s Consulting. www.jollen.org/con...
‘`

                  	
 




Linux         -               Jollen’s Consulting. www.jollen.org/consulting
•       TOOL_TOP             	
 
•       GCC_LIB_PATH               	
 
•       GLIBC_PATH
•       CROSS_CFLAGS           ...
Linux   -   Jollen’s Consulting. www.jollen.org/consulting
Makefile                      	
 


Makefile               make

Linux              -                        Jollen’s Cons...
– cross.mk
         	
               	
 
                                              	
 


Linux                 -      ...
Linux   -         Jollen’s Consulting. www.jollen.org/consulting
Linux   -         Jollen’s Consulting. www.jollen.org/consulting
•




      1.
      2.
      3.
      4.

    Linux   -         Jollen’s Consulting. www.jollen.org/consulting
Linux             -                                        Jollen’s Consulting. www.jollen.org/consulting
1.       libmad-0.15.1b.tar.gz
     cross.mk         libmad-0.15.1b/
2.
           libmad.cross
     libmad-0.15.1b/
3.
4....
./configure
Makefile                               ./
configure                 	
 
Makefile        	
 




Linux         ...
cross.mk


                  cross.mk          	
 




Linux         -              Jollen’s Consulting. www.jollen.org/co...
• configure                                   Makfile
                configure


    – CC          	
 


    – AR        ...
• configure                                                                        	
 


    – --prefix
                  ...
Madplay
                                         libid3tag
                 libmad
                                       ...
Text




http://www.pconline.com.cn/pcedu/soft/gj/sys/0502/551643.html
Definition of a Software "bug":

Webster's New Collegiate Dictionary defines a "bug" as "an unexpected defect,
fault, flaw...
Boot-time
                 	
 



Linux                  -                                          Jollen’s Consulting. w...
Linux                           -   Jollen’s Consulting. www.jollen.org/consulting
Linux                         -                     Jollen’s Consulting. www.jollen.org/consulting
printk
 kdb
 kgdb
 gdb + qemu




Linux         -         Jollen’s Consulting. www.jollen.org/consulting
debug
 printk           remote debug             N
 kdb              local debug              N
 kgdb             remote d...
Linux kernel image

    •   arch/arm/boot/Image         target              kernel
    •   arch/arm/boot/zImage

    •   a...
source level

 printk           kernel message      --

 kdb              machine code        --

 gdb + qemu       source...
Linux                         -                                           Jollen’s Consulting. www.jollen.org/consulting
Debug Symbols




    CONFIG_DEBUG_INFO = y
linux kernel for
                                                                                  s3c2410




http://www....
$ make uImage




$ cd /usr/local/bin
$ sudo wget http://www.jk2410.org/opensource/pre-built/mkimage
$ chmod a+x mkimage
qemu
                                                        kernel




http://www.jk2410.org/opensource/qemu-jk2410-20070...
cgdb




2   qemu
kernel
kernel
Linux         -   Jollen’s Consulting. www.jollen.org/consulting
cpu/arm920t/start.S
                                   • Setup vector table
           CPU
                               ...
.globl _start
_start: b         reset
          ldr          pc, _undefined_instruction
          ldr          pc, _softwa...
/*
  * the actual reset code
  */

 reset:
              /*
               * set the cpu to SVC32 mode
               */
 ...
cpu_init_crit:
         /*
          * flush v4 I/D caches
          */
         mov        r0, #0
         mcr        p15...
/*
                * before relocating, we have to setup RAM timing
                * because memory timing is board-depen...
EM_BASE:         .long       0xa0000000
MEM_START:       .long       0xc0000000

#define MDCNFG   0x00
#define MDCAS0   0x...
.globl memsetup                                      /* MDCNFG */
memsetup:                                            ldr...
relocate:                               /* relocate U-Boot to RAM           */
              adr      r0, _start        /*...
/* Set up the stack                                                 */
stack_setup:
         ldr        r0, _TEXT_BASE    ...
clear_bss:
         ldr            r0, _bss_start                     /* find start of bss segment      */
         add   ...
typedef int (init_fnc_t) (void);

init_fnc_t *init_sequence[] = {
         cpu_init,                 /* basic cpu dependen...
void start_armboot (void)
{
          init_fnc_t **init_fnc_ptr;

             for (init_fnc_ptr = init_sequence; *init_fn...
void start_linux(char *name,char *rdname)
{
  void (*theKernel)(int zero, int arch, u32 params);
  u32 exec_at = ZIMAGE_LO...
User Mode
                                           Application




                                      System Call Int...
Linux                     -                                           Jollen’s Consulting. www.jollen.org/consulting
Linux                                                                                                                     ...
Source: Jollen   Linux   (Revision 5)

                Linux                                                       -      ...
Linux                           -                                          Jollen’s Consulting. www.jollen.org/consulting
Linux                                 -                                                       Jollen’s Consulting. www.jol...
Linux         -         Jollen’s Consulting. www.jollen.org/consulting
Jollen Chen <jollen@jollen.org>


  Jollen's Consulting               Embedded Linux


 Openmoko                   Openmok...
Embedded Linux: Introduction
Embedded Linux: Introduction
Embedded Linux: Introduction
Embedded Linux: Introduction
Embedded Linux: Introduction
Upcoming SlideShare
Loading in...5
×

Embedded Linux: Introduction

3,806

Published on

嵌入式Linux簡介

Published in: Education, Technology
1 Comment
8 Likes
Statistics
Notes
No Downloads
Views
Total Views
3,806
On Slideshare
0
From Embeds
0
Number of Embeds
6
Actions
Shares
0
Downloads
538
Comments
1
Likes
8
Embeds 0
No embeds

No notes for slide

Embedded Linux: Introduction

  1. 1. Jollen’s Consulting , , , : www.jollen.org/consulting
  2. 2. Jollen’s Consulting ta@jollen.org [ ] Jollen’s Consulting Team
  3. 3.
  4. 4. Linux - Jollen’s Consulting. www.jollen.org/consulting
  5. 5. Linux - Jollen’s Consulting. www.jollen.org/consulting
  6. 6. Linux - Jollen’s Consulting. www.jollen.org/consulting
  7. 7. Linux - Jollen’s Consulting. www.jollen.org/consulting
  8. 8. Linux - Jollen’s Consulting. www.jollen.org/consulting
  9. 9. # cd / # tar zxvf arm-9tdmi-linux-gnu.tar.gz ( ) # export PATH=/opt/crosstool/gcc-3.4.1-glibc-2.3.3/ arm-9tdmi-linux-gnu/bin/:$PATH ( ) (or) # source ./armpath Linux - Jollen’s Consulting. www.jollen.org/consulting
  10. 10. – ipaddr – serverip Linux - Jollen’s Consulting. www.jollen.org/consulting
  11. 11. jollen.org # printenv bootdelay=3 ethaddr=10:10:ff:ff:ff:ff ipaddr=192.168.1.10 serverip=192.168.1.1 netmask=255.255.255.0 stdin=serial baudrate=115200 bootargs=root=/dev/ram0 rw console=ttyS0,115200 mem=64M ramdisk=16384 stdout=serial stderr=serial IP address 192.168.1.10 TFTP server IP address 192.168.1.1 Linux - Jollen’s Consulting. www.jollen.org/consulting
  12. 12. jollen.org # set ipaddr 192.168.100.15 jollen.org # set serverip 192.168.100.14 jollen.org # saveenv Saving Environment to Flash... Un-Protected 1 sectors Erasing Flash...Erasing sector 18 ... ok. Erased 1 sectors Writing to Flash... done Protected 1 sectors Linux - Jollen’s Consulting. www.jollen.org/consulting
  13. 13. • loadAddress • bootfilename Linux - Jollen’s Consulting. www.jollen.org/consulting
  14. 14. jollen.org # tftpboot 30F00000 uimage.img jollen.org # tftpboot 32000000 urootfs.img jollen.org # bootm 30F00000 32000000 Linux - Jollen’s Consulting. www.jollen.org/consulting
  15. 15. Linux - Jollen’s Consulting. www.jollen.org/consulting
  16. 16. src/cross.mk TOOL_TOP TOOL_TOP = /opt/crosstool/gcc-3.4.1-glibc-2.3.3/arm-9tdmi-linux-gnu Linux - Jollen’s Consulting. www.jollen.org/consulting
  17. 17. src/hello/ make # make [ -- Start to compile hello.c to hello.o -- ] /opt/crosstool/gcc-3.4.1-glibc-2.3.3/arm-9tdmi-linux-gnu/bin/arm-9tdmi-linux-gnu-gcc -nostdinc -I/opt/crosstool/ gcc-3.4.1-glibc-2.3.3/arm-9tdmi-linux-gnu/arm-9tdmi-linux-gnu/include -I/opt/crosstool/gcc-3.4.1-glibc-2.3.3/ arm-9tdmi-linux-gnu/lib/gcc/arm-9tdmi-linux-gnu/3.4.1/include -c hello.c [ -- Start to link hello.o to hello.gdb -- ] /opt/crosstool/gcc-3.4.1-glibc-2.3.3/arm-9tdmi-linux-gnu/bin/arm-9tdmi-linux-gnu-gcc -Wl,-nostdlib -Wl,-L,/opt/ crosstool/gcc-3.4.1-glibc-2.3.3/arm-9tdmi-linux-gnu/arm-9tdmi-linux-gnu/lib -Wl,-L,/opt/crosstool/gcc-3.4.1- glibc-2.3.3/arm-9tdmi-linux-gnu/lib/gcc/arm-9tdmi-linux-gnu/3.4.1 -Wl,-rpath,/opt/crosstool/gcc-3.4.1-glibc-2.3.3/ arm-9tdmi-linux-gnu/arm-9tdmi-linux-gnu/lib -Wl,-rpath,/lib -Wl,-rpath-link,/opt/crosstool/gcc-3.4.1-glibc-2.3.3/ arm-9tdmi-linux-gnu/arm-9tdmi-linux-gnu/lib -nostartfiles -nodefaultlibs /opt/crosstool/gcc-3.4.1-glibc-2.3.3/ arm-9tdmi-linux-gnu/arm-9tdmi-linux-gnu/lib/crt1.o /opt/crosstool/gcc-3.4.1-glibc-2.3.3/arm-9tdmi-linux-gnu/ arm-9tdmi-linux-gnu/lib/crti.o /opt/crosstool/gcc-3.4.1-glibc-2.3.3/arm-9tdmi-linux-gnu/lib/gcc/arm-9tdmi-linux-gnu/ 3.4.1/crtbegin.o hello.o /opt/crosstool/gcc-3.4.1-glibc-2.3.3/arm-9tdmi-linux-gnu/lib/gcc/arm-9tdmi-linux-gnu/3.4.1/ crtend.o /opt/crosstool/gcc-3.4.1-glibc-2.3.3/arm-9tdmi-linux-gnu/arm-9tdmi-linux-gnu/lib/crtn.o -lgcc -lgcc_eh -lc - lgcc -lgcc_eh -o hello.gdb [ -- Start to strip hello.gdb and produce hello -- ] /opt/crosstool/gcc-3.4.1-glibc-2.3.3/arm-9tdmi-linux-gnu/bin/arm-9tdmi-linux-gnu-strip -R .note -R .comment hello.gdb -o hello Linux - Jollen’s Consulting. www.jollen.org/consulting
  18. 18. • hello • hello.gdb • hello.o hello.c # arm-9tdmi-linux-gnu-objdump –x hello | more (or) # readelf –a hello | more Linux - Jollen’s Consulting. www.jollen.org/consulting
  19. 19. hello • hello copy # tftp –g –r hello 192.168.100.14 tftp (/tftpboot in our example) # chmod a+x ./hello • Target IP # ./hello address ( ifconfig ) Linux - Jollen’s Consulting. www.jollen.org/consulting
  20. 20. Linux - Jollen’s Consulting. www.jollen.org/consulting
  21. 21. Linux - Jollen’s Consulting. www.jollen.org/consulting
  22. 22. • • • • Linux - Jollen’s Consulting. www.jollen.org/consulting
  23. 23. #export PATH=/opt/crosstool/gcc-3.4.1-glibc-2.3.3/arm-9tdmi- linux-gnu/bin:$PATH #arm-9tdmi-linux-gnu-gcc -g -nostdinc -Os -Wall -mtune=arm9tdmi -march=armv4 -fomit-frame-pointer -fsigned-char -fPIC -I/opt/crosstool/gcc-3.4.1-glibc-2.3.3/arm-9tdmi-linux-gnu/ arm-9tdmi-linux-gnu/include -I/opt/crosstool/gcc-3.4.1-glibc-2.3.3/arm-9tdmi-linux-gnu/lib/ gcc/arm-9tdmi-linux-gnu/3.4.1/include -c hello.c Linux - Jollen’s Consulting. www.jollen.org/consulting
  24. 24. • -nostdinc • -I • -mtune=arm9tdmi • -march=armv4 • -fomit-frame-pointer • -fsigned-char • -fPIC • -Os • -Wall • -c ld Linux - Jollen’s Consulting. www.jollen.org/consulting
  25. 25. arm-9tdmi-linux-gnu-ld -nostdlib -L /opt/crosstool/gcc-3.4.1-glibc-2.3.3/arm-9tdmi-linux-gnu/arm-9tdmi-linux-gnu/lib -L /opt/crosstool/gcc-3.4.1-glibc-2.3.3/arm-9tdmi-linux-gnu/lib/gcc/arm-9tdmi-linux-gnu/3.4.1 -rpath-link /opt/crosstool/gcc-3.4.1-glibc-2.3.3/arm-9tdmi-linux-gnu/arm-9tdmi-linux-gnu/lib -o hello /opt/crosstool/gcc-3.4.1-glibc-2.3.3/arm-9tdmi-linux-gnu/arm-9tdmi-linux-gnu/lib/crt1.o /opt/crosstool/gcc-3.4.1-glibc-2.3.3/arm-9tdmi-linux-gnu/arm-9tdmi-linux-gnu/lib/crti.o /opt/crosstool/gcc-3.4.1-glibc-2.3.3/arm-9tdmi-linux-gnu/lib/gcc/arm-9tdmi-linux-gnu/3.4.1/ crtbegin.o hello.o /opt/crosstool/gcc-3.4.1-glibc-2.3.3/arm-9tdmi-linux-gnu/lib/gcc/arm-9tdmi-linux-gnu/3.4.1/crtend.o /opt/crosstool/gcc-3.4.1-glibc-2.3.3/arm-9tdmi-linux-gnu/arm-9tdmi-linux-gnu/lib/crtn.o -lgcc -lgcc_eh -lc -lgcc -lgcc_eh arm-9tdmi-linux-gnu-strip -R .note -R .comment hello Linux - Jollen’s Consulting. www.jollen.org/consulting
  26. 26. • -L • -o • -lc libc • -lgcc libgcc Linux - Jollen’s Consulting. www.jollen.org/consulting
  27. 27. ‘` Linux - Jollen’s Consulting. www.jollen.org/consulting
  28. 28. • TOOL_TOP • GCC_LIB_PATH • GLIBC_PATH • CROSS_CFLAGS • LDFLAGS • LIBS • LINK_S • LINK_E Linux - Jollen’s Consulting. www.jollen.org/consulting
  29. 29. Linux - Jollen’s Consulting. www.jollen.org/consulting
  30. 30. Makefile Makefile make Linux - Jollen’s Consulting. www.jollen.org/consulting
  31. 31. – cross.mk Linux - Jollen’s Consulting. www.jollen.org/consulting
  32. 32. Linux - Jollen’s Consulting. www.jollen.org/consulting
  33. 33. Linux - Jollen’s Consulting. www.jollen.org/consulting
  34. 34. • 1. 2. 3. 4. Linux - Jollen’s Consulting. www.jollen.org/consulting
  35. 35. Linux - Jollen’s Consulting. www.jollen.org/consulting
  36. 36. 1. libmad-0.15.1b.tar.gz cross.mk libmad-0.15.1b/ 2. libmad.cross libmad-0.15.1b/ 3. 4. Linux - Jollen’s Consulting. www.jollen.org/consulting
  37. 37. ./configure Makefile ./ configure Makefile Linux - Jollen’s Consulting. www.jollen.org/consulting
  38. 38. cross.mk cross.mk Linux - Jollen’s Consulting. www.jollen.org/consulting
  39. 39. • configure Makfile configure – CC – AR – LD – AS – STRIP – RANLIB – CFLAGS Linux - Jollen’s Consulting. www.jollen.org/consulting
  40. 40. • configure – --prefix – --host Linux - Jollen’s Consulting. www.jollen.org/consulting
  41. 41. Madplay libid3tag libmad zlib Building root filesystem (porting) • standalone application (e.g. thttpd) • software stacks (e.g. madplay project) • software stacks with architectural consideration (e.g. nano-X project) Linux - Jollen’s Consulting. www.jollen.org/consulting
  42. 42. Text http://www.pconline.com.cn/pcedu/soft/gj/sys/0502/551643.html
  43. 43. Definition of a Software "bug": Webster's New Collegiate Dictionary defines a "bug" as "an unexpected defect, fault, flaw, or imperfection". We need to refine this definition since it is too ambiguous. In the scope of this guarantee, a "bug", with respect to the guaranteed software, is defined as "a defect, fault, flaw or imperfection which causes the software to not operate as intended or to stop operating abruptly." http://www.autocadstandards.org/autocadstandards/bugfree/default.htm
  44. 44. Boot-time Linux - Jollen’s Consulting. www.jollen.org/consulting
  45. 45. Linux - Jollen’s Consulting. www.jollen.org/consulting
  46. 46. Linux - Jollen’s Consulting. www.jollen.org/consulting
  47. 47. printk kdb kgdb gdb + qemu Linux - Jollen’s Consulting. www.jollen.org/consulting
  48. 48. debug printk remote debug N kdb local debug N kgdb remote debug Y gdb + qemu remote debug Y Linux - Jollen’s Consulting. www.jollen.org/consulting
  49. 49. Linux kernel image • arch/arm/boot/Image target kernel • arch/arm/boot/zImage • arch/arm/boot/uImage • ./vmlinux ELF image Linux - Jollen’s Consulting. www.jollen.org/consulting
  50. 50. source level printk kernel message -- kdb machine code -- gdb + qemu source code kernel w/ symbol table kgdb source code kernel w/ symbol table Linux - Jollen’s Consulting. www.jollen.org/consulting
  51. 51. Linux - Jollen’s Consulting. www.jollen.org/consulting
  52. 52. Debug Symbols CONFIG_DEBUG_INFO = y
  53. 53. linux kernel for s3c2410 http://www.jk2410.org/opensource/linux-2.6.20.4-jk2410.tar.bz2 http://www.jk2410.org/opensource/gcc-4.1.0-glibc-2.4.tar.bz2 $ make ARCH=arm CROSS_COMPILE=/opt/crosstool/gcc-4.1.0-glibc-2.4/arm-9tdmi-linux-gnueabi/bin/ arm-9tdmi-linux-gnueabi- menuconfig $ make ARCH=arm CROSS_COMPILE=/opt/crosstool/gcc-4.1.0-glibc-2.4/arm-9tdmi-linux-gnueabi/bin/ arm-9tdmi-linux-gnueabi- uImage
  54. 54. $ make uImage $ cd /usr/local/bin $ sudo wget http://www.jk2410.org/opensource/pre-built/mkimage $ chmod a+x mkimage
  55. 55. qemu kernel http://www.jk2410.org/opensource/qemu-jk2410-20070826.tar.gz
  56. 56. cgdb 2 qemu
  57. 57. kernel
  58. 58. kernel
  59. 59. Linux - Jollen’s Consulting. www.jollen.org/consulting
  60. 60. cpu/arm920t/start.S • Setup vector table CPU • Set the CPU to SVC32 mode (reset) • Relocate to RAM • Setup stack board/lart/memsetup.S Board lib_arm/board.c • Board initialize sequence • start_armboot() • Call main_loop() board/<board>/*, eg. main_loop(): main.c board/lart/lart.c Linux - Jollen’s Consulting. www.jollen.org/consulting
  61. 61. .globl _start _start: b reset ldr pc, _undefined_instruction ldr pc, _software_interrupt ldr pc, _prefetch_abort ldr pc, _data_abort ldr pc, _not_used ldr pc, _irq ldr pc, _fiq _undefined_instruction: .word undefined_instruction _software_interrupt: .word software_interrupt _prefetch_abort: .word prefetch_abort _data_abort: .word data_abort _not_used: .word not_used _irq: .word irq _fiq: .word fiq .balignl 16,0xdeadbeef Linux - Jollen’s Consulting. www.jollen.org/consulting
  62. 62. /* * the actual reset code */ reset: /* * set the cpu to SVC32 mode */ mrs r0,cpsr bic r0,r0,#0x1f orr r0,r0,#0xd3 msr cpsr,r0 . . . #ifdef CONFIG_INIT_CRITICAL bl cpu_init_crit #endif Where memsetup be called. relocate Linux - Jollen’s Consulting. www.jollen.org/consulting
  63. 63. cpu_init_crit: /* * flush v4 I/D caches */ mov r0, #0 mcr p15, 0, r0, c7, c7, 0 /* flush v3/v4 cache */ mcr p15, 0, r0, c8, c7, 0 /* flush v4 TLB */ /* * disable MMU stuff and caches */ mrc p15, 0, r0, c1, c0, 0 bic r0, r0, #0x00002300 @ clear bits 13, 9:8 (--V- --RS) bic r0, r0, #0x00000087 @ clear bits 7, 2:0 (B--- -CAM) orr r0, r0, #0x00000002 @ set bit 2 (A) Align orr r0, r0, #0x00001000 @ set bit 12 (I) I-Cache mcr p15, 0, r0, c1, c0, 0 Linux - Jollen’s Consulting. www.jollen.org/consulting
  64. 64. /* * before relocating, we have to setup RAM timing * because memory timing is board-dependend, you will * find a memsetup.S in your board directory. */ mov ip, lr bl memsetup mov lr, ip mov pc, lr Return to reset. board/lart/memsetup.S Linux - Jollen’s Consulting. www.jollen.org/consulting
  65. 65. EM_BASE: .long 0xa0000000 MEM_START: .long 0xc0000000 #define MDCNFG 0x00 #define MDCAS0 0x04 #define MDCAS1 0x08 #define MDCAS2 0x0c #define MSC0 0x10 #define MSC1 0x14 #define MECR 0x18 mdcas0: .long 0xc71c703f mdcas1: .long 0xffc71c71 mdcas2: .long 0xffffffff /* mdcnfg: .long 0x0bb2bcbf */ mdcnfg: .long 0x0334b22f @ alt /* mcs0: .long 0xfff8fff8 */ msc0: .long 0xad8c4888 @ alt mecr: .long 0x00060006 /* mecr: .long 0x994a994a @ alt */ Linux - Jollen’s Consulting. www.jollen.org/consulting
  66. 66. .globl memsetup /* MDCNFG */ memsetup: ldr r1, mdcnfg ldr r0, MEM_BASE str r1, [r0, #MDCNFG] /* Setup the flash memory */ ldr r1, msc0 /* Set up PCMCIA space */ str r1, [r0, #MSC0] ldr r1, mecr str r1, [r0, #MECR] /* Set up the DRAM */ /* Load something to activate bank */ /* MDCAS0 */ ldr r1, mdcas0 ldr r1, MEM_START str r1, [r0, #MDCAS0] .rept 8 /* MDCAS1 */ ldr r0, [r1] ldr r1, mdcas1 .endr str r1, [r0, #MDCAS1] /* MDCAS2 */ /* everything is fine now */ ldr r1, mdcas2 mov pc, lr str r1, [r0, #MDCAS2] Linux - Jollen’s Consulting. www.jollen.org/consulting
  67. 67. relocate: /* relocate U-Boot to RAM */ adr r0, _start /* r0 <- current position of code */ ldr r1, _TEXT_BASE /* test if we run from flash or RAM */ cmp r0, r1 /* don't reloc during debug */ beq stack_setup ldr r2, _armboot_start ldr r3, _bss_start sub r2, r3, r2 /* r2 <- size of armboot */ add r2, r0, r2 /* r2 <- source end address */ copy_loop: ldmia r0!, {r3-r10} /* copy from source address [r0] */ stmia r1!, {r3-r10} /* copy to target address [r1] */ cmp r0, r2 /* until source end addreee [r2] */ ble copy_loop stack_setup Linux - Jollen’s Consulting. www.jollen.org/consulting
  68. 68. /* Set up the stack */ stack_setup: ldr r0, _TEXT_BASE /* upper 128 KiB: relocated uboot */ sub r0, r0, #CFG_MALLOC_LEN /* malloc area */ sub r0, r0, #CFG_GBL_DATA_SIZE /* bdinfo */ #ifdef CONFIG_USE_IRQ sub r0, r0, #(CONFIG_STACKSIZE_IRQ+CONFIG_STACKSIZE_FIQ) #endif sub sp, r0, #12 /* leave 3 words for abort-stack */ clear_bss Linux - Jollen’s Consulting. www.jollen.org/consulting
  69. 69. clear_bss: ldr r0, _bss_start /* find start of bss segment */ add r0, r0, #4 /* start at first byte of bss */ ldr r1, _bss_end /* stop here */ mov r2, #0x00000000 /* clear */ clbss_l:str r2, [r0] /* clear loop... */ add r0, r0, #4 cmp r0, r1 bne clbss_l . . . ldr pc, _start_armboot _start_armboot: .word start_armboot lib_arm/board.c Linux - Jollen’s Consulting. www.jollen.org/consulting
  70. 70. typedef int (init_fnc_t) (void); init_fnc_t *init_sequence[] = { cpu_init, /* basic cpu dependent setup */ board_init, /* basic board dependent setup */ interrupt_init, /* set up exceptions */ env_init, /* initialize environment */ init_baudrate, /* initialze baudrate settings */ serial_init, /* serial communications setup */ console_init_f, /* stage 1 init of console */ display_banner, /* say that we are here */ dram_init, /* configure available RAM banks */ display_dram_config, NULL, }; Linux - Jollen’s Consulting. www.jollen.org/consulting
  71. 71. void start_armboot (void) { init_fnc_t **init_fnc_ptr; for (init_fnc_ptr = init_sequence; *init_fnc_ptr; ++init_fnc_ptr) { if ((*init_fnc_ptr)() != 0) { hang (); } } . . . /* main_loop() can return to retry autoboot, if so just run it again. */ for (;;) { main_loop (); } } Linux - Jollen’s Consulting. www.jollen.org/consulting
  72. 72. void start_linux(char *name,char *rdname) { void (*theKernel)(int zero, int arch, u32 params); u32 exec_at = ZIMAGE_LOAD_ADDRESS; u32 parm_at = DRAM_BASE + 0x100; u32 machine_type; load_image(name, exec_at); /* copy image into RAM */ load_image(rdname, INITRD_LOAD_ADDRESS);/* copy initial ramdisk image into RAM */ setup_tags(parm_at); /* sets up parameters */ machine_type = get_mach_type(); /* get machine type */ irq_shutdown(); /* stop irq */ cpu_op(CPUOP_MMUCHANGE, NULL); /* turn MMU off */ theKernel = (void (*)(int, int, u32))exec_at; /* set the kernel address */ theKernel(0, machine_type, parm_at); /* jump to kernel with register set */ /* NOT REACHED */ } Linux - Jollen’s Consulting. www.jollen.org/consulting
  73. 73. User Mode Application System Call Interface Virture File System(VFS) BSD socket inet(AF_INET) Kernel Mode Buffer Cache Network Subsystem Transport(TCP,UDP) Network(IP) Character Block Network Device Driver Device Driver Device Driver Device Interface Physical Device (Hardware) Hardware Source: Jollen Linux (Revision 5) Linux - Jollen’s Consulting. www.jollen.org/consulting
  74. 74. Linux - Jollen’s Consulting. www.jollen.org/consulting
  75. 75. Linux - Jollen’s Consulting. www.jollen.org/consulting
  76. 76. Source: Jollen Linux (Revision 5) Linux - Jollen’s Consulting. www.jollen.org/consulting
  77. 77. Linux - Jollen’s Consulting. www.jollen.org/consulting
  78. 78. Linux - Jollen’s Consulting. www.jollen.org/consulting
  79. 79. Linux - Jollen’s Consulting. www.jollen.org/consulting
  80. 80. Jollen Chen <jollen@jollen.org> Jollen's Consulting Embedded Linux Openmoko Openmoko Openmoko Android OS Android Android - Android Android porting (s3c244x/s3c64x0) Linux Linux Jollen - www.jollen.org/blog www.jollen.org/consulting
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×