Coverage Report

Created: 2026-10-17 06:38

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/barebox/include/firmware.h
Line
Count
Source
1
/* SPDX-License-Identifier: GPL-2.0-only */
2
/*
3
 * Copyright (c) 2013 Juergen Beisert <kernel@pengutronix.de>, Pengutronix
4
 */
5
6
#ifndef FIRMWARE_H
7
#define FIRMWARE_H
8
9
#include <pbl.h>
10
#include <printf.h>
11
#include <types.h>
12
#include <driver.h>
13
#include <debug_ll.h>
14
#include <linux/kernel.h>
15
#include <asm/sections.h>
16
#include <crypto/sha.h>
17
#include <crypto.h>
18
19
struct firmware {
20
  size_t size;
21
  const u8 *data;
22
};
23
24
struct firmware_handler {
25
  char *id; /* unique identifier for this firmware device */
26
  char *model; /* description for this device */
27
  struct device *dev;
28
  void *priv;
29
  struct device_node *device_node;
30
  /* called once to prepare the firmware's programming cycle */
31
  int (*open)(struct firmware_handler*);
32
  /* called multiple times to program the firmware with the given data */
33
  int (*write)(struct firmware_handler*, const void*, size_t);
34
  /* called once to finish programming cycle */
35
  int (*close)(struct firmware_handler*);
36
};
37
38
struct firmware_mgr;
39
40
int firmwaremgr_register(struct firmware_handler *);
41
42
struct firmware_mgr *firmwaremgr_find(const char *);
43
#ifdef CONFIG_FIRMWARE
44
struct firmware_mgr *firmwaremgr_find_by_node(struct device_node *np);
45
int firmwaremgr_load_file(struct firmware_mgr *, const char *path);
46
char *firmware_get_searchpath(void);
47
void firmware_set_searchpath(const char *path);
48
int request_firmware(const struct firmware **fw, const char *fw_name, struct device *dev);
49
void release_firmware(const struct firmware *fw);
50
#else
51
static inline struct firmware_mgr *firmwaremgr_find_by_node(struct device_node *np)
52
{
53
  return NULL;
54
}
55
56
static inline int firmwaremgr_load_file(struct firmware_mgr *mgr, const char *path)
57
{
58
  return -ENOSYS;
59
}
60
61
static inline char *firmware_get_searchpath(void)
62
{
63
  return NULL;
64
}
65
66
static inline void firmware_set_searchpath(const char *path)
67
{
68
}
69
70
static inline int request_firmware(const struct firmware **fw, const char *fw_name,
71
           struct device *dev)
72
{
73
  return -EINVAL;
74
}
75
76
static inline void release_firmware(const struct firmware *fw)
77
{
78
}
79
#endif
80
81
void firmwaremgr_list_handlers(void);
82
83
static inline void firmware_ext_verify(const void *data_start, size_t data_size,
84
               const void *hash_start, size_t hash_size)
85
0
{
86
0
  if (pbl_barebox_verify(data_start, data_size,
87
0
             hash_start, hash_size) != 0) {
88
0
    putc_ll('!');
89
0
    panic("hash mismatch, refusing to decompress");
90
0
  }
91
0
}
Unexecuted instantiation: firmware.c:firmware_ext_verify
Unexecuted instantiation: of_firmware.c:firmware_ext_verify
Unexecuted instantiation: bfetch.c:firmware_ext_verify
Unexecuted instantiation: of_overlay.c:firmware_ext_verify
92
93
struct fwobj {
94
  size_t size;
95
  size_t uncompressed_size;
96
  void *data;
97
};
98
99
#define __get_builtin_firmware(name, offset, fwobj)     \
100
  do {                \
101
    extern char _fw_##name##_start[];     \
102
    extern char _fw_##name##_end[];       \
103
    extern char _fw_##name##_sha_start[];     \
104
    extern char _fw_##name##_sha_end[];     \
105
    (fwobj)->data = _fw_##name##_start;     \
106
    (fwobj)->size = _fw_##name##_end - _fw_##name##_start;  \
107
    if (!(offset))            \
108
      break;            \
109
    (fwobj)->data += (offset);        \
110
    firmware_ext_verify(          \
111
      (fwobj)->data, (fwobj)->size,     \
112
      _fw_##name##_sha_start,       \
113
      _fw_##name##_sha_end - _fw_##name##_sha_start \
114
    );              \
115
  } while (0)
116
117
118
#define get_builtin_firmware(name, fwobj) \
119
  __get_builtin_firmware(name, 0, fwobj)
120
121
#define get_builtin_firmware_ext(name, base, fwobj)     \
122
  __get_builtin_firmware(name, (long)base - (long)_text, fwobj)
123
124
int fwobj_uncompress(struct fwobj *fwobj, void *dest);
125
126
#define get_builtin_firmware_compressed(name, fwobj)      \
127
  do {                \
128
    extern char _fw_z_##name##_start[];     \
129
    extern char _fw_z_##name##_end[];     \
130
    extern char _fw_z_##name##_uncompressed_size[];   \
131
    (fwobj)->data = _fw_z_##name##_start;     \
132
    (fwobj)->size = _fw_z_##name##_end - _fw_z_##name##_start;\
133
    (fwobj)->uncompressed_size =        \
134
      (size_t)_fw_z_##name##_uncompressed_size; \
135
  } while (0)
136
137
static inline int firmware_next_image_check_sha256(const void *hash, bool verbose)
138
0
{
139
0
  extern char _fw_next_image_bin_sha_start[];
140
0
  int hsize = SHA256_DIGEST_SIZE;
141
0
  int ret;
142
0
143
0
  if (!IS_ENABLED(CONFIG_FIRMWARE_NEXT_IMAGE))
144
0
    return -EINVAL;
145
0
146
0
  ret = crypto_memneq(hash, _fw_next_image_bin_sha_start, hsize);
147
0
148
0
  if (verbose) {
149
0
    if (ret) {
150
0
      pr_err("next image hash mismatch!\n");
151
0
      pr_err("expected: sha256=%*phN\n", hsize, _fw_next_image_bin_sha_start);
152
0
      pr_err("found:    sha256=%*phN\n", hsize, hash);
153
0
    } else {
154
0
      pr_info("hash sha256=%*phN OK\n", hsize, _fw_next_image_bin_sha_start);
155
0
    }
156
0
  }
157
0
158
0
  return ret;
159
0
}
Unexecuted instantiation: firmware.c:firmware_next_image_check_sha256
Unexecuted instantiation: of_firmware.c:firmware_next_image_check_sha256
Unexecuted instantiation: bfetch.c:firmware_next_image_check_sha256
Unexecuted instantiation: of_overlay.c:firmware_next_image_check_sha256
160
161
#endif /* FIRMWARE_H */