ab_select.c 1.7 KB

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