Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
glaubitz opened this issue Aug 7, 2018 · 9 comments
Closed

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

glaubitz opened this issue Aug 7, 2018 · 9 comments

Comments

@glaubitz
Copy link
Contributor

glaubitz commented Aug 7, 2018

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
Copy link
Owner

vivier commented Aug 8, 2018

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 added a commit to vivier/qemu that referenced this issue Aug 8, 2018
Debian console-setup uses /proc/hardware to guess the keyboard layout.
If the file /proc/hardware cannot be opened, the installation fails.

This patch adds a pseudo /proc/hardware file to report the model of
the machine. Instead of reporting a known and fake model, it
reports "qemu-m68k", which is true, and avoids to set the configuration
for an Amiga/Apple/Atari and let the user to chose the good one.

Bug: vivier/qemu-m68k#34
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
@vivier
Copy link
Owner

vivier commented Aug 8, 2018

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
Copy link
Contributor Author

glaubitz commented Aug 8, 2018

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

@vivier
Copy link
Owner

vivier commented Aug 8, 2018

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
Copy link
Contributor Author

glaubitz commented Aug 8, 2018

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

@glaubitz
Copy link
Contributor Author

I should finally test this.

@glaubitz
Copy link
Contributor Author

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
Copy link
Contributor Author

glaubitz commented Dec 14, 2018

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 added a commit to vivier/qemu that referenced this issue May 22, 2019
Debian console-setup uses /proc/hardware to guess the keyboard layout.
If the file /proc/hardware cannot be opened, the installation fails.

This patch adds a pseudo /proc/hardware file to report the model of
the machine. Instead of reporting a known and fake model, it
reports "qemu-m68k", which is true, and avoids to set the configuration
for an Amiga/Apple/Atari and let the user to chose the good one.

Bug: vivier/qemu-m68k#34
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20190517133149.19593-3-laurent@vivier.eu>
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
vivier added a commit to vivier/qemu that referenced this issue May 22, 2019
Debian console-setup uses /proc/hardware to guess the keyboard layout.
If the file /proc/hardware cannot be opened, the installation fails.

This patch adds a pseudo /proc/hardware file to report the model of
the machine. Instead of reporting a known and fake model, it
reports "qemu-m68k", which is true, and avoids to set the configuration
for an Amiga/Apple/Atari and let the user to chose the good one.

Bug: vivier/qemu-m68k#34
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20190517133149.19593-3-laurent@vivier.eu>
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
vivier added a commit to vivier/qemu that referenced this issue May 22, 2019
Debian console-setup uses /proc/hardware to guess the keyboard layout.
If the file /proc/hardware cannot be opened, the installation fails.

This patch adds a pseudo /proc/hardware file to report the model of
the machine. Instead of reporting a known and fake model, it
reports "qemu-m68k", which is true, and avoids to set the configuration
for an Amiga/Apple/Atari and let the user to chose the good one.

Bug: vivier/qemu-m68k#34
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20190517133149.19593-3-laurent@vivier.eu>
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
vivier added a commit to vivier/qemu that referenced this issue May 22, 2019
Debian console-setup uses /proc/hardware to guess the keyboard layout.
If the file /proc/hardware cannot be opened, the installation fails.

This patch adds a pseudo /proc/hardware file to report the model of
the machine. Instead of reporting a known and fake model, it
reports "qemu-m68k", which is true, and avoids to set the configuration
for an Amiga/Apple/Atari and let the user to chose the good one.

Bug: vivier/qemu-m68k#34
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20190517133149.19593-3-laurent@vivier.eu>
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
vivier added a commit to vivier/qemu that referenced this issue May 22, 2019
Debian console-setup uses /proc/hardware to guess the keyboard layout.
If the file /proc/hardware cannot be opened, the installation fails.

This patch adds a pseudo /proc/hardware file to report the model of
the machine. Instead of reporting a known and fake model, it
reports "qemu-m68k", which is true, and avoids to set the configuration
for an Amiga/Apple/Atari and let the user to chose the good one.

Bug: vivier/qemu-m68k#34
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20190517133149.19593-3-laurent@vivier.eu>
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
vivier added a commit to vivier/qemu that referenced this issue May 22, 2019
Debian console-setup uses /proc/hardware to guess the keyboard layout.
If the file /proc/hardware cannot be opened, the installation fails.

This patch adds a pseudo /proc/hardware file to report the model of
the machine. Instead of reporting a known and fake model, it
reports "qemu-m68k", which is true, and avoids to set the configuration
for an Amiga/Apple/Atari and let the user to chose the good one.

Bug: vivier/qemu-m68k#34
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20190517133149.19593-3-laurent@vivier.eu>
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
vivier added a commit to vivier/qemu that referenced this issue May 22, 2019
Debian console-setup uses /proc/hardware to guess the keyboard layout.
If the file /proc/hardware cannot be opened, the installation fails.

This patch adds a pseudo /proc/hardware file to report the model of
the machine. Instead of reporting a known and fake model, it
reports "qemu-m68k", which is true, and avoids to set the configuration
for an Amiga/Apple/Atari and let the user to chose the good one.

Bug: vivier/qemu-m68k#34
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20190517133149.19593-3-laurent@vivier.eu>
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
@vivier
Copy link
Owner

vivier commented Nov 8, 2019

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

@vivier vivier closed this as completed Nov 8, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants