Rock64 - Simple Bare-Metal Example

I wrote a simple Bare-Metal example for the Rock64.
It just sends a few strings over the UART interface and if a special char will be received, the program resets the Rock64.

The main entry point of the program (written in Assembler):

#include <asm.h>



   mrs x0, SCTLR_EL1
   and x0, x0, #0xFFFFFFFFFFFFFFFC
   msr SCTLR_EL1, x0
   mrs x0, SCTLR_EL2
   and x0, x0, #0xFFFFFFFFFFFFFFFC
   msr SCTLR_EL2, x0
   mrs x0, MPIDR_EL1
   and x0, x0, #0x3
   cmp x0, #0
   beq L1
   b L0
   ldr x0, =_kern_stack_s
   mov sp, x0
   b kern_main
   b L2


It's a minimal setup. It just disables the MMU and the Alignment checks.
Then it reads the processor ID and let only CPU0 run the C main entry point (kern_main).

The C main entry point:

#include <dev/cru.h>
#include <dev/uart.h>

void kern_main(void)
   int c;
   uart_puts("Pine64 Rock64\r\n");
   uart_puts("Press 'r' to reset the board!\r\n");
   do {
       c = uart_getc();
   } while (c != 'r');
   while (1)

Should be self explaining.

There is also as very simple UART driver and the CRU driver for resetting the board.
The code includes a very minimal C String library.Only GCC for AArch64 is needed.

To start the application, U-Boot is needed.

I have attached the full code.
The code is also on my GitHub page available.

Oops! There is a bug in the attached archive.

Simple change the following line in the file start.S...
ldr x0, =_kern_stack_s

ldr x0, =_kern_stack_e

Attached Files
.gz   bare-metal.tar.gz (Size: 4.47 KB / Downloads: 284)
/* Beware of bugs in the above code; I have only proved it correct, not tried it */
 Original quote by Donald E. Knuth

I'm currently working on a new release for the bare-metal example.

Current reached milestones:
- Successfully implemented MMU support (Had some troubles with the translation tables in the past.)
- Implemented cleaning and invalidating for the Instruction and data cache
- Switching from EL2 (Hypervisor) to EL1 (Kernel)

Currently working on the implementation of syscalls.

Feature of the new release:
- Simple kernel (EL1) for exception/interrupt handling, device and memory management
- Small libc for userland (EL0)

New release available soon. Smile

The actual status is available at the next branch.
/* Beware of bugs in the above code; I have only proved it correct, not tried it */
 Original quote by Donald E. Knuth

Possibly Related Threads…
Thread Author Replies Views Last Post
Information Manual: Howto cross-compile Upstream U-Boot for rock64 rock7 3 4,951 04-15-2020, 05:09 PM
Last Post: rock7
Thumbs Up A guide for how I made RetroPie, RetroArch, and EmulationStation Work on the Rock64 Mrfixit2001 4 12,836 12-17-2018, 03:52 AM
Last Post: va88
  Using the Movidius NCS with rock64 markjay 0 3,483 07-02-2018, 09:51 AM
Last Post: markjay

Forum Jump:

Users browsing this thread: 1 Guest(s)