18.16.1 自寫BootLoader錯誤
ERROR 01: boot.c:62: warning: return type of 'main' is not `int' ANSWER 01: int main(void){ …… return -1;/*執行到這里就出錯了*/ } ERROR 02: boot.c: In function `main':【未聲明】 boot.c:68: warning: implicit declaration of function `uart0_init' boot.c:70: warning: implicit declaration of function `puts' boot.c:71: warning: implicit declaration of function `nand_read' ANSWER 02: 在函數前聲明即可 ERROR 03: boot.c:75: warning: passing arg 2 of `nand_read' makes pointer from integer without a cast ANSWER 03: 將整型強制類型轉換為指針 nand_read(0x60000+64, (unsigned char *)0x30008000, 0x200000); ERROR 04: init.c: In function `isBootFromNorFlash': init.c:33: warning: integer constant is too large for "long" type init.c:33: warning: overflow in implicit constant conversion init.c:34: warning: integer constant is too large for "long" type init.c:34: warning: comparison is always false due to limited range of data type ANSWER 04: 是0x12345678不是0x123456789(超出整型2^32) volatile int *p = (volatile int *)0;// int val; //用來保存原來的值,在判斷完后恢復 val = *p; *p = 0x12345678; ERROR 05: init.c:184: warning: conflicting types for built-in function 'puts' boot.c:4: warning: conflicting types for built-in function 'puts' boot.c:43: warning: conflicting types for built-in function 'strcpy' ANSWER 05: /*錯誤原因: * 編譯器自帶了strcpy和自己寫的strcpy函數類型沖突 * 在Makefile鏈接的時候加 * CPPFLAGS :=-nostdinc -nostdlib */ The ISO C90 functions abort, abs, acos, asin, atan2, atan, calloc, ceil, cosh,cos, exit, exp, fabs, floor, fmod, fprintf, fputs, frexp, fscanf, isalnum, isalpha,iscntrl, isdigit, isgraph, islower, isprint, ispunct, isspace, isupper, isxdigit,tolower, toupper, labs, ldexp, log10, log, malloc, memchr, memcmp, memcpy, memset,modf, pow, printf, putchar, puts, scanf, sinh, sin, snprintf, sprintf, sqrt, sscanf, strcat, strchr, strcmp, strcpy, strcspn, strlen, strncat, strncmp, strncpy, strpbrk,strrchr, strspn, strstr, tanh, tan, vfprintf, vprintf and vsprintf are all recognized as built-in functions unless ‘-fno-builtin’ is specified (or ‘-fno-builtin-function’ is specified for an individual function). All of these functions have corresponding versions prefixed with __builtin_. 將Makefile中CPPFLAGS := -nostdinc 改為CPPFLAGS := -nostdinc -fno-builtin
ERROR 06:
my_printf.c:(.text+0x120):undefined reference to `__aeabi_uidivmod`
my_printf.c:(.text+0x158):undefined reference to `__aeabi_uidiv`
ANSWER 06:
/*編譯器找不到除法函數*/
在arm-linux-gcc-4.3.2編譯器使用libgcc.a中的除法可以
在arm-linux-gcc-3.4.5編譯器使用lib1funcs.S中的除法可以
ERROR 07:
book@book-desktop:/work/system/linux-2.6.22.6$ sudo make uImage
編譯剛解壓的目錄時,顯示如下錯誤:
[sudo] password for lsb: make: arm-linux-gnu-gcc: Command not found
CHK include/linux/version.h
make[1]: `include/asm-arm/mach-types.h' is up to date.
CHK include/linux/utsrelease.h
CC arch/arm/kernel/asm-offsets.s
/bin/sh: arm-linux-gnu-gcc: not found
make[1]: *** [arch/arm/kernel/asm-offsets.s] Error 127
make: *** [prepare0] Error 2
ANSWER 07:
在根目錄下沒有權限。
sudo chmod 777 kernel -R
其中,kernel為內核目錄。
最值得注意的是:定目錄的Makefile 是否該為相對應的交叉工具鏈