Andrew Jeffery | 4fe996c | 2018-02-27 12:16:48 +1030 | [diff] [blame] | 1 | /* SPDX-License-Identifier: Apache-2.0 */ |
| 2 | /* Copyright (C) 2018 IBM Corp. */ |
Deepak Kodihalli | b6a446f | 2017-04-29 13:01:49 -0500 | [diff] [blame] | 3 | #pragma once |
| 4 | |
| 5 | #ifdef VIRTUAL_PNOR_ENABLED |
| 6 | |
Ratan Gupta | 8441a39 | 2017-05-05 21:42:53 +0530 | [diff] [blame] | 7 | #include <limits.h> |
Deepak Kodihalli | b6a446f | 2017-04-29 13:01:49 -0500 | [diff] [blame] | 8 | #include "pnor_partition_defs.h" |
Evan Lojewski | f1e547c | 2019-03-14 14:34:33 +1030 | [diff] [blame] | 9 | #include "backend.h" |
Deepak Kodihalli | b6a446f | 2017-04-29 13:01:49 -0500 | [diff] [blame] | 10 | |
| 11 | struct mbox_context; |
| 12 | struct vpnor_partition_table; |
| 13 | |
Ratan Gupta | 8441a39 | 2017-05-05 21:42:53 +0530 | [diff] [blame] | 14 | struct vpnor_partition_paths |
| 15 | { |
| 16 | char ro_loc[PATH_MAX]; |
Ratan Gupta | c0ef987 | 2017-06-06 14:31:37 +0530 | [diff] [blame] | 17 | char rw_loc[PATH_MAX]; |
| 18 | char prsv_loc[PATH_MAX]; |
Adriana Kobylak | c71dfd7 | 2017-07-22 11:10:43 -0500 | [diff] [blame] | 19 | char patch_loc[PATH_MAX]; |
Ratan Gupta | 8441a39 | 2017-05-05 21:42:53 +0530 | [diff] [blame] | 20 | }; |
| 21 | |
Evan Lojewski | f1e547c | 2019-03-14 14:34:33 +1030 | [diff] [blame] | 22 | struct vpnor_data { |
| 23 | struct vpnor_partition_table *vpnor; |
| 24 | struct vpnor_partition_paths paths; |
| 25 | }; |
| 26 | |
Deepak Kodihalli | b6a446f | 2017-04-29 13:01:49 -0500 | [diff] [blame] | 27 | #ifdef __cplusplus |
| 28 | extern "C" { |
| 29 | #endif |
| 30 | |
Evan Lojewski | f1e547c | 2019-03-14 14:34:33 +1030 | [diff] [blame] | 31 | /** @brief Populate the path object with the default partition paths |
| 32 | * |
| 33 | * @param[in/out] paths - A paths object in which to store the defaults |
| 34 | * |
| 35 | * Returns 0 if the call succeeds, else a negative error code. |
| 36 | */ |
| 37 | void vpnor_default_paths(struct vpnor_partition_paths *paths); |
| 38 | |
Deepak Kodihalli | b6a446f | 2017-04-29 13:01:49 -0500 | [diff] [blame] | 39 | /** @brief Create a virtual PNOR partition table. |
| 40 | * |
Evan Lojewski | f1e547c | 2019-03-14 14:34:33 +1030 | [diff] [blame] | 41 | * @param[in] backend - The backend context pointer |
| 42 | * @param[in] paths - A paths object pointer to initialise vpnor |
Deepak Kodihalli | b6a446f | 2017-04-29 13:01:49 -0500 | [diff] [blame] | 43 | * |
| 44 | * This API should be called before calling any other APIs below. If a table |
| 45 | * already exists, this function will not do anything further. This function |
| 46 | * will not do anything if the context is NULL. |
Andrew Jeffery | f96bd16 | 2018-02-26 13:05:00 +1030 | [diff] [blame] | 47 | * |
Evan Lojewski | f1e547c | 2019-03-14 14:34:33 +1030 | [diff] [blame] | 48 | * The content of the paths object is copied out, ownership is retained by the |
| 49 | * caller. |
Andrew Jeffery | f96bd16 | 2018-02-26 13:05:00 +1030 | [diff] [blame] | 50 | * |
| 51 | * Returns 0 if the call succeeds, else a negative error code. |
Ratan Gupta | 3214b51 | 2017-05-11 08:58:19 +0530 | [diff] [blame] | 52 | */ |
| 53 | |
Evan Lojewski | f1e547c | 2019-03-14 14:34:33 +1030 | [diff] [blame] | 54 | int vpnor_init(struct backend *backend, |
| 55 | const struct vpnor_partition_paths *paths); |
Ratan Gupta | 3214b51 | 2017-05-11 08:58:19 +0530 | [diff] [blame] | 56 | |
Deepak Kodihalli | 017e45c | 2017-07-12 01:06:30 -0500 | [diff] [blame] | 57 | /** @brief Copy bootloader partition (alongwith TOC) to LPC memory |
| 58 | * |
Evan Lojewski | f1e547c | 2019-03-14 14:34:33 +1030 | [diff] [blame] | 59 | * @param[in] backend - The backend context pointer |
Andrew Jeffery | f96bd16 | 2018-02-26 13:05:00 +1030 | [diff] [blame] | 60 | * |
| 61 | * @returns 0 on success, negative error code on failure |
Deepak Kodihalli | 017e45c | 2017-07-12 01:06:30 -0500 | [diff] [blame] | 62 | */ |
Evan Lojewski | f1e547c | 2019-03-14 14:34:33 +1030 | [diff] [blame] | 63 | int vpnor_copy_bootloader_partition(const struct backend *backend, void *buf, |
| 64 | uint32_t count); |
Deepak Kodihalli | 017e45c | 2017-07-12 01:06:30 -0500 | [diff] [blame] | 65 | |
Deepak Kodihalli | b6a446f | 2017-04-29 13:01:49 -0500 | [diff] [blame] | 66 | /** @brief Destroy partition table, if it exists. |
| 67 | * |
Evan Lojewski | f1e547c | 2019-03-14 14:34:33 +1030 | [diff] [blame] | 68 | * @param[in] backend - The backend context pointer |
Deepak Kodihalli | b6a446f | 2017-04-29 13:01:49 -0500 | [diff] [blame] | 69 | */ |
Evan Lojewski | f1e547c | 2019-03-14 14:34:33 +1030 | [diff] [blame] | 70 | void vpnor_destroy(struct backend *backend); |
Deepak Kodihalli | b6a446f | 2017-04-29 13:01:49 -0500 | [diff] [blame] | 71 | |
| 72 | #ifdef __cplusplus |
| 73 | } |
| 74 | #endif |
| 75 | |
| 76 | #endif |