Re: [PATCH] USB keyboard

2009-02-21 Thread Robert Millan
On Sun, Feb 08, 2009 at 08:53:23PM +0100, Robert Millan wrote:
> 
> Hi,
> 
> This patch implements USB keyboard support.  It is based on work by Marco
> Gerards, to which I made some adjustments, synced with trunk, and fixed a
> pair of bugs.

Committed.

-- 
Robert Millan

  The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and
  how) you may access your data; but nobody's threatening your freedom: we
  still allow you to remove your data and not access it at all."


___
Grub-devel mailing list
Grub-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/grub-devel


Re: [PATCH] USB keyboard

2009-02-09 Thread step21
O.k., finally got everything patched and booted from it.
What I did: Just to be sure set root with "root=(hd0,2)"
then set debug=usbkeyb or usb_keyboard (tried both)
then insmod uhci;insmod usb_keyboard; terminal_input usb_keyboard
I get no new promp and it "hangs".
To get debug output, do I have to include a #define DEBUG_USB_KEYBOARD
or something in the src too in addition to debug=usbkeyb
?



On Mon, Feb 9, 2009 at 3:27 PM, step21  wrote:
> Thanks for clarifying this.
>
>
>
> On Mon, Feb 9, 2009 at 3:09 PM, Robert Millan  wrote:
>> On Sun, Feb 08, 2009 at 09:04:56PM +0100, step21 wrote:
>>> didn't this work already? or was this only cause of efi? just while testing
>>> the input issue on my mac i attached a usb keyboard too, and that worked.
>>
>> When the firmware (BIOS/EFI/OFW) supports USB and GRUB uses its callbacks,
>> then USB keyboards can work.  Using the driver helps when the firmware
>> doesn't support USB, or when its USB support is broken in some way.
>>
>> --
>> Robert Millan
>>
>>  The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and
>>  how) you may access your data; but nobody's threatening your freedom: we
>>  still allow you to remove your data and not access it at all."
>>
>>
>> ___
>> Grub-devel mailing list
>> Grub-devel@gnu.org
>> http://lists.gnu.org/mailman/listinfo/grub-devel
>>
>


___
Grub-devel mailing list
Grub-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/grub-devel


Re: [PATCH] USB keyboard

2009-02-09 Thread step21
Thanks for clarifying this.



On Mon, Feb 9, 2009 at 3:09 PM, Robert Millan  wrote:
> On Sun, Feb 08, 2009 at 09:04:56PM +0100, step21 wrote:
>> didn't this work already? or was this only cause of efi? just while testing
>> the input issue on my mac i attached a usb keyboard too, and that worked.
>
> When the firmware (BIOS/EFI/OFW) supports USB and GRUB uses its callbacks,
> then USB keyboards can work.  Using the driver helps when the firmware
> doesn't support USB, or when its USB support is broken in some way.
>
> --
> Robert Millan
>
>  The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and
>  how) you may access your data; but nobody's threatening your freedom: we
>  still allow you to remove your data and not access it at all."
>
>
> ___
> Grub-devel mailing list
> Grub-devel@gnu.org
> http://lists.gnu.org/mailman/listinfo/grub-devel
>


___
Grub-devel mailing list
Grub-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/grub-devel


Re: [PATCH] USB keyboard

2009-02-09 Thread Robert Millan
On Sun, Feb 08, 2009 at 09:04:56PM +0100, step21 wrote:
> didn't this work already? or was this only cause of efi? just while testing
> the input issue on my mac i attached a usb keyboard too, and that worked.

When the firmware (BIOS/EFI/OFW) supports USB and GRUB uses its callbacks,
then USB keyboards can work.  Using the driver helps when the firmware
doesn't support USB, or when its USB support is broken in some way.

-- 
Robert Millan

  The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and
  how) you may access your data; but nobody's threatening your freedom: we
  still allow you to remove your data and not access it at all."


___
Grub-devel mailing list
Grub-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/grub-devel


Re: [PATCH] USB keyboard

2009-02-08 Thread step21
didn't this work already? or was this only cause of efi? just while testing
the input issue on my mac i attached a usb keyboard too, and that worked.


On Sun, Feb 8, 2009 at 8:53 PM, Robert Millan  wrote:

>
> Hi,
>
> This patch implements USB keyboard support.  It is based on work by Marco
> Gerards, to which I made some adjustments, synced with trunk, and fixed a
> pair of bugs.
>
> --
> Robert Millan
>
>  The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and
>  how) you may access your data; but nobody's threatening your freedom: we
>  still allow you to remove your data and not access it at all."
>
> ___
> Grub-devel mailing list
> Grub-devel@gnu.org
> http://lists.gnu.org/mailman/listinfo/grub-devel
>
>
___
Grub-devel mailing list
Grub-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/grub-devel


[PATCH] USB keyboard

2009-02-08 Thread Robert Millan

Hi,

This patch implements USB keyboard support.  It is based on work by Marco
Gerards, to which I made some adjustments, synced with trunk, and fixed a
pair of bugs.

-- 
Robert Millan

  The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and
  how) you may access your data; but nobody's threatening your freedom: we
  still allow you to remove your data and not access it at all."
2009-02-08  Robert Millan  

	Implement USB keyboard support (based on patch by Marco Gerards)

	* conf/i386-pc.rmk (pkglib_MODULES): Add `usb_keyboard.mod'.
	(usb_keyboard_mod_SOURCES, usb_keyboard_mod_CFLAGS)
	(usb_keyboard_mod_LDFLAGS): New variables.

	* term/usb_keyboard.c: New file.

Index: conf/i386-pc.rmk
===
--- conf/i386-pc.rmk	(revision 1982)
+++ conf/i386-pc.rmk	(working copy)
@@ -172,7 +172,7 @@ pkglib_MODULES = biosdisk.mod _chain.mod
 	ata.mod vga.mod memdisk.mod pci.mod lspci.mod \
 	aout.mod _bsd.mod bsd.mod pxe.mod pxecmd.mod datetime.mod date.mod \
 	datehook.mod lsmmap.mod \
-	usb.mod uhci.mod ohci.mod usbtest.mod usbms.mod
+	usb.mod uhci.mod ohci.mod usbtest.mod usbms.mod usb_keyboard.mod
 
 # For biosdisk.mod.
 biosdisk_mod_SOURCES = disk/i386/pc/biosdisk.c
@@ -333,6 +333,11 @@ usbms_mod_SOURCES = disk/usbms.c
 usbms_mod_CFLAGS = $(COMMON_CFLAGS)
 usbms_mod_LDFLAGS = $(COMMON_LDFLAGS)
 
+# For usb_keyboard.mod
+usb_keyboard_mod_SOURCES = term/usb_keyboard.c
+usb_keyboard_mod_CFLAGS = $(COMMON_CFLAGS)
+usb_keyboard_mod_LDFLAGS = $(COMMON_LDFLAGS)
+
 # For pxe.mod
 pxe_mod_SOURCES = fs/i386/pc/pxe.c
 pxe_mod_CFLAGS = $(COMMON_CFLAGS)
Index: term/usb_keyboard.c
===
--- term/usb_keyboard.c	(revision 0)
+++ term/usb_keyboard.c	(revision 0)
@@ -0,0 +1,257 @@
+/* Support for the HID Boot Protocol.  */
+/*
+ *  GRUB  --  GRand Unified Bootloader
+ *  Copyright (C) 2008, 2009  Free Software Foundation, Inc.
+ *
+ *  GRUB is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  GRUB is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with GRUB.  If not, see .
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+
+static char keyboard_map[128] =
+  {
+'\0', '\0', '\0', '\0', 'a', 'b', 'c', 'd',
+'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l',
+'m', 'n', 'o', 'p', 'q', 'r', 's', 't',
+'u', 'v', 'w', 'x', 'y', 'z', '1', '2',
+'3', '4', '5', '6', '7', '8', '9', '0',
+'\n', GRUB_TERM_ESC, GRUB_TERM_BACKSPACE, GRUB_TERM_TAB, ' ', '-', '=', '[',
+']', '\\', '#', ';', '\'', '`', ',', '.',
+'/', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
+'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
+'\0', '\0', GRUB_TERM_HOME, GRUB_TERM_PPAGE, GRUB_TERM_DC, GRUB_TERM_END, GRUB_TERM_NPAGE, GRUB_TERM_RIGHT,
+GRUB_TERM_LEFT, GRUB_TERM_DOWN, GRUB_TERM_UP
+  };
+
+static char keyboard_map_shift[128] =
+  {
+'\0', '\0', '\0', '\0', 'A', 'B', 'C', 'D',
+'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L',
+'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T',
+'U', 'V', 'W', 'X', 'Y', 'Z', '!', '@',
+'#', '$', '%', '^', '&', '*', '(', ')',
+'\n', '\0', '\0', '\0', ' ', '_', '+', '{',
+'}', '|', '#', ':', '"', '`', '<', '>',
+'?'
+  };
+
+static grub_usb_device_t usbdev;
+
+static void
+grub_usb_hid (void)
+{
+  struct grub_usb_desc_device *descdev;
+
+  auto int usb_iterate (grub_usb_device_t dev);
+  int usb_iterate (grub_usb_device_t dev)
+{
+  descdev = &dev->descdev;
+  
+  grub_dprintf ("usb_keyboard", "%x %x %x\n",
+		   descdev->class, descdev->subclass, descdev->protocol);
+
+#if 0
+  if (descdev->class != 0x09
+	  || descdev->subclass == 0x01
+	  || descdev->protocol != 0x02)
+	return 0;
+#endif
+
+  if (descdev->class != 0 || descdev->subclass != 0 || descdev->protocol != 0)
+	return 0;
+
+  grub_printf ("HID found!\n");
+
+  usbdev = dev;
+
+  return 1;
+}
+  grub_usb_iterate (usb_iterate);
+
+  /* Place the device in boot mode.  */
+  grub_usb_control_msg (usbdev, 0x21, 0x0B, 0, 0, 0, 0);
+
+  /* Reports everytime an event occurs and not more often than that.  */
+  grub_usb_control_msg (usbdev, 0x21, 0x0A, 0<<8, 0, 0, 0);
+}
+
+static grub_err_t
+grub_usb_keyboard_getreport (grub_usb_device_t dev, unsigned char *report)
+{
+  return grub_usb_control_msg (dev, (1 << 7) | (1 << 5) | 1, 0x01, 0, 0,
+			   8, (char *) report);
+}
+
+
+
+static int
+grub_usb