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 <malloc.h> 9 10 static int do_rkimg_test(cmd_tbl_t *cmdtp, int flag, 11 int argc, char *const argv[]) 12 { 13 struct blk_desc *dev_desc; 14 u32 *buffer; 15 int ret; 16 17 if (argc != 3) 18 return CMD_RET_USAGE; 19 20 dev_desc = blk_get_dev(argv[1], simple_strtoul(argv[2], NULL, 16)); 21 if (!dev_desc) { 22 printf("%s: dev_desc is NULL!\n", __func__); 23 return CMD_RET_FAILURE; 24 } 25 26 /* read one block from beginning of IDB data */ 27 buffer = memalign(ARCH_DMA_MINALIGN, 1024); 28 ret = blk_dread(dev_desc, 64, 2, buffer); 29 if (ret != 2) { 30 printf("%s: Failed to read data from IDB\n", __func__); 31 free(buffer); 32 return CMD_RET_FAILURE; 33 } 34 35 if (buffer[0] == 0xFCDC8C3B) { 36 ret = CMD_RET_SUCCESS; 37 38 if (!strcmp("mmc", argv[1])) 39 printf("Found IDB in SDcard\n"); 40 else 41 printf("Found IDB in U-disk\n"); 42 43 /* TAG in IDB */ 44 if (0 == buffer[128 + 104 / 4]) { 45 if (!strcmp("mmc", argv[1])) 46 env_update("bootargs", "sdfwupdate"); 47 else 48 env_update("bootargs", "usbfwupdate"); 49 } 50 } else if (buffer[0] == 0x534e4b52 || buffer[0] == 0x534e5252) { 51 /* The 0x534e4b52 & 0x534e5252 are the new idb block header tag */ 52 ret = CMD_RET_SUCCESS; 53 } else { 54 ret = CMD_RET_FAILURE; 55 } 56 57 free(buffer); 58 59 return ret; 60 } 61 62 U_BOOT_CMD( 63 rkimgtest, 3, 0, do_rkimg_test, 64 "Test if storage media have rockchip image", 65 "<devtype> <devnum>" 66 ); 67