您尚未登录。

楼主 # 2022-06-08 23:30:56

SuperSpy
会员
注册时间: 2022-04-28
已发帖子: 13
积分: 123

lcd如何与tty1相对应?

本人是新手第一次玩带linux的板子,之前按照帖子教程把荔枝派zero的板子跑了起来,但是很多东西都不是很清楚,现在想问一个有关lcd的问题:我发现很多帖子里面说如果想把启动内核的信息输出到lcd上,需要在uboot传参的时候定义bootargs为“console = tty1”,如果是串口作为控制台的话就是“console = ttyS0”。想问一下,为什么这个tty1是跟lcd所对应的呢?是内核驱动写死的嘛,还是在哪里能够设置?搜了不少资料,也都只说的是“如果需要lcd作为控制台,就设置console = tty1”之类的结论,没找到哪里讲lcd为什么跟tty1是对应的关系。我大概能猜到是内核驱动里面设置的吧,但是具体怎么回事根本不清楚,想请教一下大佬科普一下,困扰好几天了0.0还请大佬们指点!

离线

楼主 #2 2022-06-09 14:53:29

SuperSpy
会员
注册时间: 2022-04-28
已发帖子: 13
积分: 123

Re: lcd如何与tty1相对应?

@司徒 多谢多谢,我先看看资料哈~有什么不会的还给麻烦请教您哇~

离线

楼主 #3 2022-06-09 18:06:54

SuperSpy
会员
注册时间: 2022-04-28
已发帖子: 13
积分: 123

Re: lcd如何与tty1相对应?

大概浏览了一下资料,以及司徒大佬发的连接,大概了解流程:简单来说就是lcd属于framebuffer(fb)类设备,内核在注册fb类设备的时候,其中有一步骤就是设置虚拟控制终端(ttyN,N为1 2 3 4 5 6....)与fb设备之间的对应关系,其具体关系摘抄如下:
fbcon=map:<0123>

    This is an interesting option. It tells which driver gets mapped to which console. The value ‘0123’ is a sequence that gets repeated until the total length is 64 which is the number of consoles available. In the above example, it is expanded to 012301230123… and the mapping will be:

    tty | 1 2 3 4 5 6 7 8 9 ...
    fb  | 0 1 2 3 0 1 2 3 0 ...

    ('cat /proc/fb' should tell you what the fb numbers are)

    One side effect that may be useful is using a map value that exceeds the number of loaded fb drivers. For example, if only one driver is available, fb0, adding fbcon=map:1 tells fbcon not to take over the console.

fbcon.c(/home/linux/linux-5.10/drivers/video/fbdev/core/)文件中set_con2fb_map函数负责这个映射过程,该函数简介如下:
/**
*    set_con2fb_map - map console to frame buffer device
*    @unit: virtual console number to map
*    @newidx: frame buffer index to map virtual console to
*      @user: user request
*
*    Maps a virtual console @unit to a frame buffer device
*    @newidx.
*
*    This should be called with the console lock held.
static int set_con2fb_map(int unit, int newidx, int user)
{
    struct vc_data *vc = vc_cons[unit].d;
    int oldidx = con2fb_map[unit];
    struct fb_info *info = registered_fb[newidx];
    struct fb_info *oldinfo = NULL;
    int found, err = 0;

    WARN_CONSOLE_UNLOCKED();

    if (oldidx == newidx)
        return 0;

    if (!info)
        return -EINVAL;

    if (!search_for_mapped_con() || !con_is_bound(&fb_con)) {
        info_idx = newidx;
        return do_fbcon_takeover(0);
    }

    if (oldidx != -1)
        oldinfo = registered_fb[oldidx];

    found = search_fb_in_map(newidx);

    con2fb_map[unit] = newidx;
    if (!err && !found)
        err = con2fb_acquire_newinfo(vc, info, unit, oldidx);

    /*
     * If old fb is not mapped to any of the consoles,
     * fbcon should release it.
     */
    if (!err && oldinfo && !search_fb_in_map(oldidx))
        err = con2fb_release_oldinfo(vc, oldinfo, info, unit, oldidx,
                         found);

    if (!err) {
        int show_logo = (fg_console == 0 && !user &&
                 logo_shown != FBCON_LOGO_DONTSHOW);

        if (!found)
            fbcon_add_cursor_timer(info);
        con2fb_map_boot[unit] = newidx;
        con2fb_init_display(vc, info, unit, show_logo);
    }

    if (!search_fb_in_map(info_idx))
        info_idx = newidx;

    return err;
}

这个问题断断续续查找了给有一星期了,感觉自己还是学艺不精,linux内核知识博大精深,只是有关驱动的部分感觉就足够研究了,感谢司徒大佬的友情帮助。在此发帖记录一下,希望能对后面学习的人有所帮助~

离线

页脚

工信部备案:粤ICP备20025096号 Powered by FluxBB

感谢为中文互联网持续输出优质内容的各位老铁们。 QQ: 516333132, 微信(wechat): whycan_cn (哇酷网/挖坑网/填坑网) service@whycan.cn