Andrew Jeffery | acee683 | 2018-02-21 22:17:08 +1030 | [diff] [blame^] | 1 | /* |
| 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 Kodihalli | b6a446f | 2017-04-29 13:01:49 -0500 | [diff] [blame] | 19 | #pragma once |
| 20 | |
| 21 | #ifdef VIRTUAL_PNOR_ENABLED |
| 22 | |
Ratan Gupta | 8441a39 | 2017-05-05 21:42:53 +0530 | [diff] [blame] | 23 | #include <limits.h> |
Deepak Kodihalli | b6a446f | 2017-04-29 13:01:49 -0500 | [diff] [blame] | 24 | #include "pnor_partition_defs.h" |
| 25 | |
| 26 | struct mbox_context; |
| 27 | struct vpnor_partition_table; |
| 28 | |
Ratan Gupta | 8441a39 | 2017-05-05 21:42:53 +0530 | [diff] [blame] | 29 | struct vpnor_partition_paths |
| 30 | { |
| 31 | char ro_loc[PATH_MAX]; |
Ratan Gupta | c0ef987 | 2017-06-06 14:31:37 +0530 | [diff] [blame] | 32 | char rw_loc[PATH_MAX]; |
| 33 | char prsv_loc[PATH_MAX]; |
Adriana Kobylak | c71dfd7 | 2017-07-22 11:10:43 -0500 | [diff] [blame] | 34 | char patch_loc[PATH_MAX]; |
Ratan Gupta | 8441a39 | 2017-05-05 21:42:53 +0530 | [diff] [blame] | 35 | }; |
| 36 | |
Deepak Kodihalli | b6a446f | 2017-04-29 13:01:49 -0500 | [diff] [blame] | 37 | #ifdef __cplusplus |
| 38 | extern "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 Jeffery | f96bd16 | 2018-02-26 13:05:00 +1030 | [diff] [blame] | 48 | * |
| 49 | * Returns 0 if the call succeeds, else a negative error code. |
Deepak Kodihalli | b6a446f | 2017-04-29 13:01:49 -0500 | [diff] [blame] | 50 | */ |
Andrew Jeffery | f96bd16 | 2018-02-26 13:05:00 +1030 | [diff] [blame] | 51 | int init_vpnor(struct mbox_context *context); |
Deepak Kodihalli | b6a446f | 2017-04-29 13:01:49 -0500 | [diff] [blame] | 52 | |
Ratan Gupta | 3214b51 | 2017-05-11 08:58:19 +0530 | [diff] [blame] | 53 | /** @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 Jeffery | f96bd16 | 2018-02-26 13:05:00 +1030 | [diff] [blame] | 60 | * |
| 61 | * Returns 0 if the call succeeds, else a negative error code. |
Ratan Gupta | 3214b51 | 2017-05-11 08:58:19 +0530 | [diff] [blame] | 62 | */ |
| 63 | |
Andrew Jeffery | f96bd16 | 2018-02-26 13:05:00 +1030 | [diff] [blame] | 64 | int vpnor_create_partition_table_from_path(struct mbox_context *context, |
| 65 | const char* path); |
Ratan Gupta | 3214b51 | 2017-05-11 08:58:19 +0530 | [diff] [blame] | 66 | |
Deepak Kodihalli | b6a446f | 2017-04-29 13:01:49 -0500 | [diff] [blame] | 67 | |
| 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 | */ |
| 75 | size_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 | */ |
| 85 | const 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 | */ |
| 99 | const struct pnor_partition* vpnor_get_partition( |
| 100 | const struct mbox_context *context, |
| 101 | const size_t offset); |
| 102 | |
| 103 | |
Deepak Kodihalli | 017e45c | 2017-07-12 01:06:30 -0500 | [diff] [blame] | 104 | /** @brief Copy bootloader partition (alongwith TOC) to LPC memory |
| 105 | * |
| 106 | * @param[in] context - mbox context pointer |
Andrew Jeffery | f96bd16 | 2018-02-26 13:05:00 +1030 | [diff] [blame] | 107 | * |
| 108 | * @returns 0 on success, negative error code on failure |
Deepak Kodihalli | 017e45c | 2017-07-12 01:06:30 -0500 | [diff] [blame] | 109 | */ |
Andrew Jeffery | f96bd16 | 2018-02-26 13:05:00 +1030 | [diff] [blame] | 110 | int vpnor_copy_bootloader_partition(const struct mbox_context *context); |
Deepak Kodihalli | 017e45c | 2017-07-12 01:06:30 -0500 | [diff] [blame] | 111 | |
Deepak Kodihalli | b6a446f | 2017-04-29 13:01:49 -0500 | [diff] [blame] | 112 | /** @brief Destroy partition table, if it exists. |
| 113 | * |
| 114 | * @param[in] context - mbox context pointer |
| 115 | */ |
Deepak Kodihalli | 64ec3e4 | 2017-07-17 06:15:16 -0500 | [diff] [blame] | 116 | void destroy_vpnor(struct mbox_context *context); |
Deepak Kodihalli | b6a446f | 2017-04-29 13:01:49 -0500 | [diff] [blame] | 117 | |
| 118 | #ifdef __cplusplus |
| 119 | } |
| 120 | #endif |
| 121 | |
| 122 | #endif |