November 14, 2024

Porting Kyu to the Zynq - Round 1 -- first link and boot

Kyu is set up in terms of a board and an architecture. The architecture for Zynq will be "ARM", which is already finished thanks for work on the BBB and Orange Pi. So we just need to set up a Zynq board. I could set up Antminer and Ebaz and other specific boards, but that would generated endless duplication and clutter. I will just differentiate between the Antminer and Ebaz by using a handful of definitions in the board.h file.

In essence, the game will be to see how far I can get porting Kyu by simple supplying a serial console driver. I will probably want and need a timer driver also almost immediately, but we will cross that bridge when we get to it.

Getting started

I go to my Kyu working directory and run "git status". Various files need to be commited for reasons that I simply don't remember. I commit them and have a clean start for the Zynq port.

To get started, I will need to create a zynq directory and add a zynq target entry to the config script. I will also need to add these files in the "configs" directory:

I just copy the orange_pi files to get started. I also need a Makefile in the zynq directory that has a "clean" entry. I just copy the Makefile in the orange_pi diectory. Now I can type:
./config zynq
Which is sort of a milestone.

But what about the contents of these files? I compare the bbb and orange_pi versions of the two Makefiles to get a handle on what may be of interest there. The BBB is a cortex-a8 and the orange_pi is a cortex-a7, so that difference is in Makefile.inc. The top Makefile has a bunch of orange_pi cruft that I just delete.

The zynq.lds file needs a different base address for the text area, namely 0x20000000 -- that is the only change.

bypassing the network

The Kyu build system is set up to deal with this. The file kyu.h has a bunch of macros with names like "WANT_NET" for various features we may or may not want.

I have decided that in the case of WANT_NET, this ought to be in board/board.h rather than the central kyu.h since it varies from board to board. This is some kyu housekeeping that I will tackle right now.

Minimal files in the zynq directory

I will start with board.c and serial.c I create these as empty files.

At this point, the file board.h is just a copy of the orange_pi file. I make two changes:

Then I try running make to build kyu, just to see what functions are missing. Here is the list:

board_init
board_hardware_init
board_mmu_init
board_ram_init

core_stacks
board_core_startup
board_new_core

board_early_putchar

board_timer_init
board_timer_rate_set
board_get_cpu_mhz

intcon_ena
intcon_dis
intcon_irqwho

serial_init
serial_getc
serial_putc
serial_puts

board_net_init
board_net_debug
board_net_send
board_net_show
get_board_net_addr

reset_cpu
delay_us
(delay_ms)

gpio_test
test_led_on
test_led_off
That is more than I expected, but it certainly serves to guide the rest of this work. The network things will end up being stubs (for now) in board.c. The two test calls should be conditional in test_io.c and I make it so.

After adding board.c (copied from orange_pi and worked on), we reduce the above to:

console_use_ints
serial_init
serial_getc
serial_putc
serial_puts
So now we just need to add a serial (uart) driver -- with some attention to making it interrupt driven. We have already written a bare metal serial driver and can use that as a starting point. I copy it (it is extremely basic), and modify a few things and I get my first clean link. Not bad for a mornings work.

Boot it up and see what happens

I get this:
Filename 'bitcoin.bin'.
Load address: 0x20000000
Bytes transferred = 210848 (337a0 hex)
## Starting application at 0x20000000 ...
TJT in mmu_set_ttbr, page table: 20038000
 set TTBCR to 0, read back: 00000000
 set TTBR0 to 2003800b, read back: 2003800b
 set TTBR1 to 2003800b, read back: 2003800b
 set DACR to ffffffff, read back: ffffffff
TJT mmu_set_ttbr finished
And that is it. No more output and no response to characters typed.
Feedback? Questions? Drop me a line!

Tom's Computer Info / tom@mmto.org