[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [microblaze-uclinux] loadable module support in petalinux kernel 2.6
Hi,
On Tue, 2007-07-03 at 14:59 +1000, John Williams wrote:
> Hi
> Islam Samir wrote:
> > Hi, I tried to compile loadable module support into the kernel 2.6 of
> > petalinux... The compilation stopped with the following error:
>
> The kernel infrastructure for loadable modules is not yet done for
> microblaze / 2.6.
>
> It's on the radar, but no specific timeline. If you want to have a go
> at it, please do so!
last week I have started to implement module support for microblaze for
the 2.6 kernel, but I have not come far with that. Unfortunately I had
to postpone my efforts concerning due to a lack of time, I plan to
continue in a couple of weeks.
I was able to load and unload some modules using insmod, lsmod and
rmmod. Unfortunately there is a problem with the export of the module's
symbols. With some modules the kernel hangs during loading the modules.
So I guess the next step would be to check the relocations in
arch/microblaze/kernel/module.c and to properly define the exports in
arch/microblaze/kernel/microblazeksyms.c (I have only exported these
symbols that where identified missing during kernel compilation). But I
am not quite sure how to handle __ashldi3 et al. I can find the symbols
in the elf file, but can not find the definitions in the source tree, so
I guess they are included by the compiler. In other architectures these
are included in the arch/xxx/lib directory.
In case someone like to have a go at it I have attached the current
state as a patch which can be applied to the
petalinux-v0.20-rc3/software/linux-2.6.x-petalogix directory
(
cd petalinux-v0.20-rc3/software
patch -p0 < module_support.patch
)
Cheers,
Erik
--
*******************************************************
Dipl.-Ing. Erik Hansen
Entwickler / Developer
SHF Communication Technologies AG
Wilhelm-v.-Siemens-Str. 23 D; 12277 Berlin, Germany
E-Mail: hansen@xxxxxx
Phone: +49-(0)30- 772 051-0 direct: -66
Fax: +49-(0)30- 753 10 78
Web: www.shf.de
*******************************************************
Sitz der Gesellschaft/Registered Office: Berlin;
Registergericht/Register Court: AG Berlin-Charlottenburg HRB 72633;
Vorstand/Executive Board: Dr. Michael Martin, Dr. Frank Hieronymi,
Dr. Lars Klapproth (stv.);
Aufsichtsratsvorsitzender/Chairman of the Supervisory Board: Dr. Walter
L. Rust.
Diese E-Mail enthält vertrauliche und/oder rechtlich geschützte
Informationen und ist ausschließlich für den bezeichneten Adressaten
oder dessen Vertreter bestimmt. Wenn Sie nicht der richtige Adressat
sind oder diese E-Mail irrtümlich erhalten haben, informieren Sie bitte
sofort den Absender und vernichten Sie diese Mail. Jede Form der
Kenntnisnahme, Veröffentlichung, Vervielfältigung oder Weitergabe durch
andere Empfänger ist unzulässig.
This e-mail may contain confidential and/or privileged information and
is intended solely for the addressee or a representative there of. If
you are not the intended recipient (or have received this e-mail in
error) please notify the sender immediately and destroy this e-mail.
Access to, publishing and copying of the information by a third party is
unauthorised.
--
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.
diff -urpNbB ../../petalinux-v0.20-rc3/software/linux-2.6.x-petalogix/arch/microblaze/kernel/Makefile linux-2.6.x-petalogix/arch/microblaze/kernel/Makefile
--- ../../petalinux-v0.20-rc3/software/linux-2.6.x-petalogix/arch/microblaze/kernel/Makefile 2007-04-16 07:50:02.000000000 +0200
+++ linux-2.6.x-petalogix/arch/microblaze/kernel/Makefile 2007-06-22 15:09:58.000000000 +0200
@@ -12,3 +12,5 @@ obj-y += init_task.o setup.o traps.o pro
obj-y += cpu/
obj-$(CONFIG_EARLY_PRINTK) += early_printk.o
+obj-$(CONFIG_MODULES) += microblazeksyms.o module.o
+
diff -urpNbB ../../petalinux-v0.20-rc3/software/linux-2.6.x-petalogix/arch/microblaze/kernel/microblazeksyms.c linux-2.6.x-petalogix/arch/microblaze/kernel/microblazeksyms.c
--- ../../petalinux-v0.20-rc3/software/linux-2.6.x-petalogix/arch/microblaze/kernel/microblazeksyms.c 1970-01-01 01:00:00.000000000 +0100
+++ linux-2.6.x-petalogix/arch/microblaze/kernel/microblazeksyms.c 2007-06-22 15:51:00.000000000 +0200
@@ -0,0 +1,128 @@
+/*wq
+ * linux/arch/microblaze/kernel/microblazeksyms.c
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+#include <linux/module.h>
+#include <linux/string.h>
+#include <linux/cryptohash.h>
+#include <linux/delay.h>
+#include <linux/in6.h>
+#include <linux/syscalls.h>
+
+#include <asm/checksum.h>
+#include <asm/io.h>
+#include <asm/system.h>
+#include <asm/uaccess.h>
+
+/*
+ * libgcc functions - functions that are used internally by the
+ * compiler... (prototypes are not correct though, but that
+ * doesn't really matter since they're not versioned).
+ */
+extern void __ashldi3(void);
+extern void __ashrdi3(void);
+//extern void __divsi3(void);
+extern void __lshrdi3(void);
+//extern void __modsi3(void);
+//extern void __muldi3(void);
+//extern void __ucmpdi2(void);
+//extern void __udivsi3(void);
+//extern void __umodsi3(void);
+//extern void __do_div64(void);
+//
+//extern void __aeabi_idiv(void);
+//extern void __aeabi_idivmod(void);
+//extern void __aeabi_lasr(void);
+//extern void __aeabi_llsl(void);
+//extern void __aeabi_llsr(void);
+//extern void __aeabi_lmul(void);
+//extern void __aeabi_uidiv(void);
+//extern void __aeabi_uidivmod(void);
+//extern void __aeabi_ulcmp(void);
+//
+//extern void fpundefinstr(void);
+//extern void fp_enter(void);
+
+/*
+ * floating point math emulator support.
+ * These symbols will never change their calling convention...
+ */
+//EXPORT_SYMBOL_ALIAS(kern_fp_enter,fp_enter);
+//EXPORT_SYMBOL_ALIAS(fp_printk,printk);
+//EXPORT_SYMBOL_ALIAS(fp_send_sig,send_sig);
+//
+//EXPORT_SYMBOL(__backtrace);
+//
+// /* platform dependent support */
+//EXPORT_SYMBOL(__udelay);
+//EXPORT_SYMBOL(__const_udelay);
+//
+// /* networking */
+//EXPORT_SYMBOL(csum_partial);
+//EXPORT_SYMBOL(csum_partial_copy_nocheck);
+//EXPORT_SYMBOL(__csum_ipv6_magic);
+
+ /* io */
+//#ifndef __raw_readsb
+//EXPORT_SYMBOL(__raw_readsb);
+//#endif
+//#ifndef __raw_readsw
+//EXPORT_SYMBOL(__raw_readsw);
+//#endif
+//#ifndef __raw_readsl
+//EXPORT_SYMBOL(__raw_readsl);
+//#endif
+//#ifndef __raw_writesb
+//EXPORT_SYMBOL(__raw_writesb);
+//#endif
+//#ifndef __raw_writesw
+//EXPORT_SYMBOL(__raw_writesw);
+//#endif
+//#ifndef __raw_writesl
+//EXPORT_SYMBOL(__raw_writesl);
+//#endif
+
+ /* string / mem functions */
+//EXPORT_SYMBOL(strchr);
+//EXPORT_SYMBOL(strrchr);
+EXPORT_SYMBOL(memset);
+EXPORT_SYMBOL(memcpy);
+EXPORT_SYMBOL(memmove);
+//EXPORT_SYMBOL(memchr);
+//EXPORT_SYMBOL(__memzero);
+
+ /* user mem (segment) */
+//EXPORT_SYMBOL(__strnlen_user);
+//EXPORT_SYMBOL(__strncpy_from_user);
+
+ /* crypto hash */
+//EXPORT_SYMBOL(sha_transform);
+
+ /* gcc lib functions */
+EXPORT_SYMBOL(__ashldi3);
+EXPORT_SYMBOL(__ashrdi3);
+//EXPORT_SYMBOL(__divsi3);
+EXPORT_SYMBOL(__lshrdi3);
+//EXPORT_SYMBOL(__modsi3);
+//EXPORT_SYMBOL(__muldi3);
+//EXPORT_SYMBOL(__ucmpdi2);
+//EXPORT_SYMBOL(__udivsi3);
+//EXPORT_SYMBOL(__umodsi3);
+//EXPORT_SYMBOL(__do_div64);
+
+ /* bitops */
+//EXPORT_SYMBOL(_set_bit_le);
+//EXPORT_SYMBOL(_test_and_set_bit_le);
+//EXPORT_SYMBOL(_clear_bit_le);
+//EXPORT_SYMBOL(_test_and_clear_bit_le);
+//EXPORT_SYMBOL(_change_bit_le);
+//EXPORT_SYMBOL(_test_and_change_bit_le);
+//EXPORT_SYMBOL(_find_first_zero_bit_le);
+//EXPORT_SYMBOL(_find_next_zero_bit_le);
+//EXPORT_SYMBOL(_find_first_bit_le);
+//EXPORT_SYMBOL(_find_next_bit_le);
diff -urpNbB ../../petalinux-v0.20-rc3/software/linux-2.6.x-petalogix/arch/microblaze/kernel/module.c linux-2.6.x-petalogix/arch/microblaze/kernel/module.c
--- ../../petalinux-v0.20-rc3/software/linux-2.6.x-petalogix/arch/microblaze/kernel/module.c 1970-01-01 01:00:00.000000000 +0100
+++ linux-2.6.x-petalogix/arch/microblaze/kernel/module.c 2007-06-22 14:38:53.000000000 +0200
@@ -0,0 +1,124 @@
+/*
+ * linux/arch/microblaze/kernel/module.c
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ */
+#include <linux/module.h>
+#include <linux/moduleloader.h>
+#include <linux/kernel.h>
+#include <linux/elf.h>
+#include <linux/vmalloc.h>
+#include <linux/slab.h>
+#include <linux/fs.h>
+#include <linux/string.h>
+
+#include <asm/pgtable.h>
+
+void *module_alloc(unsigned long size)
+{
+ void *ret;
+ ret = (size == 0) ? NULL : vmalloc(size);
+ //printk("module_alloc (%08lx)\n", (unsigned long int)ret);
+ return ret;
+// return size == 0 ? NULL : vmalloc(size);
+}
+
+void module_free(struct module *module, void *region)
+{
+ vfree(region);
+}
+
+int module_frob_arch_sections(Elf_Ehdr *hdr,
+ Elf_Shdr *sechdrs,
+ char *secstrings,
+ struct module *mod)
+{
+ return 0;
+}
+
+int
+apply_relocate(Elf32_Shdr *sechdrs, const char *strtab, unsigned int symindex,
+ unsigned int relsec, struct module *module)
+{
+
+ printk(KERN_ERR "module %s: ADD RELOCATION unsupported\n",
+ module->name);
+ return -ENOEXEC;
+
+}
+
+int
+apply_relocate_add(Elf32_Shdr *sechdrs, const char *strtab,
+ unsigned int symindex, unsigned int relsec, struct module *module)
+{
+
+ unsigned int i;
+ Elf32_Rela *rela = (void *)sechdrs[relsec].sh_addr;
+ Elf32_Sym *sym;
+ unsigned long int *location;
+ unsigned long int locoffs;
+ unsigned long int value;
+
+ //printk("Applying add relocation section %u to %u\n",
+ // relsec, sechdrs[relsec].sh_info);
+
+ for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rela); i++) {
+
+ location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rela[i].r_offset;
+ sym = (Elf32_Sym *)sechdrs[symindex].sh_addr + ELF32_R_SYM(rela[i].r_info);
+ value = sym->st_value + rela[i].r_addend;
+
+ switch (ELF32_R_TYPE(rela[i].r_info)) {
+
+ case R_MICROBLAZE_32:
+ *location = value;
+ //printk("R_MICROBLAZE_32 (%08lx)\n", value);
+ break;
+
+ case R_MICROBLAZE_64:
+ location[0] = (location[0] & 0xFFFF0000) | value >> 16;
+ location[1] = (location[1] & 0xFFFF0000) | (value & 0xFFFF);
+ //printk("R_MICROBLAZE_64 (%08lx)\n", value);
+ break;
+
+ case R_MICROBLAZE_64_PCREL:
+ locoffs = (location[0] & 0xFFFF) << 16 | (location[1] & 0xFFFF);
+ value = value - locoffs - 4;
+ location[0] = (location[0] & 0xFFFF0000) | value >> 16;
+ location[1] = (location[1] & 0xFFFF0000) | (value & 0xFFFF);
+ //printk("R_MICROBLAZE_64_PCREL (%08lx)\n", value);
+ break;
+
+ case R_MICROBLAZE_NONE:
+ //printk("R_MICROBLAZE_NONE\n");
+ break;
+
+ default:
+ printk(KERN_ERR "module %s: Unknown relocation: %u\n",
+ module->name, ELF32_R_TYPE(rela->r_info));
+ return -ENOEXEC;
+
+ }
+
+ }
+
+ return 0;
+
+}
+
+int
+module_finalize(const Elf32_Ehdr *hdr, const Elf_Shdr *sechdrs,
+ struct module *module)
+{
+ return 0;
+}
+
+void
+module_arch_cleanup(struct module *mod)
+{
+}
diff -urpNbB ../../petalinux-v0.20-rc3/software/linux-2.6.x-petalogix/include/asm-microblaze/elf.h linux-2.6.x-petalogix/include/asm-microblaze/elf.h
--- ../../petalinux-v0.20-rc3/software/linux-2.6.x-petalogix/include/asm-microblaze/elf.h 2007-04-02 07:54:51.000000000 +0200
+++ linux-2.6.x-petalogix/include/asm-microblaze/elf.h 2007-06-21 17:00:12.000000000 +0200
@@ -11,6 +11,11 @@
#ifndef _ASM_ELF_H
#define _ASM_ELF_H
+#define EM_XILINX_MICROBLAZE 0xbaab
+#define ELF_ARCH EM_XILINX_MICROBLAZE
+
+#define elf_check_arch(x) ( (x)->e_machine == EM_XILINX_MICROBLAZE )
+
/*
* These are used to set parameters in the core dumps.
*/
diff -urpNbB ../../petalinux-v0.20-rc3/software/linux-2.6.x-petalogix/include/asm-microblaze/module.h linux-2.6.x-petalogix/include/asm-microblaze/module.h
--- ../../petalinux-v0.20-rc3/software/linux-2.6.x-petalogix/include/asm-microblaze/module.h 2007-04-02 07:54:51.000000000 +0200
+++ linux-2.6.x-petalogix/include/asm-microblaze/module.h 2007-06-22 10:11:15.000000000 +0200
@@ -11,6 +11,33 @@
#ifndef _ASM_MODULE_H
#define _ASM_MODULE_H
+//jari
+#define EM_XILINX_MICROBLAZE 0xbaab
+
+/* Microblaze Relocations */
+#define R_MICROBLAZE_NONE 0
+#define R_MICROBLAZE_32 1
+#define R_MICROBLAZE_32_PCREL 2
+#define R_MICROBLAZE_64_PCREL 3
+#define R_MICROBLAZE_32_PCREL_LO 4
+#define R_MICROBLAZE_64 5
+#define R_MICROBLAZE_32_LO 6
+#define R_MICROBLAZE_SRO32 7
+#define R_MICROBLAZE_SRW32 8
+#define R_MICROBLAZE_64_NONE 9
+#define R_MICROBLAZE_32_SYM_OP_SYM 10
+/* Keep this the last entry. */
+#define R_MICROBLAZE_NUM 11
+
+struct mod_arch_specific
+{
+ int foo;
+};
+
+#define Elf_Shdr Elf32_Shdr
+#define Elf_Sym Elf32_Sym
+#define Elf_Ehdr Elf32_Ehdr
+
typedef struct { volatile int counter; } module_t;
#endif /* _ASM_MODULE_H */