prettify

Aug 10, 2016

Linux kernel CRC checksum error

To remove the possible performance impact caused by NFS, I tried to add several test programs into my rootfs. First I added a 3M bytes file, everything is fine, then I added a lot of files with 18Mbytes in total, then suddenly my kernel can not be loaded.
U-Boot code: 00000000 -> 00047568  BSS: -> 00065340
DRAM:  Monitor len: 00065340
Ram size: 40000000
Ram top: 40000000
TLB table from 3fff0000 to 40000000
Reserving 404k for U-Boot at: 3ff8a000
Reserving 5184k for malloc() at: 3fa7a000
Reserving 176 Bytes for Board Info at: 3fa79f50
Reserving 408 Bytes for Global Data at: 3fa79db8
Reserving 11264 Bytes for FDT at: 3fa771b8
DRAM:  1 GiB
New Stack Pointer is: 3fa771a0
Relocation Offset is: 3ff8a000
Relocating to 3ff8a000, new gd at 3fa79db8, sp at 3fa771a0
Initializing board
Board: DB-88F3720-DDR3-Modular
       CPU     @ 600    [MHz]
       DDR     @ 600    [MHz]
Now running in RAM - U-Boot at: 3ff8a000
U-Boot DT blob at : 000000003fa771b8

Hit any key to stop autoboot:  0
## Booting kernel from Legacy Image at 0017ffc0 ...
   Image Name:   linux-4.1.6
   Image Type:   AArch64 Linux Kernel Image (uncompressed)
   Data Size:    15304304 Bytes = 14.6 MiB
   Load Address: 00180000
   Entry Point:  00180000
   Verifying Checksum ... Bad Data CRC
ERROR: can't get kernel image!


Weird thing is, if I load the kernel after u-boot already reach the prompt, everything is good. It looks U-boot write something into the kernel area during the init phase. How come? My first thought is to compare. U-boot has the command "cmp" to compare 2 chunk of data, what I need to do is to load an extra copy of my kernel into memory
LOAD /BINARY /ADDRESS=0x1017FFC0 OF "C:\incoming\bin\kernel_image"

Note my kernel was loaded to 0x0017FFC0 together with u-boot. Now do the compare with u-boot
U-boot>> cmp.b 0x0017ffc0 0x1017ffc0 15304308
byte at 0x0000000000fef4e0 (0x30) != byte at 0x0000000010fef4e0 (0x0)
Total of 15136032 byte(s) were the same
U-boot>> cmp.l 0xfef4e0 0x10fef4e0 0x10000
word at 0x0000000000fef4e0 (0xfef530) != word at 0x0000000010fef4e0 (0x100)
Total of 0 word(s) were the same

Let's dump the memory
U-boot>> md.l 0xfef4e0 0x100
00fef4e0: 00fef530 00000000 00020b44 00000000    0.......D.......
00fef4f0: ffffffff 00000000 00fef720 00000000    ........ .......
00fef500: 00000000 00000000 ffffffff 00000000    ................
00fef510: 0000000a 00000000 00000000 00000000    ................
00fef520: ffffffff 00000000 00000001 00000000    ................
00fef530: 00fef5e0 00000000 00021460 00000000    ........`.......
00fef540: 00fefc00 00000000 0003b527 00000000    ........'.......
00fef550: 00fef720 00000000 000313c8 00000000     ...............
00fef560: ffffffd0 00000000 00fef650 00000000    ........P.......
00fef570: 10004001 00004101 00fefc00 00000000    .@...A..........
00fef580: 00040000 000a4204 000313c8 00000000    .....B..........
00fef590: 00fef640 00000000 00021460 00000000    @.......`.......
00fef5a0: 00fefc60 00000000 0003494b 00000000    `.......KI......
00fef5b0: 00fef780 00000000 000313c8 00000000    ................
00fef5c0: ffffffe0 00000000 00fef6b0 00000000    ................
00fef5d0: 10004001 00004101 00fefc60 00000000    .@...A..`.......
00fef5e0: 00040000 000a4204 00021034 00000000    .....B..4.......
00fef5f0: 00fefc30 00000000 37316130 33666137    0.......0a177af3
00fef600: 00fef750 00000000 000313c8 00000000    P...............
00fef610: 00fef6b0 00000000 00021720 00000000    ........ .......
00fef620: 00fef750 00000000 0003b52e 00000000    P...............
00fef630: 40000000 00000000 00034776 00000000    ...@....vG......
00fef640: 00fef6e0 00000000 00021720 00000000    ........ .......
00fef650: 00fef780 00000000 0003491b 00000000    .........I......
00fef660: 00000000 00000000 40076d90 00000000    .........m.@....
00fef670: 00000000 00000000 00000000 00000000    ................
00fef680: 00000000 00800020 00000400 08010000    .... ...........
00fef690: 00040000 000a4204 00000d80 02008480    .....B..........
00fef6a0: 00fef6c0 00000000 000101e8 00000000    ................
00fef6b0: 00fef6c0 00000000 0001684c 00000000    ........Lh......
00fef6c0: 00fef6e0 00000000 0001694c 00000000    ........Li......
00fef6d0: 0000000a 00000000 000101e8 00000000    ................
00fef6e0: 00fef700 00000000 000168b4 00000000    .........h......
00fef6f0: 00fef7bb 00000000 0001689c 00000000    .........h......
00fef700: 00fef720 00000000 000101e8 00000000     ...............
00fef710: 0000003b 00000000 0003e198 00000000    ;...............
00fef720: 00fefc60 00000000 00004864 00000000    `.......dH......
00fef730: 0003e2a8 00000000 00fefc30 00000000    ........0.......
00fef740: 00fefc60 00000000 00fefc60 00000000    `.......`.......
00fef750: 00fefc20 00000000 ffffffc8 ffffff80     ...............
00fef760: 00fefc60 00000000 00fefc60 00000000    `.......`.......
00fef770: 00fefc20 00000000 ffffffc8 ffffff80     ...............
00fef780: 6f6c6552 69746163 7420676e 6633206f    Relocating to 3f
00fef790: 30613866 202c3030 2077656e 61206467    f8a000, new gd a
00fef7a0: 66332074 64393761 202c3862 61207073    t 3fa79db8, sp a
00fef7b0: 66332074 31373761 000a3061 36313032    t 3fa771a0..2016
00fef7c0: 2e31545f 6e652e30 72645f67 765f706f    _T1.0.eng_drop_v
00fef7d0: 000a0a32 00000000 00254e30 ffffffc0    2.......0N%.....
00fef7e0: 002554c8 ffffffc0 00000002 00000000    .T%.............
00fef7f0: 00000000 00000000 00000000 00000000    ................
00fef800: 00000000 00000000 00000000 00000000    ................
00fef810: 00000000 00000000 00fef878 ffffffc0    ........x.......
00fef820: 00fef858 ffffffc0 00fef8d8 ffffffc0    X...............
00fef830: 00fef8b8 ffffffc0 00fef898 ffffffc0    ................
00fef840: 00fef918 ffffffc0 00fef8f8 ffffffc0    ................
00fef850: 00000000 00000000 00699768 ffffffc0    ........h.i.....
00fef860: 000001a4 00000000 002550d0 ffffffc0    .........P%.....
00fef870: 00254ea0 ffffffc0 00699778 ffffffc0    .N%.....x.i.....
00fef880: 000001a4 00000000 00255100 ffffffc0    .........Q%.....
00fef890: 00255618 ffffffc0 00698958 ffffffc0    .V%.....X.i.....
00fef8a0: 00000124 00000000 00255040 ffffffc0    $.......@P%.....
00fef8b0: 00000000 00000000 00699780 ffffffc0    ..........i.....
00fef8c0: 00000124 00000000 00255070 ffffffc0    $.......pP%.....
00fef8d0: 00000000 00000000 006989b0 ffffffc0    ..........i.....

Look at the string "Relocating to"----it looks like this area is being used as a stack area by u-boot. What was the stack pointer when u-boot print "Relocating to"?  It was in function "setup_reloc()" but my debugger do not like the idea to set a break point on this function so I have to add an endless while loop



The stack pointer is 0xFEFC60, which is close to the mis-compare area. Of course it won't work because this stack conflict with my kernel image.  When and where is this stack pointer set? Set a break point on _main and I got



The initial stack pointer was defined by CONFIG_SYS_INIT_SP_ADDR. Refresh the definition and now the kernel can be loaded with large rootfs.

No comments:

Post a Comment