blob: e325775030f1be23102c421a14f13274e9f33af0 [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
5#ifdef VIRTUAL_PNOR_ENABLED
6
Ratan Gupta8441a392017-05-05 21:42:53 +05307#include <limits.h>
Deepak Kodihallib6a446f2017-04-29 13:01:49 -05008#include "pnor_partition_defs.h"
Evan Lojewskif1e547c2019-03-14 14:34:33 +10309#include "backend.h"
Deepak Kodihallib6a446f2017-04-29 13:01:49 -050010
11struct mbox_context;
12struct vpnor_partition_table;
13
Ratan Gupta8441a392017-05-05 21:42:53 +053014struct vpnor_partition_paths
15{
16 char ro_loc[PATH_MAX];
Ratan Guptac0ef9872017-06-06 14:31:37 +053017 char rw_loc[PATH_MAX];
18 char prsv_loc[PATH_MAX];
Adriana Kobylakc71dfd72017-07-22 11:10:43 -050019 char patch_loc[PATH_MAX];
Ratan Gupta8441a392017-05-05 21:42:53 +053020};
21
Evan Lojewskif1e547c2019-03-14 14:34:33 +103022struct vpnor_data {
23 struct vpnor_partition_table *vpnor;
24 struct vpnor_partition_paths paths;
25};
26
Deepak Kodihallib6a446f2017-04-29 13:01:49 -050027#ifdef __cplusplus
28extern "C" {
29#endif
30
Evan Lojewskif1e547c2019-03-14 14:34:33 +103031/** @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 */
37void vpnor_default_paths(struct vpnor_partition_paths *paths);
38
Deepak Kodihallib6a446f2017-04-29 13:01:49 -050039/** @brief Create a virtual PNOR partition table.
40 *
Evan Lojewskif1e547c2019-03-14 14:34:33 +103041 * @param[in] backend - The backend context pointer
42 * @param[in] paths - A paths object pointer to initialise vpnor
Deepak Kodihallib6a446f2017-04-29 13:01:49 -050043 *
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 Jefferyf96bd162018-02-26 13:05:00 +103047 *
Evan Lojewskif1e547c2019-03-14 14:34:33 +103048 * The content of the paths object is copied out, ownership is retained by the
49 * caller.
Andrew Jefferyf96bd162018-02-26 13:05:00 +103050 *
51 * Returns 0 if the call succeeds, else a negative error code.
Ratan Gupta3214b512017-05-11 08:58:19 +053052 */
53
Evan Lojewskif1e547c2019-03-14 14:34:33 +103054int vpnor_init(struct backend *backend,
55 const struct vpnor_partition_paths *paths);
Ratan Gupta3214b512017-05-11 08:58:19 +053056
Deepak Kodihalli017e45c2017-07-12 01:06:30 -050057/** @brief Copy bootloader partition (alongwith TOC) to LPC memory
58 *
Evan Lojewskif1e547c2019-03-14 14:34:33 +103059 * @param[in] backend - The backend context pointer
Andrew Jefferyf96bd162018-02-26 13:05:00 +103060 *
61 * @returns 0 on success, negative error code on failure
Deepak Kodihalli017e45c2017-07-12 01:06:30 -050062 */
Evan Lojewskif1e547c2019-03-14 14:34:33 +103063int vpnor_copy_bootloader_partition(const struct backend *backend, void *buf,
64 uint32_t count);
Deepak Kodihalli017e45c2017-07-12 01:06:30 -050065
Deepak Kodihallib6a446f2017-04-29 13:01:49 -050066/** @brief Destroy partition table, if it exists.
67 *
Evan Lojewskif1e547c2019-03-14 14:34:33 +103068 * @param[in] backend - The backend context pointer
Deepak Kodihallib6a446f2017-04-29 13:01:49 -050069 */
Evan Lojewskif1e547c2019-03-14 14:34:33 +103070void vpnor_destroy(struct backend *backend);
Deepak Kodihallib6a446f2017-04-29 13:01:49 -050071
72#ifdef __cplusplus
73}
74#endif
75
76#endif