• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2016 The Android Open Source Project
3  *
4  * SPDX-License-Identifier: BSD-2-Clause
5  */
6 
7 #include <android_bootloader.h>
8 #include <android_cmds.h>
9 #include <common.h>
10 #include <command.h>
11 
do_boot_android(cmd_tbl_t * cmdtp,int flag,int argc,char * const argv[])12 static int do_boot_android(cmd_tbl_t *cmdtp, int flag, int argc,
13 			   char * const argv[])
14 {
15 	unsigned long load_address;
16 	int ret = CMD_RET_SUCCESS;
17 	char *addr_arg_endp, *addr_str;
18 	struct blk_desc *dev_desc;
19 	disk_partition_t part_info;
20 
21 	if (argc < 4)
22 		return CMD_RET_USAGE;
23 	if (argc > 5)
24 		return CMD_RET_USAGE;
25 
26 	if (argc >= 5) {
27 		load_address = simple_strtoul(argv[4], &addr_arg_endp, 16);
28 		if (addr_arg_endp == argv[4] || *addr_arg_endp != '\0')
29 			return CMD_RET_USAGE;
30 	} else {
31 		addr_str = env_get("loadaddr");
32 		if (addr_str)
33 			load_address = simple_strtoul(addr_str, NULL, 16);
34 		else
35 			load_address = CONFIG_SYS_LOAD_ADDR;
36 	}
37 
38 	if (part_get_info_by_dev_and_name_or_num(argv[1], argv[2],
39 						 &dev_desc, &part_info) < 0) {
40 		return CMD_RET_FAILURE;
41 	}
42 
43 	ret = android_bootloader_boot_flow(dev_desc, &part_info, argv[3],
44 					   load_address);
45 	if (ret < 0) {
46 		printf("Android boot failed, error %d.\n", ret);
47 		return CMD_RET_FAILURE;
48 	}
49 	return CMD_RET_SUCCESS;
50 }
51 
52 U_BOOT_CMD(
53 	boot_android, 5, 0, do_boot_android,
54 	"Execute the Android Bootloader flow.",
55 	"<interface> <dev[:part|;part_name]> <slot> [<kernel_addr>]\n"
56 	"    - Load the Boot Control Block (BCB) from the partition 'part' on\n"
57 	"      device type 'interface' instance 'dev' to determine the boot\n"
58 	"      mode, and load and execute the appropriate kernel.\n"
59 	"      In normal and recovery mode, the kernel will be loaded from\n"
60 	"      the corresponding \"boot\" partition. In bootloader mode, the\n"
61 	"      command defined in the \"fastbootcmd\" variable will be\n"
62 	"      executed.\n"
63 	"      On Android devices with multiple slots, the pass 'slot' is\n"
64 	"      used to load the appropriate kernel. The standard slot names\n"
65 	"      are 'a' and 'b'.\n"
66 	"    - If 'part_name' is passed, preceded with a ; instead of :, the\n"
67 	"      partition name whose label is 'part_name' will be looked up in\n"
68 	"      the partition table. This is commonly the \"misc\" partition.\n"
69 );
70