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
Previous article:LDR pseudo-instruction in ARM
Next article:OK6410 tftp download kernel, file system and nand flash address related arrangement and summary
- Popular Resources
- Popular amplifiers
- Naxin Micro and Xinxian jointly launched the NS800RT series of real-time control MCUs
- How to learn embedded systems based on ARM platform
- Summary of jffs2_scan_eraseblock issues
- Application of SPCOMM Control in Serial Communication of Delphi7.0
- Using TComm component to realize serial communication in Delphi environment
- Bar chart code for embedded development practices
- Embedded Development Learning (10)
- Embedded Development Learning (8)
- Embedded Development Learning (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Intel promotes AI with multi-dimensional efforts in technology, application, and ecology
- ChinaJoy Qualcomm Snapdragon Theme Pavilion takes you to experience the new changes in digital entertainment in the 5G era
- Infineon's latest generation IGBT technology platform enables precise control of speed and position
- Two test methods for LED lighting life
- Don't Let Lightning Induced Surges Scare You
- Application of brushless motor controller ML4425/4426
- Easy identification of LED power supply quality
- World's first integrated photovoltaic solar system completed in Israel
- Sliding window mean filter for avr microcontroller AD conversion
- What does call mean in the detailed explanation of ABB robot programming instructions?
- USB Type-C® and USB Power Delivery: Designed for extended power range and battery-powered systems
- RAQ #223: How to measure and determine soft-start timing without a soft-start equation?
- RAQ #223: How to measure and determine soft-start timing without a soft-start equation?
- GigaDevice's full range of automotive-grade SPI NOR Flash GD25/55 wins ISO 26262 ASIL D functional safety certification
- GigaDevice's full range of automotive-grade SPI NOR Flash GD25/55 wins ISO 26262 ASIL D functional safety certification
- New IsoVu™ Isolated Current Probes: Bringing a New Dimension to Current Measurements
- New IsoVu™ Isolated Current Probes: Bringing a New Dimension to Current Measurements
- Infineon Technologies Launches ModusToolbox™ Motor Kit to Simplify Motor Control Development
- Infineon Technologies Launches ModusToolbox™ Motor Kit to Simplify Motor Control Development
- STMicroelectronics IO-Link Actuator Board Brings Turnkey Reference Design to Industrial Monitoring and Equipment Manufacturers
- How to select a display detector
- [Zero-knowledge ESP8266 Tutorial] Zero-knowledge WIFI Tutorial - http WEB Server Example
- 【TI recommended course】#TI millimeter wave radar technology introduction#
- 【DIY fan】Unboxing
- FOC vacuum cleaner, low voltage sensorless FOC solution, main control chip CMS32M5733Q048
- Several basic knowledge of MCU, must-read for beginners
- There are two problems when using the ST motor library
- Nokia mobile phone accessories and components replacement/replacement
- When BLE meets MEMS: The basics of inertial systems
- EEWORLD University - Working Principle of Gyroscope