diff options
Diffstat (limited to 'mdk-stage1')
-rw-r--r-- | mdk-stage1/modules.c | 74 | ||||
-rw-r--r-- | mdk-stage1/stage1.c | 11 | ||||
-rw-r--r-- | mdk-stage1/tools.c | 11 | ||||
-rw-r--r-- | mdk-stage1/tools.h | 1 |
4 files changed, 83 insertions, 14 deletions
diff --git a/mdk-stage1/modules.c b/mdk-stage1/modules.c index b3090fa18..6620c771d 100644 --- a/mdk-stage1/modules.c +++ b/mdk-stage1/modules.c @@ -26,6 +26,7 @@ #include <unistd.h> #include <string.h> #include <stdio.h> +#include <errno.h> #include "insmod.h" #include "stage1.h" #include "log.h" @@ -41,6 +42,48 @@ static struct module_deps_elem * modules_deps = NULL; static char * archive_name = "/modules/modules.mar"; int disable_modules = 0; +extern long init_module(void *, unsigned long, const char *); + + +static const char *moderror(int err) +{ + switch (err) { + case ENOEXEC: + return "Invalid module format"; + case ENOENT: + return "Unknown symbol in module"; + case ESRCH: + return "Module has wrong symbol version"; + case EINVAL: + return "Invalid parameters"; + default: + return strerror(err); + } +} + +static void *grab_file(const char *filename, unsigned long *size) +{ + unsigned int max = 16384; + int ret, fd; + void *buffer = malloc(max); + + fd = open(filename, O_RDONLY, 0); + if (fd < 0) + return NULL; + + *size = 0; + while ((ret = read(fd, buffer + *size, max - *size)) > 0) { + *size += ret; + if (*size == max) + buffer = realloc(buffer, max *= 2); + } + if (ret < 0) { + free(buffer); + buffer = NULL; + } + close(fd); + return buffer; +} /* unarchive and insmod given module * WARNING: module must not contain the trailing ".o" @@ -52,7 +95,10 @@ static enum insmod_return insmod_archived_file(const char * mod_name, char * opt int i, rc; strncpy(module_name, mod_name, sizeof(module_name)); - strcat(module_name, ".o"); + if (kernel_version() <= 4) + strcat(module_name, ".o"); + else + strcat(module_name, ".ko"); i = mar_extract_file(archive_name, module_name, "/tmp/"); if (i == 1) { log_message("file-not-found-in-archive %s (maybe you can try another boot floppy such as 'hdcdrom_usb.img' or 'network_gigabit_usb.img')", module_name); @@ -62,9 +108,26 @@ static enum insmod_return insmod_archived_file(const char * mod_name, char * opt return INSMOD_FAILED; strcat(final_name, mod_name); - strcat(final_name, ".o"); + if (kernel_version() <= 4) { + strcat(final_name, ".o"); + rc = insmod_call(final_name, options); + } else { + void *file; + unsigned long len; + + strcat(final_name, ".ko"); + file = grab_file(final_name, &len); + + if (!file) { + log_perror("\terror reading %s"); + return INSMOD_FAILED; + } + + rc = init_module(file, len, options ? options : ""); + if (rc) + log_message("\terror %s", moderror(errno)); + } - rc = insmod_call(final_name, options); unlink(final_name); /* sucking no space left on device */ if (rc) { log_message("\tfailed"); @@ -366,7 +429,10 @@ enum return_type ask_insmod(enum driver_type type) } if (results == RETURN_OK) { - choice[strlen(choice)-2] = '\0'; /* remove trailing .o */ + if (kernel_version() <= 4) + choice[strlen(choice)-2] = '\0'; /* remove trailing .o */ + else + choice[strlen(choice)-3] = '\0'; /* remove trailing .ko */ return insmod_with_options(choice, type); } else return results; diff --git a/mdk-stage1/stage1.c b/mdk-stage1/stage1.c index 526560122..4ade8eb64 100644 --- a/mdk-stage1/stage1.c +++ b/mdk-stage1/stage1.c @@ -274,16 +274,7 @@ static void expert_third_party_modules(void) #ifdef ENABLE_PCMCIA static void handle_pcmcia(char ** pcmcia_adapter) { - char buf[50]; - int fd = open("/proc/version", O_RDONLY); - int size; - if (fd == -1) - fatal_error("could not open /proc/version"); - size = read(fd, buf, sizeof(buf)); - buf[size-1] = '\0'; // -1 to eat the \n - close(fd); - buf[17] = '\0'; // enough to extract `2.2' - if (ptr_begins_static_str(buf+14, "2.2")) { + if (kernel_version() == 2) { stg1_error_message("We now use kernel pcmcia support and this won't work with a 2.2 kernel."); return; } diff --git a/mdk-stage1/tools.c b/mdk-stage1/tools.c index ea8450cef..5b2128fe9 100644 --- a/mdk-stage1/tools.c +++ b/mdk-stage1/tools.c @@ -34,6 +34,7 @@ #include <sys/mount.h> #include <sys/poll.h> #include <errno.h> +#include <sys/utsname.h> #include "stage1.h" #include "log.h" #include "mount.h" @@ -465,6 +466,16 @@ int string_array_length(char ** a) return i; } +int kernel_version(void) +{ + struct utsname val; + if (uname(&val)) { + log_perror("uname failed"); + return -1; + } + return charstar_to_int(val.release + 2); +} + int scall_(int retval, char * msg, char * file, int line) { char tmp[5000]; diff --git a/mdk-stage1/tools.h b/mdk-stage1/tools.h index 851480d2d..d8892a1ed 100644 --- a/mdk-stage1/tools.h +++ b/mdk-stage1/tools.h @@ -42,6 +42,7 @@ void handle_env(char ** env); char ** grab_env(void); char ** list_directory(char * direct); int string_array_length(char ** a); +int kernel_version(void); int scall_(int retval, char * msg, char * file, int line); #define scall(retval, msg) scall_(retval, msg, __FILE__, __LINE__) |