blob: 6b880f19f84e57e7bc0c93b16b188bc56267827e [file] [log] [blame]
Kever Yang34ead0f2019-07-09 22:05:55 +08001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * (C) Copyright 2019 Rockchip Electronics Co., Ltd
4 */
5
Simon Glass91eaa7c2023-01-07 14:57:30 -07006#include <bootstage.h>
Kever Yang34ead0f2019-07-09 22:05:55 +08007#include <debug_uart.h>
8#include <dm.h>
Simon Glassf11478f2019-12-28 10:45:07 -07009#include <hang.h>
Simon Glass97589732020-05-10 11:40:02 -060010#include <init.h>
Simon Glass0f2af882020-05-10 11:40:05 -060011#include <log.h>
Kever Yang34ead0f2019-07-09 22:05:55 +080012#include <ram.h>
13#include <spl.h>
14#include <version.h>
15#include <asm/io.h>
16#include <asm/arch-rockchip/bootrom.h>
Simon Glassbac075b2024-08-22 07:54:50 -060017#include <asm/arch-rockchip/timer.h>
Simon Glass4dcacfc2020-05-10 11:40:13 -060018#include <linux/bitops.h>
Kever Yang34ead0f2019-07-09 22:05:55 +080019
Pali Rohár6e1f0852021-08-02 15:18:38 +020020#if CONFIG_IS_ENABLED(BANNER_PRINT)
21#include <timestamp.h>
22#endif
23
Quentin Schulz66eb36c2024-11-06 12:29:43 +010024__weak void tpl_board_init(void)
25{
26}
27
Kever Yang34ead0f2019-07-09 22:05:55 +080028void board_init_f(ulong dummy)
29{
30 struct udevice *dev;
31 int ret;
32
Simon Glassf4d60392021-08-08 12:20:12 -060033#if defined(CONFIG_DEBUG_UART) && defined(CONFIG_TPL_SERIAL)
Kever Yang34ead0f2019-07-09 22:05:55 +080034 /*
35 * Debug UART can be used from here if required:
36 *
37 * debug_uart_init();
38 * printch('a');
39 * printhex8(0x1234);
40 * printascii("string");
41 */
42 debug_uart_init();
Chris Webb45dd8012019-07-19 14:23:55 +010043#ifdef CONFIG_TPL_BANNER_PRINT
Kever Yang34ead0f2019-07-09 22:05:55 +080044 printascii("\nU-Boot TPL " PLAIN_VERSION " (" U_BOOT_DATE " - " \
45 U_BOOT_TIME ")\n");
46#endif
Chris Webb45dd8012019-07-19 14:23:55 +010047#endif
Simon Glass91eaa7c2023-01-07 14:57:30 -070048 /* Init secure timer */
49 rockchip_stimer_init();
50
Kever Yang34ead0f2019-07-09 22:05:55 +080051 ret = spl_early_init();
52 if (ret) {
53 debug("spl_early_init() failed: %d\n", ret);
54 hang();
55 }
56
Johan Jonkerfebb9692022-04-09 18:55:05 +020057 /* Init ARM arch timer */
58 if (IS_ENABLED(CONFIG_SYS_ARCH_TIMER))
59 timer_init();
Kever Yang34ead0f2019-07-09 22:05:55 +080060
Quentin Schulz66eb36c2024-11-06 12:29:43 +010061 tpl_board_init();
62
Kever Yang34ead0f2019-07-09 22:05:55 +080063 ret = uclass_get_device(UCLASS_RAM, 0, &dev);
64 if (ret) {
65 printf("DRAM init failed: %d\n", ret);
66 return;
67 }
68}
69
Peng Fanaa050c52019-08-07 06:40:53 +000070int board_return_to_bootrom(struct spl_image_info *spl_image,
71 struct spl_boot_device *bootdev)
Kever Yang34ead0f2019-07-09 22:05:55 +080072{
Simon Glass91eaa7c2023-01-07 14:57:30 -070073 int ret;
74
75 bootstage_mark_name(BOOTSTAGE_ID_END_TPL, "end tpl");
Tom Rinid78c9bd2024-07-15 12:42:00 +010076 ret = bootstage_stash_default();
Simon Glass91eaa7c2023-01-07 14:57:30 -070077 if (ret)
78 debug("Failed to stash bootstage: err=%d\n", ret);
Tom Rinid78c9bd2024-07-15 12:42:00 +010079
Kever Yang34ead0f2019-07-09 22:05:55 +080080 back_to_bootrom(BROM_BOOT_NEXTSTAGE);
Peng Fanaa050c52019-08-07 06:40:53 +000081
82 return 0;
Kever Yang34ead0f2019-07-09 22:05:55 +080083}
84
85u32 spl_boot_device(void)
86{
87 return BOOT_DEVICE_BOOTROM;
88}