summaryrefslogtreecommitdiff
path: root/utils/nwztools
diff options
context:
space:
mode:
authorAmaury Pouly <amaury.pouly@gmail.com>2016-10-19 17:03:52 +0200
committerAmaury Pouly <amaury.pouly@gmail.com>2016-10-19 17:09:04 +0200
commitba91ff10e8c974e50e429d072641ac5e0acdd72e (patch)
treea8ef07988845f67e22dfed9bef3602126e831da0 /utils/nwztools
parent13d892eef1c78d14314b7d3a2cb9035e9ba1420c (diff)
downloadrockbox-ba91ff10e8c974e50e429d072641ac5e0acdd72e.tar.gz
rockbox-ba91ff10e8c974e50e429d072641ac5e0acdd72e.zip
nwztools: add a new plattools directory with code to run on the device
This is code is intended to development into a library of code for the NWZ that will be useful to write the "bootloader" on those device. At the same time, it comes with test programs that are easy to run in firmware upgrade mode and also provide a great test bench for the library. At the moment, two test programs are available: - test_display: simply prints two messages using /usr/bin/lcdmsg - test_keys: displays input key event Change-Id: I9d214894ffc9127b528fcdd3eb5d6b61f4e657a7
Diffstat (limited to 'utils/nwztools')
-rw-r--r--utils/nwztools/plattools/Makefile17
-rw-r--r--utils/nwztools/plattools/README27
-rw-r--r--utils/nwztools/plattools/nwz_keys.h60
-rw-r--r--utils/nwztools/plattools/nwz_lib.c159
-rw-r--r--utils/nwztools/plattools/nwz_lib.h64
-rw-r--r--utils/nwztools/plattools/test_display.c30
-rw-r--r--utils/nwztools/plattools/test_keys.c69
7 files changed, 426 insertions, 0 deletions
diff --git a/utils/nwztools/plattools/Makefile b/utils/nwztools/plattools/Makefile
new file mode 100644
index 0000000000..d3efdb74a3
--- /dev/null
+++ b/utils/nwztools/plattools/Makefile
@@ -0,0 +1,17 @@
1PREFIX?=arm-sony-linux-gnueabi-
2CC=$(PREFIX)gcc
3LD=$(PREFIX)gcc
4CFLAGS=-std=gnu99 -Wall -O2
5INCLUDES=-I.
6
7LIB_FILES=nwz_lib.c
8ALL_BUT_LIB=$(patsubst %.c,%.elf,$(filter-out $(LIB_FILES),$(wildcard *.c)))
9
10all: $(ALL_BUT_LIB)
11
12%.elf: %.c $(LIB_FILES)
13 $(CC) $(CFLAGS) $(INCLUDES) -o $@ $^
14
15clean:
16 rm -rf $(ALL_BUT_LIB)
17
diff --git a/utils/nwztools/plattools/README b/utils/nwztools/plattools/README
new file mode 100644
index 0000000000..e33dfeb354
--- /dev/null
+++ b/utils/nwztools/plattools/README
@@ -0,0 +1,27 @@
1Platform tools
2--------------
3
4Those tools are designed to run on the devices. They are mostly tests that can
5be run in firmware upgrade mode (using exec_file in utils/nwztools/scripts/). To
6compile those, you will need the sony nwz cross compiler. The canonical way to
7run them is as follows:
8
91) Build the tools:
10 cd /path/to/utils/nwztools/plattools
11 make
12Note that the default cross compiler prefix is arm-sony-linux-gnueabi- but it
13can be changed using PREFIX:
14PREFIX="sony-nwz-linux-gnueabi-" make
15
162) Embed the wanted excutable in a firmware upgrade for your device. The README
17in utils/nwztools/scripts contains more documentation on how to select the right
18target. For example if you want to embed test_display for the NWZ-E460 series,
19you should run:
20 cd /path/to/utils/nwztools/scripts
21 make exec_file UPG=test_display_nwze46x.upg NWZ_TARGET=nwz-e46x EXEC=../plattools/test_display.elf
22
233) Put the upgrade file on the device and trigger a firmware upgrade. Assuming
24your NWZ device is /dev/sdb1 and is mounted at /media/pamaury/WALKMAN, run:
25 cd /path/to/utils/nwztools/scripts
26 make copy_fw_upgrade UPG=test_display_nwze46x.upg NWZ_MOUNT=/media/pamaury/WALKMAN/
27 sudo make do_fw_upgrade NWZ_DEV=/dev/sdb1
diff --git a/utils/nwztools/plattools/nwz_keys.h b/utils/nwztools/plattools/nwz_keys.h
new file mode 100644
index 0000000000..8228e5b620
--- /dev/null
+++ b/utils/nwztools/plattools/nwz_keys.h
@@ -0,0 +1,60 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2016 Amaury Pouly
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21#ifndef __NWZ_KEYS_H__
22#define __NWZ_KEYS_H__
23
24/* The Sony icx_key driver reports keys via the /dev/input/event0 device and
25 * abuses the standard struct input_event. The input_event.code is split into
26 * two parts:
27 * - one part giving the code of the key just pressed/released
28 * - one part is a bitmap of various keys (such as HOLD)
29 * The status of the HOLD can be queried at any time by reading the state of
30 * the first LED.
31 */
32
33/* key code and mask */
34#define NWZ_KEY_MASK 0x1f
35#define NWZ_KEY_PLAY 0
36#define NWZ_KEY_RIGHT 1
37#define NWZ_KEY_LEFT 2
38#define NWZ_KEY_UP 3
39#define NWZ_KEY_DOWN 4
40#define NWZ_KEY_ZAPPIN 5
41#define NWZ_KEY_AD0_6 6
42#define NWZ_KEY_AD0_7 7
43/* special "key" when event is for bitmap key, like HOLD */
44#define NWZ_KEY_NONE 15
45#define NWZ_KEY_VOL_DOWN 16
46#define NWZ_KEY_VOL_UP 17
47#define NWZ_KEY_BACK 18
48#define NWZ_KEY_OPTION 19
49#define NWZ_KEY_BT 20
50#define NWZ_KEY_AD1_5 21
51#define NWZ_KEY_AD1_6 22
52#define NWZ_KEY_AD1_7 23
53
54/* bitmap of other things */
55#define NWZ_KEY_NMLHP_MASK 0x20
56#define NWZ_KEY_NCHP_MASK 0x40
57#define NWZ_KEY_HOLD_MASK 0x80
58#define NWZ_KEY_NC_MASK 0x100
59
60#endif /* __NWZ_KEYS_H__ */
diff --git a/utils/nwztools/plattools/nwz_lib.c b/utils/nwztools/plattools/nwz_lib.c
new file mode 100644
index 0000000000..ec862e638b
--- /dev/null
+++ b/utils/nwztools/plattools/nwz_lib.c
@@ -0,0 +1,159 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2016 Amaury Pouly
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21#include "nwz_lib.h"
22
23void nwz_run(const char *file, const char *args[], bool wait)
24{
25 pid_t child_pid = fork();
26 if(child_pid != 0)
27 {
28 if(wait)
29 {
30 int status;
31 waitpid(child_pid, &status, 0);
32 }
33 }
34 else
35 {
36 execvp(file, (char * const *)args);
37 _exit(1);
38 }
39}
40
41void nwz_lcdmsg(bool clear, int x, int y, const char *msg)
42{
43 const char *path_lcdmsg = "/usr/local/bin/lcdmsg";
44 const char *args[16];
45 int index = 0;
46 char locate[32];
47 args[index++] = path_lcdmsg;
48 if(clear)
49 args[index++] = "-c";
50 args[index++] = "-f";
51 args[index++] = "/usr/local/bin/font_08x12.bmp";
52 args[index++] = "-l";
53 sprintf(locate, "%d,%d", x, y);
54 args[index++] = locate;
55 args[index++] = msg;
56 args[index++] = NULL;
57 /* wait for lcdmsg to finish to avoid any race conditions in framebuffer
58 * accesses */
59 nwz_run(path_lcdmsg, args, true);
60}
61
62void nwz_lcdmsgf(bool clear, int x, int y, const char *format, ...)
63{
64 char buffer[1024];
65 va_list args;
66 va_start(args, format);
67 vsprintf(buffer, format, args);
68 va_end(args);
69 nwz_lcdmsg(clear, x, y, buffer);
70}
71
72int nwz_key_open(void)
73{
74 return open("/dev/input/event0", O_RDONLY);
75}
76
77void nwz_key_close(int fd)
78{
79 close(fd);
80}
81
82int nwz_key_get_hold_status(int fd)
83{
84 unsigned long led_hold = 0;
85 if(ioctl(fd, EVIOCGLED(sizeof(led_hold)), &led_hold) < 0)
86 return -1;
87 return led_hold;
88}
89
90int nwz_key_wait_event(int fd, long tmo_us)
91{
92 fd_set rfds;
93 struct timeval tv;
94 struct timeval *tv_ptr = NULL;
95 /* watch the input device */
96 FD_ZERO(&rfds);
97 FD_SET(fd, &rfds);
98 /* setup timeout */
99 if(tmo_us >= 0)
100 {
101 tv.tv_sec = 0;
102 tv.tv_usec = tmo_us;
103 tv_ptr = &tv;
104 }
105 return select(fd + 1, &rfds, NULL, NULL, tv_ptr);
106}
107
108int nwz_key_read_event(int fd, struct input_event *evt)
109{
110 int ret = read(fd, evt, sizeof(struct input_event));
111 if(ret != sizeof(struct input_event))
112 return -1;
113 return 1;
114}
115
116int nwz_key_event_get_keycode(struct input_event *evt)
117{
118 return evt->code & NWZ_KEY_MASK;
119}
120
121bool nwz_key_event_is_press(struct input_event *evt)
122{
123 return evt->value == 0;
124}
125
126bool nwz_key_event_get_hold_status(struct input_event *evt)
127{
128 return !!(evt->code & NWZ_KEY_HOLD_MASK);
129}
130
131static const char *nwz_keyname[NWZ_KEY_MASK + 1] =
132{
133 [0 ... NWZ_KEY_MASK] = "unknown",
134 [NWZ_KEY_PLAY] = "PLAY",
135 [NWZ_KEY_RIGHT] = "RIGHT",
136 [NWZ_KEY_LEFT] = "LEFT",
137 [NWZ_KEY_UP] = "UP",
138 [NWZ_KEY_DOWN] = "DOWN",
139 [NWZ_KEY_ZAPPIN] = "ZAPPIN",
140 [NWZ_KEY_AD0_6] = "AD0_6",
141 [NWZ_KEY_AD0_7] = "AD0_7",
142 [NWZ_KEY_NONE] = "NONE",
143 [NWZ_KEY_VOL_DOWN] = "VOL DOWN",
144 [NWZ_KEY_VOL_UP] = "VOL UP",
145 [NWZ_KEY_BACK] = "BACK",
146 [NWZ_KEY_OPTION] = "OPTION",
147 [NWZ_KEY_BT] = "BT",
148 [NWZ_KEY_AD1_5] = "AD1_5",
149 [NWZ_KEY_AD1_6] = "AD1_6",
150 [NWZ_KEY_AD1_7] = "AD1_7",
151};
152
153const char *nwz_key_get_name(int keycode)
154{
155 if(keycode <0 || keycode > NWZ_KEY_MASK)
156 return "invalid";
157 else
158 return nwz_keyname[keycode];
159}
diff --git a/utils/nwztools/plattools/nwz_lib.h b/utils/nwztools/plattools/nwz_lib.h
new file mode 100644
index 0000000000..e9d885d87a
--- /dev/null
+++ b/utils/nwztools/plattools/nwz_lib.h
@@ -0,0 +1,64 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2016 Amaury Pouly
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21#ifndef _NWZLIB_H_
22#define _NWZLIB_H_
23
24#include <stdio.h>
25#include <stdbool.h>
26#include <stdarg.h>
27#include <unistd.h>
28#include <sys/types.h>
29#include <sys/wait.h>
30#include <linux/input.h>
31#include <fcntl.h>
32
33#include "nwz_keys.h"
34
35/* run a program and exit with nonzero status in case of error
36 * argument list must be NULL terminated */
37void nwz_run(const char *file, const char *args[], bool wait);
38
39/* invoke /usr/bin/lcdmsg to display a message using the small font, optionally
40 * clearing the screen before */
41void nwz_lcdmsg(bool clear, int x, int y, const char *msg);
42void nwz_lcdmsgf(bool clear, int x, int y, const char *format, ...);
43
44/* open icx_key input device and return file descriptor */
45int nwz_key_open(void);
46void nwz_key_close(int fd);
47/* return HOLD status: 0 or 1, or -1 on error */
48int nwz_key_get_hold_status(int fd);
49/* wait for an input event (and return 1), or a timeout (return 0), or error (-1)
50 * set the timeout to -1 to block */
51int nwz_key_wait_event(int fd, long tmo_us);
52/* read an event from the device (may block unless you waited for an event before),
53 * return 1 on success, <0 on error */
54int nwz_key_read_event(int fd, struct input_event *evt);
55/* return keycode from event */
56int nwz_key_event_get_keycode(struct input_event *evt);
57/* return press/released status from event */
58bool nwz_key_event_is_press(struct input_event *evt);
59/* return HOLD status from event */
60bool nwz_key_event_get_hold_status(struct input_event *evt);
61/* get keycode name */
62const char *nwz_key_get_name(int keycode);
63
64#endif /* _NWZLIB_H_ */
diff --git a/utils/nwztools/plattools/test_display.c b/utils/nwztools/plattools/test_display.c
new file mode 100644
index 0000000000..a0dc706624
--- /dev/null
+++ b/utils/nwztools/plattools/test_display.c
@@ -0,0 +1,30 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2016 Amaury Pouly
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21#include "nwz_lib.h"
22
23int main(int argc, char **argv)
24{
25 /* clear screen and display welcome message */
26 nwz_lcdmsg(true, 0, 0, "test_display");
27 nwz_lcdmsg(false, 3, 10, "This program will stop in 5 seconds");
28 sleep(5);
29 return 0;
30}
diff --git a/utils/nwztools/plattools/test_keys.c b/utils/nwztools/plattools/test_keys.c
new file mode 100644
index 0000000000..3640e007fc
--- /dev/null
+++ b/utils/nwztools/plattools/test_keys.c
@@ -0,0 +1,69 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2016 Amaury Pouly
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21#include "nwz_lib.h"
22
23int main(int argc, char **argv)
24{
25 /* clear screen and display welcome message */
26 nwz_lcdmsg(true, 0, 0, "test_keys");
27 nwz_lcdmsg(false, 0, 2, "hold PWR OFF for 3 seconds to quit");
28 /* open input device */
29 int input_fd = nwz_key_open();
30 if(input_fd < 0)
31 {
32 nwz_lcdmsg(false, 3, 4, "Cannot open input device");
33 sleep(2);
34 return 1;
35 }
36 /* display input state in a loop */
37 int pwr_off_pressed = 0; /* 0 = no pressed, >0 = number of seconds pressed - 1 */
38 while(1)
39 {
40 /* display HOLD status */
41 nwz_lcdmsgf(false, 2, 5, "HOLD: %d", nwz_key_get_hold_status(input_fd));
42 /* wait for event */
43 int ret = nwz_key_wait_event(input_fd, 1000000);
44 if(ret != 1)
45 {
46 if(pwr_off_pressed > 0)
47 pwr_off_pressed++;
48 if(pwr_off_pressed >= 4)
49 break;
50 continue;
51 }
52 struct input_event evt;
53 if(nwz_key_read_event(input_fd, &evt) != 1)
54 continue;
55 nwz_lcdmsgf(false, 2, 6, "%s %s (HOLD=%d) ",
56 nwz_key_get_name(nwz_key_event_get_keycode(&evt)),
57 nwz_key_event_is_press(&evt) ? "pressed" : "released",
58 nwz_key_event_get_hold_status(&evt));
59 if(nwz_key_event_get_keycode(&evt) == NWZ_KEY_OPTION && nwz_key_event_is_press(&evt))
60 pwr_off_pressed = 1;
61 else
62 pwr_off_pressed = 0;
63 }
64 /* close input device */
65 close(input_fd);
66 /* finish nicely */
67 return 0;
68}
69