1 /* 2 * (C) Copyright 2019 Rockchip Electronics Co., Ltd 3 * 4 * SPDX-License-Identifier: GPL-2.0+ 5 */ 6 7 #include <common.h> 8 #include <android_image.h> 9 #include <blk.h> 10 #include <boot_rkimg.h> 11 #include <command.h> 12 #include <malloc.h> 13 14 static int do_android_print_hdr(cmd_tbl_t *cmdtp, int flag, 15 int argc, char * const argv[]) 16 { 17 struct blk_desc *dev_desc; 18 struct andr_img_hdr *hdr; 19 disk_partition_t part_info; 20 const char *part_name; 21 22 if (argc != 2) 23 return CMD_RET_USAGE; 24 25 part_name = argv[1]; 26 27 dev_desc = rockchip_get_bootdev(); 28 if (!dev_desc) { 29 printf("dev_desc is NULL!\n"); 30 return -ENODEV; 31 } 32 33 if (part_get_info_by_name(dev_desc, part_name, &part_info) < 0) { 34 printf("Failed to get \"%s\" part\n", part_name); 35 return -ENODEV; 36 } 37 38 hdr = populate_andr_img_hdr(dev_desc, &part_info); 39 if (!hdr) { 40 printf("Not an android image\n"); 41 return -EINVAL; 42 } else { 43 printf("Partition \"%s\"\n", part_info.name); 44 android_print_contents(hdr); 45 } 46 47 free(hdr); 48 49 return 0; 50 } 51 52 U_BOOT_CMD( 53 android_print_hdr, 2, 1, do_android_print_hdr, 54 "print android image header", "<partition name>" 55 ); 56