"Das U-Boot" Source Tree

cmd: avb: rework do_avb_verify_part

Use existing str_avb_slot_error() function for obtaining
verification fail reason details.
Take into account device lock state for setting correct
androidboot.verifiedbootstate kernel cmdline parameter.

Reviewed-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>
Signed-off-by: Igor Opaniuk <igor.opaniuk@gmail.com>
Link: https://lore.kernel.org/r/20240209192045.3961832-7-igor.opaniuk@foundries.io
Signed-off-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>

authored by

Igor Opaniuk and committed by
Mattijs Korpershoek
df3cfcee fc7ef0f9

+17 -33
+17 -33
cmd/avb.c
··· 250 250 const char * const requested_partitions[] = {"boot", NULL}; 251 251 AvbSlotVerifyResult slot_result; 252 252 AvbSlotVerifyData *out_data; 253 + enum avb_boot_state boot_state; 253 254 char *cmdline; 254 255 char *extra_args; 255 256 char *slot_suffix = ""; ··· 287 288 AVB_HASHTREE_ERROR_MODE_RESTART_AND_INVALIDATE, 288 289 &out_data); 289 290 290 - switch (slot_result) { 291 - case AVB_SLOT_VERIFY_RESULT_OK: 292 - /* Until we don't have support of changing unlock states, we 293 - * assume that we are by default in locked state. 294 - * So in this case we can boot only when verification is 295 - * successful; we also supply in cmdline GREEN boot state 296 - */ 291 + /* 292 + * LOCKED devices with custom root of trust setup is not supported (YELLOW) 293 + */ 294 + if (slot_result == AVB_SLOT_VERIFY_RESULT_OK) { 297 295 printf("Verification passed successfully\n"); 298 296 299 - /* export additional bootargs to AVB_BOOTARGS env var */ 297 + /* 298 + * ORANGE state indicates that device may be freely modified. 299 + * Device integrity is left to the user to verify out-of-band. 300 + */ 301 + if (unlocked) 302 + boot_state = AVB_ORANGE; 303 + else 304 + boot_state = AVB_GREEN; 300 305 301 - extra_args = avb_set_state(avb_ops, AVB_GREEN); 306 + /* export boot state to AVB_BOOTARGS env var */ 307 + extra_args = avb_set_state(avb_ops, boot_state); 302 308 if (extra_args) 303 309 cmdline = append_cmd_line(out_data->cmdline, 304 310 extra_args); ··· 308 314 env_set(AVB_BOOTARGS, cmdline); 309 315 310 316 res = CMD_RET_SUCCESS; 311 - break; 312 - case AVB_SLOT_VERIFY_RESULT_ERROR_VERIFICATION: 313 - printf("Verification failed\n"); 314 - break; 315 - case AVB_SLOT_VERIFY_RESULT_ERROR_IO: 316 - printf("I/O error occurred during verification\n"); 317 - break; 318 - case AVB_SLOT_VERIFY_RESULT_ERROR_OOM: 319 - printf("OOM error occurred during verification\n"); 320 - break; 321 - case AVB_SLOT_VERIFY_RESULT_ERROR_INVALID_METADATA: 322 - printf("Corrupted dm-verity metadata detected\n"); 323 - break; 324 - case AVB_SLOT_VERIFY_RESULT_ERROR_UNSUPPORTED_VERSION: 325 - printf("Unsupported version of avbtool was used\n"); 326 - break; 327 - case AVB_SLOT_VERIFY_RESULT_ERROR_ROLLBACK_INDEX: 328 - printf("Rollback index check failed\n"); 329 - break; 330 - case AVB_SLOT_VERIFY_RESULT_ERROR_PUBLIC_KEY_REJECTED: 331 - printf("Public key was rejected\n"); 332 - break; 333 - default: 334 - printf("Unknown error occurred\n"); 317 + } else { 318 + printf("Verification failed, reason: %s\n", str_avb_slot_error(slot_result)); 335 319 } 336 320 337 321 if (out_data)