aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndy Green <andy.green@linaro.org>2013-05-06 10:06:14 +0800
committerAndy Green <andy.green@linaro.org>2013-05-06 10:06:14 +0800
commit1391180075c406c75b28602b8b0f0c2254bd89ae (patch)
tree3c979d31bc445532310bb19bad6ff06ca917b026
parent0b27ba9cb01680aec0b4fbc4e297d7597e54e829 (diff)
downloadarm-probe-1391180075c406c75b28602b8b0f0c2254bd89ae.tar.gz
convert to use by id
This patches changes the paths in the config to use /dev/serial/by-id, and introduces a new way to program AEP USB serial number so it can differentiate between multiple AEP reliably... see ./set-aep-serial.sh Signed-off-by: Andy Green <andy.green@linaro.org>
-rw-r--r--config18
-rwxr-xr-xlibarmep/configuration.c22
-rw-r--r--libarmep/libarmep.h8
-rw-r--r--libarmep/service.c43
-rwxr-xr-xset-aep-serial.sh37
5 files changed, 91 insertions, 37 deletions
diff --git a/config b/config
index ab395d1..2daed86 100644
--- a/config
+++ b/config
@@ -4,20 +4,20 @@
PandaBoardES-B1-ANDY
# <device path>
-/dev/ttyACM0
+/dev/serial/by-id/usb-NXP_SEMICOND_ARM_Energy_Probe_S_NO00000000-if00
VDD_VCORE1 0.220000 -14.500000 -0.009721 0.011774 -0.000311 0.000943 0 SoCVCORE1/MPU VBAT #ff0000 SoC
VDD_VCORE2 0.470000 -45.000000 -0.015710 0.007876 -0.002165 0.000874 0 SoCVCORE2/IVA\\_AUDIO VBAT #c00000 SoC
VDD_VCORE3 0.470000 -27.500000 -0.016074 0.002175 -0.000272 0.000625 0 SoCVCORE3/CORE VBAT #a00000 SoC
-/dev/ttyACM1
- VDD_1V8 0.470000 -8.000000 -0.004642 0.006818 -0.000242 0.000600 0 SoCVIO\\_1V8 VBAT #a0c0e0 SoC
- VDD_V2V1 0.470000 -38.000000 -0.016012 0.005433 -0.000305 0.000400 0 SoCVDD\\_V2V1/AUDIO VBAT #0000c0 SoC
- VDD_V1V29 0.470000 -38.000000 -0.016701 0.005867 -0.000262 0.000367 0 SoCV1V29/LPDDR2 VBAT #e0e000 SoC
+#/dev/serial/by-id/usb-NXP_SEMICOND_ARM_Energy_Probe_S_NO00010002-if00
+# VDD_1V8 0.470000 -8.000000 -0.004642 0.006818 -0.000242 0.000600 0 SoCVIO\\_1V8 VBAT #a0c0e0 SoC
+# VDD_V2V1 0.470000 -38.000000 -0.016012 0.005433 -0.000305 0.000400 0 SoCVDD\\_V2V1/AUDIO VBAT #0000c0 SoC
+# VDD_V1V29 0.470000 -38.000000 -0.016701 0.005867 -0.000262 0.000367 0 SoCV1V29/LPDDR2 VBAT #e0e000 SoC
-/dev/ttyACM2
- DC_IN 0.100000 -19.500000 -0.001628 0.003839 -0.000118 0.000288 0 DC\\_IN none #000000 -
- USBHUB 0.470000 -39.000000 -0.017226 0.003700 -0.000432 0.000263 0 USBHUB VBAT #e000e0 -
- VDD_3V3 0.470000 -51.000000 -0.018237 0.006000 -0.000625 0.000433 0 VDD\\_3V3 VBAT #0000ff -
+#/dev/ttyACM2
+# DC_IN 0.100000 -19.500000 -0.001628 0.003839 -0.000118 0.000288 0 DC\\_IN none #000000 -
+# USBHUB 0.470000 -39.000000 -0.017226 0.003700 -0.000432 0.000263 0 USBHUB VBAT #e000e0 -
+# VDD_3V3 0.470000 -51.000000 -0.018237 0.006000 -0.000625 0.000433 0 VDD\\_3V3 VBAT #0000ff -
#/dev/ttyACM3
# ch10 0.470000 -29.000000 -0.016016 0.004660 -0.000393 0.000545 0 ch10
diff --git a/libarmep/configuration.c b/libarmep/configuration.c
index f6eb9aa..98070cd 100755
--- a/libarmep/configuration.c
+++ b/libarmep/configuration.c
@@ -126,6 +126,7 @@ int configure(struct aep_context *aep_context, struct aep *aep, const char *dev_
};
enum parser parser = ACPP_FIRST;
enum parser entry_parser;
+ int stanza = -1;
int index = 0;
int copy_pos = 0;
int field = 0;
@@ -135,6 +136,8 @@ int configure(struct aep_context *aep_context, struct aep *aep, const char *dev_
char linebuf[1024];
int no_copy = 0;
int ret = 0;
+ int nope = 0;
+ int n;
if (wch) {
strncpy(temp_config, config_filepath, sizeof temp_config - 2);
@@ -156,6 +159,8 @@ int configure(struct aep_context *aep_context, struct aep *aep, const char *dev_
if (aep_context->count_virtual_channels >= MAX_VIRTUAL_CHANNELS)
return -1;
ch = &aep_context->vch[aep_context->count_virtual_channels];
+ for (n = 0; n < MAX_PROBES; n++)
+ aep_context->device_paths[n][0] = '\0';
}
if (fd < 0) {
@@ -227,19 +232,22 @@ int configure(struct aep_context *aep_context, struct aep *aep, const char *dev_
break;
case APCA_CHECK_DEVPATH:
if (entry_parser == ACPP_FIRST) {
+ copy_pos = 0;
+ nope = 0;
if (c != '/') {
if (c != '\n')
parser = ACPP_SKIP;
continue;
}
- copy_pos = 1;
+ aep_context->device_paths[stanza++][copy_pos++] = c;
+ aep_context->device_paths[stanza][copy_pos] = '\0';
actions = APCA_MATCH_DEVPATH;
}
break;
case APCA_MATCH_DEVPATH:
if (parser == ACPP_FIRST) {
- if (dev_filepath[copy_pos] != '\0') {
+ if (dev_filepath[copy_pos] != '\0' || nope) {
parser = ACPP_SKIP;
actions = APCA_CHECK_DEVPATH;
copy_pos = 0;
@@ -250,12 +258,10 @@ int configure(struct aep_context *aep_context, struct aep *aep, const char *dev_
no_copy = ch == wch;
break;
}
- if (dev_filepath[copy_pos++] != c) {
- parser = ACPP_SKIP;
- actions = APCA_CHECK_DEVPATH;
- copy_pos = 0;
- break;
- }
+ aep_context->device_paths[stanza][copy_pos] = c;
+ if (dev_filepath[copy_pos++] != c)
+ nope = 1;
+ aep_context->device_paths[stanza][copy_pos] = '\0';
break;
case APCA_PULL_CHANNELS:
diff --git a/libarmep/libarmep.h b/libarmep/libarmep.h
index dafbe04..10ca101 100644
--- a/libarmep/libarmep.h
+++ b/libarmep/libarmep.h
@@ -153,8 +153,8 @@ struct interp_tables {
struct aep_channel {
struct aep *aep;
- char channel_name[64];
- char channel_name_pretty[64];
+ char channel_name[256];
+ char channel_name_pretty[256];
char supply[64]; /* parent channel name */
char colour[16]; /* #xxxxxx HTML-style colour */
char class[16]; /* optional class of power, eg, Soc */
@@ -209,7 +209,7 @@ struct aep {
struct aep_context *aep_context;
int fd;
char name[64];
- char dev_filepath[64];
+ char dev_filepath[128];
int index;
int head;
int tail;
@@ -235,8 +235,10 @@ struct aep_context {
struct aep_channel vch[MAX_VIRTUAL_CHANNELS];
int count_virtual_channels;
int auto_zero;
+ unsigned int last_scan_sec;
char config_filepath[256];
char configuration_name[64];
+ char device_paths[MAX_PROBES][256];
int highest;
int decimate;
int no_correction;
diff --git a/libarmep/service.c b/libarmep/service.c
index 798e256..7d569c0 100644
--- a/libarmep/service.c
+++ b/libarmep/service.c
@@ -22,6 +22,7 @@
#include <linux/serial.h>
+
void add_pollfd(struct aep_context *aep_context, int fd, int events)
{
aep_context->pollfds[aep_context->count_pollfds].fd = fd;
@@ -174,7 +175,6 @@ int service_aeps(struct aep_context *aep_context, int fd_with_rx)
struct timeval tv;
unsigned char *p;
unsigned char c;
- char filepath[20];
struct termios tty;
struct serial_struct sinfo;
int n, m, i, chan;
@@ -187,26 +187,32 @@ int service_aeps(struct aep_context *aep_context, int fd_with_rx)
gettimeofday(&tv, NULL);
- /* look for any new devices appearing */
+ if (tv.tv_sec == aep_context->last_scan_sec)
+ goto bail;
+
+ aep_context->last_scan_sec = tv.tv_sec;
+
+ /* look for next device appearing */
+
+ if (!aep_context->device_paths[aep_context->scan][0])
+ goto bail;
if (aep_context->aeps[aep_context->scan].fd > 0)
goto bail;
- sprintf(filepath, "/dev/ttyACM%d", aep_context->scan);
- fd = open(filepath, O_RDWR | O_NONBLOCK | O_EXCL | O_NOCTTY);
+ fd = open(aep_context->device_paths[aep_context->scan], O_RDWR | O_NONBLOCK | O_EXCL | O_NOCTTY);
if (fd < 0)
goto bail;
if (ioctl(fd, TIOCEXCL) < 0) {
fprintf(stderr, "Wasn't able to open %s exclusive",
- filepath);
+ aep_context->device_paths[aep_context->scan]);
close(fd);
goto bail;
}
-
- fprintf(stderr, "+");
+ fprintf(stderr, "+ %s\n", aep_context->device_paths[aep_context->scan]);
tcflush(fd, TCIOFLUSH);
@@ -216,13 +222,13 @@ int service_aeps(struct aep_context *aep_context, int fd_with_rx)
}
if (aep_context->verbose)
- fprintf(stderr, "initing %s fd=%d\n", filepath, fd);
+ fprintf(stderr, "initing %s fd=%d\n", aep_context->device_paths[aep_context->scan], fd);
/* enforce suitable tty state */
memset (&tty, 0, sizeof tty);
if (tcgetattr (fd, &tty)) {
- fprintf(stderr, "tcgetattr failed on %s\n", filepath);
+ fprintf(stderr, "tcgetattr failed on %s\n", aep_context->device_paths[aep_context->scan]);
close(fd);
goto bail;
}
@@ -242,11 +248,11 @@ int service_aeps(struct aep_context *aep_context, int fd_with_rx)
cfsetospeed(&tty, B115200);
tcsetattr(fd, TCSANOW, &tty);
- init_aep(aep_context, &aep_context->aeps[aep_context->scan], filepath);
+ init_aep(aep_context, &aep_context->aeps[aep_context->scan], aep_context->device_paths[aep_context->scan]);
- if (configure(aep_context, &aep_context->aeps[aep_context->scan], filepath,
+ if (configure(aep_context, &aep_context->aeps[aep_context->scan], aep_context->device_paths[aep_context->scan],
aep_context->config_filepath, NULL) < 0) {
- fprintf(stderr, "config for %s failed\n", filepath);
+ fprintf(stderr, "config for %s failed\n", aep_context->device_paths[aep_context->scan]);
close(fd);
goto bail;
}
@@ -301,12 +307,10 @@ int service_aeps(struct aep_context *aep_context, int fd_with_rx)
}
aep_context->aeps[aep_context->scan].done_config |= 1;
+ aep_context->scan++;
bail:
aep_context->scans++;
- aep_context->scan++;
- if (aep_context->scan == MAX_PROBES)
- aep_context->scan = 0;
/* if we're waiting to start but saw every channel / probe */
@@ -352,6 +356,10 @@ bail:
if (c != aep_context->matched_channel_names)
goto post_start;
+ /* still something expected? */
+ if (aep_context->device_paths[aep_context->scan][0])
+ goto post_start;
+
/* tell everyone to start */
fprintf(stderr, "Starting...\n");
@@ -360,11 +368,12 @@ bail:
for (m = 0; m <= aep_context->highest; m++) {
if (aep_context->aeps[m].fd <= 0 ||
aep_context->aeps[m].done_config != 3 ) {
- fprintf(stderr, "not starting %d fd %d done_config %d\n", m, aep_context->aeps[m].fd, aep_context->aeps[m].done_config);
+ if (aep_context->verbose)
+ fprintf(stderr, "not starting %d fd %d done_config %d\n", m, aep_context->aeps[m].fd, aep_context->aeps[m].done_config);
continue;
}
- if (aep_context->verbose)
+// if (aep_context->verbose)
fprintf(stderr, "sending start to %d\n", m);
c = AEPC_START;
if (write(aep_context->aeps[m].fd, &c, 1) != 1) {
diff --git a/set-aep-serial.sh b/set-aep-serial.sh
new file mode 100755
index 0000000..ce36144
--- /dev/null
+++ b/set-aep-serial.sh
@@ -0,0 +1,37 @@
+#!/bin/bash
+#
+# Backup firmware.bin from the mountpoint before using...
+#
+# hold down the switch on the AEP and plug into USB
+# CRP_DISABLED Mass storage device will appear containing one (fake) file
+# called "firmware.bin".
+#
+# This utility lets you change the USB serial number in your AEP, which is
+# necessary if you will use more than one.
+#
+# Example usage
+#
+# ./set-aep-serial.sh /run/media/agreen/CRP\ DISABLD/ 00010002
+
+M=$1
+
+if [ -e "$M/firmware.bin" ] ; then
+ if [ ! -e ./original-firmware.bin ] ; then
+ cp "$M/firmware.bin" ./original-firmware.bin
+ fi
+else
+ echo "First arg need to be mountpoint"
+ exit 1
+fi
+
+S=$2
+if [ ${#S} -ne 8 ] ; then
+ echo "Second arg is Serial number, needs to be 8 digits"
+ exit 1
+fi
+
+cat ./original-firmware.bin | \
+sed "s|\x1a\x03S\x00/\x00N\x00O\x00.\x00.\x00.\x00.\x00.\x00.\x00.\x00.\x00|\x1a\x03S\x00/\x00N\x00O\x00${S:0:1}\x00${S:1:1}\x00${S:2:1}\x00${S:3:1}\x00${S:4:1}\x00${S:5:1}\x00${S:6:1}\x00${S:7:1}\x00|g" | \
+dd conv=nocreat,notrunc of="$M/firmware.bin"
+
+