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