OK6410 rmmod failed to uninstall the module: No such file or directory

Publisher:MysticEssenceLatest update time:2024-09-06 Source: elecfansKeywords:OK6410 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

illustrate:

1. This document is based on Linux 2.6.32 and has been tested on TQ2440.

2. arm-linux-gcc version

Thread model: posix
gcc version 4.3.3 (Sourcery G++ Lite 2009q1-203)

1. Problem description and tracking analysis

The following error was found when using rmmod

rmmod chdir no such file or directory

Tracing the error message, we found that busybox rmmod.c is located in busybox-1.xxx/modutils/rmmod.c

The function framework is as follows

int rmmod_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;

int rmmod_main(int argc UNUSED_PARAM, char **argv)
{
//.......
if (!*argv)
bb_show_usage();

//......

while (*argv) {
char modname[MODULE_NAME_LEN];
const char *bname;

bname = bb_basename(*argv++);
if (n)
safe_strncpy(modname, bname, MODULE_NAME_LEN);
else
filename2modname(bname, modname);
if (bb_delete_module(modname, flags))
bb_error_msg_and_die("can't unload '%s': %s",
modname, moderror(errno));
}

return EXIT_SUCCESS;
}

Studying this function, we found that the core function of deleting the module is bb_delete_module. Tracing this function, in /modutils/modutils.c, we get the following function

int FAST_FUNC bb_delete_module(const char *module, unsigned int flags)
{
errno = 0;
delete_module(module, flags);
return errno;
}
This shows that the rmmod implementation relies on delete_module

Continue to track delete_module,

#ifdef __UCLIBC__
extern int delete_module(const char *module, unsigned int flags);
#else
# include
# define delete_module(mod, flags) syscall(__NR_delete_module, mod, flags)
#endif

What does this mean?

If __UCLIBC__ is defined, use the delete_module(const char *module, unsigned int flags) function in uClibc

Otherwise, the system calls the kernel's sys_delete_module function. The function prototype is as follows

asmlinkage long sys_delete_module(const char __user *  name_user,  unsigned int  flags);

Let's look at the safe_strncpy(modname, bname, MODULE_NAME_LEN); function and the filename2modname(bname, modname); function

The purpose of these two functions is to obtain the module name, and the core implementation method used is strrchr(name, '/');

char *strchr(const char *s, int c);
The strrchr() function returns a pointer to the last occurrence of  the character c in the string s.

This means that the strrchr function returns the position of the last occurrence of character C in string S.

If we use the following instruction

#rmmod  /lib/modules/2.6.32/adc.ko

After being processed by the function, modname will change back to adc.ko

It is worth noting that the bb_basename() function is as follows

const char* FAST_FUNC bb_basename(const char *name)
{
const char *cp = strrchr(name, '/');
if (cp)
return cp + 1;
return name;
} This function has been processed once

In addition, the filename2modname function

char * FAST_FUNC filename2modname(const char *filename, char *modname)
{
int i;
char *from;
if (filename == NULL)
return NULL;
if (modname == NULL)
modname = xmalloc(MODULE_NAME_LEN);
from = bb_get_last_path_component_nostrip(filename);
for (i = 0; i < (MODULE_NAME_LEN-1) && from[i] != '' &&from[i] != '.'; i++)
modname[i] = (from[i] == '-') ? '_' : from[i];
modname[i] = '';

return modname;
}

Notice

from[i] != '.' This means adc.ko will be parsed as adc

from[i] == '-'? '_' : from[i] means adc-xyz will be parsed as adc_xyz

At this point in the analysis, we also know the whole process of rmmod. The core is to use the sys_delete_module function to uninstall the driver module.

Here is the solution

2. Solution

Create rmmod.c with the following contents

#include
#include
#include
#include
#include
#include
int main(int argc, char *argv[])
{
int ret = -1;
int left_time =5;
int i=0;
if(!argv[1])
{
printf("usage: rmmod modenamen");
return -1;

}

char *modname = argv[1];

while(argv[1][i]!='')

{

//The following is for rmmod adc.ko and rmmod adc to have the same effect

if(argv[1][i]=='.'){argv[1][i]='';break;}
i++;
};

while (left_time-- > 0) {
ret = delete_module(modname, O_NONBLOCK | O_EXCL);//系统调用sys_delete_module
if (ret < 0 && errno == EAGAIN)
sleep(1);
else
break;
}
if (ret != 0) printf("Error when rmmod module %s: %sn",modname, strerror(errno));
return 0;

}

In PC

#arm-linux-gcc rmmod.c -o rmmod

In the board

#mv /sbin/rmmod /sbin/rmmod2

#mv rmmod /sbin/rmmod


Keywords:OK6410 Reference address:OK6410 rmmod failed to uninstall the module: No such file or directory

Previous article:LDR pseudo-instruction in ARM
Next article:OK6410 tftp download kernel, file system and nand flash address related arrangement and summary

Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号