ab_select.c 1.7 KB

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