2015/01/29

Debug U-Boot After Relocation

U-Boot will relocate itself during the startup. But the symbol data in u-boot was still based on the information before relocate.

This is how I debug U-Boot after relocation with ARM DS-5 debugger

1. Find out where U-Boot is relocated to
Add below to your board configuration header, like "include/configs/versatile.h" to enable the debug output.
#define DEBUG 1

2. When U-Boot starts to run, debug information will be printed out like below
...
relocation Offset is: 03fd0000
...
Now running in RAM - U-Boot at: 0bfd0000 
This indicates the relocation offset to original load address is 0x03fd0000

3. Load the symbol with
On ARM DS-5 debugger command window,
symbol-file
add-symbol-file "C:\svn\HRTK1041\bld\u-boot" 0x3fd0000
First command is to discard the current symbol table
Second command is to load the actually symbol data with offset.
Now, happy debugging.


Reference
http://www.denx.de/wiki/view/DULG/DebuggingUBoot

2015/01/19

Compile and Link ARM Bare Metal Program

An Example:
  arm-linux-gnueabi-as -g startup.s -o startup.o
  arm-linux-gnueabi-gcc -c -g test.c -o test.o
  arm-linux-gnueabi-ld -T test.ld test.o startup.o -o test.elf
  arm-linux-gnueabi-objcopy -O binary test.elf test.bin

2014/12/11

ARM Vector Table Location

Vector table could be controlled by ARM co-processor's System Control Register Bit 13


[13] V Vectors bit

This bit selects the base address of the exception vectors:

- 0 Normal exception vectors, base address 0x00000000. Software can remap this base address using the VBAR.

- 1 High exception vectors, base address 0xFFFF0000. This base address is never remapped.


Example


MRC     p15, 0, r1, c1, c0, 0      ; c1 Sys Ctrl Reg.
BIC     r1, r1, #0x2000            ; vector base to 0x00000000 or VBAR
MCR     p15, 0, r1, c1, c0, 0

LDR     r0, =Vectors               ; set VBAR, vector base to "Vector"
MCR     p15, 0, r0, c12, c0, 0



MRC     p15, 0, r1, c1, c0, 0      ; c1 Sys Ctrl Reg.
ORR     r1, r1, #0x2000            ; vector base to 0xFFFF0000
MCR     p15, 0, r1, c1, c0, 0


Reference
Cortex-A7 TRM, section 4.3.27
http://lists.denx.de/pipermail/u-boot/2014-November/195139.html

2014/12/04

Example, Volatile in GCC

Below shows how GCC optimized the code with a non-volatile variable, (which caused a bug ).
Lesson: do not forget put volatile to your hardware register variables.

// In below code "stat" and "tbr" are registers could be updated by hardware
static void helx_serial_putc(const char c)
{
 int done = 0;

 if ( c == 0xFF ) {
  return;
 }

 while ( done == 0 ) {                           
  if ( stat->bits.txEmpty ) {
   tbr->bits.data = c;            
   done = 1;
  }
 }
}


// When "stat" is defined as volatile
volatile union uart_stat *stat = (void *)rUART_STAT;

00000000 :
   0: e35000ff  cmp r0, #255 ; 0xff
   4: 012fff1e  bxeq lr
   8: e59f3024  ldr r3, [pc, #36] ; 34 
   c: e5931000  ldr r1, [r3]
  10: e59f3020  ldr r3, [pc, #32] ; 38 
  14: e5933000  ldr r3, [r3]
  18: e5d12000  ldrb r2, [r1]
  1c: e3120040  tst r2, #64 ; 0x40
  20: 0afffffc  beq 18 
  24: e5d32000  ldrb r2, [r3]
  28: e7c72010  bfi r2, r0, #0, #8
  2c: e5c32000  strb r2, [r3]
  30: e12fff1e  bx lr


// When "stat" is defined as none volatile, 
// dead loop assembly code is generated, see offset 0x28
union uart_stat *stat = (void *)rUART_STAT;

00000000 :
   0: e35000ff  cmp r0, #255 ; 0xff
   4: 012fff1e  bxeq lr
   8: e59f201c  ldr r2, [pc, #28] ; 2c 
   c: e59f301c  ldr r3, [pc, #28] ; 30 
  10: e5922000  ldr r2, [r2]
  14: e5933000  ldr r3, [r3]
  18: e5d22000  ldrb r2, [r2]
  1c: e3120040  tst r2, #64 ; 0x40
  20: 15c30000  strbne r0, [r3]
  24: 112fff1e  bxne lr
  28: eafffffe  b 28 

2014/11/28

ARM Code Sections

In source code
#pragma arm section [section_type_list]

Valid section types are:
code
rodata
rwdata
zidata

Example
#pragma arm section rwdata = "foo", rodata = "bar"


In scatter file 
RO
Constants (ex: const TEMP, etc.) and Code 

RW
Expressed initialized global variables 

ZI
Uninitialized global variables, and the variable is initialized to 0


GCC world
.text
program code

.rodata
read-only data;

.data
read-write initialized data;

.bss
read-write zero initialized data.


Reference
http://www.cprogramdevelop.com/912436/
http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0491g/BCFJBABB.html
https://sourceware.org/binutils/docs/ld/REGION_005fALIAS.html#REGION_005fALIAS

2014/11/27

VIM tips

:vim foo * | cw
Find the "foo" in files in current folder

:vim foo **/*.js | cw
Search for foo in every JavaScript file in the current directory recursively

gt
Switch between tabs

Ctrl+ww
Switch between windows

Ctrl+ws
Split window

Ctrl+r "
Paste yanked text to VIM command prompt

ma, mb
Make a marker "a" , "b"

`a, `b
Got to marker "a", "b"


Reference:
http://stackoverflow.com/questions/12526274/vim-search-text-in-folder

2014/11/04

NCQ Error Info

Host gets NCQ commands error information by issuing command ATA_CMD_READ_LOG_EXT(0x2F), page 10h.

Implementation in Linux: function ata_eh_read_log_10h().
called by ata_eh_analyze_ncq_error()/

Post Code on Blogger

Simplest way to post code to blogger for me: <pre style="background: #f0f0f0; border: 1px dashed #CCCCCC; color: black;overflow-x:...