From 4a2b8db466479ddec6ee85f9fe9d7f934016be9a Mon Sep 17 00:00:00 2001 From: Joseph Chen Date: Tue, 19 May 2020 11:16:07 +0800 Subject: [PATCH] common: add usbplug support - disable some message - add "usbplug.bin" generation - add minimum usbplug dtb support - add individual board_init_r() init sequence. Signed-off-by: Joseph Chen Change-Id: If48ee49247fca6108db3a1fbab3b403241b3a8eb --- Makefile | 15 ++++++++ common/Kconfig | 1 + common/Makefile | 4 ++ common/board_f.c | 8 +++- common/usbplug/Kconfig | 10 +++++ common/usbplug/Makefile | 2 + common/usbplug/usbplug.c | 81 ++++++++++++++++++++++++++++++++++++++++ dts/Makefile | 2 +- 8 files changed, 121 insertions(+), 2 deletions(-) create mode 100644 common/usbplug/Kconfig create mode 100644 common/usbplug/Makefile create mode 100644 common/usbplug/usbplug.c diff --git a/Makefile b/Makefile index 2f134ccbf3..de68fa12be 100644 --- a/Makefile +++ b/Makefile @@ -771,6 +771,7 @@ endif # Always append ALL so that arch config.mk's can add custom ones ALL-y += u-boot.srec u-boot.bin u-boot.sym System.map binary_size_check +ALL-$(CONFIG_SUPPORT_USBPLUG) += usbplug.bin ALL-$(CONFIG_ONENAND_U_BOOT) += u-boot-onenand.bin ifeq ($(CONFIG_SPL_FSL_PBL),y) @@ -922,6 +923,11 @@ u-boot.bin: u-boot-nodtb.bin FORCE $(call if_changed,copy) endif +ifeq ($(CONFIG_SUPPORT_USBPLUG),y) +usbplug.bin: u-boot.bin + $(call if_changed,copy) +endif + %.imx: %.bin $(Q)$(MAKE) $(build)=arch/arm/mach-imx $@ @@ -1355,12 +1361,21 @@ prepare: prepare0 # Generate some files # --------------------------------------------------------------------------- +ifeq ($(CONFIG_SUPPORT_USBPLUG),) define filechk_version.h (echo \#define PLAIN_VERSION \"$(UBOOTRELEASE)\"; \ echo \#define U_BOOT_VERSION \"U-Boot \" PLAIN_VERSION; \ echo \#define CC_VERSION_STRING \"$$(LC_ALL=C $(CC) --version | head -n 1)\"; \ echo \#define LD_VERSION_STRING \"$$(LC_ALL=C $(LD) --version | head -n 1)\"; ) endef +else +define filechk_version.h + (echo \#define PLAIN_VERSION \"$(UBOOTRELEASE)\"; \ + echo \#define U_BOOT_VERSION \"USB-PLUG \" PLAIN_VERSION; \ + echo \#define CC_VERSION_STRING \"$$(LC_ALL=C $(CC) --version | head -n 1)\"; \ + echo \#define LD_VERSION_STRING \"$$(LC_ALL=C $(LD) --version | head -n 1)\"; ) +endef +endif # The SOURCE_DATE_EPOCH mechanism requires a date that behaves like GNU date. # The BSD date on the other hand behaves different and would produce errors diff --git a/common/Kconfig b/common/Kconfig index c0708ec76a..e433dc048c 100644 --- a/common/Kconfig +++ b/common/Kconfig @@ -674,3 +674,4 @@ config HASH endmenu source "common/spl/Kconfig" +source "common/usbplug/Kconfig" diff --git a/common/Makefile b/common/Makefile index e09461f58a..468318aedf 100644 --- a/common/Makefile +++ b/common/Makefile @@ -8,6 +8,8 @@ # core ifndef CONFIG_SPL_BUILD obj-y += init/ +obj-$(CONFIG_SUPPORT_USBPLUG) += usbplug/ + obj-y += main.o obj-y += exports.o obj-$(CONFIG_HASH) += hash.o @@ -21,7 +23,9 @@ endif # # boards obj-y += board_f.o +ifndef CONFIG_SUPPORT_USBPLUG obj-y += board_r.o +endif obj-$(CONFIG_DISPLAY_BOARDINFO) += board_info.o obj-$(CONFIG_DISPLAY_BOARDINFO_LATE) += board_info.o diff --git a/common/board_f.c b/common/board_f.c index 489a7d111e..c88691439b 100644 --- a/common/board_f.c +++ b/common/board_f.c @@ -160,7 +160,9 @@ static int announce_pre_serial(void) static int announce_dram_init(void) { +#ifndef CONFIG_SUPPORT_USBPLUG puts("DRAM: "); +#endif return 0; } @@ -188,10 +190,12 @@ static int show_dram_config(void) #ifdef CONFIG_BIDRAM size += bidram_append_size(); #endif + +#ifndef CONFIG_SUPPORT_USBPLUG print_size(size, ""); board_add_ram_info(0); putc('\n'); - +#endif return 0; } @@ -672,8 +676,10 @@ static int setup_reloc(void) #endif memcpy(gd->new_gd, (char *)gd, sizeof(gd_t)); +#ifndef CONFIG_SUPPORT_USBPLUG printf("Relocation Offset: %08lx, fdt: %08lx\n", gd->reloc_off, (ulong)gd->new_fdt); +#endif debug("Relocating to %08lx, new gd at %08lx, sp at %08lx\n", gd->relocaddr, (ulong)map_to_sysmem(gd->new_gd), gd->start_addr_sp); diff --git a/common/usbplug/Kconfig b/common/usbplug/Kconfig new file mode 100644 index 0000000000..04fb1b8df9 --- /dev/null +++ b/common/usbplug/Kconfig @@ -0,0 +1,10 @@ +menu "USBPLUG" + +config SUPPORT_USBPLUG + bool "Support USB PLUG" + default n + help + Support to build U-Boot as usb plug image for download firmware. + +endmenu + diff --git a/common/usbplug/Makefile b/common/usbplug/Makefile new file mode 100644 index 0000000000..d2889dd69b --- /dev/null +++ b/common/usbplug/Makefile @@ -0,0 +1,2 @@ +obj-y += usbplug.o + diff --git a/common/usbplug/usbplug.c b/common/usbplug/usbplug.c new file mode 100644 index 0000000000..31bd1fae04 --- /dev/null +++ b/common/usbplug/usbplug.c @@ -0,0 +1,81 @@ +/* + * (C) Copyright 2020 Rockchip Electronics Co., Ltd. + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +#include +#include +#include +#include + +DECLARE_GLOBAL_DATA_PTR; + +static void initr_reloc(void) +{ + /* tell others: relocation done */ + gd->flags |= GD_FLG_RELOC | GD_FLG_FULL_MALLOC_INIT; +} + +#ifdef CONFIG_ARM +static void initr_caches(void) +{ + icache_enable(); + dcache_enable(); +} +#endif + +static void initr_malloc(void) +{ + ulong malloc_start; + + /* The malloc area is immediately below the monitor copy in DRAM */ + malloc_start = gd->relocaddr - TOTAL_MALLOC_LEN; + mem_malloc_init((ulong)map_sysmem(malloc_start, TOTAL_MALLOC_LEN), + TOTAL_MALLOC_LEN); +} + +#ifdef CONFIG_DM +static int initr_dm(void) +{ + /* Save the pre-reloc driver model and start a new one */ + gd->dm_root_f = gd->dm_root; + gd->dm_root = NULL; + + return dm_init_and_scan(false); +} +#endif + +/* + * The below functions are all __weak declared. + */ +int dram_init(void) +{ +#if CONFIG_SYS_MALLOC_LEN > SZ_64M + "CONFIG_SYS_MALLOC_LEN is over 64MB" +#endif + gd->ram_size = SZ_64M; /* default */ + + gd->bd->bi_dram[0].start = CONFIG_SYS_SDRAM_BASE; + gd->bd->bi_dram[0].size = gd->ram_size; + + return 0; +} + +/* Refers to common/board_r.c */ +void board_init_r(gd_t *new_gd, ulong dest_addr) +{ + initr_reloc(); +#ifdef CONFIG_ARM + initr_caches(); +#endif + initr_malloc(); +#ifdef CONFIG_DM + initr_dm(); +#endif + /* Setup chipselects, entering usb-plug mode */ + board_init(); + + hang(); +} + diff --git a/dts/Makefile b/dts/Makefile index 170559d288..ec341cad35 100644 --- a/dts/Makefile +++ b/dts/Makefile @@ -63,7 +63,7 @@ $(obj)/dt-spl.dtb: $(DTB) $(objtree)/tools/fdtgrep FORCE $(call if_changed,fdtgrep) endif -ifeq ($(CONFIG_USING_KERNEL_DTB),y) +ifneq ($(CONFIG_USING_KERNEL_DTB)$(CONFIG_SUPPORT_USBPLUG),) $(obj)/dt.dtb: $(DTB) $(objtree)/tools/fdtgrep FORCE $(call if_changed,fdtgrep) else