Jassi Brar | eeee432 | 2023-05-31 00:29:56 -0500 | [diff] [blame] | 1 | // 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 */ |
| 15 | void 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 Kojima | 0f8cfda | 2024-02-08 11:33:44 +0900 | [diff] [blame] | 38 | |
| 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 | */ |
| 48 | void 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 | } |