06-05-2020, 07:27 AM
(This post was last modified: 06-05-2020, 07:48 AM by krjdev.
Edit Reason: Bug in attached file
)
Hi,
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):
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:
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.
Edit:
Oops! There is a bug in the attached archive.
Simple change the following line in the file start.S...
to..
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):
Code:
#include <asm.h>
IMPORT_C(kern_main)
.text
ENTRY(_start)
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
L0:
wfe
b L0
L1:
ldr x0, =_kern_stack_s
mov sp, x0
b kern_main
L2:
wfe
b L2
.end
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:
Code:
#include <dev/cru.h>
#include <dev/uart.h>
void kern_main(void)
{
int c;
uart_init();
uart_puts("Pine64 Rock64\r\n");
uart_puts("Press 'r' to reset the board!\r\n");
do {
c = uart_getc();
} while (c != 'r');
uart_puts("Resetting...\r\n");
cru_reset();
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.
Edit:
Oops! There is a bug in the attached archive.
Simple change the following line in the file start.S...
Code:
ldr x0, =_kern_stack_s
to..
Code:
ldr x0, =_kern_stack_e
Code:
/* Beware of bugs in the above code; I have only proved it correct, not tried it */