Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[driver] add support dram lib for sun50iw9 platform init dram #4

Merged
merged 9 commits into from
Dec 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@ build/
test/
tools/*.bin
mksunxi
init_dram_bin
bin2array
.vscode/settings.json
prebuilt/
23 changes: 22 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
# Specify the minimum required version of CMake
cmake_minimum_required(VERSION 3.10)

include(ExternalProject)

# Define the path to the board loader files
set(BOARD_FLOADER_PATH ${CMAKE_SOURCE_DIR}/cmake/board/)

Expand Down Expand Up @@ -64,7 +66,6 @@ project(SyterKit C CXX ASM)

# Include other CMake modules
include(cmake/add_syterkit_app.cmake)
include(ExternalProject)

# Get the name of the compiler
string(SUBSTRING ${CMAKE_C_COMPILER} 1 -1 COMPILER_NAME)
Expand Down Expand Up @@ -103,6 +104,25 @@ set(LINK_SCRIPT_BIN ${PROJECT_BINARY_DIR}/link_bin.ld)
if (CONFIG_ARCH_ARM32)
set(ARCH_INCLUDE include/arch/arm32)

if (CONFIG_USE_DRAM_PAYLOAD)
set(ARCH_START_ADDRESS "${ARCH_BIN_START_ADDRESS}")
set(ARCH_SRAM_LENGTH "${ARCH_BIN_SRAM_LENGTH}")

configure_file(
"${PROJECT_SOURCE_DIR}/link/arm32/link_dram_payloads.ld"
"${PROJECT_BINARY_DIR}/link_bin.ld"
)

set(ARCH_START_ADDRESS "${ARCH_FEL_START_ADDRESS}")
set(ARCH_SRAM_LENGTH "${ARCH_FEL_SRAM_LENGTH}")

configure_file(
"${PROJECT_SOURCE_DIR}/link/arm32/link_dram_payloads.ld"
"${PROJECT_BINARY_DIR}/link_elf.ld"
)

else()

set(ARCH_START_ADDRESS "${ARCH_BIN_START_ADDRESS}")
set(ARCH_SRAM_LENGTH "${ARCH_BIN_SRAM_LENGTH}")

Expand All @@ -119,6 +139,7 @@ configure_file(
"${PROJECT_BINARY_DIR}/link_elf.ld"
)
endif()
endif()

# If the CONFIG_ARCH_ARM32 variable is defined, execute the following content
if (CONFIG_ARCH_RISCV64)
Expand Down
3 changes: 3 additions & 0 deletions board/longanpi-3h/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ set(APP_COMMON_SOURCE
${CMAKE_CURRENT_SOURCE_DIR}/start.S
${CMAKE_CURRENT_SOURCE_DIR}/board.c
${CMAKE_CURRENT_SOURCE_DIR}/eabi_compat.c
${CMAKE_CURRENT_SOURCE_DIR}/payloads/init_dram_bin.c
)

add_subdirectory(hello_world)

add_subdirectory(init_dram)
46 changes: 17 additions & 29 deletions board/longanpi-3h/board.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@

#include <common.h>

#include <sys-clk.h>
#include <reg-ncat.h>
#include <sys-clk.h>

#include <mmu.h>

#include <sys-dram.h>
#include <sys-gpio.h>
#include <sys-sdcard.h>
#include <sys-spi.h>
#include <sys-uart.h>
#include <sys-dram.h>
#include <sys-sdcard.h>

sunxi_serial_t uart_dbg = {
.base = SUNXI_UART0_BASE,
Expand Down Expand Up @@ -53,32 +53,20 @@ sdhci_t sdhci0 = {
.gpio_d3 = {GPIO_PIN(GPIO_PORTF, 4), GPIO_PERIPH_MUX2},
};

dram_para_t dram_para = {
.dram_clk = 792,
.dram_type = 3,
.dram_zq = 0x7b7bfb,
.dram_odt_en = 0x00,
.dram_para1 = 0x000010d2,
.dram_para2 = 0,
.dram_mr0 = 0x1c70,
.dram_mr1 = 0x42,
.dram_mr2 = 0x18,
.dram_mr3 = 0,
.dram_tpr0 = 0x004a2195,
.dram_tpr1 = 0x02423190,
.dram_tpr2 = 0x0008b061,
.dram_tpr3 = 0xb4787896,// unused
.dram_tpr4 = 0,
.dram_tpr5 = 0x48484848,
.dram_tpr6 = 0x00000048,
.dram_tpr7 = 0x1620121e,// unused
.dram_tpr8 = 0,
.dram_tpr9 = 0,// clock?
.dram_tpr10 = 0,
.dram_tpr11 = 0x00340000,
.dram_tpr12 = 0x00000046,
.dram_tpr13 = 0x34000100,
};
void neon_enable(void) {
/* set NSACR, both Secure and Non-secure access are allowed to NEON */
asm volatile("MRC p15, 0, r0, c1, c1, 2");
asm volatile("ORR r0, r0, #(0x3<<10) @ enable fpu/neon");
asm volatile("MCR p15, 0, r0, c1, c1, 2");
/* Set the CPACR for access to CP10 and CP11*/
asm volatile("LDR r0, =0xF00000");
asm volatile("MCR p15, 0, r0, c1, c0, 2");
/* Set the FPEXC EN bit to enable the FPU */
asm volatile("MOV r3, #0x40000000");
/*@VMSR FPEXC, r3*/
asm volatile("MCR p10, 7, r3, c8, c0, 0");
}


void clean_syterkit_data(void) {
/* Disable MMU, data cache, instruction cache, interrupts */
Expand Down
2 changes: 2 additions & 0 deletions board/longanpi-3h/hello_world/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ int main(void) {

sunxi_clk_dump();

printk(LOG_LEVEL_INFO, "Hello World!\n");

abort();

return 0;
Expand Down
5 changes: 5 additions & 0 deletions board/longanpi-3h/init_dram/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# SPDX-License-Identifier: Apache-2.0

add_syterkit_app(init_dram
main.c
)
40 changes: 40 additions & 0 deletions board/longanpi-3h/init_dram/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/* SPDX-License-Identifier: Apache-2.0 */

#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <types.h>

#include <log.h>

#include <common.h>

#include <sys-dram.h>

extern sunxi_serial_t uart_dbg;

int main(void) {
sunxi_serial_init(&uart_dbg);

show_banner();

sunxi_clk_init();

sunxi_clk_dump();

neon_enable();

sunxi_dram_init(NULL);

int i = 0;

while (1) {
i++;
printk(LOG_LEVEL_INFO, "Count: %d\n", i);
mdelay(1000);
}

abort();

return 0;
}
Loading