.. | .. |
---|
319 | 319 | out: |
---|
320 | 320 | return ret; |
---|
321 | 321 | } |
---|
| 322 | + |
---|
| 323 | +/* |
---|
| 324 | + * If boot A/B system fail, tries-remaining decrease 1 |
---|
| 325 | + * and do reset automatically if still bootable. |
---|
| 326 | + */ |
---|
| 327 | +int spl_ab_decrease_reset(struct blk_desc *dev_desc) |
---|
| 328 | +{ |
---|
| 329 | + AvbABData ab_data; |
---|
| 330 | + int ret; |
---|
| 331 | + |
---|
| 332 | + ret = spl_ab_data_read(dev_desc, &ab_data, "misc"); |
---|
| 333 | + if (ret) |
---|
| 334 | + return ret; |
---|
| 335 | + |
---|
| 336 | + /* If current device cannot boot, return and try other devices. */ |
---|
| 337 | + if (!spl_slot_is_bootable(&ab_data.slots[0]) && |
---|
| 338 | + !spl_slot_is_bootable(&ab_data.slots[1])) { |
---|
| 339 | + printf("A/B: no bootable slot\n"); |
---|
| 340 | + return -ENODEV; |
---|
| 341 | + } |
---|
| 342 | + |
---|
| 343 | + /* If current device still can boot, decrease and do reset. */ |
---|
| 344 | + ret = spl_ab_decrease_tries(dev_desc); |
---|
| 345 | + if (ret) |
---|
| 346 | + return ret; |
---|
| 347 | + |
---|
| 348 | + printf("A/B: slot boot fail, do reset\n"); |
---|
| 349 | + do_reset(NULL, 0, 0, NULL); |
---|
| 350 | + |
---|
| 351 | + /* |
---|
| 352 | + * Only do_reset() fail will arrive here, return a |
---|
| 353 | + * negative number, then enter maskrom in the caller. |
---|
| 354 | + */ |
---|
| 355 | + return -EINVAL; |
---|
| 356 | +} |
---|