Skip to content

Commit

Permalink
[driver] longanpi-4b support dram init
Browse files Browse the repository at this point in the history
  • Loading branch information
YuzukiTsuru committed Jan 3, 2024
1 parent c50139c commit 207dfe4
Show file tree
Hide file tree
Showing 7 changed files with 2,064 additions and 1 deletion.
3 changes: 3 additions & 0 deletions board/longanpi-4b/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)
5 changes: 5 additions & 0 deletions board/longanpi-4b/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
)
45 changes: 45 additions & 0 deletions board/longanpi-4b/init_dram/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/* SPDX-License-Identifier: Apache-2.0 */

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

#include <log.h>

#include <common.h>

#include <pmu/axp.h>
#include <sys-dram.h>
#include <sys-i2c.h>

extern sunxi_serial_t uart_dbg;

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

show_banner();

sunxi_clk_init();

sunxi_clk_dump();

mdelay(30); /* Delay 300ms for pmu bootup */

printk(LOG_LEVEL_INFO, "DRAM: DRAM Size = %dMB\n", sunxi_dram_init(NULL));

sunxi_clk_dump();

int i = 0;

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

abort();

return 0;
}
1,963 changes: 1,963 additions & 0 deletions board/longanpi-4b/payloads/init_dram_bin.c

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion cmake/board/longanpi-4b.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ set(CONFIG_BOARD_LONGANPI-4B True)
add_definitions(-DCONFIG_CHIP_SUN55IW3)

set(CONFIG_USE_DRAM_PAYLOAD True)
set(CONFIG_USE_PREBUILT_DRAM_PAYLOAD False)
set(CONFIG_USE_PREBUILT_DRAM_PAYLOAD True)
set(CONFIG_USE_DRAM_PAYLOAD_SOURCE_PATH "${CMAKE_SOURCE_DIR}/payloads/sun55iw3_libdram")
set(CONFIG_USE_DRAM_PAYLOAD_BIN_PATH "${CONFIG_USE_DRAM_PAYLOAD_SOURCE_PATH}/output/ddr.bin")
set(CONFIG_USE_DRAM_PAYLOAD_FILE_PATH "${CMAKE_SOURCE_DIR}/board/longanpi-4b/payloads/init_dram_bin.c")
Expand Down
1 change: 1 addition & 0 deletions src/drivers/sun55iw3/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@

add_library(chip_drivers-obj OBJECT
sys-clk.c
sys-dram.c
)
46 changes: 46 additions & 0 deletions src/drivers/sun55iw3/sys-dram.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/* SPDX-License-Identifier: Apache-2.0 */

#include <barrier.h>
#include <io.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <types.h>

#include <jmp.h>
#include <log.h>

#include <sys-dram.h>
#include <sys-rtc.h>

#define INIT_DRAM_BIN_BASE 0x38000

extern uint8_t __ddr_bin_start[];
extern uint8_t __ddr_bin_end[];

uint64_t sunxi_dram_init(void *para) {
uint8_t *src = __ddr_bin_start;
uint8_t *dst = (uint8_t *) INIT_DRAM_BIN_BASE;

printk(LOG_LEVEL_DEBUG, "DRAM: load dram init from 0x%08x -> 0x%08x size: %08x\n", src, dst, __ddr_bin_end - __ddr_bin_start);
memcpy(dst, src, __ddr_bin_end - __ddr_bin_start);

printk(LOG_LEVEL_DEBUG, "DRAM: Now jump to 0x%08x run DRAMINIT\n", dst);

__asm__ __volatile__("isb sy"
:
:
: "memory");
__asm__ __volatile__("dsb sy"
:
:
: "memory");
__asm__ __volatile__("dmb sy"
:
:
: "memory");
((void (*)(void)) ((void *) INIT_DRAM_BIN_BASE))();

return 0;
}

0 comments on commit 207dfe4

Please sign in to comment.