char driver for Blackfin on-chip OTP memory
PATCH 1/1 char driver for Blackfin on-chip OTP memory
From: Mike Frysinger <[email protected]>
initial char driver for otp memory
(only read supported atm ... needs real examples/docs for write support)
--- drivers/char/Kconfig | 28 +++++++ drivers/char/Makefile | 1 + drivers/char/bfin-otp.c | 203 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 232 insertions(+), 0 deletions(-) create mode 100644 drivers/char/bfin-otp.c
drivers/char/Kconfig +28 -0
@@ -492,6 +492,34 @@ config BRIQ_PANEL It's safe to say N here. +config BFIN_OTP + tristate "Blackfin On-Chip OTP Memory Support" + depends on BLACKFIN && (BF52x || BF54x) + default y + help + If you say Y here, you will get support for a character device + interface into the One Time Programmable memory pages that are + stored on the Blackfin processor. This will not get you access + to the secure memory pages however. You will need to write your + own secure code and reader for that. + + To compile this driver as a module, choose M here: the module + will be called bfin-otp. + + If unsure, it is safe to say Y. + +config BFIN_OTP_WRITE_ENABLE + bool "Enable writing support of OTP pages" + depends on BFIN_OTP + default n + help + If you say Y here, you will enable support for writing of the + OTP pages. This is dangerous by nature as you can only program + the pages once, so only enable this option when you actually + need it so as to not inadvertently clobber data. + + If unsure, say N. + config PRINTER tristate "Parallel printer support" depends on PARPORT
drivers/char/Makefile +1 -0
@@ -60,6 +60,7 @@ obj-$(CONFIG_VIOTAPE) += viotape.o obj-$(CONFIG_HVCS) += hvcs.o obj-$(CONFIG_SGI_MBCS) += mbcs.o obj-$(CONFIG_BRIQ_PANEL) += briq_panel.o +obj-$(CONFIG_BFIN_OTP) += bfin-otp.o obj-$(CONFIG_PRINTER) += lp.o obj-$(CONFIG_TIPAR) += tipar.o
drivers/char/bfin-otp.c new file +203 -0
203 lines not on this page · raw message
Signature · 1 line
1.5.3.4
Quoted 14 lines · Bryan Wu
From: Mike Frysinger <[email protected]>
initial char driver for otp memory
(only read supported atm ... needs real examples/docs for write support)Signed-off-by Mike Frysinger <[email protected]>Signed-off-by Bryan Wu <[email protected]>--- drivers/char/Kconfig | 28 +++++++ drivers/char/Makefile | 1 + drivers/char/bfin-otp.c | 203 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 232 insertions(+), 0 deletions(-) create mode 100644 drivers/char/bfin-otp.c
[...]
Quoted 26 lines
drivers/char/bfin-otp.c new file +20
-0@@ -0,0 +1,203 @@ +/* +* Blackfin On-Chip OTP Memory Interface +* Supports BF52x/BF54x +* +* Copyright 2007-2008 Analog Devices Inc. +* +* Enter bugs at http://blackfin.uclinux.org/ +* +* Licensed under the GPL-2 or later. +*/ + +#include <linux/cdev.h> +#include <linux/device.h> +#include <linux/errno.h> +#include <linux/fs.h> +#include <linux/init.h> +#include <linux/module.h> +#include <linux/mutex.h> +#include <linux/types.h> +
drivers/char/bfin-otp.c line 30
Quoted 10 lines
drivers/char/bfin-otp.c new file +10
-0+#include <asm/blackfin.h> +#include <asm/uaccess.h> + +#define stamp(fmt, args...) pr_debug("%s:%i: " fmt "\n", __func__, __LINE__, ## args) +#define stampit () stamp("here i am") + +#define DRIVER_NAME "bfin-otp" +#define PFX DRIVER_NAME ": " + +DEFINE_MUTEX (bfin_otp_lock);
static?
Quoted 5 lines
drivers/char/bfin-otp.c new file +5
-0+ +/* OTP Boot ROM functions */ +#define _BOOTROM_OTP_COMMAND 0xEF000018 +#define _BOOTROM_OTP_READ 0xEF00001A +#define _BOOTROM_OTP_WRITE 0xEF00001C
[...]
Quoted 11 lines
drivers/char/bfin-otp.c new file +11
-0+/** +* bfin_otp_init - Initialize module +* +* Registers the device and notifier handler. Actual device +* initialization is handled by bfin_otp_open(). +*/ +static int __init bfin_otp_init (void ) +{ +int ret; + +stampit ();
drivers/char/bfin-otp.c line 165
Quoted 10 lines
drivers/char/bfin-otp.c new file +10
-0+ + ret =alloc_chrdev_region (&bfin_otp_dev_node,0 ,1 ,"otp" ); +if (ret) { + printk(KERN_ERR PFX "unable to get a char device\n"); +return ret; + } + +cdev_init (&bfin_otp_cdev, &bfin_otp_fops); + bfin_otp_cdev.owner =THIS_MODULE ; + bfin_otp_cdev.ops = &bfin_otp_fops;
You don't need to set the fops again.
drivers/char/bfin-otp.c line 175
Quoted 10 lines
drivers/char/bfin-otp.c new file +10
-0+ + ret =cdev_add (&bfin_otp_cdev, bfin_otp_dev_node,1 ); +if (ret) { +unregister_chrdev_region (bfin_otp_dev_node,1 ); + printk(KERN_ERR PFX "unable to register char device\n"); +return ret; + } + + bfin_otp_class =class_create (THIS_MODULE ,"otp" ); +device_create (bfin_otp_class,NULL , bfin_otp_dev_node,"otp" );
Anyway, wouldn't be easier/better to use misc.c functionality here (misc_register() et al.)?
Quoted 5 lines
drivers/char/bfin-otp.c new file +5
-0+ + printk(KERN_INFO PFX "initialized\n"); + +return 0 ; +}
On Wed 30 Jan 2008 06:00, Jiri Slaby pondered:
Quoted 6 lines · Bryan Wu
Quoted 5 lines
From: Mike Frysinger <[email protected]>
initial char driver for otp memory
(only read supported atm ... needs real examples/docs for write support)
Quoted 8 lines
drivers/char/bfin-otp.c line 175
Quoted 5 lines
Signed-off-by Mike Frysinger <[email protected]>Signed-off-by Bryan Wu <[email protected]>drivers/char/bfin-otp.c new file +2
-0+ bfin_otp_class =class_create (THIS_MODULE ,"otp" ); +device_create (bfin_otp_class,NULL , bfin_otp_dev_node,"otp" );Anyway, wouldn't be easier/better to use
misc.cfunctionality here (misc_register()et al.)?
OTP (one time programmable) memory are not registers, they are small blocks (8k bytes) of non violate on chip memory, for storing things that you don't want other people to look at via a PCB level probe. (like keys), or things that are just helpful - like MAC addresses.
-Robin
Quoted 7 lines · Robin Getz
On Wed 30 Jan 2008 06:00, Jiri Slaby pondered:
Quoted 6 lines · Bryan Wu
Quoted 5 lines
From: Mike Frysinger <[email protected]>
initial char driver for otp memory
(only read supported atm ... needs real examples/docs for write support)
Quoted 8 lines
Quoted 6 lines
drivers/char/bfin-otp.c line 175
Quoted 5 lines
Signed-off-by Mike Frysinger <[email protected]>Signed-off-by Bryan Wu <[email protected]>drivers/char/bfin-otp.c new file +2
-0+ bfin_otp_class =class_create (THIS_MODULE ,"otp" ); +device_create (bfin_otp_class,NULL , bfin_otp_dev_node,"otp" );Anyway, wouldn't be easier/better to use
misc.cfunctionality here (misc_register()et al.)?OTP (one time programmable) memory are not registers, they are small blocks (8k bytes) of non violate on chip memory, for storing things that you don't want other people to look at via a PCB level probe. (like keys), or things that are just helpful - like MAC addresses.
Sorry, misc_register() allows you to get rid of the chrdev initialization including class creation. Maybe I'm not understanding what you are trying to explain me?
Quoted 13 lines · Robin Getz
On Wed 30 Jan 2008 06:00, Jiri Slaby pondered:
Quoted 12 lines · Bryan Wu
Quoted 10 lines
From: Mike Frysinger <[email protected]>
initial char driver for otp memory
(only read supported atm ... needs real examples/docs for write support)Signed-off-by Mike Frysinger <[email protected]>Signed-off-by Bryan Wu <[email protected]>drivers/char/bfin-otp.c new file +2
-0+ bfin_otp_class =class_create (THIS_MODULE ,"otp" ); +device_create (bfin_otp_class,NULL , bfin_otp_dev_node,"otp" );
Quoted 8 lines
Quoted 2 lines
Anyway, wouldn't be easier/better to use
misc.cfunctionality here (misc_register()et al.)?OTP (one time programmable) memory are not registers, they are small blocks (8k bytes) of non violate on chip memory, for storing things that you don't want other people to look at via a PCB level probe. (like keys), or things that are just helpful - like MAC addresses.
Jiri means this OTP char driver can use misc character driver interface as misc_register().
And one question for Jiri, what is the difference between misc char driver with other char drivers.
Because we got some other char drivers locally, maybe some day send them out.
Thanks
-Bryan
Quoted 2 lines · Bryan Wu
And one question for Jiri, what is the difference between misc char driver with other char drivers.
No difference in behaviour. Open function in misc replaces fops by your specified one (like a v4l or tty layer, or chrdev_open aswell, which will be called on each character device open).
Quoted 1 line
Because we got some other char drivers locally, maybe some day send them out.
Misc has one predefined major and is used for such uses, in which you need only one minor number. The point is not to block resting 254 minors of one major just for only one minor used.
Quoted 1 line · Jiri Slaby
specified one (like a v4l or tty layer, or
chrdev_openaswell, which
Eh, no, not the tty layer...
Quoted 4 lines · Jiri Slaby
Quoted 1 line · Bryan Wu
+DEFINE_MUTEX(bfin_otp_lock);
static?
the macro threw me ... fixed now, thanks
Quoted 9 lines
Quoted 9 lines
drivers/char/bfin-otp.c new file +9
-0+static int __init bfin_otp_init (void ) +{ +int ret; + +stampit (); + + ret =alloc_chrdev_region (&bfin_otp_dev_node,0 ,1 ,"otp" ); +if (ret) { + printk(KERN_ERR PFX "unable to get a char device\n");
Quoted 8 lines
drivers/char/bfin-otp.c line 165
Quoted 6 lines
drivers/char/bfin-otp.c new file +6
-0+return ret; + } + +cdev_init (&bfin_otp_cdev, &bfin_otp_fops); + bfin_otp_cdev.owner =THIS_MODULE ; + bfin_otp_cdev.ops = &bfin_otp_fops;You don't need to set the fops again.
i did research this a bit but the information on the topic seemed spotty and usage was inconsistent ... i guess recent things have smartened up, so i'll drop the assignment
Quoted 10 lines
drivers/char/bfin-otp.c line 175
Quoted 9 lines
drivers/char/bfin-otp.c new file +9
-0+ ret =cdev_add (&bfin_otp_cdev, bfin_otp_dev_node,1 ); +if (ret) { +unregister_chrdev_region (bfin_otp_dev_node,1 ); + printk(KERN_ERR PFX "unable to register char device\n"); +return ret; + } + + bfin_otp_class =class_create (THIS_MODULE ,"otp" ); +device_create (bfin_otp_class,NULL , bfin_otp_dev_node,"otp" );
Quoted 2 lines
Anyway, wouldn't be easier/better to use
misc.cfunctionality here (misc_register()et al.)?
probably ... i just didnt want to statically allocate a number in the range that would be Blackfin specific ...
-mike
Quoted 11 lines · Mike Frysinger
Quoted 10 lines · Jiri Slaby
Quoted 9 lines · Bryan Wu
drivers/char/bfin-otp.c new file +9
-0+ ret =cdev_add (&bfin_otp_cdev, bfin_otp_dev_node,1 ); +if (ret) { +unregister_chrdev_region (bfin_otp_dev_node,1 ); + printk(KERN_ERR PFX "unable to register char device\n"); +return ret; + } + + bfin_otp_class =class_create (THIS_MODULE ,"otp" ); +device_create (bfin_otp_class,NULL , bfin_otp_dev_node,"otp" );
Quoted 5 lines
Quoted 2 lines
Anyway, wouldn't be easier/better to use
misc.cfunctionality here (misc_register()et al.)?probably ... i just didnt want to statically allocate a number in the range that would be Blackfin specific ...
MISC_DYNAMIC_MINOR is definitely your friend ;).
Quoted 12 lines · Jiri Slaby
Quoted 11 lines · Mike Frysinger
Quoted 10 lines · Jiri Slaby
Quoted 9 lines · Bryan Wu
drivers/char/bfin-otp.c new file +9
-0+ ret =cdev_add (&bfin_otp_cdev, bfin_otp_dev_node,1 ); +if (ret) { +unregister_chrdev_region (bfin_otp_dev_node,1 ); + printk(KERN_ERR PFX "unable to register char device\n"); +return ret; + } + + bfin_otp_class =class_create (THIS_MODULE ,"otp" ); +device_create (bfin_otp_class,NULL , bfin_otp_dev_node,"otp" );
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
Anyway, wouldn't be easier/better to use
misc.cfunctionality here (misc_register()et al.)?probably ... i just didnt want to statically allocate a number in the range that would be Blackfin specific ...
MISC_DYNAMIC_MINORis definitely your friend ;).
ah, great ... i'll check it out then, thanks
-mike
Quoted 14 lines · Jiri Slaby
drivers/char/bfin-otp.c line 175
Quoted 10 lines · Bryan Wu
drivers/char/bfin-otp.c new file +10
-0+ + ret =cdev_add (&bfin_otp_cdev, bfin_otp_dev_node,1 ); +if (ret) { +unregister_chrdev_region (bfin_otp_dev_node,1 ); + printk(KERN_ERR PFX "unable to register char device\n"); +return ret; + } + + bfin_otp_class =class_create (THIS_MODULE ,"otp" ); +device_create (bfin_otp_class,NULL , bfin_otp_dev_node,"otp" );Anyway, wouldn't be easier/better to use
misc.cfunctionality here (misc_register()et al.)?
thanks, ive converted this now ... Bryan can post an updated patch :)
http://blackfin.uclinux.org/gf/project/linux-kernel/scmsvn/?action=browse&path=/trunk/drivers/char/bfin-otp.c&r1=4224&r2=4223
-mike