blob: 3170c37269aa4ddc4b9d239b4c264c093b947f4b [file] [log] [blame]
Julius Werner1cd013b2019-12-11 16:50:02 -08001/* SPDX-License-Identifier: GPL-2.0-only */
2
3#ifndef _CBFS_GLUE_H_
4#define _CBFS_GLUE_H_
5
6#include <commonlib/region.h>
7#include <console/console.h>
Julius Wernerfdabf3f2020-05-06 17:06:35 -07008#include <rules.h>
Julius Werner1cd013b2019-12-11 16:50:02 -08009
Julius Wernerfdabf3f2020-05-06 17:06:35 -070010/*
11 * This flag prevents linking hashing functions into stages where they're not required. We don't
12 * need them at all if verification is disabled. If verification is enabled without TOCTOU
13 * safety, we only need to verify the metadata hash in the initial stage and can assume it stays
14 * valid in later stages. If TOCTOU safety is required, we may need them in every stage to
15 * reverify metadata that had to be reloaded from flash (e.g. because it didn't fit the mcache).
16 * Note that this only concerns metadata hashing -- file access functions may still link hashing
17 * routines independently for file data hashing.
18 */
19#define CBFS_ENABLE_HASHING (CONFIG(CBFS_VERIFICATION) && \
20 (CONFIG(TOCTOU_SAFETY) || ENV_INITIAL_STAGE))
Julius Werner1cd013b2019-12-11 16:50:02 -080021
22#define ERROR(...) printk(BIOS_ERR, "CBFS ERROR: " __VA_ARGS__)
Wim Vervoorne48bd3a2021-04-01 10:23:13 +020023#define LOG(...) printk(BIOS_INFO, "CBFS: " __VA_ARGS__)
Julius Werner1cd013b2019-12-11 16:50:02 -080024#define DEBUG(...) do { \
25 if (CONFIG(DEBUG_CBFS)) \
26 printk(BIOS_SPEW, "CBFS DEBUG: " __VA_ARGS__); \
27} while (0)
28
29typedef const struct region_device *cbfs_dev_t;
30
31static inline ssize_t cbfs_dev_read(cbfs_dev_t dev, void *buffer, size_t offset, size_t size)
32{
33 return rdev_readat(dev, buffer, offset, size);
34}
35
36static inline size_t cbfs_dev_size(cbfs_dev_t dev)
37{
38 return region_device_sz(dev);
39}
40
41#endif /* _CBFS_GLUE_H_ */