Commit 69d0544e authored by David Griffith's avatar David Griffith 💬

Move functionality of minipro-query-db into minipro itself.

Note that I have changed the "Just read the chip ID" flag from '-d' to '-D'.
parent 72e4f127
......@@ -37,10 +37,9 @@ ifeq ($(PKG_CONFIG),)
endif
COMMON_OBJECTS=byte_utils.o database.o minipro.o fuses.o easyconfig.o version.o
OBJECTS=$(COMMON_OBJECTS) main.o minipro-query-db.o
PROGS=minipro minipro-query-db
OBJECTS=$(COMMON_OBJECTS) main.o
PROGS=minipro
MINIPRO=minipro
MINIPRO_QUERY_DB=minipro-query-db
MINIPROHEX=miniprohex
TESTS=$(wildcard tests/test_*.c);
OBJCOPY=objcopy
......@@ -83,9 +82,6 @@ $(VERSION_STRINGS):
minipro: $(VERSION_HEADER) $(VERSION_STRINGS) $(COMMON_OBJECTS) main.o
$(CC) $(COMMON_OBJECTS) main.o $(LIBS) -o $(MINIPRO)
minipro-query-db: $(VERSION_HEADER) $(VERSION_STRINGS) $(COMMON_OBJECTS) minipro-query-db.o
$(CC) $(COMMON_OBJECTS) minipro-query-db.o $(LIBS) -o $(MINIPRO_QUERY_DB)
clean:
rm -f $(OBJECTS) $(PROGS)
rm -f version.h version.c version.o
......@@ -97,13 +93,11 @@ install:
mkdir -p $(BIN_INSTDIR)
mkdir -p $(MAN_INSTDIR)
cp $(MINIPRO) $(BIN_INSTDIR)/
cp $(MINIPRO_QUERY_DB) $(BIN_INSTDIR)/
cp $(MINIPROHEX) $(BIN_INSTDIR)/
cp man/minipro.1 $(MAN_INSTDIR)/
uninstall:
rm -f $(BIN_INSTDIR)/$(MINIPRO)
rm -f $(BIN_INSTDIR)/$(MINIPRO_QUERY_DB)
rm -f $(BIN_INSTDIR)/$(MINIPROHEX)
rm -f $(MAN_INSTDIR)/minipro.1
......
......@@ -5,7 +5,7 @@ _minipro () {
if [ "$prev" = "-p" ] && [ "$cur" != "" ]
then
TXT=$(minipro-query-db -s $cur)
TXT=$(minipro -L $cur)
COMPREPLY=( $(compgen -W '$TXT' -- ${cur}) )
return 0
fi
......@@ -26,17 +26,16 @@ _minipro () {
COMPREPLY=( $(compgen -W 'r -w -p -c -i' -- ${cur}) )
}
_minipro_query_db () {
_minipro () {
COMPREPLY=()
local cur="${COMP_WORDS[COMP_CWORD]}"
if [ "$cur" != "" ]
then
local cur="${COMP_WORDS[COMP_CWORD]}"
TXT=$(minipro-query-db -s $cur)
TXT=$(minipro -L $cur)
COMPREPLY=( $(compgen -W '$TXT' -- ${cur}) )
return 0
fi
}
complete -F _minipro minipro
complete -F _minipro_query_db minipro-query-db
......@@ -64,9 +64,11 @@ void print_help_and_exit(char *progname, int rv) {
"Usage: %s [options]\n"
"options:\n"
" -l List all supported devices\n"
" -L <search> List devices beginning like this\n"
" -d <device> Show device information\n"
" -D Just read the chip ID\n"
" -r <filename> Read memory\n"
" -w <filename> Write memory\n"
" -d Just read the chip ID\n"
" -e Do NOT erase device\n"
" -u Do NOT disable write-protect\n"
" -P Do NOT enable write-protect\n"
......@@ -103,15 +105,83 @@ void print_devices_and_exit() {
exit(0);
}
void print_device_info_and_exit(device_t *device) {
printf("Name: %s\n", device->name);
/* Memory shape */
printf("Memory: %zu", device->code_memory_size / WORD_SIZE(device));
switch(device->opts4 & 0xFF000000) {
case 0x00000000:
printf(" Bytes");
break;
case 0x01000000:
printf(" Words");
break;
case 0x02000000:
printf(" Bits");
break;
default:
ERROR2("Unknown memory shape: 0x%x\n", device->opts4 & 0xFF000000);
}
if(device->data_memory_size) {
printf(" + %zu Bytes", device->data_memory_size);
}
if(device->data_memory2_size) {
printf(" + %zu Bytes", device->data_memory2_size);
}
printf("\n");
unsigned char package_details[4];
format_int(package_details, device->package_details, 4, MP_LITTLE_ENDIAN);
/* Package info */
printf("Package: ");
if(package_details[0]) {
printf("Adapter%03d.JPG\n", package_details[0]);
} else if(package_details[3]) {
printf("DIP%d\n", package_details[3] & 0x7F);
} else {
printf("ISP only\n");
}
/* ISP connection info */
printf("ISP: ");
if(package_details[1]) {
printf("ICP%03d.JPG\n", package_details[1]);
} else {
printf("-\n");
}
printf("Protocol: 0x%02x\n", device->protocol_id);
printf("Read buffer size: %zu Bytes\n", device->read_buffer_size);
printf("Write buffer size: %zu Bytes\n", device->write_buffer_size);
exit(0);
}
void parse_cmdline(int argc, char **argv) {
int8_t c;
memset(&cmdopts, 0, sizeof(cmdopts));
device_t *device;
while((c = getopt(argc, argv, "leuPvxyr:w:p:c:iIsSVhd")) != -1) {
while((c = getopt(argc, argv, "lL:d:euPvxyr:w:p:c:iIsSVhD")) != -1) {
switch(c) {
case 'l':
print_devices_and_exit();
break;
case 'L':
cmdopts.device = get_device_by_name(optarg);
for(device = &(devices[0]); device[0].name; device = &(device[1])) {
if(!strncasecmp(device[0].name, optarg, strlen(optarg))) {
printf("%s\n", device[0].name);
}
}
exit(0);
break;
case 'd':
cmdopts.device = get_device_by_name(optarg);
if (!cmdopts.device)
ERROR2("Unknown device: %s\n", optarg);
print_device_info_and_exit(cmdopts.device);
break;
case 'e':
cmdopts.no_erase=1; // 1= do not erase
break;
......@@ -177,7 +247,7 @@ void parse_cmdline(int argc, char **argv) {
cmdopts.size_error=1;
break;
case 'd':
case 'D':
cmdopts.idcheck_only = 1;
break;
......
.TH MINIPRO 1 "20 February 2014 (v0.1)" "Valentin Dudouyt"
.TH MINIPRO 1 "14 August 2018 (v0.3)"
.SH NAME
minipro \- programs various chips using the Minipro TL866XX series of programmers.
.SH SYNOPSIS
......@@ -29,6 +29,22 @@ chips.
.B \-l
Get a list of supported devices.
.TP
.B \-L <search>
List devices beginning with this string.
.TP
.B \-d <device>
Show device information.
.TP
.B \-D
Just read the chip ID and do nothing else (like reading the whole chip
contents). This is for use in scripts where you have for example
several similar chips with different IDs and want to check if the
currently inserted chip is one in your list of allowed ones. Also useful
to detect if a chip is inserted at all when using the -y option.
.TP
.B \-p <device>
Specify the device name. If the desired device name contains a space,
......
/*
* minipro-query-db.c - Standalone program to search the device database.
*
* This file is a part of Minipro.
*
* Minipro is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* Minipro is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include <unistd.h>
#include "minipro.h"
#include "byte_utils.h"
#include "database.h"
#include "error.h"
void print_help_and_exit(const char *progname) {
fprintf(stderr, "Usage: %s [-s search] [<device>]\n", progname);
exit(-1);
}
void print_device_info(device_t *device) {
printf("Name: %s\n", device->name);
/* Memory shape */
printf("Memory: %zu", device->code_memory_size / WORD_SIZE(device));
switch(device->opts4 & 0xFF000000) {
case 0x00000000:
printf(" Bytes");
break;
case 0x01000000:
printf(" Words");
break;
case 0x02000000:
printf(" Bits");
break;
default:
ERROR2("Unknown memory shape: 0x%x\n", device->opts4 & 0xFF000000);
}
if(device->data_memory_size) {
printf(" + %zu Bytes", device->data_memory_size);
}
if(device->data_memory2_size) {
printf(" + %zu Bytes", device->data_memory2_size);
}
printf("\n");
unsigned char package_details[4];
format_int(package_details, device->package_details, 4, MP_LITTLE_ENDIAN);
/* Package info */
printf("Package: ");
if(package_details[0]) {
printf("Adapter%03d.JPG\n", package_details[0]);
} else if(package_details[3]) {
printf("DIP%d\n", package_details[3] & 0x7F);
} else {
printf("ISP only\n");
}
/* ISP connection info */
printf("ISP: ");
if(package_details[1]) {
printf("ICP%03d.JPG\n", package_details[1]);
} else {
printf("-\n");
}
printf("Protocol: 0x%02x\n", device->protocol_id);
printf("Read buffer size: %zu Bytes\n", device->read_buffer_size);
printf("Write buffer size: %zu Bytes\n", device->write_buffer_size);
}
int main(int argc, char **argv) {
if(argc < 2) {
print_help_and_exit(argv[0]);
}
if(!strcmp(argv[1], "-s")) {
if(argc < 3) {
print_help_and_exit(argv[0]);
}
// Listing all devices that starts with argv[2]
device_t *device;
for(device = &(devices[0]); device[0].name; device = &(device[1])) {
if(!strncasecmp(device[0].name, argv[2], strlen(argv[2]))) {
printf("%s\n", device[0].name);
}
}
return(0);
}
device_t *device = get_device_by_name(argv[1]);
if(!device) {
ERROR("Unknown device");
}
print_device_info(device);
return(0);
}
......@@ -39,7 +39,6 @@ install -D -p -m 0644 bash_completion.d/minipro %{buildroot}/%{_sysconfdir}/bash
%license LICENSE
%doc README.md
%{_bindir}/minipro
%{_bindir}/minipro-query-db
%{_bindir}/miniprohex
%{_mandir}/man1/%{name}.*
%{_udevrulesdir}/80-minipro.rules
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment