linux driver operation

Linux character-driven operations:

1. cat /proc/devices #View unused device numbers

2. insmod memdev.ko #Install the driver module

  After installation, you can check the device number through 1).

3. rmmod memdev.ko #Uninstall the driver module

4. Create the "/dev/memdev0" device node through the "mknod /dev/memdev0 c $() 0 " command

     $() is the device number after executing 2)

5. rm /dev/memdev0 #delete the created character device

 

Linux driver: passing parameters to modules

1. module_param(name, type, perm); #Pass a single parameter

      name is both the parameter name seen by the user and the variable that accepts the parameter in the module;
      type indicates the data type of the parameter, which is one of the following: byte, short, ushort, int, uint, long, ulong, charp, bool, invbool;
      perm specifies the access permissions for the corresponding files in sysfs. Access rights are managed in the same way as linux file access rights, such as 0644, or expressed using macros in stat.h such as S_IRUGO.
            0 means to completely close the corresponding entry in sysfs.
            #define S_IRUSR 00400 Readable by file owner 
            #define S_IWUSR 00200 Writable by file owner
            #define S_IXUSR 00100 Executable by file owner
            #define S_IRGRP 00040 Readable by users in the same group as file owner
            #define S_IWGRP 00020
            #define S_IXGRP 00010
            # define S_IROTH 00004 Readable by a user of a different group than the file owner
            #define S_IWOTH 00002
            #define S_IXOTH 00001

Typical usage is as follows:
  static unsigned int int_var = 0;
  module_param(int_var, uint, S_IRUGO);
       insmod xxxx.ko int_var=x

2. module_param_array(para , type , &n_para , perm) #Pass multiple parameters

  Among them, para is both the parameter name of the external module and the variable name inside the program, type is the data type, and perm is the access permission of sysfs. The pointer nump points to an integer whose value indicates how many parameters are stored in the array para.
  para: parameter array; the size of the array is the determinant of how many parameters can be input.
  n_para: the number of parameters; this variable has no decisive role; as long as the size of the para array is large enough, when inserting a module, the number of input parameters The number will change the value of n_para, and finally the number of passed array elements is stored in n_para.

Typical usage is as follows:
  static int para[MAX_FISH];
  static int n_para;
  module_param_array(para , int , &n_para , S_IRUGO); 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324936555&siteId=291194637