blob: cd5c3b64773b0b3250ea4b055964ccd3650bb07b [file] [log] [blame]
Sughosh Ganu2eaedc92022-10-21 18:15:55 +05301// SPDX-License-Identifier: GPL-2.0-or-later
2/*
3 * Copyright (c) 2022, Linaro Limited
4 */
5
6#include <dm.h>
Sughosh Ganu7e9814c2022-10-21 18:16:02 +05307#include <efi.h>
Sughosh Ganu2eaedc92022-10-21 18:15:55 +05308#include <efi_loader.h>
Sughosh Ganu7e9814c2022-10-21 18:16:02 +05309#include <efi_variable.h>
10#include <event.h>
Sughosh Ganu2eaedc92022-10-21 18:15:55 +053011#include <fwu.h>
12#include <fwu_mdata.h>
Sughosh Ganu7e9814c2022-10-21 18:16:02 +053013#include <malloc.h>
14
15#include <linux/errno.h>
16#include <linux/types.h>
17
Jassi Brar167994f2023-03-06 17:18:28 -060018#include <u-boot/crc.h>
19
20static struct fwu_mdata g_mdata; /* = {0} makes uninit crc32 always invalid */
21static struct udevice *g_dev;
Sughosh Ganu7e9814c2022-10-21 18:16:02 +053022static u8 in_trial;
23static u8 boottime_check;
Sughosh Ganu2eaedc92022-10-21 18:15:55 +053024
Sughosh Ganu2eaedc92022-10-21 18:15:55 +053025enum {
26 IMAGE_ACCEPT_SET = 1,
27 IMAGE_ACCEPT_CLEAR,
28};
29
30enum {
31 PRIMARY_PART = 1,
32 SECONDARY_PART,
33 BOTH_PARTS,
34};
35
Sughosh Ganu7e9814c2022-10-21 18:16:02 +053036static int trial_counter_update(u16 *trial_state_ctr)
37{
38 bool delete;
39 u32 var_attr;
40 efi_status_t status;
41 efi_uintn_t var_size;
42
43 delete = !trial_state_ctr ? true : false;
44 var_size = !trial_state_ctr ? 0 : (efi_uintn_t)sizeof(*trial_state_ctr);
45 var_attr = !trial_state_ctr ? 0 : EFI_VARIABLE_NON_VOLATILE |
46 EFI_VARIABLE_BOOTSERVICE_ACCESS;
47 status = efi_set_variable_int(u"TrialStateCtr",
48 &efi_global_variable_guid,
49 var_attr,
50 var_size, trial_state_ctr, false);
51
52 if ((delete && (status != EFI_NOT_FOUND &&
53 status != EFI_SUCCESS)) ||
54 (!delete && status != EFI_SUCCESS))
55 return -1;
56
57 return 0;
58}
59
60static int trial_counter_read(u16 *trial_state_ctr)
61{
62 efi_status_t status;
63 efi_uintn_t var_size;
64
65 var_size = (efi_uintn_t)sizeof(trial_state_ctr);
66 status = efi_get_variable_int(u"TrialStateCtr",
67 &efi_global_variable_guid,
68 NULL,
69 &var_size, trial_state_ctr,
70 NULL);
71 if (status != EFI_SUCCESS) {
72 log_err("Unable to read TrialStateCtr variable\n");
73 return -1;
74 }
75
76 return 0;
77}
78
79static int fwu_trial_count_update(void)
80{
81 int ret;
82 u16 trial_state_ctr;
83
84 ret = trial_counter_read(&trial_state_ctr);
85 if (ret) {
86 log_debug("Unable to read trial_state_ctr\n");
87 goto out;
88 }
89
90 ++trial_state_ctr;
91 if (trial_state_ctr > CONFIG_FWU_TRIAL_STATE_CNT) {
92 log_info("Trial State count exceeded. Revert back to previous_active_index\n");
93 ret = fwu_revert_boot_index();
94 if (ret)
95 log_err("Unable to revert active_index\n");
96 ret = 1;
97 } else {
98 ret = trial_counter_update(&trial_state_ctr);
99 if (ret)
100 log_err("Unable to increment TrialStateCtr variable\n");
101 }
102
103out:
104 return ret;
105}
106
107static int in_trial_state(struct fwu_mdata *mdata)
108{
109 u32 i, active_bank;
110 struct fwu_image_entry *img_entry;
111 struct fwu_image_bank_info *img_bank_info;
112
113 active_bank = mdata->active_index;
114 img_entry = &mdata->img_entry[0];
115 for (i = 0; i < CONFIG_FWU_NUM_IMAGES_PER_BANK; i++) {
116 img_bank_info = &img_entry[i].img_bank_info[active_bank];
117 if (!img_bank_info->accepted) {
118 log_info("System booting in Trial State\n");
119 return 1;
120 }
121 }
122
123 return 0;
124}
125
Sughosh Ganu2eaedc92022-10-21 18:15:55 +0530126static int fwu_get_image_type_id(u8 *image_index, efi_guid_t *image_type_id)
127{
128 u8 index;
129 int i;
130 struct efi_fw_image *image;
131
132 index = *image_index;
133 image = update_info.images;
Masahisa Kojimacccea182023-06-07 14:41:51 +0900134 for (i = 0; i < update_info.num_images; i++) {
Sughosh Ganu2eaedc92022-10-21 18:15:55 +0530135 if (index == image[i].image_index) {
136 guidcpy(image_type_id, &image[i].image_type_id);
137 return 0;
138 }
139 }
140
141 return -ENOENT;
142}
143
144/**
Jassi Brar167994f2023-03-06 17:18:28 -0600145 * fwu_sync_mdata() - Update given meta-data partition(s) with the copy provided
146 * @mdata: FWU metadata structure
147 * @part: Bitmask of FWU metadata partitions to be written to
148 *
149 * Return: 0 if OK, -ve on error
150 */
151static int fwu_sync_mdata(struct fwu_mdata *mdata, int part)
152{
153 void *buf = &mdata->version;
154 int err;
155
156 if (part == BOTH_PARTS) {
157 err = fwu_sync_mdata(mdata, SECONDARY_PART);
158 if (err)
159 return err;
160 part = PRIMARY_PART;
161 }
162
163 /*
164 * Calculate the crc32 for the updated FWU metadata
165 * and put the updated value in the FWU metadata crc32
166 * field
167 */
168 mdata->crc32 = crc32(0, buf, sizeof(*mdata) - sizeof(u32));
169
170 err = fwu_write_mdata(g_dev, mdata, part == PRIMARY_PART);
171 if (err) {
172 log_err("Unable to write %s mdata\n",
173 part == PRIMARY_PART ? "primary" : "secondary");
174 return err;
175 }
176
177 /* update the cached copy of meta-data */
178 memcpy(&g_mdata, mdata, sizeof(struct fwu_mdata));
179
180 return 0;
181}
182
183static inline int mdata_crc_check(struct fwu_mdata *mdata)
184{
185 void *buf = &mdata->version;
186 u32 calc_crc32 = crc32(0, buf, sizeof(*mdata) - sizeof(u32));
187
188 return calc_crc32 == mdata->crc32 ? 0 : -EINVAL;
189}
190
191/**
Jassi Brar1e917a62023-03-06 17:18:48 -0600192 * fwu_get_mdata() - Read, verify and return the FWU metadata
Jassi Brar167994f2023-03-06 17:18:28 -0600193 * @mdata: Output FWU metadata read or NULL
194 *
195 * Read both the metadata copies from the storage media, verify their checksum,
196 * and ascertain that both copies match. If one of the copies has gone bad,
197 * restore it from the good copy.
198 *
199 * Return: 0 if OK, -ve on error
200 */
Jassi Brar1e917a62023-03-06 17:18:48 -0600201int fwu_get_mdata(struct fwu_mdata *mdata)
Jassi Brar167994f2023-03-06 17:18:28 -0600202{
203 int err;
204 bool parts_ok[2] = { false };
205 struct fwu_mdata s, *parts_mdata[2];
206
207 parts_mdata[0] = &g_mdata;
208 parts_mdata[1] = &s;
209
210 /* if mdata already read and ready */
211 err = mdata_crc_check(parts_mdata[0]);
212 if (!err)
213 goto ret_mdata;
214 /* else read, verify and, if needed, fix mdata */
215
216 for (int i = 0; i < 2; i++) {
217 parts_ok[i] = false;
218 err = fwu_read_mdata(g_dev, parts_mdata[i], !i);
219 if (!err) {
220 err = mdata_crc_check(parts_mdata[i]);
221 if (!err)
222 parts_ok[i] = true;
223 else
224 log_debug("mdata : %s crc32 failed\n", i ? "secondary" : "primary");
225 }
226 }
227
228 if (parts_ok[0] && parts_ok[1]) {
229 /*
230 * Before returning, check that both the
231 * FWU metadata copies are the same.
232 */
233 err = memcmp(parts_mdata[0], parts_mdata[1], sizeof(struct fwu_mdata));
234 if (!err)
235 goto ret_mdata;
236
237 /*
238 * If not, populate the secondary partition from the
239 * primary partition copy.
240 */
241 log_info("Both FWU metadata copies are valid but do not match.");
242 log_info(" Restoring the secondary partition from the primary\n");
243 parts_ok[1] = false;
244 }
245
246 for (int i = 0; i < 2; i++) {
247 if (parts_ok[i])
248 continue;
249
250 memcpy(parts_mdata[i], parts_mdata[1 - i], sizeof(struct fwu_mdata));
251 err = fwu_sync_mdata(parts_mdata[i], i ? SECONDARY_PART : PRIMARY_PART);
252 if (err) {
253 log_debug("mdata : %s write failed\n", i ? "secondary" : "primary");
254 return err;
255 }
256 }
257
258ret_mdata:
259 if (!err && mdata)
260 memcpy(mdata, parts_mdata[0], sizeof(struct fwu_mdata));
261
262 return err;
263}
264
265/**
Sughosh Ganu2eaedc92022-10-21 18:15:55 +0530266 * fwu_get_active_index() - Get active_index from the FWU metadata
267 * @active_idx: active_index value to be read
268 *
269 * Read the active_index field from the FWU metadata and place it in
270 * the variable pointed to be the function argument.
271 *
272 * Return: 0 if OK, -ve on error
273 *
274 */
275int fwu_get_active_index(uint *active_idx)
276{
Jassi Brar246ec2a2023-03-06 17:18:41 -0600277 int ret = 0;
278 struct fwu_mdata *mdata = &g_mdata;
Sughosh Ganu2eaedc92022-10-21 18:15:55 +0530279
280 /*
281 * Found the FWU metadata partition, now read the active_index
282 * value
283 */
Jassi Brar246ec2a2023-03-06 17:18:41 -0600284 *active_idx = mdata->active_index;
Sughosh Ganu2eaedc92022-10-21 18:15:55 +0530285 if (*active_idx >= CONFIG_FWU_NUM_BANKS) {
286 log_debug("Active index value read is incorrect\n");
287 ret = -EINVAL;
288 }
289
290 return ret;
291}
292
293/**
294 * fwu_set_active_index() - Set active_index in the FWU metadata
295 * @active_idx: active_index value to be set
296 *
297 * Update the active_index field in the FWU metadata
298 *
299 * Return: 0 if OK, -ve on error
300 *
301 */
302int fwu_set_active_index(uint active_idx)
303{
304 int ret;
Jassi Brar246ec2a2023-03-06 17:18:41 -0600305 struct fwu_mdata *mdata = &g_mdata;
Sughosh Ganu2eaedc92022-10-21 18:15:55 +0530306
307 if (active_idx >= CONFIG_FWU_NUM_BANKS) {
308 log_debug("Invalid active index value\n");
309 return -EINVAL;
310 }
311
Sughosh Ganu2eaedc92022-10-21 18:15:55 +0530312 /*
313 * Update the active index and previous_active_index fields
314 * in the FWU metadata
315 */
Jassi Brar246ec2a2023-03-06 17:18:41 -0600316 mdata->previous_active_index = mdata->active_index;
317 mdata->active_index = active_idx;
Sughosh Ganu2eaedc92022-10-21 18:15:55 +0530318
319 /*
320 * Now write this updated FWU metadata to both the
321 * FWU metadata partitions
322 */
Jassi Brar246ec2a2023-03-06 17:18:41 -0600323 ret = fwu_sync_mdata(mdata, BOTH_PARTS);
Sughosh Ganu2eaedc92022-10-21 18:15:55 +0530324 if (ret) {
325 log_debug("Failed to update FWU metadata partitions\n");
326 ret = -EIO;
327 }
328
329 return ret;
330}
331
332/**
333 * fwu_get_image_index() - Get the Image Index to be used for capsule update
334 * @image_index: The Image Index for the image
335 *
336 * The FWU multi bank update feature computes the value of image_index at
337 * runtime, based on the bank to which the image needs to be written to.
338 * Derive the image_index value for the image.
339 *
340 * Currently, the capsule update driver uses the DFU framework for
341 * the updates. This function gets the DFU alt number which is to
342 * be used as the Image Index
343 *
344 * Return: 0 if OK, -ve on error
345 *
346 */
347int fwu_get_image_index(u8 *image_index)
348{
349 int ret, i;
350 u8 alt_num;
351 uint update_bank;
352 efi_guid_t *image_guid, image_type_id;
Jassi Brar246ec2a2023-03-06 17:18:41 -0600353 struct fwu_mdata *mdata = &g_mdata;
Sughosh Ganu2eaedc92022-10-21 18:15:55 +0530354 struct fwu_image_entry *img_entry;
355 struct fwu_image_bank_info *img_bank_info;
356
Sughosh Ganu2eaedc92022-10-21 18:15:55 +0530357 ret = fwu_plat_get_update_index(&update_bank);
358 if (ret) {
359 log_debug("Failed to get the FWU update bank\n");
360 goto out;
361 }
362
363 ret = fwu_get_image_type_id(image_index, &image_type_id);
364 if (ret) {
365 log_debug("Unable to get image_type_id for image_index %u\n",
366 *image_index);
367 goto out;
368 }
369
370 ret = -EINVAL;
371 /*
372 * The FWU metadata has been read. Now get the image_uuid for the
373 * image with the update_bank.
374 */
375 for (i = 0; i < CONFIG_FWU_NUM_IMAGES_PER_BANK; i++) {
376 if (!guidcmp(&image_type_id,
Jassi Brar246ec2a2023-03-06 17:18:41 -0600377 &mdata->img_entry[i].image_type_uuid)) {
378 img_entry = &mdata->img_entry[i];
Sughosh Ganu2eaedc92022-10-21 18:15:55 +0530379 img_bank_info = &img_entry->img_bank_info[update_bank];
380 image_guid = &img_bank_info->image_uuid;
Jassi Brar246ec2a2023-03-06 17:18:41 -0600381 ret = fwu_plat_get_alt_num(g_dev, image_guid, &alt_num);
Sughosh Ganu2eaedc92022-10-21 18:15:55 +0530382 if (ret) {
383 log_debug("alt_num not found for partition with GUID %pUs\n",
384 image_guid);
385 } else {
386 log_debug("alt_num %d for partition %pUs\n",
387 alt_num, image_guid);
388 *image_index = alt_num + 1;
389 }
390
391 goto out;
392 }
393 }
394
Jassi Brar167994f2023-03-06 17:18:28 -0600395 log_err("Partition with the image type %pUs not found\n",
396 &image_type_id);
Sughosh Ganu2eaedc92022-10-21 18:15:55 +0530397
398out:
399 return ret;
400}
401
402/**
403 * fwu_revert_boot_index() - Revert the active index in the FWU metadata
404 *
405 * Revert the active_index value in the FWU metadata, by swapping the values
406 * of active_index and previous_active_index in both copies of the
407 * FWU metadata.
408 *
409 * Return: 0 if OK, -ve on error
410 *
411 */
412int fwu_revert_boot_index(void)
413{
414 int ret;
415 u32 cur_active_index;
Jassi Brar246ec2a2023-03-06 17:18:41 -0600416 struct fwu_mdata *mdata = &g_mdata;
Sughosh Ganu2eaedc92022-10-21 18:15:55 +0530417
418 /*
419 * Swap the active index and previous_active_index fields
420 * in the FWU metadata
421 */
Jassi Brar246ec2a2023-03-06 17:18:41 -0600422 cur_active_index = mdata->active_index;
423 mdata->active_index = mdata->previous_active_index;
424 mdata->previous_active_index = cur_active_index;
Sughosh Ganu2eaedc92022-10-21 18:15:55 +0530425
426 /*
427 * Now write this updated FWU metadata to both the
428 * FWU metadata partitions
429 */
Jassi Brar246ec2a2023-03-06 17:18:41 -0600430 ret = fwu_sync_mdata(mdata, BOTH_PARTS);
Sughosh Ganu2eaedc92022-10-21 18:15:55 +0530431 if (ret) {
432 log_debug("Failed to update FWU metadata partitions\n");
433 ret = -EIO;
434 }
435
436 return ret;
437}
438
439/**
440 * fwu_clrset_image_accept() - Set or Clear the Acceptance bit for the image
441 * @img_type_id: GUID of the image type for which the accepted bit is to be
442 * set or cleared
443 * @bank: Bank of which the image's Accept bit is to be set or cleared
444 * @action: Action which specifies whether image's Accept bit is to be set or
445 * cleared
446 *
447 * Set/Clear the accepted bit for the image specified by the img_guid parameter.
448 * This indicates acceptance or rejection of image for subsequent boots by some
449 * governing component like OS(or firmware).
450 *
451 * Return: 0 if OK, -ve on error
452 *
453 */
454static int fwu_clrset_image_accept(efi_guid_t *img_type_id, u32 bank, u8 action)
455{
456 int ret, i;
Jassi Brar246ec2a2023-03-06 17:18:41 -0600457 struct fwu_mdata *mdata = &g_mdata;
Sughosh Ganu2eaedc92022-10-21 18:15:55 +0530458 struct fwu_image_entry *img_entry;
459 struct fwu_image_bank_info *img_bank_info;
460
Jassi Brar246ec2a2023-03-06 17:18:41 -0600461 img_entry = &mdata->img_entry[0];
Sughosh Ganu2eaedc92022-10-21 18:15:55 +0530462 for (i = 0; i < CONFIG_FWU_NUM_IMAGES_PER_BANK; i++) {
463 if (!guidcmp(&img_entry[i].image_type_uuid, img_type_id)) {
464 img_bank_info = &img_entry[i].img_bank_info[bank];
465 if (action == IMAGE_ACCEPT_SET)
466 img_bank_info->accepted |= FWU_IMAGE_ACCEPTED;
467 else
468 img_bank_info->accepted = 0;
469
Jassi Brar246ec2a2023-03-06 17:18:41 -0600470 ret = fwu_sync_mdata(mdata, BOTH_PARTS);
Sughosh Ganu2eaedc92022-10-21 18:15:55 +0530471 goto out;
472 }
473 }
474
475 /* Image not found */
476 ret = -ENOENT;
477
478out:
479 return ret;
480}
481
482/**
483 * fwu_accept_image() - Set the Acceptance bit for the image
484 * @img_type_id: GUID of the image type for which the accepted bit is to be
485 * cleared
486 * @bank: Bank of which the image's Accept bit is to be set
487 *
488 * Set the accepted bit for the image specified by the img_guid parameter. This
489 * indicates acceptance of image for subsequent boots by some governing component
490 * like OS(or firmware).
491 *
492 * Return: 0 if OK, -ve on error
493 *
494 */
495int fwu_accept_image(efi_guid_t *img_type_id, u32 bank)
496{
497 return fwu_clrset_image_accept(img_type_id, bank,
498 IMAGE_ACCEPT_SET);
499}
500
501/**
502 * fwu_clear_accept_image() - Clear the Acceptance bit for the image
503 * @img_type_id: GUID of the image type for which the accepted bit is to be
504 * cleared
505 * @bank: Bank of which the image's Accept bit is to be cleared
506 *
507 * Clear the accepted bit for the image type specified by the img_type_id parameter.
508 * This function is called after the image has been updated. The accepted bit is
509 * cleared to be set subsequently after passing the image acceptance criteria, by
510 * either the OS(or firmware)
511 *
512 * Return: 0 if OK, -ve on error
513 *
514 */
515int fwu_clear_accept_image(efi_guid_t *img_type_id, u32 bank)
516{
517 return fwu_clrset_image_accept(img_type_id, bank,
518 IMAGE_ACCEPT_CLEAR);
519}
Sughosh Ganu7d6e2c52022-10-21 18:15:59 +0530520
521/**
522 * fwu_plat_get_update_index() - Get the value of the update bank
523 * @update_idx: Bank number to which images are to be updated
524 *
525 * Get the value of the bank(partition) to which the update needs to be
526 * made.
527 *
528 * Note: This is a weak function and platforms can override this with
529 * their own implementation for selection of the update bank.
530 *
531 * Return: 0 if OK, -ve on error
532 *
533 */
534__weak int fwu_plat_get_update_index(uint *update_idx)
535{
536 int ret;
537 u32 active_idx;
538
539 ret = fwu_get_active_index(&active_idx);
540 if (ret < 0)
541 return -1;
542
543 *update_idx = (active_idx + 1) % CONFIG_FWU_NUM_BANKS;
544
545 return ret;
546}
Sughosh Ganu7e9814c2022-10-21 18:16:02 +0530547
548/**
Jassi Brara7e45412023-05-31 00:30:06 -0500549 * fwu_plat_get_bootidx() - Get the value of the boot index
550 * @boot_idx: Boot index value
551 *
552 * Get the value of the bank(partition) from which the platform
553 * has booted. This value is passed to U-Boot from the earlier
554 * stage bootloader which loads and boots all the relevant
555 * firmware images
556 */
557__weak void fwu_plat_get_bootidx(uint *boot_idx)
558{
559 int ret;
560
561 ret = fwu_get_active_index(boot_idx);
562 if (ret < 0)
563 *boot_idx = 0; /* Dummy value */
564}
565
566/**
Sughosh Ganu7e9814c2022-10-21 18:16:02 +0530567 * fwu_update_checks_pass() - Check if FWU update can be done
568 *
569 * Check if the FWU update can be executed. The updates are
570 * allowed only when the platform is not in Trial State and
571 * the boot time checks have passed
572 *
573 * Return: 1 if OK, 0 if checks do not pass
574 *
575 */
576u8 fwu_update_checks_pass(void)
577{
578 return !in_trial && boottime_check;
579}
580
581/**
582 * fwu_empty_capsule_checks_pass() - Check if empty capsule can be processed
583 *
584 * Check if the empty capsule can be processed to either accept or revert
585 * an earlier executed update. The empty capsules need to be processed
586 * only when the platform is in Trial State and the boot time checks have
587 * passed
588 *
589 * Return: 1 if OK, 0 if not to be allowed
590 *
591 */
592u8 fwu_empty_capsule_checks_pass(void)
593{
594 return in_trial && boottime_check;
595}
596
Sughosh Ganu86794052022-10-21 18:16:03 +0530597/**
598 * fwu_trial_state_ctr_start() - Start the Trial State counter
599 *
600 * Start the counter to identify the platform booting in the
601 * Trial State. The counter is implemented as an EFI variable.
602 *
603 * Return: 0 if OK, -ve on error
604 *
605 */
606int fwu_trial_state_ctr_start(void)
607{
608 int ret;
609 u16 trial_state_ctr;
610
611 trial_state_ctr = 0;
612 ret = trial_counter_update(&trial_state_ctr);
613 if (ret)
614 log_err("Unable to initialise TrialStateCtr\n");
615
616 return ret;
617}
618
Sughosh Ganu7e9814c2022-10-21 18:16:02 +0530619static int fwu_boottime_checks(void *ctx, struct event *event)
620{
621 int ret;
622 u32 boot_idx, active_idx;
Sughosh Ganu7e9814c2022-10-21 18:16:02 +0530623
Sughosh Ganu873cf8a2022-10-21 18:16:05 +0530624 /* Don't have boot time checks on sandbox */
625 if (IS_ENABLED(CONFIG_SANDBOX)) {
626 boottime_check = 1;
627 return 0;
628 }
629
Jassi Brar246ec2a2023-03-06 17:18:41 -0600630 ret = uclass_first_device_err(UCLASS_FWU_MDATA, &g_dev);
631 if (ret) {
632 log_debug("Cannot find fwu device\n");
633 return ret;
634 }
635
Jassi Brar1e917a62023-03-06 17:18:48 -0600636 ret = fwu_get_mdata(NULL);
Jassi Brar246ec2a2023-03-06 17:18:41 -0600637 if (ret) {
638 log_debug("Unable to read meta-data\n");
639 return ret;
640 }
Sughosh Ganu7e9814c2022-10-21 18:16:02 +0530641
642 /*
643 * Get the Boot Index, i.e. the bank from
644 * which the platform has booted. This value
645 * gets passed from the ealier stage bootloader
646 * which booted u-boot, e.g. tf-a. If the
647 * boot index is not the same as the
648 * active_index read from the FWU metadata,
649 * update the active_index.
650 */
651 fwu_plat_get_bootidx(&boot_idx);
652 if (boot_idx >= CONFIG_FWU_NUM_BANKS) {
653 log_err("Received incorrect value of boot_index\n");
654 return 0;
655 }
656
657 ret = fwu_get_active_index(&active_idx);
658 if (ret) {
659 log_err("Unable to read active_index\n");
660 return 0;
661 }
662
663 if (boot_idx != active_idx) {
664 log_info("Boot idx %u is not matching active idx %u, changing active_idx\n",
665 boot_idx, active_idx);
666 ret = fwu_set_active_index(boot_idx);
667 if (!ret)
668 boottime_check = 1;
669
670 return 0;
671 }
672
673 if (efi_init_obj_list() != EFI_SUCCESS)
674 return 0;
675
Jassi Brar246ec2a2023-03-06 17:18:41 -0600676 in_trial = in_trial_state(&g_mdata);
Sughosh Ganu7e9814c2022-10-21 18:16:02 +0530677 if (!in_trial || (ret = fwu_trial_count_update()) > 0)
678 ret = trial_counter_update(NULL);
679
680 if (!ret)
681 boottime_check = 1;
682
683 return 0;
684}
685EVENT_SPY(EVT_MAIN_LOOP, fwu_boottime_checks);