blob: beb9cede4fdc7ddcae2d728ee6aa59ee4961094a [file] [log] [blame]
Andrew Jefferyacee6832018-02-21 22:17:08 +10301/*
2 * Mailbox Daemon Implementation
3 *
4 * Copyright 2018 IBM
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 *
18 */
Deepak Kodihallib6a446f2017-04-29 13:01:49 -050019#pragma once
20
21#ifdef VIRTUAL_PNOR_ENABLED
22
Ratan Gupta8441a392017-05-05 21:42:53 +053023#include <limits.h>
Deepak Kodihallib6a446f2017-04-29 13:01:49 -050024#include "pnor_partition_defs.h"
25
26struct mbox_context;
27struct vpnor_partition_table;
28
Ratan Gupta8441a392017-05-05 21:42:53 +053029struct vpnor_partition_paths
30{
31 char ro_loc[PATH_MAX];
Ratan Guptac0ef9872017-06-06 14:31:37 +053032 char rw_loc[PATH_MAX];
33 char prsv_loc[PATH_MAX];
Adriana Kobylakc71dfd72017-07-22 11:10:43 -050034 char patch_loc[PATH_MAX];
Ratan Gupta8441a392017-05-05 21:42:53 +053035};
36
Deepak Kodihallib6a446f2017-04-29 13:01:49 -050037#ifdef __cplusplus
38extern "C" {
39#endif
40
41/** @brief Create a virtual PNOR partition table.
42 *
43 * @param[in] context - mbox context pointer
44 *
45 * This API should be called before calling any other APIs below. If a table
46 * already exists, this function will not do anything further. This function
47 * will not do anything if the context is NULL.
Andrew Jefferyf96bd162018-02-26 13:05:00 +103048 *
49 * Returns 0 if the call succeeds, else a negative error code.
Deepak Kodihallib6a446f2017-04-29 13:01:49 -050050 */
Andrew Jefferyf96bd162018-02-26 13:05:00 +103051int init_vpnor(struct mbox_context *context);
Deepak Kodihallib6a446f2017-04-29 13:01:49 -050052
Ratan Gupta3214b512017-05-11 08:58:19 +053053/** @brief Create a virtual PNOR partition table.
54 *
55 * @param[in] context - mbox context pointer
56 * @param[in] path - location of the partition file
57 *
58 * This API is same as above one but it reads the partition file from
59 * from the given location(path).
Andrew Jefferyf96bd162018-02-26 13:05:00 +103060 *
61 * Returns 0 if the call succeeds, else a negative error code.
Ratan Gupta3214b512017-05-11 08:58:19 +053062 */
63
Andrew Jefferyf96bd162018-02-26 13:05:00 +103064int vpnor_create_partition_table_from_path(struct mbox_context *context,
65 const char* path);
Ratan Gupta3214b512017-05-11 08:58:19 +053066
Deepak Kodihallib6a446f2017-04-29 13:01:49 -050067
68/** @brief Get partition table size, in blocks (1 block = 4KB)
69 *
70 * @param[in] context - mbox context pointer
71 *
72 * @returns partition table size. 0 if no table exists, or if the
73 * context is NULL.
74 */
75size_t vpnor_get_partition_table_size(const struct mbox_context *context);
76
77
78/** @brief Get virtual PNOR partition table with host-compatible byte-ordering
79 *
80 * @param[in] context - mbox context pointer
81 *
82 * @returns pointer to partition table, NULL if partition table doesn't
83 * exist or if the context is NULL.
84 */
85const struct pnor_partition_table* vpnor_get_partition_table(
86 const struct mbox_context *context);
87
88
89/** @brief Get a specific partition, by PNOR offset. The returned
90 * partition is such that the offset lies in that partition's
91 * boundary.
92 *
93 * @param[in] context - mbox context pointer
94 * @param[in] offset - PNOR offset
95 *
96 * @returns const pointer to pnor_partition, NULL if partition table doesn't
97 * exist or if the context is NULL
98 */
99const struct pnor_partition* vpnor_get_partition(
100 const struct mbox_context *context,
101 const size_t offset);
102
103
Deepak Kodihalli017e45c2017-07-12 01:06:30 -0500104/** @brief Copy bootloader partition (alongwith TOC) to LPC memory
105 *
106 * @param[in] context - mbox context pointer
Andrew Jefferyf96bd162018-02-26 13:05:00 +1030107 *
108 * @returns 0 on success, negative error code on failure
Deepak Kodihalli017e45c2017-07-12 01:06:30 -0500109 */
Andrew Jefferyf96bd162018-02-26 13:05:00 +1030110int vpnor_copy_bootloader_partition(const struct mbox_context *context);
Deepak Kodihalli017e45c2017-07-12 01:06:30 -0500111
Deepak Kodihallib6a446f2017-04-29 13:01:49 -0500112/** @brief Destroy partition table, if it exists.
113 *
114 * @param[in] context - mbox context pointer
115 */
Deepak Kodihalli64ec3e42017-07-17 06:15:16 -0500116void destroy_vpnor(struct mbox_context *context);
Deepak Kodihallib6a446f2017-04-29 13:01:49 -0500117
118#ifdef __cplusplus
119}
120#endif
121
122#endif