프레임버퍼 로드 가능 커널 모듈에 메모리를 할당하는 방법(Linux)

프레임버퍼 로드 가능 커널 모듈에 메모리를 할당하는 방법(Linux)

저는 e-reader를 Raspberry Pi의 외부 화면으로 사용할 수 있도록 "가짜" 프레임 버퍼 장치를 작성하고 있습니다. e-reader 부분은 잘 작동합니다(https://github.com/lllandsmeer/inkvt), 하지만 이제는 Linux에서 외부 화면으로 표시되기를 원합니다.

가상 Linux 프레임 버퍼가 "가장 쉬운" 것이지만 Linux에 가짜 화면(xrandr에 표시됨)을 추가하는 다른 옵션이 있을까요?

어쨌든 이것은 현재 커널 모듈입니다. /dev/fbX쿼리 후에 fbset올바르게 구성된 것처럼 보이는 장치를 생성합니다 . 그런데 사용하려고 하면 실패하고 fbcat: Corrupted page table at address 7fd7d5c90000dmesg에서 오류가 발생합니다.

메모리 영역( )을 잘못 설정했기 때문인 것 같습니다 char mem[]. instread를 사용해 보았지만 kalloc그것도 작동하지 않습니다. 어떻게 해야 하나요?

#include <linux/init.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/fb.h>

#define WIDTH 256
#define HEIGHT 256

static char mem[WIDTH*HEIGHT*3];

static void op_fillrect(struct fb_info * info, const struct fb_fillrect * rect) {
    printk(KERN_ALERT "fillrect\n");
}

static void op_copyarea(struct fb_info * info, const struct fb_copyarea * area) {
    printk(KERN_ALERT "copyarea\n");
}

static void op_imageblit(struct fb_info * info, const struct fb_image * image) {
    printk(KERN_ALERT "imageblit\n");
}

static struct fb_info * info;

static struct fb_ops ops = {
    .owner = THIS_MODULE,
    .fb_fillrect = op_fillrect,
    .fb_copyarea = op_copyarea,
    .fb_imageblit = op_imageblit,
};

static const struct fb_fix_screeninfo fix = {
    .id = "LennartFB",
    .smem_start = (unsigned long)mem,
    .smem_len = sizeof(mem),
    .type = FB_TYPE_PACKED_PIXELS,
    .visual = FB_VISUAL_TRUECOLOR,
    .line_length = 256,
};

static const struct fb_var_screeninfo var = {
    .xres = WIDTH,
    .yres = HEIGHT,
    .xres_virtual = WIDTH,
    .yres_virtual = HEIGHT,
    .bits_per_pixel = 24,
    .height = 256,
    .width = 256,
    .vmode = FB_VMODE_NONINTERLACED,
    .red = { .length = 8, .offset = 16, },
    .green = { .length = 8, .offset = 8, },
    .blue = { .length = 8, .offset = 0, }
};

static int mod_init(void) {
    int err;
    info = framebuffer_alloc(0, 0);
    if (!info) return -1;
    info->fbops = &ops;
    info->fix = fix;
    info->var = var;
    info->screen_base = mem;
    err = fb_alloc_cmap(&info->cmap, 2, 0);
    if (err < 0) return -2;
    err = register_framebuffer(info);
    if (err < 0) return -3;
    return 0;
}

static void mod_exit(void) {
    return;
}

module_init(mod_init);
module_exit(mod_exit);
MODULE_LICENSE("GPL v3");

정보:

[ 4984.929380] fbcat: Corrupted page table at address 7fd7d5c90000
[ 4984.929385] PGD 8000000277709067 P4D 8000000277709067 PUD 3eb108067 PMD 2c732e067 PTE 800fffffc0f5d235
[ 4984.929391] Bad pagetable: 000d [#1] SMP PTI
[ 4984.929396] CPU: 11 PID: 8076 Comm: fbcat Tainted: P           OE     5.3.0-46-generic #38~18.04.1-Ubuntu
[ 4984.929398] Hardware name: Acer Aspire A715-72G/Charmeleon_CFS, BIOS V1.19 07/13/2018
[ 4984.929403] RIP: 0033:0x55fa6cb22e98

관련 정보