Loading...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 | // SPDX-License-Identifier: GPL-2.0+ /* * Utility functions * * Copyright 2025 Canonical Ltd * Written by Simon Glass <simon.glass@canonical.com> */ #define LOG_CATEGORY UCLASS_BOOTCTL #include <alist.h> #include <bootctl.h> #include <dm.h> #include <log.h> #include <stdarg.h> #include <vsprintf.h> #include <bootctl/logic.h> #include <bootctl/measure.h> #include <bootctl/oslist.h> #include <bootctl/state.h> #include <bootctl/ui.h> #include <bootctl/util.h> /** * bc_printf() - Print a string to the display * * @fmt: printf() format string for log record * @...: Optional parameters, according to the format string @fmt * Return: Number of characters emitted */ int bc_printf(struct udevice *disp, const char *fmt, ...) { struct bc_ui_ops *ops = bc_ui_get_ops(disp); char buf[CONFIG_SYS_CBSIZE]; va_list args; int count; int ret; va_start(args, fmt); count = vsnprintf(buf, sizeof(buf), fmt, args); va_end(args); ret = ops->print(disp, buf); if (ret) return log_msg_ret("bpp", ret); return count; } int bc_ui_show(struct udevice *disp) { struct bc_ui_ops *ops = bc_ui_get_ops(disp); int ret; ret = ops->show(disp); if (ret) return log_msg_ret("bds", ret); return 0; } int bc_ui_add(struct udevice *dev, struct osinfo *info) { struct bc_ui_ops *ops = bc_ui_get_ops(dev); int ret; ret = ops->add(dev, info); if (ret) return log_msg_ret("bda", ret); return 0; } int bc_ui_render(struct udevice *disp) { struct bc_ui_ops *ops = bc_ui_get_ops(disp); int ret; ret = ops->render(disp); if (ret) return log_msg_ret("bds", ret); return 0; } int bc_ui_poll(struct udevice *disp, int *seqp, bool *selectedp) { struct bc_ui_ops *ops = bc_ui_get_ops(disp); int ret; ret = ops->poll(disp, seqp, selectedp); if (ret) return log_msg_ret("bdp", ret); return ret; } void bc_oslist_setup_iter(struct oslist_iter *iter) { memset(iter, '\0', sizeof(struct oslist_iter)); } int bc_oslist_next(struct udevice *dev, struct oslist_iter *iter, struct osinfo *info) { struct bc_oslist_ops *ops = bc_oslist_get_ops(dev); int ret; log_debug("oslist flags %x\n", iter->bf_iter.flags); ret = ops->next(dev, iter, info); if (ret) return log_msg_ret("bon", ret); return 0; } int bc_state_load(struct udevice *dev) { struct bc_state_ops *ops = bc_state_get_ops(dev); int ret; ret = ops->load(dev); if (ret) return log_msg_ret("bsl", ret); return 0; } int bc_state_save(struct udevice *dev) { struct bc_state_ops *ops = bc_state_get_ops(dev); int ret; ret = ops->save(dev); if (ret) return log_msg_ret("bss", ret); return 0; } int bc_state_save_to_buf(struct udevice *dev, struct abuf *buf) { struct bc_state_ops *ops = bc_state_get_ops(dev); int ret; ret = ops->save_to_buf(dev, buf); if (ret) return log_msg_ret("bsb", ret); return 0; } int bc_state_clear(struct udevice *dev) { struct bc_state_ops *ops = bc_state_get_ops(dev); int ret; ret = ops->clear(dev); if (ret) return log_msg_ret("bsc", ret); return 0; } int bc_state_read_bool(struct udevice *dev, const char *key, bool *valp) { struct bc_state_ops *ops = bc_state_get_ops(dev); int ret; ret = ops->read_bool(dev, key, valp); if (ret) return log_msg_ret("srb", ret); return 0; } int bc_state_write_bool(struct udevice *dev, const char *key, bool val) { struct bc_state_ops *ops = bc_state_get_ops(dev); int ret; ret = ops->write_bool(dev, key, val); if (ret) return log_msg_ret("swb", ret); return 0; } int bc_state_read_int(struct udevice *dev, const char *key, long *valp) { struct bc_state_ops *ops = bc_state_get_ops(dev); int ret; ret = ops->read_int(dev, key, valp); if (ret) return log_msg_ret("sri", ret); return 0; } int bc_state_write_int(struct udevice *dev, const char *key, long val) { struct bc_state_ops *ops = bc_state_get_ops(dev); int ret; ret = ops->write_int(dev, key, val); if (ret) return log_msg_ret("swi", ret); return 0; } int bc_state_read_str(struct udevice *dev, const char *key, const char **valp) { struct bc_state_ops *ops = bc_state_get_ops(dev); int ret; ret = ops->read_str(dev, key, valp); if (ret) return log_msg_ret("srs", ret); return 0; } int bc_state_write_str(struct udevice *dev, const char *key, const char *val) { struct bc_state_ops *ops = bc_state_get_ops(dev); int ret; ret = ops->write_str(dev, key, val); if (ret) return log_msg_ret("sws", ret); return 0; } int bc_logic_prepare(struct udevice *dev) { struct bc_logic_ops *ops = bc_logic_get_ops(dev); int ret; ret = ops->prepare(dev); if (ret) return log_msg_ret("blp", ret); return 0; } int bc_logic_start(struct udevice *dev) { struct bc_logic_ops *ops = bc_logic_get_ops(dev); int ret; ret = ops->start(dev); if (ret) return log_msg_ret("bls", ret); return 0; } int bc_logic_poll(struct udevice *dev) { struct bc_logic_ops *ops = bc_logic_get_ops(dev); int ret; ret = ops->poll(dev); if (ret) return log_msg_ret("blP", ret); return 0; } int bc_measure_start(struct udevice *dev) { struct bc_measure_ops *ops = bc_measure_get_ops(dev); int ret; ret = ops->start(dev); if (ret) return log_msg_ret("blM", ret); return 0; } int bc_measure_process(struct udevice *dev, const struct osinfo *osinfo, struct alist *result) { struct bc_measure_ops *ops = bc_measure_get_ops(dev); int ret; alist_init_struct(result, struct measure_info); ret = ops->process(dev, osinfo, result); if (ret) return log_msg_ret("blm", ret); return 0; } void show_measures(struct alist *result) { struct measure_info *res; /* TODO: expand to show more info? */ printf("Measurement report:"); alist_for_each(res, result) printf(" %s", bootflow_img_type_name(res->img->type)); printf("\n"); } |