Template Information

Trang

Chủ đề

BSP (44) Device Drivers (43) WinCE (38) WINDOWS DRIVER (19) Linux Device Drivers (18) ARM (17) Android tools and tips (17) DRIVER FILES (16) Windows Device Driver (16) AUDIO DRIVER (12) 8051 (8) OMAP (7) PRINTER DRIVER FILES (7) C Programming (6) ASUS MOTHERBOARD (5) Interfacing (5) NETWORK ADAPTER (5) VIDEO DRIVER (5) CANON (3) Device Driver Downloads (3) MOBILE PHONE (3) Asus Driver (2) EPSON (2) Epson Printer Driver (2) HP LAPTOP DRIVER (2) LAPTOP DRIVER FILES (2) Logitech Driver (2) NETWORK ADAPTOR (2) OMAP 4430 (2) drivers download (2) ACER (1) ACER TABLET (1) ALL IN ONE DRIVER (1) Acer Aspire 5738 Drivers (1) Analog-to-Digital (1) Asus Drivers (1) Asus Motherboard Drivers (1) Chip Architecture (1) DELL (1) Dell D610 Drivers (1) Dell Drivers (1) Device Drivers Download (1) Device drivers interview questions (1) Display Driver (1) Drivers Download for Windows 7 (1) EEPROMs (1) Free Asus Motherboard Drivers (1) Free Drivers Download for Windows 7 (1) GRAPHIC DRIVER (1) HP Driver (1) Hardware (1) Intel Drivers (1) Intel P35 (1) Intel P35 chipset drivers (1) I²C (1) LAPTOP SERVICE MANUAL (1) LCD (1) Logitech Mouse Driver (1) Logitech webcam driver (1) MODEM DRIVER (1) Motherboard Drivers for Windows 7 (1) PARALLEL PORT (1) Pc Driver (1) RTOS (1) Real Time Clock (1) Sensors (1) USB CABLE DRIVER (1) WEBCAM DRIVER (1) WIRELESS ADAPTOR (1) Windows 7 Drivers (1) Windows Mobile (1) acer driver (1) acer driver downloads (1) acer laptop driver (1) chipset drivers (1) network card driver (1) network driver download (1) sdcc (1)

Bài viết ngẫu nhiên

Xem phim HD Online

Số lượt views

Hiển thị các bài đăng có nhãn OMAP. Hiển thị tất cả bài đăng
Hiển thị các bài đăng có nhãn OMAP. Hiển thị tất cả bài đăng

Android eMMC Booting

Thứ Năm, 18 tháng 8, 2011 / 07:00

eMMC binaries

This is the efi partition table as exists on the emmc
Sector#    Size Name

256 128K xloader

512 256K bootloader

2048 8M recovery

18432 8M boot

34816 512M system

1083392 256M cache

1607680 512M userdata

2656256 2183M media

Creating the GPT table

On Target

  1. Connect a USB cable to the OTG port on your platform

  2. Boot your platform up with a stock u-boot and MLO

  3. Once you platform is booted you will see the following:

Fastboot entered...

On Host Machine

locate fastboot in you android filesystem
cd $mydroid/out/host/linux-x86/bin/fastboot

Search for fastboot devices
fastboot devices

Create GPT table on eMMC/SD card
fastboot oem format

From the android build these are the binaries that go into each partition:
Sector#    Size Name            Binary

256 128K xloader MLO

512 256K bootloader u-boot.bin

2048 8M recovery recovery.img

18432 8M boot boot.img

34816 512M system system.img

1083392 256M cache cache.img

1607680 512M userdata userdata.img

2656256 2183M media none



File locations

  • MLO --> x-loader/MLO

  • u-boot --> u-boot/u-boot.bin

  • boot.img --> need to create using zImage + ramdisk.img

  • recovery.img ---> need to create using zImage + ramdisk-recovery.img

  • system.img --> $mydroid/out/target/product/<platform>/system.img

  • cache.img -->

  • userdata.img --> $mydroid/out/target/product/<platform>/userdata.img



All these partitions can be flashed with the given binary using fastboot.
fastboot flash <name> <binary>

Example flashing of all partitions
fastboot flash xloader     MLO

fastboot flash bootloader u-boot.bin

fastboot flash recovery recovery.img

fastboot flash boot boot.img

fastboot flash system system.img

fastboot flash cache cache.img

fastboot flash userdata userdata.img

Modifying .IMG Files

Typically when you want to modify any of the partitions, you would need to unzip-modify-rezip and then fastboot flash.
Following section talks about how to do that for each partition
BOOT.IMG
boot.img = zImage + ramdisk.img

zImage = kernel image

ramdisk.img = out/target/product/blaze/root/

 %./out/host/linux-x86/bin/mkbootimg

--kernel zImage

--ramdisk ramdisk.img

--base 0x80000000

--cmdline "console=ttyO2,115200n8 mem=456M@0x80000000 mem=512M@0xA0000000 init=/init vram=10M omapfb.vram=0:4M androidboot.console=ttyO2"

--board omap4

-o boot.img.new

Output: boot.img.new

**Note: bootarg is passed to kernel via --cmdline option above

To "just" boot boot.img (before flashing) you can use:
%fastboot boot boot.img

RAMDISK.IMG
 %mkdir root

 %cd root

 %gunzip -c ../ramdisk.img | cpio -i

<make changes to root/ contents...>

 %./out/host/linux-x86/bin/mkbootfs root/ | ./out/host/linux-x86/bin/minigzip >ramdisk.img.new

#output: ramdisk.img.new

** Note: any init.rc changes will need to use this method

RECOVERY.IMG
Is just like boot.img. 

recovery.img = zImage + ramdisk-recovery.img

*Follow the same steps as boot.img for packing/unpacking

SYSTEM.IMG
#uncompress

 %./out/host/linux-x86/bin/simg2img system.img system.img.raw

#mount to directory mnt-point/

 %mkdir mnt-point

 %sudo mount -t ext4 -o loop system.img.raw mnt-point/

#modify any .so or apk in the mnt-point/ directory

#rezip

 %sudo out/host/linux-x86/bin/make_ext4fs -s -l 512M -a system system.img.new mnt-point/

 %sudo umount mnt-point/

Output: system.img.new

Instead of having to reflash the whole big system.img, one can selective update any binary in /system folder on running target
%adb remount

%adb push <local> <remote>

Eg:

%adb remount

%adb push out/target/product/blaze/obj/lib/overlay.omap4.so /system/lib/hw/overlay.omap4.so

%adb sync

USERDATA.IMG
#uncompress

 %./out/host/linux-x86/bin/simg2img userdata.img userdata.img.raw

#mount to directory mnt-point/

 %mkdir mnt-point

 %sudo mount -t ext4 -o loop userdata.img.raw mnt-point/

#modify any .so or apk in the mnt-point/ directory

#rezip

 %sudo ./out/host/linux-x86/bin/make_ext4fs -s -l 512M -a userdata userdata.img.new mnt/

 %sudo umount mnt-point/

Output: userdata.img.new

CACHE.IMG
#This is empty ext4 fs image

 %mkdir mnt-point/

 %sudo ./make_ext4fs -s -l 256M -a cache cache.img mnt-point/

Output: cache.img

TI Android build setup

Copy kernel zImage, u-boot.bin and MLO for your board in folder device/ti/blaze/boot/.
Rename as:
 %mv MLO MLO_es2.2_emu 

or

 %mv MLO MLO_es2.2_gp

(based on your board being GP or EMU)

Next start standard android build and all img files are generated in:
out/target/product/blaze/*.img

A script is introduced in TI Android release to make this flashing process easier: device/ti/blaze/boot/fastboot.sh
Usage:

cd device/ti/blaze/boot/

%fastboot.sh --emu

or

%fastboot.sh --gp

Running this script will flash whole android system on your board.
Thứ Năm, 18 tháng 8, 2011 07:00 Đọc tiếp >>

How to write U-Boot (Bootloader) - 2nd part

Thứ Tư, 20 tháng 7, 2011 / 22:05

1.1.3 U-Boot Linux boot process
U-Boot using the tag list (tagged list) to the Linux way of passing parameters. The data structure is marked tag, in the U-Boot source directory include / asm-arm / setup.h defined as follows:

struct tag_header {

u32 size; / * said the joint u tag data structure in real terms the size of the data stored in * /

u32 tag; / * that the type of tag * /

};

struct tag {

struct tag_header hdr;

union {

struct tag_core core;

struct tag_mem32 mem;

struct tag_videotext videotext;

struct tag_ramdisk ramdisk;

struct tag_initrd initrd;

struct tag_serialnr serialnr;

struct tag_revision revision;

struct tag_videolfb videolfb;

struct tag_cmdline cmdline;

/ *

* Acorn specific

* /

struct tag_acorn acorn;

/ *

* DC21285 specific

* /

struct tag_memclk memclk;

} U;

};
U-Boot to boot using the command bootm already loaded into memory in the kernel. The bootm command actually invokes a do_bootm function. For the Linux kernel, do_bootm function call function to set the mark do_bootm_linux list and start the kernel. do_bootm_linux function lib_arm / bootm.c defined as follows:

59 int do_bootm_linux (int flag, int argc, char * argv [], bootm_headers_t * images)

60 {

61 bd_t * bd = gd-> bd;

62 char * s;

63 int machid = bd-> bi_arch_number;

64 void (* theKernel) (int zero, int arch, uint params);

65

66 # ifdef CONFIG_CMDLINE_TAG

67 char * commandline = getenv ("bootargs"); / * U-Boot environment variables bootargs * /

68 # endif

... ...

73 theKernel = (void (*) (int, int, uint)) images-> ep; / * get kernel entry address * /

... ...

86 # if defined (CONFIG_SETUP_MEMORY_TAGS) | | \

87 defined (CONFIG_CMDLINE_TAG) | | \

88 defined (CONFIG_INITRD_TAG) | | \

89 defined (CONFIG_SERIAL_TAG) | | \

90 defined (CONFIG_REVISION_TAG) | | \

91 defined (CONFIG_LCD) | | \

92 defined (CONFIG_VFD)

93 setup_start_tag (bd); / * set ATAG_CORE flag * /

... ...

100 # ifdef CONFIG_SETUP_MEMORY_TAGS

101 setup_memory_tags (bd); / * set the memory to be marked * /

102 # endif

103 # ifdef CONFIG_CMDLINE_TAG

104 setup_commandline_tag (bd, commandline); / * set the command-line flags * /

105 # endif

... ...

113 setup_end_tag ​​(bd); / * set ATAG_NONE flags * /

114 # endif

115

116 / * we assume that the kernel is in place * /

117 printf ("\ nStarting kernel ... \ n \ n");

... ...

126 cleanup_before_linux (); / * start the kernel before the final setting of the CPU * /

127

128 theKernel (0, machid, bd-> bi_boot_params); / * call kernel * /

129 / * does not return * /

130

131 return 1;

132}

Which setup_start_tag, setup_memory_tags, setup_end_tag ​​function lib_arm / bootm.c defined as follows:

(1) setup_start_tag function

static void setup_start_tag (bd_t * bd)

{

params = (struct tag *) bd-> bi_boot_params; / * start address of kernel parameters * /

params-> hdr.tag = ATAG_CORE;

params-> hdr.size = tag_size (tag_core);

params-> u.core.flags = 0;

params-> u.core.pagesize = 0;

params-> u.core.rootdev = 0;

params = tag_next (params);

}

Tag list must ATAG_CORE start, setup_start_tag function parameters in the kernel set the start address of a ATAG_CORE tag.

(2) setup_memory_tags function

static void setup_memory_tags (bd_t * bd)

{

int i;

/ * Set a memory tag * /

for (i = 0; i
params-> hdr.tag = ATAG_MEM;

params-> hdr.size = tag_size (tag_mem32);

params-> u.mem.start = bd-> bi_dram [i]. start;

params-> u.mem.size = bd-> bi_dram [i]. size;

params = tag_next (params);

}

}

setup_memory_tags function sets a ATAG_MEM tag that contains the starting memory address, memory size, these two parameters.

(3) setup_end_tag ​​function

static void setup_end_tag ​​(bd_t * bd)

{

params-> hdr.tag = ATAG_NONE;

params-> hdr.size = 0;

}

Marked the end of the list must be marked ATAG_NONE, setup_end_tag ​​function sets a ATAG_NONE tag that marks the end of the list.

U-Boot after the set list will mark a call to the kernel. But before calling the kernel, CPU must meet the following conditions:

(1) CPU register settings
r0 = 0
r1 = machine code
r2 = kernel parameter marker list start address in RAM

(2) CPU operating modes
Disable IRQ and FIQ interrupts
CPU model for the SVC

(3) the failure of Data Cache and Instruction Cache

do_bootm_linux called cleanup_before_linux function in the complete prohibition and make the Cache fail interrupt function. cleanup_before_linux function cpu/arm920t/cpu. the definition:

int cleanup_before_linux (void)

{

/ *

* This function is called just before we call linux

* It prepares the processor for linux

*

* We turn off caches etc ...

* /

disable_interrupts (); / * prohibit FIQ / IRQ interrupt * /

/ * Turn off I / D-cache * /

icache_disable (); / * Instruction Cache failure to make * /

dcache_disable (); / * Cache the data fail * /

/ * Flush I / D-cache * /

cache_flush (); / * Refresh Cache * /

return 0;

}

As the U-Boot has been working since the start in the SVC mode, the CPU operating mode no need to set up.

do_bootm_linux in:

64 void (* theKernel) (int zero, int arch, uint params);

... ...

73 theKernel = (void (*) (int, int, uint)) images-> ep;

... ...

128 theKernel (0, machid, bd-> bi_boot_params);

73 lines of code to the kernel entry address ï ¿ ½ images-> epï ¿ ½ cast a function pointer. According ATPCS rules, functions, number of parameters more than 4, the use of r0 ~ r3 four registers to pass parameters. So the first line of the function call 128 to 0 will be placed in r0, into machine code machid r1, kernel parameters address bd-> bi_boot_params into r2, thus completing the register set, and finally to the kernel entry address.

Here, U-Boot's work is over, the system jumps to the Linux kernel code execution.
1.1.4 U-Boot command to add the method and process of U-Boot command

The following command to add a menu (Start menu) as an example to explain U-Boot to add commands.

(1) establishing common / cmd_menu.c

General command on the source code used on common directory, and the development board proprietary source code is placed on the command board / directory, and accustomed to "cmd_ . C" for the file name.

(2) defines "menu" command

In cmd_menu.c use the following code defines "menu" command:

_BOOT_CMD (

menu, 3, 0, do_menu,

"Menu - display a menu, to select the items to do something \ n",

"- Display a menu, to select the items to do something"

);

One U_BOOT_CMD command format is as follows:

U_BOOT_CMD (name, maxargs, rep, cmd, usage, help)

The significance of each parameter as follows:

name: command name, not a string, but in U_BOOT_CMD using "#" symbol into a string

maxargs: command the largest number of parameters

rep: whether to automatically repeat (press Enter key to whether it will repeat)

cmd: The command corresponding to the response function

usage: the use of a short description (string)

help: the use of a more detailed description (string)

Save command in the memory field will help take some of the memory, by configuring U-Boot can choose whether to help save the field. If include / configs / mini2440.h CONFIG_SYS_LONGHELP defined macro, then use U-Boot to a command, help command will display help information when the contents of the field usage and help, otherwise only shows usage field content.

U_BOOT_CMD macro in include / command.h defined:

# Define U_BOOT_CMD (name, maxargs, rep, cmd, usage, help) \

cmd_tbl_t __u_boot_cmd_ # # name Struct_Section = {# name, maxargs, rep, cmd, usage, help}

"# #" And "#" are pre-compiled a string concatenation operator ,"##" function, "#" followed by that followed a string.

Which cmd_tbl_t in include / command.h defined as follows:

struct cmd_tbl_s {

char * name; / * command name * /

int maxargs; / * maximum number of arguments * /

int repeatable; / * whether to automatically repeat * /

int (* cmd) (struct cmd_tbl_s *, int, int, char *[]); / * response function * /

char * usage; / * short help * /

# Ifdef CONFIG_SYS_LONGHELP

char * help; / * more detailed help information * /

# Endif

# Ifdef CONFIG_AUTO_COMPLETE

/ * The auto completion function * /

int (* complete) (int argc, char * argv [], char last_char, int maxv, char * cmdv []);

# Endif

};

typedef struct cmd_tbl_s cmd_tbl_t;

A cmd_tbl_t structure variable contains a command called the information they need.

Which Struct_Section in include / command.h defined as follows:

# Define Struct_Section __attribute__ ((unused, section (". U_boot_cmd")))

All with __attribute__ ((unused, section (". U_boot_cmd")) attributes declared variables will be stored in ". U_boot_cmd" section, and even if the variables are not explicit in the code using the compiler does not generate warning message.

Connect the U-Boot script u-boot.lds defined ". U_boot_cmd" section:

. =.;

__u_boot_cmd_start =.; / * will __u_boot_cmd_start designated as the current address * /

. U_boot_cmd: {* (. U_boot_cmd)}

__u_boot_cmd_end =.; / * will __u_boot_cmd_end specified as the current address * /

This indicates that with the ï ¿ ½. U_boot_cmdï ¿ ½ declare a function or variable will be stored in the ï ¿ ½ u_boot_cmdï ¿ ½ segments. So long as the U-Boot command corresponding cmd_tbl_t all variables with ï ¿ ½. U_boot_cmdï ¿ ½ statement, the compiler will automatically be placed in ï ¿ ½ u_boot_cmdï ¿ ½ section to find cmd_tbl_t variable between as long as __u_boot_cmd_start and __u_boot_cmd_end find it.

Therefore ï ¿ ½ menuï ¿ ½ macro command after the commencement of the definition is as follows:

cmd_tbl_t __u_boot_cmd_menu __attribute__ ((unused, section (". u_boot_cmd"))) = {menu, 3, 0, do_menu, "menu - display a menu, to select the items to do something \ n", "- display a menu, to select the items to do something "}

In essence, is to use the information U_BOOT_CMD macro constructs a cmd_tbl_t type of structure. Compiler structure on the ï ¿ ½ u_boot_cmdï ¿ ½ segment, execute the command you can ï ¿ ½ u_boot_cmdï ¿ ½ segment to the corresponding cmd_tbl_t find the type of structure.

(3) to achieve a function of command

Add ï ¿in cmd_menu.c ½ menuï ¿ ½ order response function implementation. Specific implementation code slightly:

int do_menu (cmd_tbl_t * cmdtp, int flag, int argc, char * argv [])

{

/ * Implement the code slightly * /

}

(4) common / cmd_menu.c compiled u-boot.bin

In common / Makefile add the following code:

COBJS-$ (CONFIG_BOOT_MENU) + = cmd_menu.o

In include/configs/mini2440.h participate in such a code:

# Define CONFIG_BOOT_MENU 1

Download U-Boot to recompile, you can use menu commands

(5) menu command in the process

Enter the U-Boot ï ¿ ½ menuï ¿ ½ command is executed, U-Boot to receive input string ï ¿ ½ menuï ¿ ½, passed to run_command function. run_command function call common / command.c implemented find_cmd function __u_boot_cmd_start and __u_boot_cmd_end between the find command, and returns the menu command cmd_tbl_t structure. Then run_command function uses the return cmd_tbl_t structure function pointer call menu command response function do_menu, thus completing the execution of the command.

Author: heaad

http://www.cnblogs.com/heaad/

E-mail: prabhat.b@gracelabs.com
Thứ Tư, 20 tháng 7, 2011 22:05 Đọc tiếp >>

How to write U-Boot (Bootloader)

Thứ Ba, 19 tháng 7, 2011 / 23:54

1.1 U-Boot working process

U-Boot to boot the kernel of the process can be divided into two stages, two stages of the following functions:

(1) The first stage from
Hardware initialization
Load U-Boot code to RAM space for the second stage
Set stack
Jump to the entrance of the second phase of the code

(2) The second phase of the function
Initialize the hardware devices used at this stage
Testing the system memory map
Read the kernel from Flash to RAM,
Set boot parameters for the kernel
Call kernel
1.1.1 U-Boot start the first stage of code analysis

The first phase of the corresponding file is cpu/arm920t/start.S and board/samsung/mini2440/lowlevel_init.S.

U-Boot start the first stage of the process is as follows:

Figure 2.1 U-Boot start the first stage of the process

According cpu/arm920t/u-boot.lds connection specified:

ENTRY (_start)

SECTIONS

{

. = 0×00000000;

. = ALIGN (4);

. Text:

{

cpu/arm920t/start.o (. text)

board/samsung/mini2440/lowlevel_init.o (. text)

board/samsung/mini2440/nand_read.o (. text)

* (. Text)

}

… …

}

The first link is cpu/arm920t/start.o, so u-boot.bin code cpu/arm920t/start.o entry, its source code in the cpu/arm920t/start.S. Here we analyze the cpu/arm920t/start.S implementation.
1. Hardware device initialization

(1) set an exception vector

cpu/arm920t/start.S at the beginning of the following code:

. Globl _start

_start: b start_code / * reset * /

ldr pc, _undefined_instruction / * undefined instruction vector * /

ldr pc, _software_interrupt / * software interrupt vector * /

ldr pc, _prefetch_abort / * Prefetch instruction exception vector * /

ldr pc, _data_abort / * exception vector data manipulation * /

ldr pc, _not_used / * not used * /

ldr pc, _irq / * irq interrupt vector * /

ldr pc, _fiq / * fiq interrupt vector * /

/ * Interrupt vector table entry address * /

_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,0 xdeadbeef

The above code sets the ARM exception vector table, each exception vector described below:

Table 2.1 ARM exception vector table
Address
Abnormal
Entry mode
Description

0×00000000
Reset
Management
Valid reset level, reset exception, the program jumps to the reset process at the implementation

0×00000004
Undefined instruction
Undefined mode
Instruction could not have handled, resulting in an undefined instruction exception

0×00000008
Software interrupt
Management
SWI instruction execution generated for user mode operation instruction program calls the privileged

0x0000000c
Stored instructions
Abort mode
Address of the instruction prefetch the processor does not exist, or the address is not allowed to access the current instruction to generate instruction prefetch abort exception

0×00000010
Data Manipulation
Abort mode
Address of the instruction processor data access does not exist or access the address is not allowed when the current instruction to generate the data abort exception

0×00000014
Unused
Unused
Unused

0×00000018
IRQ
IRQ
External interrupt request is valid, and I bit in the CPSR is 0, a IRQ exception

0x0000001c
FIQ
FIQ
Fast interrupt request pin is active, and the F bit in the CPSR is 0, generate FIQ exception


There are these exceptions in the cpu/arm920t/start.S corresponding exception handler. When an exception is generated, CPU exception number according to the scale anomaly found in the corresponding exception vector, and then run at the jump instruction exception vector, CPU to jump to the corresponding exception handler execution.
 Reset exception vector in which the instruction "b start_code" determine the U-Boot boot will automatically jump to the label "start_code" at the execution.

(2) CPU into the SVC mode

start_code:

/ *

* Set the cpu to SVC32 mode

* /

mrs r0, cpsr

bic r0, r0, # 0x1f / * mode bits cleared * /

orr r0, r0, # 0xd3 / * mode bit is set to "10011" (management), and interrupt and fast interrupt prohibition against bit position 1 * /

msr cpsr, r0

The above code will set the CPU mode bit of work to management, and interrupt and fast interrupt prohibition against bit position one, thus shielding the IRQ and FIQ interrupts.
(3) Set the control register address

# If defined (CONFIG_S3C2400)

# Define pWTCON 0×15300000

# Define INTMSK 0×14400008

# Define CLKDIVN 0×14800014

# Else / * s3c2410 s3c2440 the following four registers with the same address * /

# Define pWTCON 0×53000000 / * WATCHDOG control register address * /

# Define INTMSK 0x4A000008 / * INTMSK register address * /

# Define INTSUBMSK 0x4A00001C / * INTSUBMSK register address * /

# Define CLKDIVN 0x4C000014 / * CLKDIVN register address * /

# Endif

S3c2440 on the development board with the above code to complete the WATCHDOG, INTMSK, INTSUBMSK, CLKDIVN four register address setting. Each register address see references [4].
(4) Close Watchdog

ldr r0, = pWTCON

mov r1, # 0×0

str r1, [r0] / * watchdog controller, the lowest level is 0, the watchdog reset signal is not output * /

The above code is written to the Watchdog control register 0, the watchdog off. Otherwise, the U-Boot startup, CPU will continue to reboot.

(5) maskable interrupt

/ *

* Mask all IRQs by setting all bits in the INTMR – default

* /

mov r1, # 0xffffffff / * someone is set to a corresponding interrupt mask * /

ldr r0, = INTMSK

str r1, [r0]

INTMSK is the main interrupt mask register, each corresponding to SRCPND (interrupt pin register) in the one, that SRCPND the appropriate representatives of the CPU interrupt request is being processed.

According to Reference 4, INTMSK register is a 32-bit registers, each corresponding to an interrupt, write to them all the location 0xffffffff will INTMSK a register to mask the corresponding interrupt.

# If defined (CONFIG_S3C2440)

ldr r1, = 0x7fff

ldr r0, = INTSUBMSK

str r1, [r0]

# Endif

INTSUBMSK SUBSRCPND in each one corresponding to that SUBSRCPND the appropriate representatives of the CPU interrupt request is being processed.

According to Reference 4, INTSUBMSK register is a 32 bit register, but only a low 15. To write to 0x7fff is to INTSUBMSK register all valid bit (low 15) set a to mask the corresponding interrupt.
(6) set MPLLCON, UPLLCON, CLKDIVN

# If defined (CONFIG_S3C2440)

# Define MPLLCON 0x4C000004

# Define UPLLCON 0x4C000008

ldr r0, = CLKDIVN

mov r1, # 5

str r1, [r0]

ldr r0, = MPLLCON

ldr r1, = 0x7F021

str r1, [r0]

ldr r0, = UPLLCON

ldr r1, = 0×38022

str r1, [r0]

# Else

/ * FCLK: HCLK: PCLK = 1:2:4 * /

/ * Default FCLK is 120 MHz! * /

ldr r0, = CLKDIVN

mov r1, # 3

str r1, [r0]

# Endif

CPU power on a few milliseconds, the crystal output stability, FCLK = Fin (crystal frequency), CPU to execute instructions. But in fact, FCLK can be higher than Fin, to improve the system clock, the software needed to enable the PLL. This requires setting CLKDIVN, MPLLCON, UPLLCON the three registers.

CLKDIVN register sets FCLK, HCLK, PCLK ratio among the three can be set according to Table 2.2.

Table 2.2 S3C2440's CLKDIVN Register format
CLKDIVN
Bit
Help
Initial value

HDIVN
[2:1]
00: HCLK = FCLK / 1.

01: HCLK = FCLK / 2.

10: HCLK = FCLK / 4 (when CAMDIVN [9] = 0 pm)

HCLK = FCLK / 8 (when CAMDIVN [9] = 1 pm)

11: HCLK = FCLK / 3 (when CAMDIVN [8] = 0 pm)

HCLK = FCLK / 6 (when CAMDIVN [8] = 1 pm)
00

PDIVN
[0]
0: PCLK = HCLK / 1 1: PCLK = HCLK / 2
0


Set CLKDIVN to 5, will HDIVN set to binary 10, the CAMDIVN [9] has not been changed, the default is 0, so HCLK = FCLK / 4. PDIVN is set to 1, so PCLK = HCLK / 2. So divider FCLK: HCLK: PCLK = 1:4:8.

MPLLCON register used to set multiple FCLK and Fin. MPLLCON bits [19:12] called MDIV, bits [9:4] is called PDIV, bits [1:0] is called SDIV.

For S3C2440, FCLK relationship with Fin as the following formula:

MPLL (FCLK) = (2 � m � Fin) / (p � 14 2 s'>)

Where: m = MDIC +8, p = PDIV +2, s = SDIV

MPLLCON and UPLLCON can reference the value of 4 "PLL VALUE SELECTION TABLE" setting. Part of the table are summarized as follows:

Table 2.3 PLL value recommendation
Input Frequency
Output frequency
MDIV
PDIV
SDIV

12.0000MHz
48.00 MHz
56 (0×38)
2
2

12.0000MHz
405.00 MHz
127 (0x7f)
2
1


When mini2440 system frequency is set to 405MHZ, USB clock frequency is set to 48MHZ, the system can be stabilized to run, so set MPLLCON and UPLLCON as:

MPLLCON = (0x7f <<12) | (0×02 <<4) | (0×01) = 0x7f021

UPLLCON = (0×38 <<12) | (0×02 <<4) | (0×02) = 0×38022

 (7) Close the MMU, cache

Read on:

# Ifndef CONFIG_SKIP_LOWLEVEL_INIT

bl cpu_init_crit

# Endif

cpu_init_crit this code in the U-Boot starts normally only need to do that if U-Boot from RAM to start, you should comment out the code.

The following analysis of what to do about cpu_init_crit in the end:

320 # ifndef CONFIG_SKIP_LOWLEVEL_INIT

321 cpu_init_crit:

322 / *

323 * the data cache and instruction cache is invalid * /

324 * /

325 mov r0, # 0

326 mcr p15, 0, r0, c7, c7, 0 / * write 0 to the c7 will ICache and DCache void * /

327 mcr p15, 0, r0, c8, c7, 0 / * write 0 to c8 TLB will fail * /

328

329 / *

330 * disable MMU stuff and caches

331 * /

332 mrc p15, 0, r0, c1, c0, 0 / * read control register to r0 in the * /

333 bic r0, r0, # 0×00002300 @ clear bits 13, 9:8 (- V– RS)

334 bic r0, r0, # 0×00000087 @ clear bits 7, 2:0 (B —-CAM)

335 orr r0, r0, # 0×00000002 @ set bit 2 (A) Align

336 orr r0, r0, # 0×00001000 @ set bit 12 (I) I-Cache

337 mcr p15, 0, r0, c1, c0, 0 / * Save r0 to the control register * /

338

339 / *

340 * before relocating, we have to setup RAM timing

341 * because memory timing is board-dependend, you will

342 * find a lowlevel_init.S in your board directory.

343 * /

344 mov ip, lr

345

346 bl lowlevel_init

347

348 mov lr, ip

349 mov pc, lr

350 # endif / * CONFIG_SKIP_LOWLEVEL_INIT * /

Code c0, c1, c7, c8 are the ARM920T coprocessor CP15 registers. Where c7 is the cache control register, c8 is the TLB control register. 325 ~ 327 lines of code to 0 written c7, c8, the Cache, TLB void.

332 ~ 337 lines of code to turn off the MMU. This is by modifying the c1 CP15 registers to achieve, look at the c1 CP15 register format (only the bits used in the code listed):
Table 2.3 CP15 of c1 register format (Part I)
15
14
13
12
11
10
9
8
7
6
5
4
3
2
1
0

.
.
V
I
.
.
R
S
B
.
.
.
.
C
A
M


The significance of each bit is as follows:

V: express exception to the location scale, 0: exception vector at 0×00000000; 1: exception vector in 0xFFFF0000
I: 0: off ICaches; 1: Open ICaches
R, S: used in conjunction with page table descriptors to identify memory access with
B: 0: CPU is little endian; 1: CPU is big endian
C: 0: off DCaches; 1: Open DCaches
A: 0: data access alignment checking when no address; 1: data access address when alignment checking
M: 0: off MMU; 1: Open the MMU

332 ~ 337 lines of code to the M c1 position zero, closed the MMU.

(8) RAM control register initialization

Which lowlevel_init memory initialization is complete the work, because the memory initialization is dependent on the development board, so lowlevel_init generic code on the board following the appropriate directory. For mini2440, lowlevel_init defined in board/samsung/mini2440/lowlevel_init.S as follows:

45 # define BWSCON 0×48000000 / * 13 more storage start address * /

… …

129 _TEXT_BASE:

130. Word TEXT_BASE

131

132. Globl lowlevel_init

133 lowlevel_init:

134 / * memory control configuration * /

135 / * make r0 relative the current location so that it * /

136 / * reads SMRDATA out of FLASH rather than memory! * /

137 ldr r0, = SMRDATA

138 ldr r1, _TEXT_BASE

139 sub r0, r0, r1 / * SMRDATA by _TEXT_BASE is offset register 13 * /

140 ldr r1, = BWSCON / * Bus Width Status Controller * /

141 add r2, r0, # 13 * 4

1420:

143 ldr r3, [r0], # 4 / * register values ​​to each of the 13 assigned to the corresponding register * /

144 str r3, [r1], # 4

145 cmp r2, r0

146 bne 0b

147

148 / * everything is fine now * /

149 mov pc, lr

150

151. Ltorg

152 / * the literal pools origin * /

153

154 SMRDATA: / * The following are the 13 register values ​​* /

155. Word … …

156. Word … …

… …
 lowlevel_init initialization register 13 to achieve the RAM clock initialization. lowlevel_init function for U-Boot from NAND Flash or NOR Flash boot situation are valid.

U-Boot.lds link script with the following code:

. Text:

{

cpu/arm920t/start.o (. text)

board/samsung/mini2440/lowlevel_init.o (. text)

board/samsung/mini2440/nand_read.o (. text)

… …

}

board/samsung/mini2440/lowlevel_init.o will be linked to cpu/arm920t/start.o back, so board / samsung/mini2440/lowlevel_init.o U-Boot is also the first 4KB of code.

U-Boot in the NAND Flash start, lowlevel_init.o will automatically be read to the CPU internal 4KB of internal RAM. So the first 137 to 146 lines of code copied from the CPU registers internal RAM to the appropriate register values.

For the U-Boot boot in the case of NOR Flash, as determined when U-Boot connected U-Boot address is the address in memory, at which point U-Boot NOR Flash is still, so still need to read in the NOR Flash get data to the RAM.

NOR Flash as the start address is 0, and U-Boot to load into memory the starting address is TEXT_BASE, SMRDATA the address label is in the Flash SMRDATA-TEXT_BASE.

In summary, lowlevel_init role is to start the 13 SMRDATA copies the value of start address [BWSCON] 13 registers, thus completing the storage controller settings.

(9) Copy the second phase of U-Boot code to RAM

cpu/arm920t/start.S the original code is only support boot from NOR Flash, and a modified U-Boot is now in the NOR Flash and NAND Flash started on both realize the idea is this:

bl bBootFrmNORFlash / * determine the U-Boot in NAND Flash or NOR Flash boot * /

cmp r0, # 0 / * r0 storage bBootFrmNORFlash function return value, return 0 if the NAND Flash start, or that start in the NOR Flash * /

beq nand_boot / * Jump to NAND Flash boot code * /

/ * NOR Flash boot code * /

b stack_setup / * skip start code * NAND Flash /

nand_boot:

/ * NAND Flash boot code * /

stack_setup:

/ * Other code * /
Role is to determine the function of which bBootFrmNORFlash U-Boot in NAND Flash or NOR Flash boot boot boot NOR Flash if it returns 1, otherwise it returns 0. According to ATPCS rules, the function return value will be stored in r0 register, so after the function call bBootFrmNORFlash according able to judge the value of r0 U-Boot in the NAND Flash or NOR Flash boot start. bBootFrmNORFlash function is defined in the board/samsung/mini2440/nand_read.c as follows:

int bBootFrmNORFlash (void)

{

volatile unsigned int * pdw = (volatile unsigned int *) 0;

unsigned int dwVal;

dwVal = * pdw; / * first record the original data * /

* Pdw = 0×12345678;

if (* pdw! = 0×12345678) / * write fails, start in the NOR Flash * /

{

return 1;

}

else / * write success that started in the NAND Flash * /

{

* Pdw = dwVal; / * restore original data * /

return 0;

}

}

Either from the NAND Flash NOR Flash or from the start, the address 0 for the U-Boot for the first instruction "b start_code".

For the situation from the NAND Flash start, it starts 4KB of code will be automatically copied to the internal 4K memory, CPU, so you can modify the direct assignment method.

For the situation from the start NOR Flash, NOR Flash is the beginning of the address 0, must pass a certain sequence of commands to write data to NOR Flash, so can this difference to distinguish from the NAND Flash or NOR Flash boot: to address 0 to write a data, and then read out, if we find that the failure to write NOR Flash, otherwise NAND Flash.

NOR Flash started to analyze the following part of the code:

208 adr r0, _start / * r0 <- current position of code * /

209 ldr r1, _TEXT_BASE / * test if we run from flash or RAM * /

/ * U-Boot to determine whether it is downloaded to the RAM to run, and if so, no longer copied to the RAM in, and this usually happens only when debugging U-Boot * /

210 cmp r0, r1 / * _start equal _TEXT_BASE that is downloaded to the RAM to run * /

211 beq stack_setup

212 / * The following front label until nand_boot are NOR Flash boot code * /

213 ldr r2, _armboot_start

214 ldr r3, _bss_start

215 sub r2, r3, r2 / * r2 <- size of armboot * /

216 add r2, r0, r2 / * r2 <- source end address * /

217 / * move to the U-Boot itself in RAM * /

218 copy_loop:
 219 ldmia r0!, {R3-r10} / * from the address [r0] the NOR Flash 8 characters read into the data * /

220 stmia r1!, {R3-r10} / * r3 to r10 registers the data replication to address [r1] memory * /

221 cmp r0, r2 / * until source end addreee [r2] * /

222 ble copy_loop

223 b stack_setup / * skip start code * NAND Flash /

NAND Flash start again following analysis of part of the code:

nand_boot:

mov r1, # NAND_CTL_BASE

ldr r2, = ((7 <<12) | (7 <<8) | (7 <<4) | (0 <<0))

str r2, [r1, # oNFCONF] / * set NFCONF register * /

/ * Set NFCONT, initialize the ECC encoder / decoder, prohibiting NAND Flash Chip Select * /

ldr r2, = ((1 <<4) | (0 <<1) | (1 <<0))

str r2, [r1, # oNFCONT]

ldr r2, = (0×6) / * set NFSTAT * /

str r2, [r1, # oNFSTAT]

/ * Reset command before the first use of NAND Flash Reset * /

mov r2, # 0xff

strb r2, [r1, # oNFCMD]

mov r3, # 0

/ * Call the C function nand_read_ll ready for the stack * /

ldr sp, DW_STACK_START

mov fp, # 0

/ * The following first set r0 to r2, and then call the function U-Boot nand_read_ll read RAM * /

ldr r0, = TEXT_BASE / * destination address: U-Boot start address in RAM * /

mov r1, # 0×0 / * Source Address: U-Boot in the NAND Flash in the beginning of the address * /

mov r2, # 0×30000 / * copy the size of the file must be large compared with u-boot.bin, and the NAND Flash block size must be an integer multiple of, where is set to 0×30000 (192KB) * /

bl nand_read_ll / * jump to nand_read_ll function, U-Boot to start copying RAM * /

tst r0, # 0×0 / * check the return value is correct * /

beq stack_setup

bad_nand_read:

loop2: b loop2 / / infinite loop

. Align 2

DW_STACK_START:. Word STACK_BASE + STACK_SIZE-4

One NAND_CTL_BASE, oNFCONF other in include/configs/mini2440.h defined as follows:

# Define NAND_CTL_BASE 0x4E000000 / / NAND Flash control register base address

# Define STACK_BASE 0x33F00000 / / base address of stack

# Define STACK_SIZE 0×8000 / / size of stack

# Define oNFCONF 0×00 / * NFCONF NAND_CTL_BASE offset relative to the address * /

# Define oNFCONT 0×04 / * NFCONT NAND_CTL_BASE offset relative to the address * /

# Define oNFADDR 0x0c / * NFADDR NAND_CTL_BASE offset relative to the address * /

# Define oNFDATA 0×10 / * NFDATA NAND_CTL_BASE offset relative to the address * /

# Define oNFCMD 0×08 / * NFCMD NAND_CTL_BASE offset relative to the address * /

# Define oNFSTAT 0×20 / * NFSTAT NAND_CTL_BASE offset relative to the address * /

# Define oNFECC 0x2c / * NFECC NAND_CTL_BASE offset relative to the address * /

NAND Flash control register set of each data sheet in the S3C2440 is described in detail here not introduced.

Code nand_read_ll function in the NAND Flash in handling U-Boot to RAM, the function is defined in the board/samsung/mini2440/nand_read.c.

According to the size of NAND Flash page can be divided into two kinds: 512B/page and 2048B/page's. The two NAND Flash read operation is different. Hence the need for U-Boot to identify the type of NAND Flash, and then use the appropriate read, that can automatically adapt to nand_read_ll function of two NAND Flash.

Reference data sheet S3C2440 can know: According to the NFCONF register Bit3 (AdvFlash (Read only)) and Bit2 (PageSize (Read only)) can determine the type of NAND Flash. Bit2, Bit3 and NAND Flash's block type of relationship as follows:
Table 2.4 NFCONF the Bit3, Bit2 relationship with NAND Flash
Bit2 Bit3
0
1

0
256 B / page
512 B / page

1
1024 B / page
2048 B / page


As the NAND Flash only 512B/page and 2048 B / page two, so register under NFCONF Bit3 NAND Flash can be a distinction between the two.

See the complete code in nand_read_ll board/samsung/mini2440/nand_read.c function, here are a pseudo-code:

int nand_read_ll (unsigned char * buf, unsigned long start_addr, int size)

{

/ / Register under NFCONF Bit3 to distinguish two kinds of NAND Flash

if (NFCONF & 0×8) / * Bit is 1, that is 2KB/page the NAND Flash * /

{

////////////////////////////////////

2K block of the NAND Flash Read

////////////////////////////////////

}

else / * Bit is 0, that is 512B/page the NAND Flash * /

{

/////////////////////////////////////

Read 512B block of the NAND Flash

/////////////////////////////////////

}

return 0;

}

(10) set the stack

/ * Set the stack * /

stack_setup:

ldr r0, _TEXT_BASE / * upper 128 KiB: relocated uboot * /

sub r0, r0, # CONFIG_SYS_MALLOC_LEN / * malloc area * /

sub r0, r0, # CONFIG_SYS_GBL_DATA_SIZE / * Skip the global data area * /

# Ifdef CONFIG_USE_IRQ

sub r0, r0, # (CONFIG_STACKSIZE_IRQ + CONFIG_STACKSIZE_FIQ)

# Endif

sub sp, r0, # 12 / * leave 3 words for abort-stack * /

As long as the sp has not been used a pointer to the memory set to complete the stack. According to the above code to know U-Boot memory usage, and as shown below:


Figure 2.2 U-Boot memory usage

(11) Clear BSS section

clear_bss:

ldr r0, _bss_start / * BSS segment start address specified in the u-boot.lds * /

ldr r1, _bss_end / * BSS segment end address, specified in the u-boot.lds * /

mov r2, # 0×00000000

clbss_l: str r2, [r0] / * clear the bss segment * /

add r0, r0, # 4

cmp r0, r1

ble clbss_l
 The initial value is 0, no initial value of global variables, static variables will be automatically placed in BSS segment. These variables should be assigned the initial value is 0, otherwise the initial value of these variables will be a random value, if some programs do not directly use the uninitialized variable will cause unknown consequences.

(12) jump to the entrance of the second phase of the code

ldr pc, _start_armboot

_start_armboot:. word start_armboot

Jump to the second phase of the code at the entrance start_armboot.
1.1.2 U-Boot start the second stage of code analysis

start_armboot function lib_arm / board.c defined, is the U-Boot code for the second phase of the entrance. U-Boot start the second phase of the process is as follows:

Figure 2.3 U-Boot the second phase of the implementation process

Start_armboot function before the analysis to look at some important data structures:

(1) gd_t structure

U-Boot uses a structure gd_t global data area to store the data, the structure in include / asm-arm / global_data.h defined as follows:

typedef struct global_data {

bd_t * bd;

unsigned long flags;

unsigned long baudrate;

unsigned long have_console; / * serial_init () was called * /

unsigned long env_addr; / * Address of Environment struct * /

unsigned long env_valid; / * Checksum of Environment valid? * /

unsigned long fb_base; / * base address of frame buffer * /

void ** jt; / * jump table * /

} Gd_t;

U-Boot uses a pointer stored in the register to record the global data area gd address:

# Define DECLARE_GLOBAL_DATA_PTR register volatile gd_t * gd asm ("r8")

DECLARE_GLOBAL_DATA_PTR gd_t global data structure to define a pointer, the pointer stored in the specified register r8. The statement also avoid compiler r8 assigned to other variables. Anyone who wants to access the global data area code, as long as the code at the beginning of accession "DECLARE_GLOBAL_DATA_PTR" line of code, and then you can use to access the global data pointer gd zone.

According to U-Boot memory map can be calculated using the gd value:

gd = TEXT_BASE-CONFIG_SYS_MALLOC_LEN – sizeof (gd_t)

(2) bd_t structure

bd_t in include / asm-arm.u / u-boot.h defined as follows:

typedef struct bd_info {

int bi_baudrate; / * Serial communication baud rate * /

unsigned long bi_ip_addr; / * IP address * /

struct environment_s * bi_env; / * start address of environment variables * /

ulong bi_arch_number; / * native code development board * /

ulong bi_boot_params; / * start address of kernel parameters * /

struct / * RAM configuration information * /

{
ulong start;

ulong size;

} Bi_dram [CONFIG_NR_DRAM_BANKS];

} Bd_t;

When U-Boot to boot the kernel to pass parameters to give the kernel, then we should use gd_t, bd_t structure the information to set the mark list.

(3) init_sequence array

U-Boot to use an array to store init_sequence development board for most every function of the implementation of the initialization function pointer. init_sequence array has more compiler options, remove the compiler option init_sequence array as follows:

typedef int (init_fnc_t) (void);

init_fnc_t * init_sequence [] = {

board_init, / * development board specific configuration –board/samsung/mini2440/mini2440.c * /

timer_init, / * clock initialization – cpu/arm920t/s3c24x0/timer.c * /

env_init, / * initialize the environment variable –common/env_flash.c or common / env_nand.c * /

init_baudrate, / * initialize the baud rate – lib_arm / board.c * /

serial_init, / * Serial initialization – drivers/serial/serial_s3c24x0.c * /

console_init_f, / * control communications platform initialization phase 1 – common / console.c * /

display_banner, / * print the U-Boot version, compile time – gedit lib_arm / board.c * /

dram_init, / * allocation of available RAM – board/samsung/mini2440/mini2440.c * /

display_dram_config, / * display RAM size – lib_arm / board.c * /

NULL,

};

Board/samsung/mini2440/mini2440.c which board_init defined function, the function sets the MPLLCOM, UPLLCON, and some GPIO register values, also set the U-Boot and kernel boot parameters of the machine code address:

/ * MINI2440 development board of the machine code * /

gd-> bd-> bi_arch_number = MACH_TYPE_MINI2440;

/ * The kernel boot parameter address * /

gd-> bd-> bi_boot_params = 0×30000100;

Which dram_init function board/samsung/mini2440/mini2440.c defined as follows:

int dram_init (void)

{

/ * The mini2440 only * /

gd-> bd-> bi_dram [0]. start = PHYS_SDRAM_1;

gd-> bd-> bi_dram [0]. size = PHYS_SDRAM_1_SIZE;

return 0;

}

mini2440 32MB of SDRAM using two components of the 64MB of memory, connected to the memory controller BANK6, address space is 0×30000000 ~ 0×34000000.

In include/configs/mini2440.h in PHYS_SDRAM_1 and PHYS_SDRAM_1_SIZE were defined as a 0×30000000 and 0×04000000 (64M).

After analyzing the above data structure, to analyze the start_armboot following functions:

void start_armboot (void)

{

init_fnc_t ** init_fnc_ptr;

char * s;

… …

/ * Calculate the address of global data structures gd * /

gd = (gd_t *) (_armboot_start – CONFIG_SYS_MALLOC_LEN – sizeof (gd_t));

… …
 memset ((void *) gd, 0, sizeof (gd_t));

gd-> bd = (bd_t *) ((char *) gd – sizeof (bd_t));

memset (gd-> bd, 0, sizeof (bd_t));

gd-> flags | = GD_FLG_RELOC;

monitor_flash_len = _bss_start – _armboot_start;

/ * One by one call init_sequence array initialization function * /

for (init_fnc_ptr = init_sequence; * init_fnc_ptr; + + init_fnc_ptr) {

if ((* init_fnc_ptr) ()! = 0) {

hang ();

}

}

/ * Armboot_start in cpu/arm920t/start.S be initialized to u-boot.lds connection script _start * /

mem_malloc_init (_armboot_start – CONFIG_SYS_MALLOC_LEN,

CONFIG_SYS_MALLOC_LEN);

/ * NOR Flash initialization * /

# Ifndef CONFIG_SYS_NO_FLASH

/ * Configure available FLASH banks * /

display_flash_config (flash_init ());

# Endif / * CONFIG_SYS_NO_FLASH * /

… …

/ * NAND Flash initialization * /

# If defined (CONFIG_CMD_NAND)

puts ("NAND:");

nand_init (); / * go init the NAND * /

# Endif

… …

/ * Configure the environment variables and re-position * /

env_relocate ();

… …

/ * Get from the IP address of environment variables * /

gd-> bd-> bi_ip_addr = getenv_IPaddr ("ipaddr");

stdio_init (); / * get the devices list going. * /

jumptable_init ();

… …

console_init_r (); / * fully init console as a device * /

… …

/ * Enable exceptions * /

enable_interrupts ();

# Ifdef CONFIG_USB_DEVICE

usb_init_slave ();

# Endif

/ * Initialize from environment * /

if ((s = getenv ("loadaddr"))! = NULL) {

load_addr = simple_strtoul (s, NULL, 16);

}
# If defined (CONFIG_CMD_NET)

if ((s = getenv ("bootfile"))! = NULL) {

copy_filename (BootFile, s, sizeof (BootFile));

}

# Endif

… …

/ * Initialize adapter * /

# If defined (CONFIG_CMD_NET)

# If defined (CONFIG_NET_MULTI)

puts ("Net:");

# Endif

eth_initialize (gd-> bd);

… …

# Endif

/ * Main_loop () can return to retry autoboot, if so just run it again. * /

for (;;) {

main_loop ();

}

/ * NOTREACHED – no way out of command loop except booting * /

}

main_loop function in common / main.c defined. Under normal circumstances, a number of seconds into the main_loop not function

















Thứ Ba, 19 tháng 7, 2011 23:54 Đọc tiếp >>

Porting of Android On Beagle board

Thứ Hai, 18 tháng 7, 2011 / 04:17

Porting of Android On Beagle board.

1.Overview
2.Hardware requirement.
3.Software requirement.
4.Beagle board.
5.Setup.
6.Building Kernel Image.
7.Building Android File system.
8.Building Linux file system with Android file system.
9.Setting Up The Boot Parameters and Booting the Linux kernel
10.Script file to start android services.
11.Flashing the NAND
12.Testing.





1.Overview

Android is a software stack for mobile devices that includes an operating system, middleware and key applications. To learn more about android check the below link http://developer.android.com/guide/basics/what-is-android.html. Android stack
uses Linux-2.6 kernel. Since this project is porting Android on Beagle board, the linux-2.6 kernel added a full support for Beagle board and its peripherals and android specific subsystems.

2.Hardware requirement

1. Beagle Board Rev-B6.
2. Null Modem Serial Cable.
3. S-video cable.
4. Mini-B to A USB cable.
5. SD/MMC card.
6. SD/MMC card Reader.
7. Monitor with S-video support.(Or TV tuner card with S-video support).

3.Software requirement

1. Linux kernel 2.6.22.18-TIomap3 (2.6_kernel_revb-v2.tar.gz -
Beagle board based).
2. Android Patch – Patching above kernel to get android specific supports.
3. Linux File System – ramdisk image (ALSA-FS).
4. Android file system. Extracted form emulator discussed below.
5. Arm Toolchain – cross compiler(arm-2007q3-51-arm-none-linux-
gnueabi-i686-pc-linux-gnu.tar.bz2).
6. Script file to start android services.



4.Beagle Board

BeagleBoard, a low cost OMAP3530 based board. POP (Package on Package) is a technique where the memory, NAND and SDRAM, are mounted on top of the OMAP3530. The different peripheral support the following


o Microprocessor unit (MPU) subsystem based on the ARM Cortex-A8™ processor.
o POP Memory interface
o 1Gb MDDR (128Mbytes)
o 2Gb NAND Flash (256 Mbytes)
o 24 Bit RGB Display interface (DSS)
o SD/MMC interface (The connector can supports 7 different types of card)
o USB OTG interface
o NTSC/PAL/S-Video output
o Power management
o Serial interface
o I2C interface
o I2S Audio interface (McBSP2)
o Expansion McBSP1
o JTAG debugging interface

More about Beagle board can get from http://beagleboard.org/ and http://elinux.org/BeagleBoard . Documents also available over this link. Source code for beagle board, booting procedure and compiling procedure can be found in http://code.google.com/p/beagleboard/

Boot Sequence:
Reset Button:
When pressed and released, causes a full power on reset of the BeagleBoard. It should be noted that currently, the reset will not work when the Linux kernel is running. To reset the board from the kernel operation, a power cycle is required.

User/Boot Button:
A button is provided on the BeagleBoard to provide two functions:
• Force a change in the boot sequence of the OMAP3530.
• Used as an application button that can be used by SW as needed.
When used in conjunction with the RESET button, it will force a change
to the order in which boot sources are checked as viable boot sources.
If the button is pressed while the RESET button is released, the sequence becomes:
o USB
o UART
o MMC1
o NAND
Even though the NAND may have a program in it, if a card is placed in the MMC slot, it will try to boot from it first. If it is not there, it will boot from NAND. There is also the option to have a serial download application that will program the NAND if connected to the serial or USB ports. In this scenario the internal ROM will stop on either the serial or USB port and start the download process from there. It does require an application to be run on the host PC in order to perform this function.
If the user button is not pressed at reset, the sequence in which the internal ROM looks for viable boot sources is as follows:
o NAND
o USB
o UART3
o MMC1
In this case, NAND overrides every option and will always boot from NAND if there is data in the NAND. If the NAND is empty, then the other sources are available to be used based on the boot order.

5.Setup

1. Make sure Beagle power is in OFF state by removing the 5V
supply and the USB host connection.
2. Connect the IDC UART cable the Beagle Board and using a Null-
Modem serial cable connect it to a UART port on a Linux
machine.
3. Have terminal program, such as Minicom running on the host
machine.
4. Configure the terminal program for (BAUD RATE - 115200, DATA- 8 bit,
PARITY- none, STOP - 1bit, FLOW CONTROL – none).
5. Insert the MMC/SD card (that is prepared as described above) into MMC/SD slot on Beagle Board.
6. Connect a TV (NTSC-M) to S-video port. Power ON TV.
7. Make three partitions over the SD card. One should be VFAT filesystem while
other two with EXT2 filesystem.
a) mmcblk0p1 – first partition – filesystem vfat – keep uImage
b) mmcblk0p2 – second partition – filesystem ext2 – keep linux with
android filesystem
c) mmcblk0p3 – third partition – filesystem ext2 – keep android
filesystem
6.Building Kernel Image

1. Configure Linux-2.6 kernel mentioned above with full beagleboard and
android support.

make ARCH=arm CROSS_COMPILE=$(Path of tool chain)/bin/arm-eabi- menuconfig

By default the kernel will have video output LCD. Change it to TV rather
than LCD. File to be change can be found in Linux-kernel/arch/arm/plot- omap-display.c

2. Compile kernel by fallowing command.
make ARCH=arm CROSS_COMPILE=$(Path of tool chain)/bin/arm-eabi- uImage

3. Copy uImage from Linux-kernel/arch/arch/boot folder to SD/MMC card with the following command to vfat partition,
mount /dev/sdxx /mnt.
cp arch/arm/boot/uImage /mnt.
umount /mnt





8. Building Android Filesystem

Extract the data.tar system.tar ramdisk.img with following commands. Which forms Android filesystem.

a) Download android SDK android-sdk-linux_x86-1.0_r1.zip and setup the path in
/root/.bash_profile

b) steps for extracting system and data from emulator...

source :................
http://wiki.kldp.org/wiki.php/AndroidPortingOnRealTarget
http://discuz-android.blogspot.com/2008/01/extract-google-android-file-system.html

c) step by step extracting system and data from emulator...
now get inside tools directory

1) mksdcard card 100M card.img // create an empty card image.
2) emulator -sdcard card.img // starting emulator.
Note: Download busybox binary for android.
3) adb -d 1 push busybox /system/bin/busybox // push busybox into emulator
4) adb shell
5) chmod +x /busybox
6) busybox tar -c /data.tar /data
7) busybox tar -c /system.tar /system
8) mount -o loop card.img mnt/
9) adb pull /data.tar . // extracting data
8) adb pull /system.tar . // extracting system

d) Get the ramdisk.img from SDK_PATH/tools/lib/images/ramdisk.img

steps for extracting ramdisk.img ..........

1) cp ramdisk.img ramdisk.gz
2) gunzip ramdisk.gz
3) cd target_fs
4) cpio -iv < ../ramdisk

e) Now Android file system is ready. Which means it should have

directories : system and data etc sys dev sbin
files : init init.rc


7.Building Linux filesystem with Android filesystem

Linux Filesystem used is rd-ext2-8M.bin (With Stream video support)
Source Link : http://code.google.com/p/beagleboard/downloads/list

a) gunzip -d < rd-ext2-8M.bin > ramdisk
b) mkdir linux-fs
c) mount -o loop ramdisk linux-fs/

d) cd linux-fs/
e) mkdir android – keep android file system extracted as per above, in this android directory.
f)copy linux file system with Android support to mmcblkp2 of sd card.
mount /dev/sdx2 /mnt
cp -av linux-fs/* /mnt/
umount /mnt

9)Setting Up The Boot Parameters and Booting the Linux kernel

In order to boot the Linux Kernel, kernel parameters need to be placed in Flash. This section describes the commands to boot the kernel up.

Steps for loading Kernel and File system images from SD card

a) mmcinit; // initialize mmc card.
b) fatload mmc 0:1 0x80300000 uImage // kernel image
c) fatload mmc 0:1 0x81600000 initrd.bin // file system ramdisk_image

Steps for loading Kernel and File System images serially

a) Boot the beagle board and type the following command at shell

command : loady ram_address Image.

b) Now open Minicom with 115200 baud Rate.
c) press ctrl A+Z , you will get menu in that select 'S' to send Image
and now select 'ymodem' protocol then press enter.
d) Now use space bar to select the intended file to send and press enter.
Which opens a dialog box showing file sending process sectors by sectors.

Prerequisites : MMC card should have 3 partitions.

a) First partition (EXT2) to have only android file system.
b) Second Partition (EXT2) to have Linux and android file system in a
separate directory.
c) This is of vfat type partition to have initrd.bin image and uImage files.

Steps for Android Booting in Beagle board :

a) Directly boot from Android Kernel into the android file system. i.e let the
android kernel directly start /init from android file system.

1. Setup the bootargs.
setenv bootargs console=ttyS2,115200n8,n8 noinitrd root=/dev/mmcblk0p1
rw rootfstype=ext2 init=/init nohz=off

2. Run these commands in Flash, type :
saveenv // to save
printenv // to display

3. Type the following command next: // if MMC card Present
mmcinit; // initialize mmc card.
fatload mmc 0:1 0x80300000 uImage; copy image to certain location.
4. bootm 0x80300000; // booting the kernel

b) Manually booting to android file system from normal linux file system.
Note:Disable autostart in /etc/init.rc for dbus-daemon, app_process and runtime.

1. Setup the bootargs.
setenv bootargs console=ttyS2,115200n8 noinitrd root=/dev/mmcblk0p2
rootfstype=ext2 rw rootdelay=1 init=/linuxrc nohz=off
2. Run these commands in Flash, type :
saveenv // to save
printenv // to display
3. Type the following command next: // if MMC card Present
mmcinit; // initialize mmc card.
fatload mmc 0:1 0x80300000 uImage; copy image to certain location.
4. bootm 0x80300000; // booting the kernel

Steps for Normal Bootup of Beagle board with Linux kernel and ramdisk image:

1. Setup the bootargs.
setenv bootargs console=ttyS2,115200n8 ro rootfstype=ext2 rootdelay=1
ramdisk_size=32768 init=/linuxrc root=/dev/console initrd=0x81600000,60M
nohz=off
2. Run these commands in Flash, type :
saveenv // to save
printenv // to display
3. Type the following command next: // if MMC card Present
mmcinit; // initialize mmc card.
fatload mmc 0:1 0x80300000 uImage;
fatload mmc 0:1 0x81600000 initrd.bin
4. bootm 0x80300000; // booting the kernel




10.Create a Script file to start android services(android_start.sh) using vi editor

#!/bin/sh
ln -s /android/system /system
ln -s /android/data /data

#copy all android etc file
cp /android/etc/* /etc -R

export PATH=/sbin:/system/sbin:/system/bin:$PATH
export LD_LIBRARY_PATH=/system/lib
export ANDROID_ROOT=/system
export ANDROID_ASSETS=/system/app
export ANDROID_DATA=/data
export EXTERNAL_STORAGE=/sdcard
export DRM_CONTENT=/data/drm/content

/bin/chmod -R a+rw /data /tmp
/bin/chmod -R a+rw /dev/binder

chroot /android /init

/system/bin/app_process -Xzygote /system/bin --zygote &
/system/bin/dbus-daemon --system &
runtime &




11.Flashing the Nand

Prerequisites:

1) MMC card to be formated with single partition as vfat.
2) Need device to host converter cable.
3) Need UART serial cable.
4) Need to download source files.
Note:
Source Link : http://code.google.com/p/beagleboard/wiki/BeagleSourceCode



Steps to perform Flashing from u-boot using SD/MMC card.

1) Make sure that all below mentioned files are ready.
x-load.bin.ift
MLO
u-boot.bin
kernel-image(uImage)
ramdisk.bin(file system)
2) copy the files into MMC card as with name given below in a order.
x-load.bin.ift for Nand as x-load.bin.ift
MLO as MLO
u-boot to flash onto Nand as flash-uboot.bin
u-boot.bin for MMC boot as u-boot.bin
ramdisk Image as rd-ext2.bin
Kernel(uImage) as uImage
3) Then insert the MMC card into slot and power up while pressing User button.
Commands to write into Nand Memory
mmcinit;
X-load
fatload mmc 0 0x80200000 x-load.bin.ift;
(fatload mmc partition:partition number ram_adress image)
nand unlock;
nand ecc hw;
nand erase 0 80000;
(nand erase offset size)
nand write 0x80200000 0 80000;
(nand write address offset size)
nand lock

Flash-u-boot
fatload mmc 0 0x80200000 flash-uboot.bin;
nand unlock;
nand ecc sw; nand erase 80000 0x1e0000;
nand write 0x80200000 80000 0x1e0000; nand lock;
Kernel
fatload mmc 0 0x80300000 uImage;nand unlock nand ecc hw nand erase 0x280000 0x500000 nand write 0x80300000 0x280000 0x1e0000 ( nand write address offset kernel_size )
nand lock
File_System
nand unlock
nand ecc hw
nand erase 0x780000 0xf88000
nand write 0x81600000 0x780000 0x400000
(nand write address offset File_System_size)
nand lock
4) Now reboot the board and press reset button.
Steps to perform Flashing from Serial cable.

1) Download beagle_recover.tar.bz2
Source Link: http://groups.google.com/group/beagleboard/files
2) Extract the contents. And setup the connection using serial cable and
Beagle board and power it up.
3) Get inside the beagle_recover directory and run
$./recover_beagle.sh ttyS0
4) Which flashes contents x-load.bin.ift and u-boot.bin into NAND memeory.


Table of Memory Partitioning :

Ram_address Nand Flash offset Size
Start End
X-Loader 0x80200000 0x000000 - 0x80000 0x0080000
U-boot 0x 80200000 0x080000 - 0x260000 0x01e0000
Boot Env-Nand 0x80200000 0x260000 - 0x00280000 0x0020000
Kernel offset 0x80300000 0x280000 - 0x00780000 0x0500000
File System Offset 0x81600000 0x780000 - 0x10000000 0x0f88000





12.Testing

TARGET:
1.Boot with kernel on beagle-board.

HOST:
1.Run the script file.
./android_start.sh


Thứ Hai, 18 tháng 7, 2011 04:17 Đọc tiếp >>

Details of Boot from NAND

Thứ Năm, 23 tháng 6, 2011 / 08:44

Stage 1: Processor ROM Code
Stage 1 is the execution of the OMAP2420 processor ROM code. This ROM code cannot
be modified by the system designer. Only NAND Flash devices supported by the ROM
code can be used for boot-from-NAND with the OMAP2420 device. If the ROM code
does not support a particular NAND Flash device, contact a Texas Instruments representative
to determine if additional ROM code is available that will support the Micron
NAND Flash device.
After a power-on-reset is initiated, the ROM code reads the SYS.BOOT register to determine
the memory interface configuration and programs the general-purpose memory
controller (GPMC) accordingly. Then the ROM code issues a RESET (FFh) command (see
Figure 2) to the NAND Flash device, followed by a READ ID (90h) command (see Figure 3
on page 5). The READ ID operation enables the OMAP2420 processor to determine how
the NAND Flash device is configured and whether this device is supported by the ROM
code.
Bad Blocks
The ROM code expects the X-Loader to be in block 0, 1, 2, or 3 of the NAND Flash device
and can use any of these blocks in the boot process. After the NAND Flash device configuration
has been determined, the OMAP2420 processor ROM code performs a badblock
check on these blocks.
Block 0 of the MT29F1G08ABB device is guaranteed to be good for 1,000 PROGRAM/
ERASE cycles, so in the majority of cases, the ROM code will not have to look beyond
block 0 for a bootable image.
Code Shadowing to the OMAP Processor SRAM
After the NAND Flash device configuration has been verified and the bad blocks have
been checked, the process of copying (shadowing) the X-Loader from the NAND Flash
device to the internal SRAM of the OMAP2420 processor begins.
First, the ROM code reads bytes 1 through 4 of the X-Loader to determine the size of the
file; then it reads bytes 5 through 8 of the X-Loader, which contain the destination
address in SRAM where the X-Loader will be shadowed (see Figure 6 on page 8). The
ROM code then shadows the X-Loader from the NAND Flash device to the OMAP2420
processor SRAM (see Figure 4), and finally, the system jumps to the SRAM address where
the first byte of the X-Loader is stored.
Error Correction Code
The ROM code contains error correction code and checks for errors in the X-Loader. The
ECC scheme is a Hamming code capable of detecting 2-bit errors and correcting one
1-bit error per 512 bytes.
• When a 1-bit error is detected in a 512-byte sector, the ROM code will use the ECC to
correct the error, and the boot process will continue from that block.
• When a 2-bit error is detected in a 512-byte sector, the ROM code will skip this block
and attempt to boot from the next block.
• When an error of 3 bits or more is detected, effects on the system may vary and may
include hanging.
Stage 2: Bootstrap
Stage 2 of the boot process is dependent on NAND Flash in the sense that the X-Loader
is stored in the NAND Flash. It is important to remember that this X-Loader is executed
in the OMAP processor SRAM, so the image must fit in the available SRAM.
In a Linux-based system, the stage 2 boot consists of an X-Loader that bootstraps
U-Boot. This bootstrap includes:
• Information for each supported CPU architecture
• A configuration file for each supported board
• NAND Flash driver code
• Serial driver code (to support debug and development efforts)
Building the X-Loader
Building the X-Loader is a critical step in developing a boot-from-NAND system.
Figure 5 on page 8 shows the process for converting source code to a raw binary
X-Loader that can be stored in the Micron NAND Flash device. The “Boot_image” prefix
in the file names is provided only as an example; actual file names can be designated by
the system designer. Figure 6 on page 8 illustrates how the Boot_image.bin code is laid
out in the NAND Flash.
1. Compile the X-Loader source code into an executable format. The example in
Figure 5 on page 8 shows how the source code comprises Boot_image.c and
Boot_image.h; the executable is Boot_image.out.
2. Execute the OST Tools to sign the target file Boot_image.out. When this process is
complete, an 8-byte header is included in the Boot_image.ift file. Bytes 1 through 4 of
Boot_image.ift contain the file size. Bytes 5 through 8 contain the OMAP processor
SRAM address where the X-Loader will be loaded and executed (see Figure 6 on
page 8). OST Tools are available from TI. (See OST Tools documentation for additional
details.)
3. Format the Boot_image.ift file resulting from step 2 for 2KB/page NAND Flash. Code
must be developed for this purpose if it is not available from TI.
To format the Boot_image.ift file, calculate the ECC for each 512-byte sector. Then
store the result in the appropriate area of the file. See Figure 7 on page 9 for boot code,
bad block marking, and ECC storage in a typical page of an MT29F1G08ABB NAND
Flash device programmed for boot-from-NAND in an OMAP2420-based system.
4. Program a copy of the Boot_image.bin file to each of the first four good blocks of the
NAND Flash device. The MT29F1G08ABB device identifies a good block as one that
has 0xFF data at byte 0x800 in both page 0 and page 1.
Stage 3: Boot Loader
Stage 3 of the boot process is heavily dependent on the OS. In a Linux system, the stage 3
boot consists of U-Boot, the OS boot loader for Linux. U-Boot resides in the NAND Flash
but is shadowed to DRAM for execution (as mentioned in the stage 2 boot description).
U-Boot Considerations
• The memory map must be configured to support boot-from-NAND.
• U-Boot must contain NAND Flash support such that it can read and write to the
NAND Flash device.
• U-Boot environment data should be written such that it can be stored in a single
block (128KB) of the Micron MT29F1G08ABB NAND Flash device.
• The CFG_NAND_BOOT configuration label is stored in a board configuration file and
is used to differentiate NAND U-Boot from NOR U-Boot.
Stage 4: Operating System
The final stage of the boot process involves the initial execution of the OS. The operating
system kernel is stored in NAND Flash and shadowed to DRAM for execution as
described in the stage 3 boot description. When the system jumps to the beginning of
the OS code (see Figures 10), the OS takes control of the system.
Writing Binary Images to NAND Flash with Limited OST Tools Support
Some versions of the OST Tools do not fully support Micron NAND Flash devices. In
these cases, it is necessary to develop an alternative method for loading the boot code
into the NAND Flash device. A workstation similar to the one shown in Figure 11 is
required. In addition, modified X-Loader and U-Boot software are required. Contact
your Micron representative for the modified software.
Thứ Năm, 23 tháng 6, 2011 08:44 Đọc tiếp >>

Boot Stages in Boot from NAND

Stage 1: Processor ROM Code
During power-on, or after a RESET operation, the OMAP2420 processor runs its internal
ROM code. Note that only NAND Flash devices supported by the OMAP2420 processor
ROM can be used for the boot process (see Table 2 on page 4).
Stage 2: Bootstrap
X-Loader is an example of stage 2 bootstrap code. The X-Loader code is stored in the
NAND Flash, and the ROM code copies it to the OMAP processor SRAM for execution.
Stage 3: Boot Loader
Stage 3 is the boot loader, which is used to copy the operating system code from the
NAND Flash to the DRAM; in this case U-Boot is the boot loader code. The U-Boot code
is stored in NAND Flash, and the stage 2 code copies it to the DRAM for execution.
Stage 4: Operating System
The OS code, such as the Linux kernel, is stored in the NAND Flash, and the stage 3 code
copies it to the DRAM, where it is executed. The boot process is complete after this stage
as the OS takes control of the system.
Thứ Năm, 23 tháng 6, 2011 08:41 Đọc tiếp >>

Boot from NAND

NAND Flash memory devices are designed for applications requiring nonvolatile, highdensity,
solid-state storage media. Historically, NAND Flash has been used extensively in
applications such as mass storage cards and digital cameras. With its low cost and high
performance, NAND Flash is beginning to make its way into more complex embedded
systems where NOR Flash has dominated in the past—for example, in mobile phones.
In complex embedded systems, one of the challenges associated with a change from
NOR Flash to NAND Flash has been the boot process. NOR Flash has been a popular
choice for these systems because it contains a traditional memory interface (including
both address and data buses), making it capable of execute-in-place (XIP) operation. XIP
memory enables the system CPU to execute code directly from the memory device
because the boot code is stored on and executed from a single device.
NAND Flash is a page-oriented memory device that does not inherently support XIP, at
least not in the same manner as a typical XIP memory device. Operating system and
boot code can be stored in NAND Flash memory, but the code must be copied (or shadowed)
to DRAM before it can be executed. This requires system designers to modify the
boot process for their systems when using NAND Flash. The payoff for this modification
is that the system benefits from the lower cost of NAND Flash as the storage solution and
the higher performance of DRAM as the XIP memory.
This technical note discusses a boot-from-NAND solution for applications using the
Texas Instruments™ (TI) OMAP2420 processor and the Micron® MT29F1G08ABB
NAND Flash device. The technical note provides a four-stage boot sequence. Stages 1
and 2 are independent of the operating system (OS); however, they are highly dependent
on system hardware. Thus, the primary focus of this technical note is on stage 1 and
stage 2 boot processes.
Additional system details:
• TI OMAP2420 H4 with processor daughter card “Menelaus ES 2.0”;
S/N: 750-0006, Rev C.
• The boot-from-NAND concepts discussed are OS independent; however, the Linux
OS is used as an example in some explanations.
Note that secure booting via the OMAP™ high-security (HS) device is not in the scope of
this document. However, NAND Flash booting for HS and GP differs only in the generation
of the X-Loader. Thus, the solution discussed here is generally applicable to both
the HS and GP processors.
Thứ Năm, 23 tháng 6, 2011 08:38 Đọc tiếp >>