一看二做三总结
分类: LINUX
2010-02-24 01:11:38
1. S3C2440 data sheet;
2. Arm Assemble instruction;
3. Develop Board Data Sheet;
4. Develop environment: arm-linux-gcc3.4.1 u-boot1.1.6
Chapter 2: Led control
1. Browse the data sheet, utu2440-f-main-v45 sch.pdf, the LED are controlled by EINT4~EINT7.
2. Browse the data sheet, S3C2440.pdf, to search for the EINT control register. EINT is equal to the GPF, and we can control it via the CPECON Register and the GPFDATA Register.
If we want to turn on the LED1 and LED3 and turn off the LED2 and the LED4, the assemble program is below:
.text /.* start of test segment */
.global _start /.* illustrate the type of the symbol _start */
_start: /.* a symbol */
LDR R1, =0x56000040 /.* move the immediate number to the R1 */
MOV R2, #0x00005500 /.* move the short immediate number to the R2 */
STR R2, [R1] /.* store the value pointed by R1 to R2 */
LDR R1, =0x56000044
MOV R2, #0x000000F0
STR R2, [R1]
MAIN_LOOP:
B MAIN_LOOP /.* dead loop */
Chapter 3: C Language Init Error
Oh my God, I have finished my first C Language program: Led On.
At first, the CPU can not run the C Language functions. The User must initialize the environment that the C Languae need. It contains the stack and lr registers. The first funtions (entry point) should be a Assemble function. its contents is below:
/* ctr0.s: used to set the environment of C Language */ .text .global _start _start: ldr sp,=0x1000 /* set stack */ bl main halt_loop: b halt_loop |
Note: the stack’s start address is 0x1000. Why? Why not at the SDRAM (0x30000000)? That’s because the special of s3c2440. It has a 4K ram in the chip . Usually, it is used to store the boot code. After the booting, we can erase it and use it as the stack at Init period.
the makefile is below:
SRC_PATH = . TOOL_PATH = tools OBJ_PATH = tmp TEST_SRC = $(wildcard *.c) TEST_ASM = $(wildcard *.s) TEST_OBJ = $(addprefix $(OBJ_PATH)/,$(subst .c,.o,$(TEST_SRC))) TEST_OBJ += $(filter-out $(OBJ_PATH)/crt0.o,$(addprefix $(OBJ_PATH)/,$(subst .s,.o,$(TEST_ASM)))) .PHONY:default default:$(OBJ_PATH)/test.bin @echo "start compile" $(OBJ_PATH)/test.bin:$(OBJ_PATH)/crt0.o $(TEST_OBJ) arm-linux-ld -Ttext 0x30000000 -e _start -g $^ -o $(subst .bin,.elf,$@) # convert the kernel into a raw binary image: arm-linux-objcopy -O binary -R .note -R .comment -S $(subst .bin,.elf,$@) $@ $(OBJ_PATH)/%.o:%.s mkdir -p $(OBJ_PATH) arm-linux-gcc -g -c $< -o $@ $(OBJ_PATH)/%.o:%.c mkdir -p $(OBJ_PATH) arm-linux-gcc -g -c $< -o $@ |
the led_on.c is below:
#define GPFCON (*(volatile unsigned long *)0x56000050) #define GPFDAT (*(volatile unsigned long *)0x56000054) int main() { GPFCON = 0x00005500; GPFDAT = 0x000000a0; while(1); } |
When I finished the compile, I downloaded the test.elf to the board and run it by below command:
> tftp 0x30000000 test.elf
> go 0x30000000
Then an error occurred and the log was below:
## Starting application at 0x30000000 ... undefined instruction pc : [<30000024>] lr : [<33f89ad0>] sp : 33d5fb44 ip : 00000001 fp : 00000000 r10: 33d5fd71 r9 : 00000000 r8 : 33d5ffdc r7 : 33d5fc71 r6 : 00000002 r5 : 33d5fe68 r4 : 30000000? |
The reason is that the file I should download is th test.bin, not the test.elf. The elf file is a kind of file format. It cannot run directly in the memory. The bin file is the memory image, so it can run directly in the memory.
The first problem is that there was no the file: curses.h, so that I cannot run the command, make menuconfig, to config the kernel. I searhed on the Baidu and find the problem is the lack of libcurses. Run command as below in the termimal:
apt-get install libcurses*-dev
Then I can run the “make menuconfig”.
The second problem is that the target “prepare3” in the top makefile(896) should not run the command, so I delete the it:
Original |
prepare3: include/config/kernel.release ifneq ($(KBUILD_SRC),) @echo ' Using $(srctree) as source for kernel' $(Q)if [ -f $(srctree)/.config -o -d $(srctree)/include/config ]; then \ echo " $(srctree) is not clean, please run 'make mrproper'";\ echo " in the '$(srctree)' directory.";\ /bin/false; \ fi; $(Q)if [ ! -d include2 ]; then mkdir -p include2; fi; $(Q)ln -fsn $(srctree)/include/asm-$(SRCARCH) include2/asm endif |
New |
prepare3: include/config/kernel.release |
The last problem is that the command, “cp ./drivers/video/logo/logo_linux_240320_clut224.ppm ./drivers/video/logo/logo_linux_clut224.ppm”, can not be executed. I should change the first “.” to “..”, as below:
“cp ../drivers/video/logo/logo_linux_240320_clut224.ppm ./drivers/video/logo/logo_linux_clut224.ppm”.
Now, I can finish the compile of the kernel. The next step is to modify the config from the sdk2410 to sdk2440.
Good night.