legionus / kbd

Mirror of https://git.kernel.org/pub/scm/linux/kernel/git/legion/kbd.git
https://kbd-project.org
Other
84 stars 41 forks source link

Save previous font and Unicode map broken #94

Closed Tecol87 closed 1 year ago

Tecol87 commented 1 year ago

Saving the previous font is broken since 2.6.0. The tty just shows garbage. It works to save a font with 2.5.1 and load it with 2.6.0.

Steps to reproduce:

# setfont default8x16
# # save font
# setfont -O /tmp/myfont
# # load font
# setfont /tmp/myfont
setfont: ERROR setfont.c:141 try_loadfont: font position 32 is nonblank
setfont: ERROR setfont.c:153 try_loadfont: background will look funny
legionus commented 1 year ago

Hm. I can't reproduce it.

#!/bin/sh -e
kbd-2.16.0/src/setfont /lib/kbd/consolefonts/default8x16.psfu.gz
kbd-2.16.0/src/setfont -O /tmp/default8x16.psfu
kbd-2.16.0/src/setfont /tmp/default8x16.psfu

The script runs without errors.

$ kbd-2.15.1/src/setfont -O /tmp/UniCyr_8x16.psf.v2.15.1
$ kbd-2.16.0/src/setfont -O /tmp/UniCyr_8x16.psf.v2.16.0

$ file /tmp/UniCyr_8x16.psf.v2.15.1 /tmp/UniCyr_8x16.psf.v2.16.0
/tmp/UniCyr_8x16.psf.v2.15.1: Linux/i386 PC Screen Font v1 data, 256 characters, Unicode directory, 8x16
/tmp/UniCyr_8x16.psf.v2.16.0: Linux/i386 PC Screen Font v1 data, 256 characters, Unicode directory, 8x16

$ cmp /tmp/UniCyr_8x16.psf.v2.15.1 /tmp/UniCyr_8x16.psf.v2.16.0; echo $?
0

$ kbd-2.16.0/src/setfont /tmp/UniCyr_8x16.psf.v2.16.0; echo $?
0

I don't see any difference in font dumps between old and current version.

legionus commented 1 year ago

@Tecol87 Please provide more information.

Tecol87 commented 1 year ago

@legionus Thank you very much. This happens on my uptodate arch linux system with ter-u32b and default8x16. If I load the resulting font, it shows diamonds where no character is and it shows mostly spaces and some uncommon special characters where a character is.

cmp /tmp/myfont-1*
/tmp/myfont-15.1.psfu /tmp/myfont-16.0.psfu differ: byte 109, line 1

Here are the two different fonts files. I gzipped them, because github does not accept .psfu files. myfont-15.1.psfu.gz myfont-16.0.psfu.gz

I don't know what additional data I can provide, but I am happy to provide any data or info you request, also I am happy to try patches.

legionus commented 1 year ago

What kernel version are you using?

Tecol87 commented 1 year ago

@legionus 6.3.8-arch1-1

Tecol87 commented 1 year ago

@legionus Good catch, this does not happen with 6.1.34-1 (and not with 6.3.4). Do you know how to debug this or where to send it? Otherwise I'll have a look at what kernel mailing list this fits. (and try to bisect it tomorrow).

legionus commented 1 year ago

@Tecol87 It seems to be related to tall font support. Could you try the for-master branch fix ?

https://github.com/legionus/kbd/archive/1e15af4d8b272ca50e9ee1d0c584c5859102c848.zip

Tecol87 commented 1 year ago

@legionus Thank you, sadly the behavior is the same.

legionus commented 1 year ago

@Tecol87 Interesting. Then could you please attach the output of the command:

strace -o /tmp/setfont.log setfont /tmp/myfont
legionus commented 1 year ago

Ops. Sorry. Not output, but /tmp/setfont.log itself.

Tecol87 commented 1 year ago

@legionus Here is the strace log. setfont.log.gz

Tecol87 commented 1 year ago

@legionus Sorry, the log is from 6.3.5 (while bisecting). I attach a log from 6.3.8 (save and load).

setfont-load.log.gz setfont-save.log.gz

Tecol87 commented 1 year ago

Is there a reason you want the strace from loading the font? I thought the problem is saving the font (-O). The saved font from 2.6.0 and 1e15af4d8b272ca50e9ee1d0c584c5859102c848 do not differ. If I save a font under 6.1.34 and load it under 6.3.8, the font loads correct.

legionus commented 1 year ago

The thing is that kernel 6.2 introduced support for tall fonts. They need to be fetched and loaded via a new operation. Then this font will be written to the file. Then you try to read this file again and load it into the kernel.

You have a normal font in the linux kernel so there is no difference. The old setfont retrieves the font according to the old scheme and write it. The result is a correct .psfu. The new setfont on a new kernel should use the new mechanism (should be visible in strace). I think that at the time of writing the font to the file, the psfu header is written incorrectly and therefore an error occurs at the time of loading the font.

Tecol87 commented 1 year ago

Thank you very much for the detailed explanation. I had a look at the files and there are differences in the first 16kb (17kb total). Very often content in 6.1 is zero in the 6.3 file, besides that, I was not able to recognize a pattern. (Also I don't have knowledge about psfu files).

legionus commented 1 year ago

Unfortunately I have an older kernel and can't reproduce this problem. But I tried to fix the font reading/writing in for-master. Please try this version.

https://github.com/legionus/kbd/archive/refs/heads/for-master.zip

Tecol87 commented 1 year ago

@legionus Thank you very much for your time and work! The font changed a bit, now the diamonds are squares and the random characters are different. I attach the strace logs and the font file.

setfont-load.log.gz setfont-save.log.gz my_font.gz

legionus commented 1 year ago

@Tecol87 Thank you. Now the situation has become perfectly clear. Please try the for-master version again. I believe the problem is fixed there.

Tecol87 commented 1 year ago

@legionus It works like a charm, thank you very much! Respect for fixing this without the new kernel!

legionus commented 1 year ago

Fixed in master.