|
| 1 | +/** |
| 2 | + * @file image-ram-stage.h |
| 3 | + * @brief Whole-image RAM staging helpers (platform-independent) |
| 4 | + * |
| 5 | + * Copyright Northern.tech AS |
| 6 | + * |
| 7 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 | + * you may not use this file except in compliance with the License. |
| 9 | + * You may obtain a copy of the License at |
| 10 | + * |
| 11 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | + * |
| 13 | + * Unless required by applicable law or agreed to in writing, software |
| 14 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 15 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | + * See the License for the specific language governing permissions and |
| 17 | + * limitations under the License. |
| 18 | + */ |
| 19 | + |
| 20 | +#ifndef __MENDER_IMAGE_RAM_STAGE_PRIV_H__ |
| 21 | +#define __MENDER_IMAGE_RAM_STAGE_PRIV_H__ |
| 22 | + |
| 23 | +#ifdef __cplusplus |
| 24 | +extern "C" { |
| 25 | +#endif /* __cplusplus */ |
| 26 | + |
| 27 | +#include <stdbool.h> |
| 28 | +#include <stddef.h> |
| 29 | +#include <stdint.h> |
| 30 | + |
| 31 | +#include <mender/utils.h> |
| 32 | + |
| 33 | +typedef struct mender_image_ram_stage { |
| 34 | + uint8_t *buf; |
| 35 | + size_t capacity; |
| 36 | + size_t length; |
| 37 | +} mender_image_ram_stage_t; |
| 38 | + |
| 39 | +/** |
| 40 | + * @brief Try to allocate a staging buffer for @p size bytes |
| 41 | + * @param stage Staging state (must not be NULL) |
| 42 | + * @param size Artifact payload size |
| 43 | + * @param enabled When false, leave stage inactive (direct-to-flash) |
| 44 | + * @param max_size When > 0 and size > max_size, leave stage inactive |
| 45 | + * @return MENDER_OK always (inactive stage is a valid outcome); MENDER_FAIL on bad args |
| 46 | + * |
| 47 | + * Allocation uses mender_malloc. Failure to allocate leaves the stage inactive. |
| 48 | + */ |
| 49 | +mender_err_t mender_image_ram_stage_begin(mender_image_ram_stage_t *stage, size_t size, bool enabled, size_t max_size); |
| 50 | + |
| 51 | +bool mender_image_ram_stage_active(const mender_image_ram_stage_t *stage); |
| 52 | + |
| 53 | +/** |
| 54 | + * @brief Copy a download chunk into the staging buffer |
| 55 | + * @return MENDER_OK, or MENDER_FAIL on overflow / inactive stage / bad args |
| 56 | + */ |
| 57 | +mender_err_t mender_image_ram_stage_write(mender_image_ram_stage_t *stage, const void *data, size_t index, size_t length); |
| 58 | + |
| 59 | +/** Free staging buffer and clear state. */ |
| 60 | +void mender_image_ram_stage_reset(mender_image_ram_stage_t *stage); |
| 61 | + |
| 62 | +#ifdef __cplusplus |
| 63 | +} |
| 64 | +#endif /* __cplusplus */ |
| 65 | + |
| 66 | +#endif /* __MENDER_IMAGE_RAM_STAGE_PRIV_H__ */ |
0 commit comments