4 (C) Copyright 2007 Rodolfo Giometti <giometti@enneenne.com>
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
21 This driver implements the support for Linux of Silicon Labs (Silabs)
22 C2 Interface used for in-system programming of micro controllers.
24 By using this driver you can reprogram the in-system flash without EC2
25 or EC3 debug adapter. This solution is also useful in those systems
26 where the micro controller is connected via special GPIOs pins.
31 The C2 Interface main references are at (http://www.silabs.com)
32 Silicon Laboratories site], see:
34 - AN127: FLASH Programming via the C2 Interface at
35 http://www.silabs.com/public/documents/tpub_doc/anote/Microcontrollers/Small_Form_Factor/en/an127.pdf, and
38 http://www.silabs.com/public/documents/tpub_doc/spec/Microcontrollers/en/C2spec.pdf,
40 however it implements a two wire serial communication protocol (bit
41 banging) designed to enable in-system programming, debugging, and
42 boundary-scan testing on low pin-count Silicon Labs devices. Currently
43 this code supports only flash programming but extensions are easy to
49 Once the driver is loaded you can use sysfs support to get C2port's
50 info or read/write in-system flash.
52 # ls /sys/class/c2port/c2port0/
53 access flash_block_size flash_erase rev_id
54 dev_id flash_blocks_num flash_size subsystem/
55 flash_access flash_data reset uevent
57 Initially the C2port access is disabled since you hardware may have
58 such lines multiplexed with other devices so, to get access to the
59 C2port, you need the command:
61 # echo 1 > /sys/class/c2port/c2port0/access
63 after that you should read the device ID and revision ID of the
64 connected micro controller:
66 # cat /sys/class/c2port/c2port0/dev_id
68 # cat /sys/class/c2port/c2port0/rev_id
71 However, for security reasons, the in-system flash access in not
72 enabled yet, to do so you need the command:
74 # echo 1 > /sys/class/c2port/c2port0/flash_access
76 After that you can read the whole flash:
78 # cat /sys/class/c2port/c2port0/flash_data > image
82 # echo 1 > /sys/class/c2port/c2port0/flash_erase
86 # cat image > /sys/class/c2port/c2port0/flash_data
88 after writing you have to reset the device to execute the new code:
90 # echo 1 > /sys/class/c2port/c2port0/reset