blob: e147f9da54285f2df97f86ff6f00ad69175e57c9 [file] [log] [blame]
Bo Lv72d0e902023-01-02 14:27:34 +00001// SPDX-License-Identifier: (GPL-2.0+ OR MIT)
2/*
3 * Copyright (c) 2019 Amlogic, Inc. All rights reserved.
4 */
5
6#include <common.h>
7#include <command.h>
8#include <env.h>
9#include <malloc.h>
10#include <asm/byteorder.h>
11#include <config.h>
12#include <asm/amlogic/arch/io.h>
13#include <amlogic/partition_table.h>
14#include <amlogic/libavb/libavb.h>
15#include <version.h>
16#include <amlogic/storage.h>
17
18#include "cmd_bootctl_utils.h"
19#ifndef getenv
20#define getenv env_get
21#endif
22
23#define MISC_BUFSIZE_AVB 2080
24#define MISC_BUFSIZE_VAB 2080
25#define MISC_BUFSIZE_NORMAL 1088
26
27static size_t g_miscbuf_size;
28
29int aml_get_boot_mode(void)
30{
31#if defined(CONFIG_UNIFY_BOOTLOADER) && !defined(CONFIG_SYSTEM_RTOS)
32// If need enable unify bootloader function, we need do:
33// 1. Add #define CONFIG_UNIFY_BOOTLOADER in board/amlogic/configs/xxx.h
34// 2. Add below dts config
35// cur-sys-type = "systype-xxx"; xxx is rdk or atv or yocto
36// in "arch/arm64/boot/dts/amlogic/xx.dts" top node
37 char cmdbuf[128] = {0};
38 int ret = 0;
39 char *temp_env = NULL;
40
41 memset(cmdbuf, 0, sizeof(cmdbuf));
42 sprintf(cmdbuf, "fdt get value env-cur-sys-type / cur-sys-type;");
43
44 ret = run_command(cmdbuf, 0);
45 if (ret)
46 printf("%s fdt get error\n", __func__);
47 else
48 temp_env = getenv("env-cur-sys-type");
49
50 if (strcmp(temp_env, "systype-atv") == 0) {
51 printf("we are run in atv\n");
52 return BOOT_MODE_VAB;
53 } else if (strcmp(temp_env, "systype-rdk") == 0) {
54 printf("we are run in rdk\n");
55 return BOOT_MODE_AVB;
56 } else if (strcmp(temp_env, "systype-yocto") == 0) {
57 printf("we are run in yocto\n");
58 return BOOT_MODE_AVB;
59 }
60
61 printf("we are run in %s fall to avb\n", temp_env);
62 return BOOT_MODE_AVB;
63#else
64#if defined(CONFIG_CMD_BOOTCTOL_AVB) && defined(CONFIG_CMD_BOOTCTOL_VAB)
65 printf("boot in VAB mode\n");
66 return BOOT_MODE_VAB;
67#endif
68
69#if defined(CONFIG_CMD_BOOTCTOL_AVB)
70 printf("boot in AVB mode\n");
71 return BOOT_MODE_AVB;
72#endif
73 return BOOT_MODE_NORMAL;
74#endif
75}
76
77int boot_info_open_partition(char *miscbuf)
78{
79 char *partition = "misc";
80
81 if (g_miscbuf_size <= 0) {
82 int boot_mode = aml_get_boot_mode();
83
84 switch (boot_mode) {
85 case BOOT_MODE_VAB:
86 g_miscbuf_size = MISC_BUFSIZE_VAB;
87 break;
88 case BOOT_MODE_AVB:
89 g_miscbuf_size = MISC_BUFSIZE_AVB;
90 break;
91 default:
92 g_miscbuf_size = MISC_BUFSIZE_NORMAL;
93 break;
94 }
95 }
96
97 printf("%s Start read %s partition datas\n", __func__, partition);
98 if (store_read((const char *)partition,
99 0, g_miscbuf_size, (unsigned char *)miscbuf) < 0) {
100 printf("failed to store read %s.\n", partition);
101 return -1;
102 }
103
104 return 0;
105}
106