模块中的未知符号 / v7_flush_dcache_all 在 linux 内核模块中未定义

Unknown symbol in module / v7_flush_dcache_all undefined in linux kernel module

我正在尝试创建一个 linux 内核模块来禁用数据缓存。我正在尝试在 arch/arm/include/asm/cacheflush.h 中使用 v7_exit_coherency_flush(all) 函数,并且此函数调用 v7_flush_dcache_all,我发现它位于 arch/arm/mm/arch-v7.S.

我的问题是,当我尝试制作我的模块时,我收到警告

WARNING: "v7_flush_dcache_all  [/home/pi/Documents/ARMHammer/kern/my_kernel/cache_disable.ko] undefined!

当我尝试插入模块时出现错误

insmod: ERROR: could not insert module cache_disable.ko: Unknown symbol in module

所以看起来 ach-v7.S 文件没有被读取。我试着简单地将它包含在我的主文件中,但是产生了很多错误,可能是因为它是一个程序集文件。

此时我几乎陷入困境,是否可以通过某种方式将程序集文件包含在 Makefile 中,或者我可能没有包含所有必需的 .h 文件?

不管怎样,这是我的主文件

#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/init.h>
#include <linux/sched.h>    /* For current */
#include <linux/tty.h>      /* For the tty declarations */
#include <linux/version.h>  /* For LINUX_VERSION_CODE */
#include <linux/mm.h>

#include <asm/cp15.h>
#include <asm/cacheflush.h>
#include <asm/glue-cache.h>
#include <asm/shmparam.h>
#include <asm/cachetype.h>
#include <asm/outercache.h>

// #include "my_cache-v7.h"


MODULE_LICENSE("GPL");
MODULE_AUTHOR("Peter Jay Salzman");


static void print_string(char *str)
{
    struct tty_struct *my_tty;
    #if ( LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,5) )
        my_tty = current->tty;
    #else
        my_tty = current->signal->tty;
    #endif

        if (my_tty != NULL) {
            ((my_tty->ops)->write) (my_tty, /* The tty itself */
    #if ( LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,9) )     
                           0,   /* Don't take the string 
                               from user space        */
    #endif
                           str, /* String                 */
                           strlen(str));    /* Length */
    #if ( LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,9) )     
            ((my_tty->ops)->write) (my_tty, 0, "52", 2);
    #else
            ((my_tty->ops)->write) (my_tty, "52", 2);
    #endif
    }
}

static int __init print_string_init(void)
{
    v7_exit_coherency_flush(all);

    print_string("The module has been inserted.  Hello world!");
    return 0;
}

static void __exit print_string_exit(void)
{
    print_string("The module has been removed.  Farewell world!");
}

module_init(print_string_init);
module_exit(print_string_exit);

和我的 Makefile

obj-m += cache_disable.o
KDIR = /home/pi/linux/
all:
    make -C $(KDIR) M=$(PWD) modules

clean:
    make -C $(KDIR) M=$(PWD) clean

此外,如果有人知道禁用缓存的更简单方法,我会洗耳恭听!

v7_exit_coherency_flush() 用于电源管理代码以干净地从内核中取出 CPU 以关闭它的电源 - 它不能从随机模块调用,这是有充分理由的。如果你真的想以奇怪和微妙的方式丢失数据并使机器崩溃,你不妨完全绕过内核函数并使用一个简单的内联汇编直接命中 SCTLR*.

我不敢想象你想要实现什么,但如果你真的想 运行 Linux(非常缓慢)关闭缓存,你需要重建内核, 关闭 CONFIG_SMP 以打开 CONFIG_CPU_DCACHE_DISABLE。这是唯一可能有效的模糊支持方法。

* 我什至不打算解释,这是个糟糕的主意。