"Das U-Boot" Source Tree
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge https://source.denx.de/u-boot/custodians/u-boot-usb

Tom Rini b03b4904 57cb92de

+241 -49
+70
common/usb.c
··· 28 28 #include <common.h> 29 29 #include <command.h> 30 30 #include <dm.h> 31 + #include <dm/device_compat.h> 31 32 #include <log.h> 32 33 #include <malloc.h> 33 34 #include <memalign.h> ··· 1084 1085 return 0; 1085 1086 } 1086 1087 1088 + static int usb_device_is_ignored(u16 id_vendor, u16 id_product) 1089 + { 1090 + ulong vid, pid; 1091 + char *end; 1092 + const char *cur = NULL; 1093 + 1094 + /* ignore list depends on env support */ 1095 + if (!CONFIG_IS_ENABLED(ENV_SUPPORT)) 1096 + return 0; 1097 + 1098 + cur = env_get("usb_ignorelist"); 1099 + 1100 + /* parse "usb_ignorelist" strictly */ 1101 + while (cur && cur[0] != '\0') { 1102 + vid = simple_strtoul(cur, &end, 0); 1103 + /* 1104 + * If strtoul did not parse a single digit or the next char is 1105 + * not ':' the ignore list is malformed. 1106 + */ 1107 + if (cur == end || end[0] != ':') 1108 + return -EINVAL; 1109 + 1110 + cur = end + 1; 1111 + pid = simple_strtoul(cur, &end, 0); 1112 + /* Consider '*' as wildcard for the product ID */ 1113 + if (cur == end && end[0] == '*') { 1114 + pid = U16_MAX + 1; 1115 + end++; 1116 + } 1117 + /* 1118 + * The ignore list is malformed if no product ID / wildcard was 1119 + * parsed or entries are not separated by ',' or terminated with 1120 + * '\0'. 1121 + */ 1122 + if (cur == end || (end[0] != ',' && end[0] != '\0')) 1123 + return -EINVAL; 1124 + 1125 + if (id_vendor == vid && (pid > U16_MAX || id_product == pid)) 1126 + return -ENODEV; 1127 + 1128 + if (end[0] == '\0') 1129 + break; 1130 + cur = end + 1; 1131 + } 1132 + 1133 + return 0; 1134 + } 1135 + 1087 1136 int usb_select_config(struct usb_device *dev) 1088 1137 { 1089 1138 unsigned char *tmpbuf = NULL; ··· 1098 1147 le16_to_cpus(&dev->descriptor.idVendor); 1099 1148 le16_to_cpus(&dev->descriptor.idProduct); 1100 1149 le16_to_cpus(&dev->descriptor.bcdDevice); 1150 + 1151 + /* ignore devices from usb_ignorelist */ 1152 + err = usb_device_is_ignored(dev->descriptor.idVendor, 1153 + dev->descriptor.idProduct); 1154 + if (err == -ENODEV) { 1155 + debug("Ignoring USB device 0x%x:0x%x\n", 1156 + dev->descriptor.idVendor, dev->descriptor.idProduct); 1157 + return err; 1158 + } else if (err == -EINVAL) { 1159 + /* 1160 + * Continue on "usb_ignorelist" parsing errors. The list is 1161 + * parsed for each device returning the error would result in 1162 + * ignoring all USB devices. 1163 + * Since the parsing error is independent of the probed device 1164 + * report errors with printf instead of dev_err. 1165 + */ 1166 + printf("usb_ignorelist parse error in \"%s\"\n", 1167 + env_get("usb_ignorelist")); 1168 + } else if (err < 0) { 1169 + return err; 1170 + } 1101 1171 1102 1172 /* 1103 1173 * Kingston DT Ultimate 32GB USB 3.0 seems to be extremely sensitive
+56 -3
common/usb_kbd.c
··· 24 24 #include <usb.h> 25 25 26 26 /* 27 + * USB vendor and product IDs used for quirks. 28 + */ 29 + #define USB_VENDOR_ID_APPLE 0x05ac 30 + #define USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_2021 0x029c 31 + #define USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_FINGERPRINT_2021 0x029a 32 + #define USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_NUMPAD_2021 0x029f 33 + 34 + #define USB_VENDOR_ID_KEYCHRON 0x3434 35 + 36 + #define USB_HID_QUIRK_POLL_NO_REPORT_IDLE BIT(0) 37 + 38 + /* 27 39 * If overwrite_console returns 1, the stdin, stderr and stdout 28 40 * are switched to the serial port, else the settings in the 29 41 * environment are used ··· 106 118 unsigned long last_report; 107 119 struct int_queue *intq; 108 120 121 + uint32_t ifnum; 122 + 109 123 uint32_t repeat_delay; 110 124 111 125 uint32_t usb_in_pointer; ··· 150 164 */ 151 165 static void usb_kbd_setled(struct usb_device *dev) 152 166 { 153 - struct usb_interface *iface = &dev->config.if_desc[0]; 154 167 struct usb_kbd_pdata *data = dev->privptr; 168 + struct usb_interface *iface = &dev->config.if_desc[data->ifnum]; 155 169 ALLOC_ALIGN_BUFFER(uint32_t, leds, 1, USB_DMA_MINALIGN); 156 170 157 171 *leds = data->flags & USB_KBD_LEDMASK; ··· 365 379 #if defined(CONFIG_SYS_USB_EVENT_POLL_VIA_CONTROL_EP) 366 380 struct usb_interface *iface; 367 381 struct usb_kbd_pdata *data = dev->privptr; 368 - iface = &dev->config.if_desc[0]; 382 + iface = &dev->config.if_desc[data->ifnum]; 369 383 usb_get_report(dev, iface->desc.bInterfaceNumber, 370 384 1, 0, data->new, USB_KBD_BOOT_REPORT_SIZE); 371 385 if (memcmp(data->old, data->new, USB_KBD_BOOT_REPORT_SIZE)) { ··· 464 478 struct usb_interface *iface; 465 479 struct usb_endpoint_descriptor *ep; 466 480 struct usb_kbd_pdata *data; 481 + unsigned int quirks = 0; 467 482 int epNum; 468 483 469 484 if (dev->descriptor.bNumConfigurations != 1) ··· 496 511 497 512 debug("USB KBD: found interrupt EP: 0x%x\n", ep->bEndpointAddress); 498 513 514 + switch (dev->descriptor.idVendor) { 515 + case USB_VENDOR_ID_APPLE: 516 + case USB_VENDOR_ID_KEYCHRON: 517 + quirks |= USB_HID_QUIRK_POLL_NO_REPORT_IDLE; 518 + break; 519 + default: 520 + break; 521 + } 522 + 499 523 data = malloc(sizeof(struct usb_kbd_pdata)); 500 524 if (!data) { 501 525 printf("USB KBD: Error allocating private data\n"); ··· 508 532 /* allocate input buffer aligned and sized to USB DMA alignment */ 509 533 data->new = memalign(USB_DMA_MINALIGN, 510 534 roundup(USB_KBD_BOOT_REPORT_SIZE, USB_DMA_MINALIGN)); 535 + 536 + data->ifnum = ifnum; 511 537 512 538 /* Insert private data into USB device structure */ 513 539 dev->privptr = data; ··· 534 560 usb_set_idle(dev, iface->desc.bInterfaceNumber, 0, 0); 535 561 #endif 536 562 563 + /* 564 + * Apple and Keychron keyboards do not report the device state. Reports 565 + * are only returned during key presses. 566 + */ 567 + if (quirks & USB_HID_QUIRK_POLL_NO_REPORT_IDLE) { 568 + debug("USB KBD: quirk: skip testing device state\n"); 569 + return 1; 570 + } 537 571 debug("USB KBD: enable interrupt pipe...\n"); 538 572 #ifdef CONFIG_SYS_USB_EVENT_POLL_VIA_INT_QUEUE 539 573 data->intq = create_int_queue(dev, data->intpipe, 1, ··· 561 595 { 562 596 char *stdinname; 563 597 struct stdio_dev usb_kbd_dev; 598 + unsigned int ifnum; 599 + unsigned int max_ifnum = min((unsigned int)USB_MAX_ACTIVE_INTERFACES, 600 + (unsigned int)dev->config.no_of_if); 564 601 int error; 565 602 566 603 /* Try probing the keyboard */ 567 - if (usb_kbd_probe_dev(dev, 0) != 1) 604 + for (ifnum = 0; ifnum < max_ifnum; ifnum++) { 605 + if (usb_kbd_probe_dev(dev, ifnum) == 1) 606 + break; 607 + } 608 + if (ifnum >= max_ifnum) 568 609 return -ENOENT; 569 610 570 611 /* Register the keyboard */ ··· 730 771 .bInterfaceClass = USB_CLASS_HID, 731 772 .bInterfaceSubClass = USB_SUB_HID_BOOT, 732 773 .bInterfaceProtocol = USB_PROT_HID_KEYBOARD, 774 + }, 775 + { 776 + USB_DEVICE(USB_VENDOR_ID_APPLE, 777 + USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_2021), 778 + }, 779 + { 780 + USB_DEVICE(USB_VENDOR_ID_APPLE, 781 + USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_FINGERPRINT_2021), 782 + }, 783 + { 784 + USB_DEVICE(USB_VENDOR_ID_APPLE, 785 + USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_NUMPAD_2021), 733 786 }, 734 787 { } /* Terminating entry */ 735 788 };
+13
doc/usage/environment.rst
··· 366 366 This means the count of blocks we can receive before 367 367 sending ack to server. 368 368 369 + usb_ignorelist 370 + Ignore USB devices to prevent binding them to an USB device driver. This can 371 + be used to ignore devices are for some reason undesirable or causes crashes 372 + u-boot's USB stack. 373 + An example for undesired behavior is the keyboard emulation of security keys 374 + like Yubikeys. U-boot currently supports only a single USB keyboard device 375 + so try to probe an useful keyboard device. The default environment blocks 376 + Yubico devices as common devices emulating keyboards. 377 + Devices are matched by idVendor and idProduct. The variable contains a comma 378 + separated list of idVendor:idProduct pairs as hexadecimal numbers joined 379 + by a colon. '*' functions as a wildcard for idProduct to block all devices 380 + with the specified idVendor. 381 + 369 382 vlan 370 383 When set to a value < 4095 the traffic over 371 384 Ethernet is encapsulated/received over 802.1q
+5
drivers/usb/host/xhci-ring.c
··· 685 685 reset_ep(udev, ep_index); 686 686 687 687 ring = virt_dev->eps[ep_index].ring; 688 + if (!ring) 689 + return -EINVAL; 690 + 688 691 /* 689 692 * How much data is (potentially) left before the 64KB boundary? 690 693 * XHCI Spec puts restriction( TABLE 49 and 6.4.1 section of XHCI Spec) ··· 871 874 ep_index = usb_pipe_ep_index(pipe); 872 875 873 876 ep_ring = virt_dev->eps[ep_index].ring; 877 + if (!ep_ring) 878 + return -EINVAL; 874 879 875 880 /* 876 881 * Check to see if the max packet size for the default control
+80 -46
drivers/usb/host/xhci.c
··· 475 475 } 476 476 477 477 /** 478 - * Configure the endpoint, programming the device contexts. 478 + * Fill endpoint contexts for interface descriptor ifdesc. 479 479 * 480 - * @param udev pointer to the USB device structure 481 - * Return: returns the status of the xhci_configure_endpoints 480 + * @param udev pointer to the USB device structure 481 + * @param ctrl pointer to the xhci pravte device structure 482 + * @param virt_dev pointer to the xhci virtual device structure 483 + * @param ifdesc pointer to the USB interface config descriptor 484 + * Return: returns the status of xhci_init_ep_contexts_if 482 485 */ 483 - static int xhci_set_configuration(struct usb_device *udev) 486 + static int xhci_init_ep_contexts_if(struct usb_device *udev, 487 + struct xhci_ctrl *ctrl, 488 + struct xhci_virt_device *virt_dev, 489 + struct usb_interface *ifdesc 490 + ) 484 491 { 485 - struct xhci_container_ctx *in_ctx; 486 - struct xhci_container_ctx *out_ctx; 487 - struct xhci_input_control_ctx *ctrl_ctx; 488 - struct xhci_slot_ctx *slot_ctx; 489 492 struct xhci_ep_ctx *ep_ctx[MAX_EP_CTX_NUM]; 490 493 int cur_ep; 491 - int max_ep_flag = 0; 492 494 int ep_index; 493 495 unsigned int dir; 494 496 unsigned int ep_type; 495 - struct xhci_ctrl *ctrl = xhci_get_ctrl(udev); 496 - int num_of_ep; 497 - int ep_flag = 0; 498 497 u64 trb_64 = 0; 499 - int slot_id = udev->slot_id; 500 - struct xhci_virt_device *virt_dev = ctrl->devs[slot_id]; 501 - struct usb_interface *ifdesc; 502 498 u32 max_esit_payload; 503 499 unsigned int interval; 504 500 unsigned int mult; 505 501 unsigned int max_burst; 506 502 unsigned int avg_trb_len; 507 503 unsigned int err_count = 0; 508 - 509 - out_ctx = virt_dev->out_ctx; 510 - in_ctx = virt_dev->in_ctx; 504 + int num_of_ep = ifdesc->no_of_ep; 511 505 512 - num_of_ep = udev->config.if_desc[0].no_of_ep; 513 - ifdesc = &udev->config.if_desc[0]; 514 - 515 - ctrl_ctx = xhci_get_input_control_ctx(in_ctx); 516 - /* Initialize the input context control */ 517 - ctrl_ctx->add_flags = cpu_to_le32(SLOT_FLAG); 518 - ctrl_ctx->drop_flags = 0; 519 - 520 - /* EP_FLAG gives values 1 & 4 for EP1OUT and EP2IN */ 521 - for (cur_ep = 0; cur_ep < num_of_ep; cur_ep++) { 522 - ep_flag = xhci_get_ep_index(&ifdesc->ep_desc[cur_ep]); 523 - ctrl_ctx->add_flags |= cpu_to_le32(1 << (ep_flag + 1)); 524 - if (max_ep_flag < ep_flag) 525 - max_ep_flag = ep_flag; 526 - } 527 - 528 - xhci_inval_cache((uintptr_t)out_ctx->bytes, out_ctx->size); 529 - 530 - /* slot context */ 531 - xhci_slot_copy(ctrl, in_ctx, out_ctx); 532 - slot_ctx = xhci_get_slot_ctx(ctrl, in_ctx); 533 - slot_ctx->dev_info &= ~(cpu_to_le32(LAST_CTX_MASK)); 534 - slot_ctx->dev_info |= cpu_to_le32(LAST_CTX(max_ep_flag + 1) | 0); 535 - 536 - xhci_endpoint_copy(ctrl, in_ctx, out_ctx, 0); 537 - 538 - /* filling up ep contexts */ 539 506 for (cur_ep = 0; cur_ep < num_of_ep; cur_ep++) { 540 507 struct usb_endpoint_descriptor *endpt_desc = NULL; 541 508 struct usb_ss_ep_comp_descriptor *ss_ep_comp_desc = NULL; ··· 561 528 avg_trb_len = max_esit_payload; 562 529 563 530 ep_index = xhci_get_ep_index(endpt_desc); 564 - ep_ctx[ep_index] = xhci_get_ep_ctx(ctrl, in_ctx, ep_index); 531 + ep_ctx[ep_index] = xhci_get_ep_ctx(ctrl, virt_dev->in_ctx, 532 + ep_index); 565 533 566 534 /* Allocate the ep rings */ 567 535 virt_dev->eps[ep_index].ring = xhci_ring_alloc(ctrl, 1, true); ··· 612 580 ep_ctx[ep_index]->reserved[0] = 613 581 cpu_to_le32(EP_BPKTS(1) | EP_BBM(1)); 614 582 } 583 + } 584 + 585 + return 0; 586 + } 587 + 588 + /** 589 + * Configure the endpoint, programming the device contexts. 590 + * 591 + * @param udev pointer to the USB device structure 592 + * Return: returns the status of the xhci_configure_endpoints 593 + */ 594 + static int xhci_set_configuration(struct usb_device *udev) 595 + { 596 + struct xhci_container_ctx *out_ctx; 597 + struct xhci_container_ctx *in_ctx; 598 + struct xhci_input_control_ctx *ctrl_ctx; 599 + struct xhci_slot_ctx *slot_ctx; 600 + int err; 601 + int cur_ep; 602 + int max_ep_flag = 0; 603 + struct xhci_ctrl *ctrl = xhci_get_ctrl(udev); 604 + int num_of_ep; 605 + int ep_flag = 0; 606 + int slot_id = udev->slot_id; 607 + struct xhci_virt_device *virt_dev = ctrl->devs[slot_id]; 608 + struct usb_interface *ifdesc; 609 + unsigned int ifnum; 610 + unsigned int max_ifnum = min((unsigned int)USB_MAX_ACTIVE_INTERFACES, 611 + (unsigned int)udev->config.no_of_if); 612 + 613 + out_ctx = virt_dev->out_ctx; 614 + in_ctx = virt_dev->in_ctx; 615 + 616 + ctrl_ctx = xhci_get_input_control_ctx(in_ctx); 617 + /* Initialize the input context control */ 618 + ctrl_ctx->add_flags = cpu_to_le32(SLOT_FLAG); 619 + ctrl_ctx->drop_flags = 0; 620 + 621 + for (ifnum = 0; ifnum < max_ifnum; ifnum++) { 622 + ifdesc = &udev->config.if_desc[ifnum]; 623 + num_of_ep = ifdesc->no_of_ep; 624 + /* EP_FLAG gives values 1 & 4 for EP1OUT and EP2IN */ 625 + for (cur_ep = 0; cur_ep < num_of_ep; cur_ep++) { 626 + ep_flag = xhci_get_ep_index(&ifdesc->ep_desc[cur_ep]); 627 + ctrl_ctx->add_flags |= cpu_to_le32(1 << (ep_flag + 1)); 628 + if (max_ep_flag < ep_flag) 629 + max_ep_flag = ep_flag; 630 + } 631 + } 632 + 633 + xhci_inval_cache((uintptr_t)out_ctx->bytes, out_ctx->size); 634 + 635 + /* slot context */ 636 + xhci_slot_copy(ctrl, in_ctx, out_ctx); 637 + slot_ctx = xhci_get_slot_ctx(ctrl, in_ctx); 638 + slot_ctx->dev_info &= ~(cpu_to_le32(LAST_CTX_MASK)); 639 + slot_ctx->dev_info |= cpu_to_le32(LAST_CTX(max_ep_flag + 1) | 0); 640 + 641 + xhci_endpoint_copy(ctrl, in_ctx, out_ctx, 0); 642 + 643 + /* filling up ep contexts */ 644 + for (ifnum = 0; ifnum < max_ifnum; ifnum++) { 645 + ifdesc = &udev->config.if_desc[ifnum]; 646 + err = xhci_init_ep_contexts_if(udev, ctrl, virt_dev, ifdesc); 647 + if (err < 0) 648 + return err; 615 649 } 616 650 617 651 return xhci_configure_endpoints(udev, false);
+11
include/env_default.h
··· 99 99 #ifdef CONFIG_SYS_SOC 100 100 "soc=" CONFIG_SYS_SOC "\0" 101 101 #endif 102 + #ifdef CONFIG_USB_HOST 103 + "usb_ignorelist=" 104 + #ifdef CONFIG_USB_KEYBOARD 105 + /* Ignore Yubico devices. Currently only a single USB keyboard device is 106 + * supported and the emulated HID keyboard Yubikeys present is useless 107 + * as keyboard. 108 + */ 109 + "0x1050:*," 110 + #endif 111 + "\0" 112 + #endif 102 113 #ifdef CONFIG_ENV_IMPORT_FDT 103 114 "env_fdt_path=" CONFIG_ENV_FDT_PATH "\0" 104 115 #endif
+6
include/usb.h
··· 49 49 */ 50 50 #define USB_TIMEOUT_MS(pipe) (usb_pipebulk(pipe) ? 5000 : 1000) 51 51 52 + /* 53 + * The xhcd hcd driver prepares only a limited number interfaces / endpoints. 54 + * Define this limit so that drivers do not exceed it. 55 + */ 56 + #define USB_MAX_ACTIVE_INTERFACES 2 57 + 52 58 /* device request (setup) */ 53 59 struct devrequest { 54 60 __u8 requesttype;