Skip to content

Commit 78b3b34

Browse files
committed
Added code to load the pruss driver module from inside the program. No scripting needed anymore.
1 parent 302af04 commit 78b3b34

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

pruss.c

+17-5
Original file line numberDiff line numberDiff line change
@@ -113,16 +113,20 @@ int map_device( const char* uio_name)
113113
// provide the maps in the wrong order.
114114
for (map_nr = 0 ; map_nr < MAX_UIO_MAPS ; ++map_nr) {
115115
DIR* dir = opendir( path);
116-
if (debug && debug_level > 2) {
117-
printf( " opendir( '%s') returned %d, errno = %d\n", path, (int)dir, errno);
118-
}
119116
if (dir == NULL) {
117+
if (debug && debug_level > 2) {
118+
printf( " opendir( '%s') failed, errno = %d\n", path, errno);
119+
}
120120
if (errno == ENOENT) {
121121
break; // done
122122
} else {
123123
perror( " Cannot open map directory");
124124
exit( 1);
125125
}
126+
} else {
127+
if (debug && debug_level > 2) {
128+
printf( " opendir( '%s') returned %d\n", path, (int)dir);
129+
}
126130
}
127131
closedir( dir);
128132
info = &map_info[ map_nr];
@@ -263,13 +267,21 @@ int locate_pruss_device( const char* driver_name, char* drv_name, int drv_name_l
263267
DIR* dir;
264268
struct dirent* de;
265269
int found = 0;
270+
266271
// for each driver instance of type 'driver_name', scan all subdirs of
267272
// /sys/bus/platform/devices/<driver_name>.<instance>/uio/
268273
snprintf( buffer, sizeof( buffer), "/sys/bus/platform/drivers/%s", driver_name);
269274
dir = opendir( buffer);
270275
if (dir <= 0) {
271-
perror( "Platform driver not found");
272-
exit( 1);
276+
printf( "module '%s' is not loaded, trying to load it...\n", driver_name);
277+
system( "/sbin/modprobe uio_pruss");
278+
// FIXME: find proper solution: mmap later on will fail if we don't delay here
279+
system( "sleep 1");
280+
dir = opendir( buffer);
281+
if (dir <= 0) {
282+
perror( "Platform driver not found");
283+
exit( 1);
284+
}
273285
}
274286
for (de = readdir( dir) ; de ; de = readdir( dir)) {
275287
if (de < 0) {

0 commit comments

Comments
 (0)