Blame view

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