vivier / qemu-m68k

Other
40 stars 6 forks source link

Adding support for /proc/hardware in qemu-user #34

Closed glaubitz closed 4 years ago

glaubitz commented 6 years ago

On linux-m68k, the kernel adds a pseudo file called hardware to the /proc filesystem in order to display some hardware information. Some packages like console-setup use this information to detect the type of m68k hardware being used.

See: https://salsa.debian.org/installer-team/console-setup/blob/master/debian/keyboard-configuration.config#L300

Since console-setup is required for some packages to be built like xorg-server, I have written a very small kernel module which adds the pseudo file containing Model: Atari Falcon (with Afterburner040) which I just copied from the Aranym emulator.

The source code for the kernel module is:

#include <linux/module.h>
#include <linux/proc_fs.h>
#include <linux/seq_file.h>

static int hello_proc_show(struct seq_file *m, void *v) {
  seq_printf(m, "Model:          Atari Falcon (with Afterburner040)\n");
  return 0;
}

static int hello_proc_open(struct inode *inode, struct  file *file) {
  return single_open(file, hello_proc_show, NULL);
}

static const struct file_operations hello_proc_fops = {
  .owner = THIS_MODULE,
  .open = hello_proc_open,
  .read = seq_read,
  .llseek = seq_lseek,
  .release = single_release,
};

static int __init hello_proc_init(void) {
  proc_create("hardware", 0, NULL, &hello_proc_fops);
  return 0;
}

static void __exit hello_proc_exit(void) {
  remove_proc_entry("hardware", NULL);
}

MODULE_LICENSE("GPL");
module_init(hello_proc_init);
module_exit(hello_proc_exit);

Now, in order to improve compatibility, I was wondering whether it would make sense to add support for the /proc/hardware pseudo file to qemu-user as well? Of course, this would apply to qemu-user on Linux only.

vivier commented 6 years ago

Now, in order to improve compatibility, I was wondering whether it would make sense to add support for the /proc/hardware pseudo file to qemu-user as well? Of course, this would apply to qemu-user on Linux only.

Yes, it's easy to add. We need the same thing for sparc glibc(?) installer that checks /proc/cpuinfo to know if the system is sun4v or sun4u.

vivier commented 6 years ago

I have pushed a patch in my branch linux-user-proc. The model that is reported is "qemu-m68k", let me know if there is any problem with that.

# uname -a
Linux Quad 4.17.9-200.fc28.x86_64 #1 SMP Mon Jul 23 21:41:29 UTC 2018 m68k GNU/Linux
# cat /proc/hardware
Model:      qemu-m68k
glaubitz commented 6 years ago

Have you tried whether this allows installing the console-setup package?

vivier commented 6 years ago

Yes, it works but it asks to "select the model of the keyboard of this machine", I don't know if it could be a problem or not.

glaubitz commented 6 years ago

Most likely not since the package will be installed with debconf in non-interactive mode during package builds. I'll test that tomorrow.

glaubitz commented 5 years ago

I should finally test this.

glaubitz commented 5 years ago

Without the patch:

(sid-m68k-sbuild)root@nofan:/# export DEBIAN_FRONTEND=noninteractive ; apt install keyboard-configuration 
Reading package lists... Done
Building dependency tree       
Reading state information... Done
(...)
Selecting previously unselected package keyboard-configuration.
(Reading database ... 19725 files and directories currently installed.)
Preparing to unpack .../keyboard-configuration_1.187_all.deb ...
Unpacking keyboard-configuration (1.187) ...
Setting up keyboard-configuration (1.187) ...
/usr/bin/locale: Cannot set LC_CTYPE to default locale: No such file or directory
/usr/bin/locale: Cannot set LC_MESSAGES to default locale: No such file or directory
/usr/bin/locale: Cannot set LC_ALL to default locale: No such file or directory
/usr/bin/locale: Cannot set LC_CTYPE to default locale: No such file or directory
/usr/bin/locale: Cannot set LC_MESSAGES to default locale: No such file or directory
/usr/bin/locale: Cannot set LC_ALL to default locale: No such file or directory
/bin/sed: can't read /proc/hardware: No such file or directory
dpkg: error processing package keyboard-configuration (--configure):
 installed keyboard-configuration package post-installation script subprocess returned error exit status 2
Processing triggers for man-db (2.8.4-3) ...
Not building database; man-db/auto-update is not 'true'.
Errors were encountered while processing:
 keyboard-configuration
E: Sub-process /usr/bin/dpkg returned an error code (1)
(sid-m68k-sbuild)root@nofan:/#

With the (rebased) patch applied:

(sid-m68k-sbuild)root@nofan:/# export DEBIAN_FRONTEND=noninteractive ; apt install keyboard-configuration
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following NEW packages will be installed:
  keyboard-configuration
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 0 B/397 kB of archives.
After this operation, 2575 kB of additional disk space will be used.
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
        LANGUAGE = "en_US:en",
        LC_ALL = "en_US.UTF-8",
        LC_CTYPE = "en_US.UTF-8",
        LANG = "en_US.UTF-8"
    are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").
debconf: delaying package configuration, since apt-utils is not installed
E: Can not write log (Is /dev/pts mounted?) - posix_openpt (19: No such device)
Selecting previously unselected package keyboard-configuration.
(Reading database ... 14921 files and directories currently installed.)
Preparing to unpack .../keyboard-configuration_1.187_all.deb ...
Unpacking keyboard-configuration (1.187) ...
Setting up keyboard-configuration (1.187) ...
/usr/bin/locale: Cannot set LC_CTYPE to default locale: No such file or directory
/usr/bin/locale: Cannot set LC_MESSAGES to default locale: No such file or directory
/usr/bin/locale: Cannot set LC_ALL to default locale: No such file or directory
/usr/bin/locale: Cannot set LC_CTYPE to default locale: No such file or directory
/usr/bin/locale: Cannot set LC_MESSAGES to default locale: No such file or directory
/usr/bin/locale: Cannot set LC_ALL to default locale: No such file or directory
Processing triggers for man-db (2.8.4-3) ...
Not building database; man-db/auto-update is not 'true'.
(sid-m68k-sbuild)root@nofan:/#

So, it fixes the issue for me. Can we get it upstreamed?

glaubitz commented 5 years ago

I have used this rebased version:

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 280137da8c..4042b75942 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -6694,7 +6694,7 @@ static int is_proc_myself(const char *filename, const char *entry)
     return 0;
 }

-#if defined(HOST_WORDS_BIGENDIAN) != defined(TARGET_WORDS_BIGENDIAN)
+#if defined(HOST_WORDS_BIGENDIAN) != defined(TARGET_WORDS_BIGENDIAN) || defined(TARGET_M68K)
 static int is_proc(const char *filename, const char *entry)
 {
     return strcmp(filename, entry) == 0;
@@ -6738,6 +6738,14 @@ static int open_net_route(void *cpu_env, int fd)
 }
 #endif

+#if defined(TARGET_M68K)
+static int open_hardware(void *cpu_env, int fd)
+{
+    dprintf(fd, "Model:\t\tqemu-m68k\n");
+    return 0;
+}
+#endif
+
 static int do_openat(void *cpu_env, int dirfd, const char *pathname, int flags, mode_t mode)
 {
     struct fake_open {
@@ -6754,6 +6762,9 @@ static int do_openat(void *cpu_env, int dirfd, const char *pathname, int flags,
 #if defined(HOST_WORDS_BIGENDIAN) != defined(TARGET_WORDS_BIGENDIAN)
         { "/proc/net/route", open_net_route, is_proc },
 #endif
+#if defined(TARGET_M68K)
+        { "/proc/hardware", open_hardware, is_proc },
+#endif
         { NULL, NULL, NULL }
     };
vivier commented 4 years ago

added by 4ab6713ef6d9 ("linux-user: add pseudo /proc/hardware for m68k")