blob: b76aa98e1f320a7cf870b7d7f4764abc41101b20 [file] [log] [blame]
Andrew Jeffery4fe996c2018-02-27 12:16:48 +10301/* SPDX-License-Identifier: Apache-2.0 */
2/* Copyright (C) 2018 IBM Corp. */
Deepak Kodihallib6a446f2017-04-29 13:01:49 -05003#pragma once
4
Ratan Gupta8441a392017-05-05 21:42:53 +05305#include <limits.h>
Deepak Kodihallib6a446f2017-04-29 13:01:49 -05006#include "pnor_partition_defs.h"
Evan Lojewskif1e547c2019-03-14 14:34:33 +10307#include "backend.h"
Deepak Kodihallib6a446f2017-04-29 13:01:49 -05008
9struct mbox_context;
10struct vpnor_partition_table;
11
Ratan Gupta8441a392017-05-05 21:42:53 +053012struct vpnor_partition_paths
13{
14 char ro_loc[PATH_MAX];
Ratan Guptac0ef9872017-06-06 14:31:37 +053015 char rw_loc[PATH_MAX];
16 char prsv_loc[PATH_MAX];
Adriana Kobylakc71dfd72017-07-22 11:10:43 -050017 char patch_loc[PATH_MAX];
Ratan Gupta8441a392017-05-05 21:42:53 +053018};
19
Evan Lojewskif1e547c2019-03-14 14:34:33 +103020struct vpnor_data {
21 struct vpnor_partition_table *vpnor;
22 struct vpnor_partition_paths paths;
23};
24
Deepak Kodihallib6a446f2017-04-29 13:01:49 -050025#ifdef __cplusplus
26extern "C" {
27#endif
28
Evan Lojewskif1e547c2019-03-14 14:34:33 +103029/** @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 Jeffery5320f6e2019-03-15 12:40:41 +103035#ifdef VIRTUAL_PNOR_ENABLED
Evan Lojewskif1e547c2019-03-14 14:34:33 +103036void vpnor_default_paths(struct vpnor_partition_paths *paths);
Andrew Jeffery5320f6e2019-03-15 12:40:41 +103037#else
38static inline void vpnor_default_paths(struct vpnor_partition_paths *paths)
39{
40 memset(paths, 0, sizeof(*paths));
41}
42#endif
Evan Lojewskif1e547c2019-03-14 14:34:33 +103043
Andrew Jeffery5320f6e2019-03-15 12:40:41 +103044#ifdef VIRTUAL_PNOR_ENABLED
Deepak Kodihallib6a446f2017-04-29 13:01:49 -050045/** @brief Create a virtual PNOR partition table.
46 *
Evan Lojewskif1e547c2019-03-14 14:34:33 +103047 * @param[in] backend - The backend context pointer
48 * @param[in] paths - A paths object pointer to initialise vpnor
Deepak Kodihallib6a446f2017-04-29 13:01:49 -050049 *
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 Jefferyf96bd162018-02-26 13:05:00 +103053 *
Evan Lojewskif1e547c2019-03-14 14:34:33 +103054 * The content of the paths object is copied out, ownership is retained by the
55 * caller.
Andrew Jefferyf96bd162018-02-26 13:05:00 +103056 *
57 * Returns 0 if the call succeeds, else a negative error code.
Ratan Gupta3214b512017-05-11 08:58:19 +053058 */
59
Evan Lojewskif1e547c2019-03-14 14:34:33 +103060int vpnor_init(struct backend *backend,
61 const struct vpnor_partition_paths *paths);
Ratan Gupta3214b512017-05-11 08:58:19 +053062
Deepak Kodihalli017e45c2017-07-12 01:06:30 -050063/** @brief Copy bootloader partition (alongwith TOC) to LPC memory
64 *
Evan Lojewskif1e547c2019-03-14 14:34:33 +103065 * @param[in] backend - The backend context pointer
Andrew Jefferyf96bd162018-02-26 13:05:00 +103066 *
67 * @returns 0 on success, negative error code on failure
Deepak Kodihalli017e45c2017-07-12 01:06:30 -050068 */
Evan Lojewskif1e547c2019-03-14 14:34:33 +103069int vpnor_copy_bootloader_partition(const struct backend *backend, void *buf,
70 uint32_t count);
Deepak Kodihalli017e45c2017-07-12 01:06:30 -050071
Deepak Kodihallib6a446f2017-04-29 13:01:49 -050072/** @brief Destroy partition table, if it exists.
73 *
Evan Lojewskif1e547c2019-03-14 14:34:33 +103074 * @param[in] backend - The backend context pointer
Deepak Kodihallib6a446f2017-04-29 13:01:49 -050075 */
Evan Lojewskif1e547c2019-03-14 14:34:33 +103076void vpnor_destroy(struct backend *backend);
Deepak Kodihallib6a446f2017-04-29 13:01:49 -050077
78#ifdef __cplusplus
79}
80#endif
81
82#endif