1 /* 2 * (C) Copyright 2020 Rockchip Electronics Co., Ltd. 3 * 4 * SPDX-License-Identifier: GPL-2.0+ 5 */ 6 7 #include <common.h> 8 #include <mapmem.h> 9 #include <malloc.h> 10 #include <dm/root.h> 11 12 DECLARE_GLOBAL_DATA_PTR; 13 initr_reloc(void)14static void initr_reloc(void) 15 { 16 /* tell others: relocation done */ 17 gd->flags |= GD_FLG_RELOC | GD_FLG_FULL_MALLOC_INIT; 18 } 19 20 #ifdef CONFIG_ARM initr_caches(void)21static void initr_caches(void) 22 { 23 icache_enable(); 24 dcache_enable(); 25 } 26 #endif 27 initr_malloc(void)28static void initr_malloc(void) 29 { 30 ulong malloc_start; 31 32 /* The malloc area is immediately below the monitor copy in DRAM */ 33 malloc_start = gd->relocaddr - TOTAL_MALLOC_LEN; 34 mem_malloc_init((ulong)map_sysmem(malloc_start, TOTAL_MALLOC_LEN), 35 TOTAL_MALLOC_LEN); 36 } 37 38 #ifdef CONFIG_DM initr_dm(void)39static int initr_dm(void) 40 { 41 /* Save the pre-reloc driver model and start a new one */ 42 gd->dm_root_f = gd->dm_root; 43 gd->dm_root = NULL; 44 45 return dm_init_and_scan(false); 46 } 47 #endif 48 49 /* 50 * The below functions are all __weak declared. 51 */ dram_init(void)52int dram_init(void) 53 { 54 #if CONFIG_SYS_MALLOC_LEN > SZ_64M 55 "CONFIG_SYS_MALLOC_LEN is over 64MB" 56 #endif 57 gd->ram_size = SZ_64M; /* default */ 58 59 gd->bd->bi_dram[0].start = CONFIG_SYS_SDRAM_BASE; 60 gd->bd->bi_dram[0].size = gd->ram_size; 61 62 return 0; 63 } 64 65 /* Refers to common/board_r.c */ board_init_r(gd_t * new_gd,ulong dest_addr)66void board_init_r(gd_t *new_gd, ulong dest_addr) 67 { 68 initr_reloc(); 69 #ifdef CONFIG_ARM 70 initr_caches(); 71 #endif 72 initr_malloc(); 73 #ifdef CONFIG_DM 74 initr_dm(); 75 #endif 76 /* Setup chipselects, entering usb-plug mode */ 77 board_init(); 78 79 hang(); 80 } 81 82