From da041cba1fc1eb055b195f9ce190d8a1e67ba2f5 Mon Sep 17 00:00:00 2001 From: Yifeng Zhao Date: Wed, 20 Jan 2021 14:31:05 +0800 Subject: [PATCH] arch: rockchip: add set dfu alt info api Signed-off-by: Yifeng Zhao Change-Id: Idc6bd66c5b85a2bb100da3f270dd86b48dec8886 --- arch/arm/mach-rockchip/Makefile | 1 + arch/arm/mach-rockchip/dfu_alt_info.c | 66 +++++++++++++++++++++++++++ 2 files changed, 67 insertions(+) create mode 100644 arch/arm/mach-rockchip/dfu_alt_info.c diff --git a/arch/arm/mach-rockchip/Makefile b/arch/arm/mach-rockchip/Makefile index 57e73452da..5375a84cee 100644 --- a/arch/arm/mach-rockchip/Makefile +++ b/arch/arm/mach-rockchip/Makefile @@ -77,3 +77,4 @@ obj-$(CONFIG_SPL_BUILD) += $(obj-spl-y) obj-$(CONFIG_TPL_BUILD) += $(obj-tpl-y) obj-$(CONFIG_ROCKCHIP_PRELOADER_ATAGS) += rk_atags.o +obj-$(CONFIG_SET_DFU_ALT_INFO) += dfu_alt_info.o diff --git a/arch/arm/mach-rockchip/dfu_alt_info.c b/arch/arm/mach-rockchip/dfu_alt_info.c new file mode 100644 index 0000000000..74fa4eb788 --- /dev/null +++ b/arch/arm/mach-rockchip/dfu_alt_info.c @@ -0,0 +1,66 @@ +/* + * (C) Copyright 2021 Rockchip Electronics Co., Ltd + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +#include +#include +#include + +#define CONFIG_SET_DFU_ALT_BUF_LEN (SZ_1K) +static char *get_dfu_alt(char *interface, char *devstr) +{ + struct blk_desc *dev_desc; + char *alt_boot; + + dev_desc = rockchip_get_bootdev(); + if (!dev_desc) { + printf("%s: dev_desc is NULL!\n", __func__); + return NULL; + } + + switch (dev_desc->if_type) { +#ifdef CONFIG_MMC + case IF_TYPE_MMC: + alt_boot = DFU_ALT_BOOT_EMMC; + break; +#endif +#ifdef CONFIG_MTD_BLK + case IF_TYPE_MTD: + alt_boot = DFU_ALT_BOOT_MTD; + break; +#endif + default: + printf("[dfu ERROR]:Boot device type is invalid!\n"); + return NULL; + } + + return alt_boot; +} + +void set_dfu_alt_info(char *interface, char *devstr) +{ + size_t buf_size = CONFIG_SET_DFU_ALT_BUF_LEN; + ALLOC_CACHE_ALIGN_BUFFER(char, buf, buf_size); + char *alt_info = "Settings not found!"; + char *status = "error!\n"; + char *alt_setting; + int offset = 0; + + puts("DFU alt info setting: "); + + alt_setting = get_dfu_alt(interface, devstr); + if (alt_setting) { + env_set("dfu_alt_boot", alt_setting); + offset = snprintf(buf, buf_size, "%s", alt_setting); + } + + if (offset) { + alt_info = buf; + status = "done\n"; + } + + env_set("dfu_alt_info", alt_info); + puts(status); +}