ab_select.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. // SPDX-License-Identifier: BSD-2-Clause
  2. /*
  3. * Copyright (C) 2017 The Android Open Source Project
  4. */
  5. #include <common.h>
  6. #include <android_ab.h>
  7. #include <command.h>
  8. #include <env.h>
  9. #include <part.h>
  10. static int do_ab_select(struct cmd_tbl *cmdtp, int flag, int argc,
  11. char *const argv[])
  12. {
  13. int ret;
  14. struct blk_desc *dev_desc;
  15. struct disk_partition part_info;
  16. char slot[2];
  17. if (argc != 4)
  18. return CMD_RET_USAGE;
  19. /* Lookup the "misc" partition from argv[2] and argv[3] */
  20. if (part_get_info_by_dev_and_name_or_num(argv[2], argv[3],
  21. &dev_desc, &part_info,
  22. false) < 0) {
  23. return CMD_RET_FAILURE;
  24. }
  25. ret = ab_select_slot(dev_desc, &part_info);
  26. if (ret < 0) {
  27. printf("Android boot failed, error %d.\n", ret);
  28. return CMD_RET_FAILURE;
  29. }
  30. /* Android standard slot names are 'a', 'b', ... */
  31. slot[0] = BOOT_SLOT_NAME(ret);
  32. slot[1] = '\0';
  33. env_set(argv[1], slot);
  34. printf("ANDROID: Booting slot: %s\n", slot);
  35. return CMD_RET_SUCCESS;
  36. }
  37. U_BOOT_CMD(ab_select, 4, 0, do_ab_select,
  38. "Select the slot used to boot from and register the boot attempt.",
  39. "<slot_var_name> <interface> <dev[:part|#part_name]>\n"
  40. " - Load the slot metadata from the partition 'part' on\n"
  41. " device type 'interface' instance 'dev' and store the active\n"
  42. " slot in the 'slot_var_name' variable. This also updates the\n"
  43. " Android slot metadata with a boot attempt, which can cause\n"
  44. " successive calls to this function to return a different result\n"
  45. " if the returned slot runs out of boot attempts.\n"
  46. " - If 'part_name' is passed, preceded with a # instead of :, the\n"
  47. " partition name whose label is 'part_name' will be looked up in\n"
  48. " the partition table. This is commonly the \"misc\" partition.\n"
  49. );