Silicon C2 Interface

From EnneEnneWiki

Contents

If you like C2port Linux support make a donation with PayPal - it's fast, free and secure!


This driver implements the support for Linux 2.6.27-rc6 and later of Silicon Labs (Silabs) C2 Interface used for in-system programming of micro controllers.

By using this driver you can reprogram the in-system flash without EC2 or EC3 debug adapter. This solution is also useful in those systems where the micro controller is connected via special GPIOs pins.

This manual will show how to compile the driver and how to use the methods it exports into the user space in order to allow a normal process to read and write the in-system flash memory of all micro controllers connected with a C2 Interface.

References

The C2 Interface main references are at Silicon Laboratories site (see AN127: FLASH Programming via the C2 Interface and C2 Specification), however it implements a two wire serial communication protocol (bit banging) designed to enable in-system programming, debugging, and boundary-scan testing on low pin-count Silicon Labs devices. Currently this code supports only flash programming but extensions are easy to add.

The stable driver's source code is available on my server as patch.

Please, note that this driver is derived from a main job, that is the Eurotech_WWPC#WWPC1100.

Patching the kernel and compilation

To patch the kernel get the patch and use the following command into your kernel source tree:

$ patch -p1 < 0001-C2port-add-c2port-support.patch
patching file drivers/misc/Kconfig
patching file drivers/misc/Makefile
patching file drivers/misc/c2port_core.c
patching file include/linux/c2port.h 

or just use git-am if you are using a GIT repository.

Doing this simply adds a new API to easily define new interfaces but no new C2 port will be added to the system! In order to add a new C2 port you should write your own C2 client. As example of that you should do you may take a look at this patch or this file those add C2 port support for two developing boards of mine.

As you can see you have only to define a main struct as follow:

static struct c2port_ops wwpc1100_c2port_ops = {
	block_size	: 512, /* bytes */
	blocks_num	:  15, /* total flash size: 7680 bytes */

	access		: wwpc1100_c2port_access,
	c2d_dir		: wwpc1100_c2port_c2d_dir,
	c2d_get		: wwpc1100_c2port_c2d_get,
	c2d_set		: wwpc1100_c2port_c2d_set,
	c2ck_set	: wwpc1100_c2port_c2ck_set,
};

and then define the bodies of its methods. That's all, since the protocol issues are carried out by my core support. :)

Well, after patching the kernel and adding your specific code just reconfigure your system adding the C2 port support into misc devices:

<M> Silicon Labs C2 port Linux support (EXPERIMENTAL)                              

and then recompile the kernel as usual.

Loading the driver

Once the driver is loaded, or during the boot time you should see something like that:

Silicon Labs C2 port support v. 0.50.0 - (C) 2007 Rodolfo Giometti

and if you define a new C2port you'll see also:

c2port0: new C2 port added
c2port0: flash has 15 blocks x 512 bytes (7680 bytes total) 

Using the driver

Once the driver is loaded you can use sysfs support to get C2port's info or read/write in-system flash.

# ls /sys/class/c2port/c2port0/
access            flash_block_size  flash_erase       rev_id
dev_id            flash_blocks_num  flash_size        subsystem/
flash_access      flash_data        reset             uevent

Initially the C2port access is disabled since you hardware may have such lines multiplexed with other devices so, to get access to the C2port, you need the command:

# echo 1 > /sys/class/c2port/c2port0/access 

after that you should read the device ID and revision ID of the connected micro controller:

# cat /sys/class/c2port/c2port0/dev_id 
8
# cat /sys/class/c2port/c2port0/rev_id 
1

However, for security reasons, the in-system flash access in not enabled yet, to do so you need the command:

# echo 1 > /sys/class/c2port/c2port0/flash_access

After that you can read the whole flash:

 # cat /sys/class/c2port/c2port0/flash_data > image

erase it:

# echo 1 > /sys/class/c2port/c2port0/flash_erase 

and write it:

 # cat image > /sys/class/c2port/c2port0/flash_data

after writing you have to reset the device to execute the new code:

# echo 1 > /sys/class/c2port/c2port0/reset

Utility program

As utility I develop also hex2image tool who can be used to directly program the in-system flash starting from an HEX file. Once you have compiled the tool (with just the make command) you can usse it as follow:

# ./hex2image -S $(cat /sys/class/c2port/c2port0/flash_size) < image.hex \
> /sys/class/c2port/c2port0/flash_data 

The tool is available here.




If you like C2port Linux support make a donation with PayPal - it's fast, free and secure!
Personal tools