blob: 26031795b09d97d6bb9f83c7e573f4e4cf56ad44 [file] [log] [blame]
Jassi Brareeee4322023-05-31 00:29:56 -05001// SPDX-License-Identifier: GPL-2.0-or-later
2/*
3 * Copyright (c) 2023, Linaro Limited
4 */
5
6#include <efi_loader.h>
7#include <fwu.h>
8#include <fwu_mdata.h>
9#include <memalign.h>
10#include <mtd.h>
11
12#define DFU_ALT_BUF_LEN 256
13
14/* Generate dfu_alt_info from partitions */
15void set_dfu_alt_info(char *interface, char *devstr)
16{
17 ALLOC_CACHE_ALIGN_BUFFER(char, buf, DFU_ALT_BUF_LEN);
18 struct mtd_info *mtd;
19 int ret;
20
21 memset(buf, 0, sizeof(buf));
22
23 mtd_probe_devices();
24
25 mtd = get_mtd_device_nm("nor1");
26 if (IS_ERR_OR_NULL(mtd))
27 return;
28
29 ret = fwu_gen_alt_info_from_mtd(buf, DFU_ALT_BUF_LEN, mtd);
30 if (ret < 0) {
31 log_err("Error: Failed to generate dfu_alt_info. (%d)\n", ret);
32 return;
33 }
34 log_debug("Make dfu_alt_info: '%s'\n", buf);
35
36 env_set("dfu_alt_info", buf);
37}
Masahisa Kojima0f8cfda2024-02-08 11:33:44 +090038
39/**
40 * fwu_plat_get_bootidx() - Get the value of the boot index
41 * @boot_idx: Boot index value
42 *
43 * Get the value of the bank(partition) from which the platform
44 * has booted. This value is passed to U-Boot from the earlier
45 * stage bootloader which loads and boots all the relevant
46 * firmware images
47 */
48void fwu_plat_get_bootidx(uint *boot_idx)
49{
50 int ret;
51 u32 buf;
52 size_t readlen;
53 struct mtd_info *mtd;
54
55 *boot_idx = 0;
56
57 mtd_probe_devices();
58 mtd = get_mtd_device_nm("nor1");
59 if (IS_ERR_OR_NULL(mtd))
60 return;
61
62 ret = mtd_read(mtd, SCB_PLAT_METADATA_OFFSET, sizeof(buf),
63 &readlen, (u_char *)&buf);
64 if (ret < 0)
65 return;
66
67 *boot_idx = buf;
68}