2015/05/12

Play U-Boot on Qemu, 2015 version

Package Installation
  sudo apt-get install qemu-system  gcc-arm-none-eabi
  sudo apt-get -o Dpkg::Options::="--force-overwrite" install gdb-arm-none-eabi


U-Boot Build
Get u-boot source from ftp://ftp.denx.de/pub/u-boot/ , I got version u-boot-2015.01.tar.bz2
Extract the source and on console:
  cd u-boot-2015.01
  make versatileqemu_config ARCH=arm CROSS_COMPILE=arm-none-eabi-
  make all ARCH=arm CROSS_COMPILE=arm-none-eabi-
To print out the actual compile and linker command:
  make all ARCH=arm CROSS_COMPILE=arm-none-eabi- KBUILD_VERBOSE=1


Run the U-Boot in Qemu
  qemu-system-arm -M versatilepb -m 128M -nographic -kernel u-boot.bin
You should see U-Boot prompt "VersatilePB # " on the console
To exit QEMU, press “Ctrl a” and then “x”.


Problem Shooting
Run with logging every instruction exectuted
  qemu-system-arm -M versatilepb -m 128M -nographic -kernel u-boot.bin -d in_asm,cpu -D qemu.log -singlestep

Disassemble U-Boot
  arm-none-eabi-objdump -d u-boot

Check memory map info
  gvim u-boot.map
  nm u-boot

To Clean
  make clean
  make mrproper

To enable debug message
in include/configs/versatial.h
add
#define DEBUG 1


Debug with GDB 
Install the gdb for arm
 sudo apt-get -o Dpkg::Options::="--force-overwrite" install gdb-arm-none-eabi


qemu-system-arm  -m some_machine -m 256M -nographic -kernel some_image.bin -s

on the other terminal

ddd --debugger arm-none-eabi-gdb
(gdb) symbol-file ~/git/lhx/vmlinux
(gdb)
(gdb) target remote :1234
(gdb) break setup_arch
(gdb) c

Reference
https://balau82.wordpress.com/2010/02/28/hello-world-for-bare-metal-arm-using-qemu/
http://infocenter.arm.com/help/topic/com.arm.doc.dui0224i/DUI0224I_realview_platform_baseboard_for_arm926ej_s_ug.pdf
http://infocenter.arm.com/help/topic/com.arm.doc.ddi0183g/DDI0183G_uart_pl011_r1p5_trm.pdf http://git.savannah.gnu.org/cgit/qemu.git/tree/hw/versatilepb.c
https://balau82.wordpress.com/2010/11/30/emulating-arm-pl011-serial-ports/
http://elinux.org/Virtual_Development_Board

2015/04/27

Qemu Interrupt Simulation

This is an example.




// creates VIC 
sysbus_create_varargs("pl190", 0x10140000, ARM_CPU_IRQ, ARM_CPU_FIQ)
  qdev_create
    pl190_init
      // input GPIO, 32 inputs, set input handler
      qdev_init_gpio_in(..,pl190_set_irq,32)
      // output GPIO, 2 outputs
      sysbus_init_irq(... &s->irq)
      sysbus_init_irq(... &s->frq)
    // connect pl190 GPIO out to CPU GPIO in
    sysbus_connect_irq(n, IRQ or FIO)

      
pl190_set_irq will be called if any input GPIO were raised. 
// PL190's interrupt handler
pl190_set_irq, 
  pl190_update
    // raise the GPIO output, which connects to CPU's GPIO input
    qemu_set_irq(s->irq, ...)
    qemu_set_irq(s->frq, ...)

// CPU's interrupt handler
arm_cpu_set_irq
  cpu_interrupt
    tcg_handle_interrupt

2015/04/06

Kernel Early Print


Before the first early prink, __create_page_tables in arch/arm/kernel/head.S will create mapping entry of IO space for UART.


 /*
  * Map in IO space for serial debugging.
  * This allows debug messages to be output
  * via a serial console before paging_init.
  */
 addruart r7, r3, r0

 mov r3, r3, lsr #SECTION_SHIFT
 mov r3, r3, lsl #PMD_ORDER

 add r0, r4, r3
 mov r3, r7, lsr #SECTION_SHIFT
 ldr r7, [r10, #PROCINFO_IO_MMUFLAGS] @ io_mmuflags
 orr r3, r7, r3, lsl #SECTION_SHIFT

2015/03/24

LOG: Struggling with HeliosX on DS-5

add-symbol-file "U:\svn\ub\u-boot\u-boot"  0x7fce000

break boot_jump_linux
break putstr
// hungs on printing the ending of the "I am Linux and I am on the HeliosX".
// seems the ending 0 has some problems.

add-symbol-file "U:\git\linux_hx\arch\arm\boot\compressed\vmlinux"  0x9000000

Import Memory Parameters
0x09000000
Check "Import file as binary image"
U:\Desktop\Link to linux_hx\zImage.bin

Interrupt (pause) the target
restore "U:\git\linux_hx\arch\arm\boot\zImage" binary S:0x09000000
add-symbol-file "U:\git\linux_hx\arch\arm\boot\compressed\vmlinux"  0x9000000
hbreak putstr
hbreak decompress_kernel
hbreak start

Section GOT and PLT

PLT:procedure linkage table
GOT: global offset table


https://www.technovelty.org/linux/plt-and-got-the-key-to-code-sharing-and-dynamic-libraries.html

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:...