Microblaze [ PART2 ]

: Presentation
: eCos HAL
: Virtex5 Target board
: Footprint / Dhrystone Benchmark
: Creating external IPs

I. Microblaze eCos HAL

As per March 2012, the Microblaze eCos HAL is not complete, you can follow the progress from the bitbucket repository. The toolchain used for developing the HAL is located in the tools section. Note that a possible bug in binutil ( Bug #11085 ) makes it impossible to use the -relax option that is passed by default by GCC during linking.

a. HAL design:
_> Architecture HAL:
The architectural HAL contains the common layer for the microblaze core. It includes, setting up the processor, handling of the ROM vectors, copying and initializing of the data sections, common interrupt and exception handlers, kernel context switch, GDB stubs, GPROF _mcount routine etc.
_> Variant HAL:
The variant HAL called generic HAL contains a set of peripherals that makes useable the processor (interrupt contoller, RTC, UART debug channel etc.). The variant HAL could be named Xilinx HAL since it currently includes Xilinx peripherals only. However, It should be generic enough so that other custom made peripherals can be included ( to be used as interrupt contoller or real time clock timer for instance). Most peripherals are defined with there name, based address, interrupt number when required and optionaly peripheral ID.
_> Platform HAL:
The plaftorm HAL mostly takes care of the memory layout of the target as well as selecting the appropriate peripherals to be instanciated by the variant HAL. Finally, the plaftorm HAL can include any plaftorm related type of initialization or even setting up additional periperals.

b. State of the HAL:

HAL / Peripheral State
Exception handling Completed
Cache handling Completed
RTC [ XPS Timer ] Completed
IRQ [ XPS INTC ] Completed
UART [ XPS UART Lite ] Completed
UART [ XPS UART 16550 ] Completed
Ethernet MAC [ TEMAC ] In progress
Ethernet MAC [ EthernetLite ] No support planned
GDB stub Missing
SMP Missing

Board support Comment
Xilinx Spartan3A-DSP Tested under QEMU without Ethernet support (EthernetLite not supported in eCos). Redboot tested.
Xilinx Spartan3AN Tested on Target with Redboot as boot loader. Ethernet OK
Custom V6 kit Tested with Ethernet support

Current HAL (diff from the ecos public repository):

    ./hal/microblaze/arch/current/ChangeLog
    ./hal/microblaze/arch/current/cdl/hal_mb.cdl
    ./hal/microblaze/arch/current/include/arch.inc
    ./hal/microblaze/arch/current/include/basetype.h
    ./hal/microblaze/arch/current/include/hal_arch.h
    ./hal/microblaze/arch/current/include/hal_intr.h
    ./hal/microblaze/arch/current/include/hal_io.h
    ./hal/microblaze/arch/current/include/mb_stub.h
    ./hal/microblaze/arch/current/include/hal_cache.h
    ./hal/microblaze/arch/current/src/hal_misc.c
    ./hal/microblaze/arch/current/src/hal_mk_defs.c
    ./hal/microblaze/arch/current/src/mb.ld
    ./hal/microblaze/arch/current/src/mb_stub.c
    ./hal/microblaze/arch/current/src/context.S
    ./hal/microblaze/arch/current/src/vectors.S

    ./hal/microblaze/generic/current/ChangeLog
    ./hal/microblaze/generic/current/cdl/hal_mb_generic.cdl
    ./hal/microblaze/generic/current/include/hal_cache.h
    ./hal/microblaze/generic/current/include/hal_diag.h
    ./hal/microblaze/generic/current/include/hal_diag_uart16550.inl
    ./hal/microblaze/generic/current/include/hal_diag_uartlite.inl
    ./hal/microblaze/generic/current/include/plf_stub.h
    ./hal/microblaze/generic/current/include/variant.inc
    ./hal/microblaze/generic/current/include/var_arch.h
    ./hal/microblaze/generic/current/include/var_cache.h
    ./hal/microblaze/generic/current/include/var_io.h
    ./hal/microblaze/generic/current/include/var_mpmc.h
    ./hal/microblaze/generic/current/include/var_ll_fifo.h
    ./hal/microblaze/generic/current/include/var_intr.h
    ./hal/microblaze/generic/current/src/hal_diag.c
    ./hal/microblaze/generic/current/src/mb_generic_misc.c

    ./hal/microblaze/spartan3adsp/current/ChangeLog
    ./hal/microblaze/spartan3adsp/current/cdl/hal_mb_spartan3adsp.cdl
    ./hal/microblaze/spartan3adsp/current/include/pkgconf/mlt_mb_spartan3adsp_bram.h
    ./hal/microblaze/spartan3adsp/current/include/pkgconf/mlt_mb_spartan3adsp_bram.ldi
    ./hal/microblaze/spartan3adsp/current/include/pkgconf/mlt_mb_spartan3adsp_ram.h
    ./hal/microblaze/spartan3adsp/current/include/pkgconf/mlt_mb_spartan3adsp_ram.ldi
    ./hal/microblaze/spartan3adsp/current/include/pkgconf/mlt_mb_spartan3adsp_rom.h
    ./hal/microblaze/spartan3adsp/current/include/pkgconf/mlt_mb_spartan3adsp_rom.ldi
    ./hal/microblaze/spartan3adsp/current/include/pkgconf/mlt_mb_spartan3adsp_qemu.h
    ./hal/microblaze/spartan3adsp/current/include/pkgconf/mlt_mb_spartan3adsp_qemu.ldi
    ./hal/microblaze/spartan3adsp/current/include/pkgconf/mlt_mb_spartan3adsp_romram.h
    ./hal/microblaze/spartan3adsp/current/include/pkgconf/mlt_mb_spartan3adsp_romram.ldi
    ./hal/microblaze/spartan3adsp/current/include/plf_arch.h
    ./hal/microblaze/spartan3adsp/current/include/plf_intr.h
    ./hal/microblaze/spartan3adsp/current/include/plf_io.h
    ./hal/microblaze/spartan3adsp/current/include/plf_cache.h
    ./hal/microblaze/spartan3adsp/current/include/platform.inc
    ./hal/microblaze/spartan3adsp/current/src/mb_spartan3adsp_misc.c
    ./hal/microblaze/spartan3adsp/current/misc/default_QEMU.ecm

    ./hal/microblaze/spartan3an/current/ChangeLog
    ./hal/microblaze/spartan3an/current/cdl/hal_mb_spartan3an.cdl
    ./hal/microblaze/spartan3an/current/include/pkgconf/mlt_mb_spartan3an_ram.h
    ./hal/microblaze/spartan3an/current/include/pkgconf/mlt_mb_spartan3an_ram.ldi
    ./hal/microblaze/spartan3an/current/include/pkgconf/mlt_mb_spartan3an_rom.h
    ./hal/microblaze/spartan3an/current/include/pkgconf/mlt_mb_spartan3an_rom.ldi
    ./hal/microblaze/spartan3an/current/include/pkgconf/mlt_mb_spartan3an_romram.h
    ./hal/microblaze/spartan3an/current/include/pkgconf/mlt_mb_spartan3an_romram.ldi
    ./hal/microblaze/spartan3an/current/include/pkgconf/mlt_mb_spartan3an_ram_nobram.h
    ./hal/microblaze/spartan3an/current/include/pkgconf/mlt_mb_spartan3an_ram_nobram.ldi
    ./hal/microblaze/spartan3an/current/include/pkgconf/mlt_mb_spartan3an_rom_nobram.h
    ./hal/microblaze/spartan3an/current/include/pkgconf/mlt_mb_spartan3an_rom_nobram.ldi
    ./hal/microblaze/spartan3an/current/include/pkgconf/mlt_mb_spartan3an_romram_nobram.h
    ./hal/microblaze/spartan3an/current/include/pkgconf/mlt_mb_spartan3an_romram_nobram.ldi
    ./hal/microblaze/spartan3an/current/include/plf_arch.h
    ./hal/microblaze/spartan3an/current/include/plf_intr.h
    ./hal/microblaze/spartan3an/current/include/plf_io.h
    ./hal/microblaze/spartan3an/current/include/plf_cache.h
    ./hal/microblaze/spartan3an/current/include/platform.inc
    ./hal/microblaze/spartan3an/current/src/mb_spartan3an_misc.c
    ./hal/microblaze/spartan3an/current/misc/default_RAM.ecm

    ./hal/microblaze/v6_kit/current/ChangeLog
    ./hal/microblaze/v6_kit/current/cdl/hal_mb_v6_kit.cdl
    ./hal/microblaze/v6_kit/current/include/pkgconf/mlt_mb_v6_kit_bram.h
    ./hal/microblaze/v6_kit/current/include/pkgconf/mlt_mb_mb_v6_kit_bram.ldi
    ./hal/microblaze/v6_kit/current/include/plf_arch.h
    ./hal/microblaze/v6_kit/current/include/plf_intr.h
    ./hal/microblaze/v6_kit/current/include/plf_io.h
    ./hal/microblaze/v6_kit/current/include/plf_cache.h
    ./hal/microblaze/v6_kit/current/include/platform.inc
    ./hal/microblaze/v6_kit/current/src/mb_mb_v6_kit_misc.c
    ./hal/microblaze/v6_kit/current/misc/default_BRAM.ecm

    ./devs/serial/microblaze/16550/current/ChangeLog
    ./devs/serial/microblaze/16550/current/cdl/mb_uart16550.cdl
    ./devs/serial/microblaze/16550/current/include/mb_uart16550.inl

    ./devs/serial/microblaze/uart_lite/current/ChangeLog
    ./devs/serial/microblaze/uart_lite/current/cdl/mb_uart_lite.cdl
    ./devs/serial/microblaze/uart_lite/current/src/mb_uart_lite.c

    ./devs/flash/microblaze/spartan3an/current/ChangeLog
    ./devs/flash/microblaze/spartan3an/current/cdl/flash_spartan3an.cdl
    ./devs/flash/microblaze/spartan3an/current/src/flash_spartan3an.c

    ./devs/eth/xilinx/temac/current/ChangeLog
    ./devs/eth/xilinx/temac/current/cdl/temac.cdl
    ./devs/eth/xilinx/temac/current/include/if_temac_dma.inl
    ./devs/eth/xilinx/temac/current/include/if_temac_ll_fifo.inl
    ./devs/eth/xilinx/temac/current/include/if_temac.h
    ./devs/eth/xilinx/temac/current/include/if_temac.inl
    ./devs/eth/xilinx/temac/current/src/if_temac.c

II. Running microblaze eCos port with QEMU (board emulation)

QEMU has board support for the Xilinx Spartan 3ADSP1800 kit and can be used as starting point to debug the eCos architectural HAL. The binary blob for this board is located in: qemu-0.14.0-rc2/pc-bios/petalogix-s3adsp1800.dtb

The board emulates the following peripherals:
- 128KB of BRAM memory mapped at @ 0x00000000
- 128MB of RAM memory mapped at @ 0x90000000
- 16MB flash mapped at @ 0xA0000000
- XPS irq controller mapped at @ 0x81800000 ( IVR is available )
- XPS UARTLite serial mapped at @ 0x84000000 with IRQ mapped to # 3
- XPS timers mapped at @ 0x83C00000 with IRQ mapped to # 0
- XPS EthernetLite mapped at @ 0x81000000 with IRQ mapped to # 1
Thanks to a great post from Ant Micro, it is possible to customize QEMU for any boards, changing memory layout, IRQ mapping etc.

a. Compile eCos microblaze port with QEMU support:
$ ecosconfig new spartan3adsp default
$ configtool ecos.ecc -> select QEMU startup type
$ ecosconfig tree
$ make
$ _> Link with your application or make -s tests IGNORE_LINK_ERRORS=y

b. QEMU:
Fetch the latest source code from GIT repository and compile QEMU for the targeted architecture (Microblaze in this case). QEMU newer than 0.14.0 (excluded) is required to be able to single step while debugging ( Bug #550863 ):
$ git clone git://git.qemu.org/qemu.git
$ cd qemu
$ ./configure --target-list=microblaze-linux-user,microblaze-softmmu
$ make
The relevant result is the program qemu/microblaze-softmmu/qemu-system-microblaze and will be used to emulate the Xilinx board.

Start the emulator for the spartan3adsp target, the qemu console shall appear:
$ ./qemu-system-microblaze -M petalogix-s3adsp1800 -kernel $HOME/workspace/ecos/xilinx/bin/out/main.elf -net none -nographic -serial file:/tmp/systemd-console -S -s
Warning: missing libfdt, cannot pass cmdline to kernel!
Warning: nic xilinx,ethlite.0 has no peer
QEMU 0.13.92 monitor - type 'help' for more information
(qemu)

c. Running eCos kernel test application with QEMU
./qemu-system-microblaze -M petalogix-s3adsp1800 -kernel $HOME/workspace/ecos/xilinx_k/install/tests/kernel/current/tests/timeslice -net none -nographic -S -s
Warning: missing libfdt, cannot pass cmdline to kernel!
Warning: nic xilinx,ethlite.0 has no peer

-> use GDB to move program counter (PC) to address 0x0 and run:

INFO:
 Thread        CPU  0        Total
      0      98412597     98412597
      1      96924663     96924663
 Total      195337260
Threads             2
INFO:
INFO:
 Thread        CPU  0        Total
      0      60459182     60459182
      1      60086415     60086415
      2      62033181     62033181
 Total      182578778
Threads             3
INFO:
INFO:
 Thread        CPU  0        Total
      0      45355377     45355377
      1      43591014     43591014
      2      43328668     43328668
      3      45830119     45830119
 Total      178105178

Threads             4
INFO:
INFO:
 Thread        CPU  0        Total
      0      37039580     37039580
      1      34676834     34676834
      2      33771327     33771327
      3      35201184     35201184
      4      36856536     36856536
 Total      177545461
Threads             5
INFO:
INFO:
 Thread        CPU  0        Total
      0      34247672     34247672
      1      35060140     35060140
      2      35692132     35692132
      3      34577299     34577299
      4      31891194     31891194
      5      30501238     30501238
 Total      201969675
Threads             6
INFO:
PASS:
EXIT:

d. Running RedBoot with QEMU

+
RedBoot(tm) bootstrap and debug environment [ROM]
Non-certified release, version UNKNOWN - built 23:12:09, Nov 20 2011

Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
Free Software Foundation, Inc.
RedBoot is free software, covered by the eCos license, derived from the
GNU General Public License. You are welcome to change it and/or distribute
copies of it under certain conditions. Under the license terms, RedBoot's
source code and full license terms must have been made available to you.
Redboot comes with ABSOLUTELY NO WARRANTY.

Platform: Xilinx Spartan3-DSP (Microblaze SoftCore) 
RAM: 0x90000000-0x97fff000 [0x90001de0-0x97fff000 available]
RedBoot> 
RedBoot> 
	

III. Running eCos HTTPD package on spartan3an KIT

$ ecosconfig new spartan3an net
$ configtool ecos.ecc -> select JTAG startup type and configure eCos HAL to match the HW (interrupts mapping etc..)
$ ecosconfig tree
$ make
$ make tests

Load install/tests/net/httpd/current/tests/httpd from GDB and run the application:

[cyg_net_init] Init: mbinit(0x00000000)
[cyg_net_init] Init: cyg_net_init_devs(0x00000000)
Init device 'temac_eth0'
[cyg_net_init] Init: loopattach(0x00000000)
[cyg_net_init] Init: ifinit(0x00000000)
[cyg_net_init] Init: domaininit(0x00000000)
[cyg_net_init] Init: cyg_net_add_domain(0x4405d240)
New domain internet at 0x00000000
[cyg_net_init] Init: cyg_net_add_domain(0x4405cc80)
New domain route at 0x00000000
[cyg_net_init] Init: call_route_init(0x00000000)
[cyg_net_init] Done
BOOTP[eth0] op: REPLY
       htype: Ethernet
        hlen: 6
        hops: 0
         xid: 0x0
        secs: 0
       flags: 0x0
       hw_addr: 00:20:0e:10:39:89
     client IP: 192.168.0.6
         my IP: 192.168.0.6
     server IP: 192.168.0.101
    gateway IP: 192.168.0.4
  options:
        subnet mask: 255.255.255.0
       IP broadcast: 192.168.1.255g
            gateway: 192.168.0.4
Route - dst: 0.0.0.0, mask: 0.0.0.0, gateway: 192.168.0.4
	

Loading of the httpd application was also successfully tested using redboot for the spartan3an KIT. From the HTTP application, you can monitor the threads, the network interface or even write to memory: