ldrinfo.c 4.73 KB
Newer Older
1
/*
Bin Meng's avatar
Bin Meng committed
2
 * U-Boot - ldrinfo
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 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192
 *
 * Copyright (c) 2010 Analog Devices Inc.
 *
 * See file CREDITS for list of people who contributed to this
 * project.
 *
 * Licensed under the GPL-2 or later.
 */

#include <config.h>
#include <common.h>
#include <command.h>

#include <asm/blackfin.h>
#include <asm/mach-common/bits/bootrom.h>

static uint32_t ldrinfo_header(const void *addr)
{
	uint32_t skip = 0;

#if defined(__ADSPBF561__)
	/* BF56x has a 4 byte global header */
	uint32_t header, sign;
	static const char * const spi_speed[] = {
		"500K", "1M", "2M", "??",
	};

	memcpy(&header, addr, sizeof(header));

	sign = (header & GFLAG_56X_SIGN_MASK) >> GFLAG_56X_SIGN_SHIFT;
	printf("Header: %08X ( %s-bit-flash wait:%i hold:%i spi:%s %s)\n",
		header,
		(header & GFLAG_56X_16BIT_FLASH) ? "16" : "8",
		(header & GFLAG_56X_WAIT_MASK) >> GFLAG_56X_WAIT_SHIFT,
		(header & GFLAG_56X_HOLD_MASK) >> GFLAG_56X_HOLD_SHIFT,
		spi_speed[(header & GFLAG_56X_SPI_MASK) >> GFLAG_56X_SPI_SHIFT],
		sign == GFLAG_56X_SIGN_MAGIC ? "" : "!!hdrsign!! ");

	skip = 4;
#endif

	    /* |Block @ 12345678: 12345678 12345678 12345678 12345678 | */
#if defined(__ADSPBF531__) || defined(__ADSPBF532__) || defined(__ADSPBF533__) || \
    defined(__ADSPBF534__) || defined(__ADSPBF536__) || defined(__ADSPBF537__) || \
    defined(__ADSPBF538__) || defined(__ADSPBF539__) || defined(__ADSPBF561__)
	printf("                  Address  Count    Flags\n");
#else
	printf("                  BCode    Address  Count    Argument\n");
#endif

	return skip;
}

struct ldr_flag {
	uint16_t flag;
	const char *desc;
};

static uint32_t ldrinfo_block(const void *base_addr)
{
	uint32_t count;

	printf("Block @ %08X: ", (uint32_t)base_addr);

#if defined(__ADSPBF531__) || defined(__ADSPBF532__) || defined(__ADSPBF533__) || \
    defined(__ADSPBF534__) || defined(__ADSPBF536__) || defined(__ADSPBF537__) || \
    defined(__ADSPBF538__) || defined(__ADSPBF539__) || defined(__ADSPBF561__)

	uint32_t addr, pval;
	uint16_t flags;
	int i;
	static const struct ldr_flag ldr_flags[] = {
		{ BFLAG_53X_ZEROFILL,    "zerofill"  },
		{ BFLAG_53X_RESVECT,     "resvect"   },
		{ BFLAG_53X_INIT,        "init"      },
		{ BFLAG_53X_IGNORE,      "ignore"    },
		{ BFLAG_53X_COMPRESSED,  "compressed"},
		{ BFLAG_53X_FINAL,       "final"     },
	};

	memcpy(&addr, base_addr, sizeof(addr));
	memcpy(&count, base_addr+4, sizeof(count));
	memcpy(&flags, base_addr+8, sizeof(flags));

	printf("%08X %08X %04X ( ", addr, count, flags);

	for (i = 0; i < ARRAY_SIZE(ldr_flags); ++i)
		if (flags & ldr_flags[i].flag)
			printf("%s ", ldr_flags[i].desc);

	pval = (flags & BFLAG_53X_PFLAG_MASK) >> BFLAG_53X_PFLAG_SHIFT;
	if (pval)
		printf("gpio%i ", pval);
	pval = (flags & BFLAG_53X_PPORT_MASK) >> BFLAG_53X_PPORT_SHIFT;
	if (pval)
		printf("port%c ", 'e' + pval);

	if (flags & BFLAG_53X_ZEROFILL)
		count = 0;
	if (flags & BFLAG_53X_FINAL)
		count = 0;
	else
		count += sizeof(addr) + sizeof(count) + sizeof(flags);

#else

	const uint8_t *raw8 = base_addr;
	uint32_t bcode, addr, arg, sign, chk;
	int i;
	static const struct ldr_flag ldr_flags[] = {
		{ BFLAG_SAFE,        "safe"      },
		{ BFLAG_AUX,         "aux"       },
		{ BFLAG_FILL,        "fill"      },
		{ BFLAG_QUICKBOOT,   "quickboot" },
		{ BFLAG_CALLBACK,    "callback"  },
		{ BFLAG_INIT,        "init"      },
		{ BFLAG_IGNORE,      "ignore"    },
		{ BFLAG_INDIRECT,    "indirect"  },
		{ BFLAG_FIRST,       "first"     },
		{ BFLAG_FINAL,       "final"     },
	};

	memcpy(&bcode, base_addr, sizeof(bcode));
	memcpy(&addr, base_addr+4, sizeof(addr));
	memcpy(&count, base_addr+8, sizeof(count));
	memcpy(&arg, base_addr+12, sizeof(arg));

	printf("%08X %08X %08X %08X ( ", bcode, addr, count, arg);

	if (addr % 4)
		printf("!!addralgn!! ");
	if (count % 4)
		printf("!!cntalgn!! ");

	sign = (bcode & BFLAG_HDRSIGN_MASK) >> BFLAG_HDRSIGN_SHIFT;
	if (sign != BFLAG_HDRSIGN_MAGIC)
		printf("!!hdrsign!! ");

	chk = 0;
	for (i = 0; i < 16; ++i)
		chk ^= raw8[i];
	if (chk)
		printf("!!hdrchk!! ");

	printf("dma:%i ", bcode & BFLAG_DMACODE_MASK);

	for (i = 0; i < ARRAY_SIZE(ldr_flags); ++i)
		if (bcode & ldr_flags[i].flag)
			printf("%s ", ldr_flags[i].desc);

	if (bcode & BFLAG_FILL)
		count = 0;
	if (bcode & BFLAG_FINAL)
		count = 0;
	else
		count += sizeof(bcode) + sizeof(addr) + sizeof(count) + sizeof(arg);

#endif

	printf(")\n");

	return count;
}

static int do_ldrinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
	const void *addr;
	uint32_t skip;

	/* Get the address */
	if (argc < 2)
		addr = (void *)load_addr;
	else
		addr = (void *)simple_strtoul(argv[1], NULL, 16);

	/* Walk the LDR */
	addr += ldrinfo_header(addr);
	do {
		skip = ldrinfo_block(addr);
		addr += skip;
	} while (skip);

	return 0;
}

U_BOOT_CMD(
	ldrinfo, 2, 0, do_ldrinfo,
	"validate ldr image in memory",
	"[addr]\n"
);