mirror of
https://github.com/xboot/xrock.git
synced 2024-11-23 01:44:46 +08:00
[xrock]update some command
This commit is contained in:
parent
be89d0408e
commit
4f20c27a65
44
README.md
44
README.md
@ -56,28 +56,28 @@ For 32-bits windows, you can using `i686-w64-mingw32-` instead of `x86_64-w64-mi
|
||||
|
||||
```shell
|
||||
usage:
|
||||
xrock maskrom <ddr> <usbplug> [--rc4-off] - Initial chip using ddr and usbplug in maskrom mode
|
||||
xrock download <loader> - Initial chip using loader in maskrom mode
|
||||
xrock ready - Show chip ready or not
|
||||
xrock version - Show chip version
|
||||
xrock capability - Show capability information
|
||||
xrock reset [maskrom] - Reset chip to normal or maskrom mode
|
||||
xrock hexdump <address> <length> - Dump memory region in hex
|
||||
xrock dump <address> <length> - Binary memory dump to stdout
|
||||
xrock read <address> <length> <file> - Read memory to file
|
||||
xrock write <address> <file> - Write file to memory
|
||||
xrock exec <address> [dtb] - Call function address
|
||||
xrock otp <length> - Dump otp memory in hex
|
||||
xrock sn - Read serial number
|
||||
xrock sn <string> - Write serial number
|
||||
xrock vs read <index> <length> [type] - Read vendor storage
|
||||
xrock vs write <index> <string> [type] - Write vendor storage
|
||||
xrock storage - Read storage media list
|
||||
xrock storage <index> - Switch storage media and show list
|
||||
xrock flash - Detect flash and show information
|
||||
xrock flash erase <sector> <count> - Erase flash sector
|
||||
xrock flash read <sector> <count> <file> - Read flash sector to file
|
||||
xrock flash write <sector> <file> - Write file to flash sector
|
||||
xrock maskrom <ddr> <usbplug> [--rc4-off] - Initial chip using ddr and usbplug in maskrom mode
|
||||
xrock download <loader> - Initial chip using loader in maskrom mode
|
||||
xrock ready - Show chip ready or not
|
||||
xrock version - Show chip version
|
||||
xrock capability - Show capability information
|
||||
xrock reset [maskrom] - Reset chip to normal or maskrom mode
|
||||
xrock dump <address> <length> - Dump memory region in hex format
|
||||
xrock read <address> <length> <file> - Read memory to file
|
||||
xrock write <address> <file> - Write file to memory
|
||||
xrock exec <address> [dtb] - Call function address
|
||||
xrock otp <length> - Dump otp memory in hex format
|
||||
xrock sn - Read serial number
|
||||
xrock sn <string> - Write serial number
|
||||
xrock vs dump <index> <length> [type] - Dump vendor storage in hex format
|
||||
xrock vs read <index> <length> <file> [type] - Read vendor storage
|
||||
xrock vs write <index> <file> [type] - Write vendor storage
|
||||
xrock storage - Read storage media list
|
||||
xrock storage <index> - Switch storage media and show list
|
||||
xrock flash - Detect flash and show information
|
||||
xrock flash erase <sector> <count> - Erase flash sector
|
||||
xrock flash read <sector> <count> <file> - Read flash sector to file
|
||||
xrock flash write <sector> <file> - Write file to flash sector
|
||||
extra:
|
||||
xrock extra maskrom --rc4 <on|off> [--sram <file> --delay <ms>] [--dram <file> --delay <ms>] [...]
|
||||
```
|
||||
|
106
main.c
106
main.c
@ -20,28 +20,28 @@ static void usage(void)
|
||||
printf(" QQ: 8192542\r\n");
|
||||
|
||||
printf("usage:\r\n");
|
||||
printf(" xrock maskrom <ddr> <usbplug> [--rc4-off] - Initial chip using ddr and usbplug in maskrom mode\r\n");
|
||||
printf(" xrock download <loader> - Initial chip using loader in maskrom mode\r\n");
|
||||
printf(" xrock ready - Show chip ready or not\r\n");
|
||||
printf(" xrock version - Show chip version\r\n");
|
||||
printf(" xrock capability - Show capability information\r\n");
|
||||
printf(" xrock reset [maskrom] - Reset chip to normal or maskrom mode\n");
|
||||
printf(" xrock hexdump <address> <length> - Dump memory region in hex\r\n");
|
||||
printf(" xrock dump <address> <length> - Binary memory dump to stdout\r\n");
|
||||
printf(" xrock read <address> <length> <file> - Read memory to file\r\n");
|
||||
printf(" xrock write <address> <file> - Write file to memory\r\n");
|
||||
printf(" xrock exec <address> [dtb] - Call function address\r\n");
|
||||
printf(" xrock otp <length> - Dump otp memory in hex\r\n");
|
||||
printf(" xrock sn - Read serial number\r\n");
|
||||
printf(" xrock sn <string> - Write serial number\r\n");
|
||||
printf(" xrock vs read <index> <length> [type] - Read vendor storage\r\n");
|
||||
printf(" xrock vs write <index> <string> [type] - Write vendor storage\r\n");
|
||||
printf(" xrock storage - Read storage media list\r\n");
|
||||
printf(" xrock storage <index> - Switch storage media and show list\r\n");
|
||||
printf(" xrock flash - Detect flash and show information\r\n");
|
||||
printf(" xrock flash erase <sector> <count> - Erase flash sector\r\n");
|
||||
printf(" xrock flash read <sector> <count> <file> - Read flash sector to file\r\n");
|
||||
printf(" xrock flash write <sector> <file> - Write file to flash sector\r\n");
|
||||
printf(" xrock maskrom <ddr> <usbplug> [--rc4-off] - Initial chip using ddr and usbplug in maskrom mode\r\n");
|
||||
printf(" xrock download <loader> - Initial chip using loader in maskrom mode\r\n");
|
||||
printf(" xrock ready - Show chip ready or not\r\n");
|
||||
printf(" xrock version - Show chip version\r\n");
|
||||
printf(" xrock capability - Show capability information\r\n");
|
||||
printf(" xrock reset [maskrom] - Reset chip to normal or maskrom mode\n");
|
||||
printf(" xrock dump <address> <length> - Dump memory region in hex format\r\n");
|
||||
printf(" xrock read <address> <length> <file> - Read memory to file\r\n");
|
||||
printf(" xrock write <address> <file> - Write file to memory\r\n");
|
||||
printf(" xrock exec <address> [dtb] - Call function address\r\n");
|
||||
printf(" xrock otp <length> - Dump otp memory in hex format\r\n");
|
||||
printf(" xrock sn - Read serial number\r\n");
|
||||
printf(" xrock sn <string> - Write serial number\r\n");
|
||||
printf(" xrock vs dump <index> <length> [type] - Dump vendor storage in hex format\r\n");
|
||||
printf(" xrock vs read <index> <length> <file> [type] - Read vendor storage\r\n");
|
||||
printf(" xrock vs write <index> <file> [type] - Write vendor storage\r\n");
|
||||
printf(" xrock storage - Read storage media list\r\n");
|
||||
printf(" xrock storage <index> - Switch storage media and show list\r\n");
|
||||
printf(" xrock flash - Detect flash and show information\r\n");
|
||||
printf(" xrock flash erase <sector> <count> - Erase flash sector\r\n");
|
||||
printf(" xrock flash read <sector> <count> <file> - Read flash sector to file\r\n");
|
||||
printf(" xrock flash write <sector> <file> - Write file to flash sector\r\n");
|
||||
|
||||
printf("extra:\r\n");
|
||||
printf(" xrock extra maskrom --rc4 <on|off> [--sram <file> --delay <ms>] [--dram <file> --delay <ms>] [...]\r\n");
|
||||
@ -222,25 +222,6 @@ int main(int argc, char * argv[])
|
||||
else
|
||||
rock_reset(&ctx, 0);
|
||||
}
|
||||
else if(!strcmp(argv[1], "hexdump"))
|
||||
{
|
||||
argc -= 2;
|
||||
argv += 2;
|
||||
if(argc == 2)
|
||||
{
|
||||
uint32_t addr = strtoul(argv[0], NULL, 0);
|
||||
size_t len = strtoul(argv[1], NULL, 0);
|
||||
char * buf = malloc(len);
|
||||
if(buf)
|
||||
{
|
||||
rock_read(&ctx, addr, buf, len);
|
||||
hexdump(addr, buf, len);
|
||||
free(buf);
|
||||
}
|
||||
}
|
||||
else
|
||||
usage();
|
||||
}
|
||||
else if(!strcmp(argv[1], "dump"))
|
||||
{
|
||||
argc -= 2;
|
||||
@ -253,7 +234,7 @@ int main(int argc, char * argv[])
|
||||
if(buf)
|
||||
{
|
||||
rock_read(&ctx, addr, buf, len);
|
||||
fwrite(buf, len, 1, stdout);
|
||||
hexdump(addr, buf, len);
|
||||
free(buf);
|
||||
}
|
||||
}
|
||||
@ -374,10 +355,10 @@ int main(int argc, char * argv[])
|
||||
argv += 2;
|
||||
if(argc > 0)
|
||||
{
|
||||
if(!strcmp(argv[0], "read") && (argc >= 3))
|
||||
if(!strcmp(argv[0], "dump") && (argc >= 3))
|
||||
{
|
||||
int index = strtoul(argv[1], NULL, 0);
|
||||
int len = strtoul(argv[2], NULL, 0);
|
||||
int len = XMIN((int)strtoul(argv[2], NULL, 0), 512);
|
||||
int type = (argc == 4) ? strtoul(argv[3], NULL, 0) : 0;
|
||||
if(len > 0)
|
||||
{
|
||||
@ -390,26 +371,33 @@ int main(int argc, char * argv[])
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(!strcmp(argv[0], "read") && (argc >= 4))
|
||||
{
|
||||
int index = strtoul(argv[1], NULL, 0);
|
||||
int len = XMIN((int)strtoul(argv[2], NULL, 0), 512);
|
||||
int type = (argc == 5) ? strtoul(argv[4], NULL, 0) : 0;
|
||||
if(len > 0)
|
||||
{
|
||||
uint8_t * buf = malloc(len);
|
||||
if(buf)
|
||||
{
|
||||
if(rock_vs_read(&ctx, type, index, buf, len))
|
||||
file_save(argv[3], buf, len);
|
||||
free(buf);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(!strcmp(argv[0], "write") && (argc >= 3))
|
||||
{
|
||||
int index = strtoul(argv[1], NULL, 0);
|
||||
int type = (argc == 4) ? strtoul(argv[3], NULL, 0) : 0;
|
||||
int len = strlen(argv[2]);
|
||||
if(len > 0)
|
||||
uint64_t len;
|
||||
void * buf = file_load(argv[2], &len);
|
||||
if(buf && (len > 0))
|
||||
{
|
||||
uint8_t * buf = malloc(len + 8);
|
||||
if(buf)
|
||||
{
|
||||
memset(buf, 0, sizeof(len + 8));
|
||||
write_le32(&buf[0], 1);
|
||||
write_le32(&buf[4], len);
|
||||
memcpy(&buf[8], argv[2], len);
|
||||
if(rock_vs_write(&ctx, type, index, buf, len + 8))
|
||||
printf("Write vendor storage success\r\n");
|
||||
else
|
||||
printf("Failed to write vendor storage\r\n");
|
||||
free(buf);
|
||||
}
|
||||
if(!rock_vs_write(&ctx, type, index, buf, (len > 512) ? 512 : len))
|
||||
printf("Failed to write vendor storage\r\n");
|
||||
free(buf);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
10
misc.c
10
misc.c
@ -2,15 +2,21 @@
|
||||
|
||||
uint64_t file_save(const char * filename, void * buf, uint64_t len)
|
||||
{
|
||||
FILE * out = fopen(filename, "wb");
|
||||
FILE * out;
|
||||
int r;
|
||||
|
||||
if(strcmp(filename, "-") == 0)
|
||||
out = stdout;
|
||||
else
|
||||
out = fopen(filename, "wb");
|
||||
if(!out)
|
||||
{
|
||||
perror("Failed to open output file");
|
||||
exit(-1);
|
||||
}
|
||||
r = fwrite(buf, len, 1, out);
|
||||
fclose(out);
|
||||
if(out != stdout)
|
||||
fclose(out);
|
||||
return r;
|
||||
}
|
||||
|
||||
|
14
x.h
14
x.h
@ -149,8 +149,18 @@ static inline void write_be32(void * addr, uint32_t val)
|
||||
p[3] = (val >> 0) & 0xff;
|
||||
}
|
||||
|
||||
#define ARRAY_SIZE(array) (sizeof(array) / sizeof((array)[0]))
|
||||
#define X(...) ("" #__VA_ARGS__ "")
|
||||
#define XMAP(x, ia, ib, oa, ob) ((x - ia) * (ob - oa) / (ib - ia) + oa)
|
||||
#define XMIN(a, b) ({typeof(a) _amin = (a); typeof(b) _bmin = (b); (void)(&_amin == &_bmin); _amin < _bmin ? _amin : _bmin;})
|
||||
#define XMAX(a, b) ({typeof(a) _amax = (a); typeof(b) _bmax = (b); (void)(&_amax == &_bmax); _amax > _bmax ? _amax : _bmax;})
|
||||
#define XCLAMP(v, a, b) XMIN(XMAX(a, v), b)
|
||||
|
||||
#define XFLOOR(x) ((x) > 0 ? (int)(x) : (int)((x) - 0.9999999999))
|
||||
#define XROUND(x) ((x) > 0 ? (int)((x) + 0.5) : (int)((x) - 0.5))
|
||||
#define XCEIL(x) ((x) > 0 ? (int)((x) + 0.9999999999) : (int)(x))
|
||||
#define XDIV255(x) ((((int)(x) + 1) * 257) >> 16)
|
||||
|
||||
#define ARRAY_SIZE(array) (sizeof(array) / sizeof((array)[0]))
|
||||
#define X(...) ("" #__VA_ARGS__ "")
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user