blob: 7e4f6a79418ab24fbb2b1cb4f36d9bbd8f4fc777 [file] [log] [blame]
Mauro Carvalho Chehab433b1b02020-06-15 08:50:15 +02001.. SPDX-License-Identifier: GPL-2.0
2.. include:: <isonum.txt>
3
4===============
5C2 port support
6===============
Rodolfo Giometti4e17e1d2008-11-12 13:27:12 -08007
8(C) Copyright 2007 Rodolfo Giometti <giometti@enneenne.com>
9
10This program is free software; you can redistribute it and/or modify
11it under the terms of the GNU General Public License as published by
12the Free Software Foundation; either version 2 of the License, or
13(at your option) any later version.
14
15This program is distributed in the hope that it will be useful,
16but WITHOUT ANY WARRANTY; without even the implied warranty of
17MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18GNU General Public License for more details.
19
20
21
22Overview
23--------
24
25This driver implements the support for Linux of Silicon Labs (Silabs)
26C2 Interface used for in-system programming of micro controllers.
27
28By using this driver you can reprogram the in-system flash without EC2
29or EC3 debug adapter. This solution is also useful in those systems
30where the micro controller is connected via special GPIOs pins.
31
32References
33----------
34
Alexander A. Klimov93431e02020-05-26 08:05:44 +020035The C2 Interface main references are at (https://www.silabs.com)
Rodolfo Giometti4e17e1d2008-11-12 13:27:12 -080036Silicon Laboratories site], see:
37
38- AN127: FLASH Programming via the C2 Interface at
Mauro Carvalho Chehab433b1b02020-06-15 08:50:15 +020039 https://www.silabs.com/Support Documents/TechnicalDocs/an127.pdf
Rodolfo Giometti4e17e1d2008-11-12 13:27:12 -080040
41- C2 Specification at
Mauro Carvalho Chehab433b1b02020-06-15 08:50:15 +020042 https://www.silabs.com/pages/DownloadDoc.aspx?FILEURL=Support%20Documents/TechnicalDocs/an127.pdf&src=SearchResults
Rodolfo Giometti4e17e1d2008-11-12 13:27:12 -080043
44however it implements a two wire serial communication protocol (bit
45banging) designed to enable in-system programming, debugging, and
46boundary-scan testing on low pin-count Silicon Labs devices. Currently
47this code supports only flash programming but extensions are easy to
48add.
49
50Using the driver
51----------------
52
53Once the driver is loaded you can use sysfs support to get C2port's
Mauro Carvalho Chehab433b1b02020-06-15 08:50:15 +020054info or read/write in-system flash::
Rodolfo Giometti4e17e1d2008-11-12 13:27:12 -080055
Mauro Carvalho Chehab433b1b02020-06-15 08:50:15 +020056 # ls /sys/class/c2port/c2port0/
57 access flash_block_size flash_erase rev_id
58 dev_id flash_blocks_num flash_size subsystem/
59 flash_access flash_data reset uevent
Rodolfo Giometti4e17e1d2008-11-12 13:27:12 -080060
61Initially the C2port access is disabled since you hardware may have
62such lines multiplexed with other devices so, to get access to the
Mauro Carvalho Chehab433b1b02020-06-15 08:50:15 +020063C2port, you need the command::
Rodolfo Giometti4e17e1d2008-11-12 13:27:12 -080064
Mauro Carvalho Chehab433b1b02020-06-15 08:50:15 +020065 # echo 1 > /sys/class/c2port/c2port0/access
Rodolfo Giometti4e17e1d2008-11-12 13:27:12 -080066
67after that you should read the device ID and revision ID of the
Mauro Carvalho Chehab433b1b02020-06-15 08:50:15 +020068connected micro controller::
Rodolfo Giometti4e17e1d2008-11-12 13:27:12 -080069
Mauro Carvalho Chehab433b1b02020-06-15 08:50:15 +020070 # cat /sys/class/c2port/c2port0/dev_id
71 8
72 # cat /sys/class/c2port/c2port0/rev_id
73 1
Rodolfo Giometti4e17e1d2008-11-12 13:27:12 -080074
75However, for security reasons, the in-system flash access in not
Mauro Carvalho Chehab433b1b02020-06-15 08:50:15 +020076enabled yet, to do so you need the command::
Rodolfo Giometti4e17e1d2008-11-12 13:27:12 -080077
Mauro Carvalho Chehab433b1b02020-06-15 08:50:15 +020078 # echo 1 > /sys/class/c2port/c2port0/flash_access
Rodolfo Giometti4e17e1d2008-11-12 13:27:12 -080079
Mauro Carvalho Chehab433b1b02020-06-15 08:50:15 +020080After that you can read the whole flash::
Rodolfo Giometti4e17e1d2008-11-12 13:27:12 -080081
Mauro Carvalho Chehab433b1b02020-06-15 08:50:15 +020082 # cat /sys/class/c2port/c2port0/flash_data > image
Rodolfo Giometti4e17e1d2008-11-12 13:27:12 -080083
Mauro Carvalho Chehab433b1b02020-06-15 08:50:15 +020084erase it::
Rodolfo Giometti4e17e1d2008-11-12 13:27:12 -080085
Mauro Carvalho Chehab433b1b02020-06-15 08:50:15 +020086 # echo 1 > /sys/class/c2port/c2port0/flash_erase
Rodolfo Giometti4e17e1d2008-11-12 13:27:12 -080087
Mauro Carvalho Chehab433b1b02020-06-15 08:50:15 +020088and write it::
Rodolfo Giometti4e17e1d2008-11-12 13:27:12 -080089
Mauro Carvalho Chehab433b1b02020-06-15 08:50:15 +020090 # cat image > /sys/class/c2port/c2port0/flash_data
Rodolfo Giometti4e17e1d2008-11-12 13:27:12 -080091
Mauro Carvalho Chehab433b1b02020-06-15 08:50:15 +020092after writing you have to reset the device to execute the new code::
Rodolfo Giometti4e17e1d2008-11-12 13:27:12 -080093
Mauro Carvalho Chehab433b1b02020-06-15 08:50:15 +020094 # echo 1 > /sys/class/c2port/c2port0/reset