- Assembly code
.text.global _start_start: ldr sp, =4096 bl close_watchdog bl memsetup bl testarmled: ldr r0, =0x56000010 mov r1, #0x15400 str r1, [r0] ldr r0, =0x56000014 mov r1, #0 str r1, [r0]loop: b loop
//Makefile
- Assembly code
all: clean arm-linux-gcc -c myhead.s myinit.c arm-linux-ld -Ttext 0x00000000 myhead.o myinit.o -o test.elf arm-linux-objcopy -O binary -S test.elf test.bin arm-linux-objdump -D -m arm test.elf > test.dis -rm -f *.o *.elfclean: -rm -f *.bin~ ~
- C/C++ code
typedef volatile unsigned int PLONG32;struct mini2440 { PLONG32 NFCONF; //4E000000 PLONG32 NFCONT; //04 PLONG32 NFCMMD; //08 PLONG32 NFADDR; //0c PLONG32 NFDATA; //10 PLONG32 NFMECCD0; //14 PLONG32 NFMECCD1; //18 PLONG32 NFSECCD; //1c PLONG32 NFSTAT; //20 PLONG32 NFESTAT0; //24 PLONG32 NFESTAT1; //28 PLONG32 NFMECC0; //2c PLONG32 NFMECC1; //30 PLONG32 NFSECC; //34 PLONG32 NFSBLK; //38 PLONG32 NFEBLK; //3c};void close_watchdog();void memsetup();void led();void test();struct mini2440 * addr = (struct mini2440 *)0x4e000000; //这样编译出来的BIN 为32K//如果改为 struct mini2440 *const addr = (struct mini2440 *const)0x4e000000; 编译出来的BIN 为328字节// WHY?void close_watchdog(){#define rWTCON (*((volatile unsigned long *)0x53000000)) rWTCON = 0;}void memsetup(){ int i = 0; unsigned long *p = (unsigned long *)0x48000000; /* SDRAM 13个寄存器的值*/ unsigned long const mem_cfg_val[]={ 0x22011110, //BWSCON 0x00000700, //BANKCON0 0x00000700, //BANKCON1 0x00000700, //BANKCON2 0x00000700, //BANKCON3 0x00000700, //BANKCON4 0x00000700, //BANKCON5 0x00018005, //BANKCON6 0x00018005, //BANKCON7 0x008C07A3, //REFRESH 0x000000B1, //BANKSIZE 0x00000030, //MRSRB6 0x00000030, //MRSRB7 }; for(; i < 13; i++) p[i] = mem_cfg_val[i];}void led(){#define rGPBCON (*(volatile unsigned long *)0x56000010)#define rGPBDAT (*(volatile unsigned long *)0x56000014) rGPBCON = 0x15400; rGPBDAT = 0; while (1);}void test(){ if(addr == (struct mini2440 *)0x4e000000) led(); while (1);}
------解决方案--------------------
加上const表示静态的数据段了,你是不可以去更改const后面定义的数据值的,并且它是被你定义到flash区区了,所以会变得很小吧。