1 /* SPDX-License-Identifier: BSD-3-Clause */ 2 3 #ifndef _CBFS_CBFS_GLUE_H 4 #define _CBFS_CBFS_GLUE_H 5 6 #include <libpayload-config.h> 7 #include <boot_device.h> 8 #include <stdbool.h> 9 #include <stdio.h> 10 11 #define CBFS_ENABLE_HASHING CONFIG(LP_CBFS_VERIFICATION) 12 #define CBFS_HASH_HWCRYPTO cbfs_hwcrypto_allowed() 13 14 #define ERROR(...) printf("CBFS ERROR: " __VA_ARGS__) 15 #define LOG(...) printf("CBFS: " __VA_ARGS__) 16 #define DEBUG(...) \ 17 do { \ 18 if (CONFIG(LP_DEBUG_CBFS)) \ 19 printf("CBFS DEBUG: " __VA_ARGS__); \ 20 } while (0) 21 22 struct cbfs_dev { 23 size_t offset; 24 size_t size; 25 }; 26 27 struct cbfs_boot_device { 28 struct cbfs_dev dev; 29 void *mcache; 30 size_t mcache_size; 31 }; 32 33 typedef const struct cbfs_dev *cbfs_dev_t; 34 cbfs_dev_read(cbfs_dev_t dev,void * buffer,size_t offset,size_t size)35static inline ssize_t cbfs_dev_read(cbfs_dev_t dev, void *buffer, size_t offset, size_t size) 36 { 37 if (offset + size < offset || offset + size > dev->size) 38 return CB_ERR_ARG; 39 40 return boot_device_read(buffer, dev->offset + offset, size); 41 } 42 cbfs_dev_size(cbfs_dev_t dev)43static inline size_t cbfs_dev_size(cbfs_dev_t dev) 44 { 45 return dev->size; 46 } 47 48 bool cbfs_hwcrypto_allowed(void); 49 50 #endif /* _CBFS_CBFS_GLUE_H */ 51