xref: /rk3399_rockchip-uboot/arch/arm/mach-rockchip/dfu_alt_info.c (revision c3e08fa050aa3e8eb31fbd76f4d1e28c00ffe0b4)
1 /*
2  * (C) Copyright 2021 Rockchip Electronics Co., Ltd
3  *
4  * SPDX-License-Identifier:     GPL-2.0+
5  */
6 
7 #include <common.h>
8 #include <boot_rkimg.h>
9 #include <memalign.h>
10 
11 #define CONFIG_SET_DFU_ALT_BUF_LEN	(SZ_1K)
12 static char *get_dfu_alt(char *interface, char *devstr)
13 {
14 	struct blk_desc *dev_desc;
15 	char *alt_boot;
16 
17 	dev_desc = rockchip_get_bootdev();
18 	if (!dev_desc) {
19 		printf("%s: dev_desc is NULL!\n", __func__);
20 		return NULL;
21 	}
22 
23 	switch (dev_desc->if_type) {
24 #ifdef CONFIG_MMC
25 	case IF_TYPE_MMC:
26 		alt_boot = DFU_ALT_BOOT_EMMC;
27 		break;
28 #endif
29 #ifdef CONFIG_MTD_BLK
30 	case IF_TYPE_MTD:
31 		alt_boot = DFU_ALT_BOOT_MTD;
32 		break;
33 #endif
34 	default:
35 		printf("[dfu ERROR]:Boot device type is invalid!\n");
36 		return NULL;
37 	}
38 
39 	return alt_boot;
40 }
41 
42 void set_dfu_alt_info(char *interface, char *devstr)
43 {
44 	size_t buf_size = CONFIG_SET_DFU_ALT_BUF_LEN;
45 	ALLOC_CACHE_ALIGN_BUFFER(char, buf, buf_size);
46 	char *alt_info = "Settings not found!";
47 	char *status = "error!\n";
48 	char *alt_setting;
49 	int offset = 0;
50 
51 	puts("DFU alt info setting: ");
52 
53 	alt_setting = get_dfu_alt(interface, devstr);
54 	if (alt_setting) {
55 		env_set("dfu_alt_boot", alt_setting);
56 		offset = snprintf(buf, buf_size, "%s", alt_setting);
57 	}
58 
59 	if (offset) {
60 		alt_info = buf;
61 		status = "done\n";
62 	}
63 
64 	env_set("dfu_alt_info", alt_info);
65 	puts(status);
66 }
67