blob: 122c9339583e8805cff4c1e703bd1f95a9160d7a [file] [log] [blame]
Deepak Kodihallib6a446f2017-04-29 13:01:49 -05001#pragma once
2
3#ifdef VIRTUAL_PNOR_ENABLED
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"
7
8struct mbox_context;
9struct vpnor_partition_table;
10
Ratan Gupta8441a392017-05-05 21:42:53 +053011struct vpnor_partition_paths
12{
13 char ro_loc[PATH_MAX];
Ratan Guptac0ef9872017-06-06 14:31:37 +053014 char rw_loc[PATH_MAX];
15 char prsv_loc[PATH_MAX];
Adriana Kobylakc71dfd72017-07-22 11:10:43 -050016 char patch_loc[PATH_MAX];
Ratan Gupta8441a392017-05-05 21:42:53 +053017};
18
Deepak Kodihallib6a446f2017-04-29 13:01:49 -050019#ifdef __cplusplus
20extern "C" {
21#endif
22
23/** @brief Create a virtual PNOR partition table.
24 *
25 * @param[in] context - mbox context pointer
26 *
27 * This API should be called before calling any other APIs below. If a table
28 * already exists, this function will not do anything further. This function
29 * will not do anything if the context is NULL.
Andrew Jefferyf96bd162018-02-26 13:05:00 +103030 *
31 * Returns 0 if the call succeeds, else a negative error code.
Deepak Kodihallib6a446f2017-04-29 13:01:49 -050032 */
Andrew Jefferyf96bd162018-02-26 13:05:00 +103033int init_vpnor(struct mbox_context *context);
Deepak Kodihallib6a446f2017-04-29 13:01:49 -050034
Ratan Gupta3214b512017-05-11 08:58:19 +053035/** @brief Create a virtual PNOR partition table.
36 *
37 * @param[in] context - mbox context pointer
38 * @param[in] path - location of the partition file
39 *
40 * This API is same as above one but it reads the partition file from
41 * from the given location(path).
Andrew Jefferyf96bd162018-02-26 13:05:00 +103042 *
43 * Returns 0 if the call succeeds, else a negative error code.
Ratan Gupta3214b512017-05-11 08:58:19 +053044 */
45
Andrew Jefferyf96bd162018-02-26 13:05:00 +103046int vpnor_create_partition_table_from_path(struct mbox_context *context,
47 const char* path);
Ratan Gupta3214b512017-05-11 08:58:19 +053048
Deepak Kodihallib6a446f2017-04-29 13:01:49 -050049
50/** @brief Get partition table size, in blocks (1 block = 4KB)
51 *
52 * @param[in] context - mbox context pointer
53 *
54 * @returns partition table size. 0 if no table exists, or if the
55 * context is NULL.
56 */
57size_t vpnor_get_partition_table_size(const struct mbox_context *context);
58
59
60/** @brief Get virtual PNOR partition table with host-compatible byte-ordering
61 *
62 * @param[in] context - mbox context pointer
63 *
64 * @returns pointer to partition table, NULL if partition table doesn't
65 * exist or if the context is NULL.
66 */
67const struct pnor_partition_table* vpnor_get_partition_table(
68 const struct mbox_context *context);
69
70
71/** @brief Get a specific partition, by PNOR offset. The returned
72 * partition is such that the offset lies in that partition's
73 * boundary.
74 *
75 * @param[in] context - mbox context pointer
76 * @param[in] offset - PNOR offset
77 *
78 * @returns const pointer to pnor_partition, NULL if partition table doesn't
79 * exist or if the context is NULL
80 */
81const struct pnor_partition* vpnor_get_partition(
82 const struct mbox_context *context,
83 const size_t offset);
84
85
Deepak Kodihalli017e45c2017-07-12 01:06:30 -050086/** @brief Copy bootloader partition (alongwith TOC) to LPC memory
87 *
88 * @param[in] context - mbox context pointer
Andrew Jefferyf96bd162018-02-26 13:05:00 +103089 *
90 * @returns 0 on success, negative error code on failure
Deepak Kodihalli017e45c2017-07-12 01:06:30 -050091 */
Andrew Jefferyf96bd162018-02-26 13:05:00 +103092int vpnor_copy_bootloader_partition(const struct mbox_context *context);
Deepak Kodihalli017e45c2017-07-12 01:06:30 -050093
Deepak Kodihallib6a446f2017-04-29 13:01:49 -050094/** @brief Destroy partition table, if it exists.
95 *
96 * @param[in] context - mbox context pointer
97 */
Deepak Kodihalli64ec3e42017-07-17 06:15:16 -050098void destroy_vpnor(struct mbox_context *context);
Deepak Kodihallib6a446f2017-04-29 13:01:49 -050099
100#ifdef __cplusplus
101}
102#endif
103
104#endif