Major device number automatic detection
authorImran Navruzbekov <imran.n@samsung.com>
Fri, 18 Jan 2013 13:38:19 +0000 (17:38 +0400)
committerImran Navruzbekov <imran.n@samsung.com>
Tue, 22 Jan 2013 14:01:07 +0000 (18:01 +0400)
Delete variable target_device_major from .conf file.
Fixed situation when not display correctly demangled function names.

driver/Makefile.am
driver/device_driver.c
driver/swap_driver.sh

index 303cc68..bb1b87f 100644 (file)
@@ -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 ; \
index 2cbd4b0..c497286 100644 (file)
@@ -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;
 }
 
index 4993ff7..720b8a5 100755 (executable)
@@ -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}//"`
-