From aa35c7c148aa9b458edae02092aaf222de07f8d3 Mon Sep 17 00:00:00 2001 From: Imran Navruzbekov Date: Fri, 18 Jan 2013 17:38:19 +0400 Subject: [PATCH] Major device number automatic detection Delete variable target_device_major from .conf file. Fixed situation when not display correctly demangled function names. --- driver/Makefile.am | 4 +--- driver/device_driver.c | 19 +++++++------------ driver/swap_driver.sh | 24 ++++++++++-------------- 3 files changed, 18 insertions(+), 29 deletions(-) diff --git a/driver/Makefile.am b/driver/Makefile.am index 303cc68..bb1b87f 100644 --- a/driver/Makefile.am +++ b/driver/Makefile.am @@ -10,7 +10,6 @@ if ANDROID android_opt = -D__ANDROID android = yes else -dev_major = @TARGET_DEVICE_MAJOR@ dev_path = @TARGET_DEVICE_PATH@ endif @@ -50,8 +49,7 @@ install-exec-local: install -m 755 $(driver_module_dir)/insmod.sh $(prefix)/bin if [ "$(android)" != "yes" ] ; then \ - sed "s|__DEV_MAJOR__|$(dev_major)|" $(driver_module_dir)/$(module_name).sh | \ - sed "s|__DEV_NAME__|`basename $(dev_path)`|" | \ + sed "s|__DEV_NAME__|`basename $(dev_path)`|" $(driver_module_dir)/$(module_name).sh | \ sed "s|__DEV_DIR__|`dirname $(dev_path)`|" > \ $(prefix)/$(module_name).sh ; chmod +x $(prefix)/$(module_name).sh ; \ chmod +x $(driver_module_dir)/patchko.sh ; \ diff --git a/driver/device_driver.c b/driver/device_driver.c index 2cbd4b0..c497286 100644 --- a/driver/device_driver.c +++ b/driver/device_driver.c @@ -65,20 +65,15 @@ typedef void (* dbi_module_callback)(); int device_init (void) { int nReserved = 0; - int nRetVal = register_chrdev(device_major, device_name, &device_fops); - if (nRetVal < 0) { - EPRINTF("Cannot register character device! [%s, %d]", device_name, device_major); - nReserved = register_chrdev(0, device_name, &device_fops); - if(nReserved >= 0) - { - unregister_chrdev(nReserved, device_name); - EPRINTF("Please, create a new device node with major number [%d],\n\tand pass it as module parameter!", nReserved); - } + nReserved = register_chrdev(0, device_name, &device_fops); + if(nReserved < 0) + { + unregister_chrdev(nReserved, device_name); + EPRINTF("Cannot register character device!"); return -1; - } else if(nRetVal > 0) { - EPRINTF("Cannot register this device major number! [%d]\n\tTrying a new one. [%d]", device_major, nRetVal); - device_major = nRetVal; } + EPRINTF("New device node with major number [%d], was created\n", nReserved); + device_major = nReserved; return 0; } diff --git a/driver/swap_driver.sh b/driver/swap_driver.sh index 4993ff7..720b8a5 100755 --- a/driver/swap_driver.sh +++ b/driver/swap_driver.sh @@ -6,7 +6,6 @@ MODULE_FILE=swap_driver # device name DEVICE=__DEV_NAME__ -DEVICE_MAJOR=__DEV_MAJOR__ # name of device visible in /proc/devices DEVICE_NAME=${DEVICE} @@ -42,6 +41,16 @@ if [ "${MAJOR}" != "" ] ; then fi fi +# load driver module +echo "loading module '${MODULE_FILE}'" +./bin/insmod.sh ${MODULE_FILE}.ko device_name=${DEVICE_NAME} +if [ $? -ne 0 ]; then + echo "Error: Unable to load Swap Driver!" + exit 1 +fi + +MAJOR=`sed "/${DEVICE_NAME}/ ! d" /proc/devices | sed "s/ ${DEVICE_NAME}//"` +DEVICE_MAJOR=${MAJOR} if [ ! -c ${DEVICE_FILE} ] ; then echo "WARNING: Creating device node with major number [${DEVICE_MAJOR}]!" mknod ${DEVICE_FILE} c ${DEVICE_MAJOR} 0 @@ -50,17 +59,4 @@ if [ ! -c ${DEVICE_FILE} ] ; then exit 1 fi chmod a+r ${DEVICE_FILE} -else - # stat is better, but DTV doesn't have stat - DEVICE_MAJOR=`ls -l ${DEVICE_FILE} | awk '{sub(/,/,"",$5); print $5}'` fi - -# load driver module -echo "loading module '${MODULE_FILE}'" -./bin/insmod.sh ${MODULE_FILE}.ko device_name=${DEVICE_NAME} device_major=${DEVICE_MAJOR} -if [ $? -ne 0 ]; then - echo "Error: Unable to load Swap Driver!" - exit 1 -fi -MAJOR=`sed "/${DEVICE_NAME}/ ! d" /proc/devices | sed "s/ ${DEVICE_NAME}//"` - -- 2.7.4