summaryrefslogtreecommitdiff
path: root/firmware
diff options
context:
space:
mode:
Diffstat (limited to 'firmware')
-rw-r--r--firmware/SOURCES1
-rw-r--r--firmware/drivers/generic_i2c.c34
-rw-r--r--firmware/export/generic_i2c.h10
-rw-r--r--firmware/target/arm/tms320dm320/i2c-dm320.c8
-rw-r--r--firmware/target/arm/tms320dm320/i2c-dm320.h3
-rw-r--r--firmware/target/arm/tms320dm320/sansa-connect/cryptomem-sansaconnect.c80
-rw-r--r--firmware/target/arm/tms320dm320/sansa-connect/cryptomem-sansaconnect.h27
-rw-r--r--firmware/usbstack/usb_core.c20
8 files changed, 183 insertions, 0 deletions
diff --git a/firmware/SOURCES b/firmware/SOURCES
index 109a40b161..b1024d97da 100644
--- a/firmware/SOURCES
+++ b/firmware/SOURCES
@@ -1274,6 +1274,7 @@ target/arm/tms320dm320/sansa-connect/tnetv105_cppi.c
1274target/arm/tms320dm320/sansa-connect/tnetv105_usb_drv.c 1274target/arm/tms320dm320/sansa-connect/tnetv105_usb_drv.c
1275target/arm/tms320dm320/sansa-connect/usb-sansaconnect.c 1275target/arm/tms320dm320/sansa-connect/usb-sansaconnect.c
1276target/arm/tms320dm320/sansa-connect/avr-sansaconnect.c 1276target/arm/tms320dm320/sansa-connect/avr-sansaconnect.c
1277target/arm/tms320dm320/sansa-connect/cryptomem-sansaconnect.c
1277target/arm/tms320dm320/sansa-connect/backlight-sansaconnect.c 1278target/arm/tms320dm320/sansa-connect/backlight-sansaconnect.c
1278target/arm/tms320dm320/sansa-connect/pcm-sansaconnect.c 1279target/arm/tms320dm320/sansa-connect/pcm-sansaconnect.c
1279target/arm/tms320dm320/sansa-connect/wifi-sansaconnect.c 1280target/arm/tms320dm320/sansa-connect/wifi-sansaconnect.c
diff --git a/firmware/drivers/generic_i2c.c b/firmware/drivers/generic_i2c.c
index effb5372b4..9fd90b5b2c 100644
--- a/firmware/drivers/generic_i2c.c
+++ b/firmware/drivers/generic_i2c.c
@@ -198,6 +198,40 @@ end:
198 return ret; 198 return ret;
199} 199}
200 200
201int i2c_write_read_data(int bus_index, int bus_address,
202 const unsigned char* buf_write, int count_write,
203 unsigned char* buf_read, int count_read)
204{
205 int i;
206 int ret = 0;
207 const struct i2c_interface *iface = i2c_if[bus_index];
208
209 i2c_start(iface);
210 if (!i2c_outb(iface, bus_address))
211 {
212 ret = -2;
213 goto end;
214 }
215
216 for(i = 0;i < count_write;i++)
217 {
218 if (!i2c_outb(iface, buf_write[i]))
219 {
220 ret = -3;
221 goto end;
222 }
223 }
224
225 for(i = 0;i < count_read-1;i++)
226 buf_read[i] = i2c_inb(iface, true);
227
228 buf_read[i] = i2c_inb(iface, false);
229
230end:
231 i2c_stop(iface);
232 return ret;
233}
234
201/* returns bus index which can be used as a handle, or <0 on error */ 235/* returns bus index which can be used as a handle, or <0 on error */
202int i2c_add_node(const struct i2c_interface *iface) 236int i2c_add_node(const struct i2c_interface *iface)
203{ 237{
diff --git a/firmware/export/generic_i2c.h b/firmware/export/generic_i2c.h
index f71736acf0..9fdba26836 100644
--- a/firmware/export/generic_i2c.h
+++ b/firmware/export/generic_i2c.h
@@ -49,5 +49,15 @@ int i2c_write_data(int bus_index, int bus_address, int address,
49int i2c_read_data(int bus_index, int bus_address, int address, 49int i2c_read_data(int bus_index, int bus_address, int address,
50 unsigned char* buf, int count); 50 unsigned char* buf, int count);
51 51
52/* Special function for devices that can appear on I2C bus but do not
53 * comply to I2C specification. Such devices include AT88SC6416C crypto
54 * memory. To read data from AT88SC6416C, a write I2C transaction starts,
55 * 3 bytes are written and then, in the middle of transaction, the device
56 * starts sending data.
57 */
58int i2c_write_read_data(int bus_index, int bus_address,
59 const unsigned char* buf_write, int count_write,
60 unsigned char* buf_read, int count_read);
61
52#endif /* _GEN_I2C_ */ 62#endif /* _GEN_I2C_ */
53 63
diff --git a/firmware/target/arm/tms320dm320/i2c-dm320.c b/firmware/target/arm/tms320dm320/i2c-dm320.c
index 629dae394c..364d3b5c17 100644
--- a/firmware/target/arm/tms320dm320/i2c-dm320.c
+++ b/firmware/target/arm/tms320dm320/i2c-dm320.c
@@ -294,4 +294,12 @@ int i2c_read_bytes(unsigned short address, unsigned short reg,
294 return i2c_read_data(dm320_i2c_bus, address, reg, buf, count); 294 return i2c_read_data(dm320_i2c_bus, address, reg, buf, count);
295} 295}
296 296
297int i2c_write_read_bytes(unsigned short address,
298 const unsigned char* buf_write, int count_write,
299 unsigned char* buf_read, int count_read)
300{
301 return i2c_write_read_data(dm320_i2c_bus, address, buf_write, count_write,
302 buf_read, count_read);
303}
304
297#endif 305#endif
diff --git a/firmware/target/arm/tms320dm320/i2c-dm320.h b/firmware/target/arm/tms320dm320/i2c-dm320.h
index 7dfc19f046..43271692eb 100644
--- a/firmware/target/arm/tms320dm320/i2c-dm320.h
+++ b/firmware/target/arm/tms320dm320/i2c-dm320.h
@@ -31,6 +31,9 @@ int i2c_read(unsigned short address, unsigned char* buf, int count);
31#ifdef HAVE_SOFTWARE_I2C 31#ifdef HAVE_SOFTWARE_I2C
32int i2c_read_bytes(unsigned short address, unsigned short reg, 32int i2c_read_bytes(unsigned short address, unsigned short reg,
33 unsigned char* buf, int count); 33 unsigned char* buf, int count);
34int i2c_write_read_bytes(unsigned short address,
35 const unsigned char* buf_write, int count_write,
36 unsigned char* buf_read, int count_read);
34#endif 37#endif
35 38
36#endif 39#endif
diff --git a/firmware/target/arm/tms320dm320/sansa-connect/cryptomem-sansaconnect.c b/firmware/target/arm/tms320dm320/sansa-connect/cryptomem-sansaconnect.c
new file mode 100644
index 0000000000..ac01525500
--- /dev/null
+++ b/firmware/target/arm/tms320dm320/sansa-connect/cryptomem-sansaconnect.c
@@ -0,0 +1,80 @@
1/***************************************************************************
2* __________ __ ___.
3* Open \______ \ ____ ____ | | _\_ |__ _______ ___
4* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7* \/ \/ \/ \/ \/
8* $Id: $
9*
10* Copyright (C) 2021 by Tomasz Moń
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
22#include <ctype.h>
23#include "cryptomem-sansaconnect.h"
24#include "i2c-dm320.h"
25
26/* Command values */
27#define WRITE_USER_ZONE 0xB0
28#define READ_USER_ZONE 0xB2
29#define SYSTEM_WRITE 0xB4
30#define SYSTEM_READ 0xB6
31#define VERIFY_CRYPTO 0xB8
32#define VERIFY_PASSWORD 0xBA
33
34/* SYSTEM_WRITE ADDR 1 values */
35#define WRITE_CONFIG 0x00
36#define WRITE_FUSES 0x01
37#define SEND_CHECKSUM 0x02
38#define SET_USER_ZONE 0x03
39
40int cryptomem_read_deviceid(char deviceid[32])
41{
42 int ret;
43 unsigned int i;
44 unsigned char cmd_data[3];
45
46 /* It is assumed that other I2C communication has already taken place
47 * (e.g. power_init()) before this function is called and thus we don't
48 * have to send atleast 5 dummy clock cycles here.
49 */
50
51 cmd_data[0] = SET_USER_ZONE;
52 cmd_data[1] = 0;
53 cmd_data[2] = 0;
54 ret = i2c_write(SYSTEM_WRITE, cmd_data, sizeof(cmd_data));
55 if (ret < 0)
56 {
57 return ret;
58 }
59
60 cmd_data[0] = 0;
61 cmd_data[1] = 0;
62 cmd_data[2] = 32;
63 ret = i2c_write_read_bytes(READ_USER_ZONE, cmd_data, sizeof(cmd_data),
64 deviceid, 32);
65 if (ret < 0)
66 {
67 return ret;
68 }
69
70 /* Verify that deviceid contains only printable ASCII characters */
71 for (i = 0; i < 32; i++)
72 {
73 if (!isprint(deviceid[i]))
74 {
75 return -1;
76 }
77 }
78
79 return 0;
80}
diff --git a/firmware/target/arm/tms320dm320/sansa-connect/cryptomem-sansaconnect.h b/firmware/target/arm/tms320dm320/sansa-connect/cryptomem-sansaconnect.h
new file mode 100644
index 0000000000..b6b52d3b2c
--- /dev/null
+++ b/firmware/target/arm/tms320dm320/sansa-connect/cryptomem-sansaconnect.h
@@ -0,0 +1,27 @@
1/***************************************************************************
2* __________ __ ___.
3* Open \______ \ ____ ____ | | _\_ |__ _______ ___
4* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7* \/ \/ \/ \/ \/
8* $Id: $
9*
10* Copyright (C) 2021 by Tomasz Moń
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
22#ifndef _CRYPTOMEM_SANSACONNECT_H_
23#define _CRYPTOMEM_SANSACONNECT_H_
24
25int cryptomem_read_deviceid(char deviceid[32]);
26
27#endif /* _CRYPTOMEM_SANSACONNECT_H_ */
diff --git a/firmware/usbstack/usb_core.c b/firmware/usbstack/usb_core.c
index 3d187c8cab..b291dc7655 100644
--- a/firmware/usbstack/usb_core.c
+++ b/firmware/usbstack/usb_core.c
@@ -62,6 +62,10 @@
62#include "ocotp-imx233.h" 62#include "ocotp-imx233.h"
63#endif 63#endif
64 64
65#ifdef SANSA_CONNECT
66#include "cryptomem-sansaconnect.h"
67#endif
68
65#ifndef USB_MAX_CURRENT 69#ifndef USB_MAX_CURRENT
66#define USB_MAX_CURRENT 500 70#define USB_MAX_CURRENT 500
67#endif 71#endif
@@ -327,6 +331,22 @@ static void set_serial_descriptor(void)
327 } 331 }
328 usb_string_iSerial.bLength = 2 + 2 * (1 + IMX233_NUM_OCOTP_OPS * 8); 332 usb_string_iSerial.bLength = 2 + 2 * (1 + IMX233_NUM_OCOTP_OPS * 8);
329} 333}
334#elif defined(SANSA_CONNECT)
335static void set_serial_descriptor(void)
336{
337 char deviceid[32];
338 short* p = &usb_string_iSerial.wString[1];
339 int i;
340
341 if(!cryptomem_read_deviceid(deviceid)) {
342 for(i = 0; i < 32; i++) {
343 *p++ = deviceid[i];
344 }
345 usb_string_iSerial.bLength = 2 + 2 * (1 + 32);
346 } else {
347 device_descriptor.iSerialNumber = 0;
348 }
349}
330#elif (CONFIG_STORAGE & STORAGE_ATA) 350#elif (CONFIG_STORAGE & STORAGE_ATA)
331/* If we don't know the device serial number, use the one 351/* If we don't know the device serial number, use the one
332 * from the disk */ 352 * from the disk */