From 96093145cb6549a6058627a7aa196e86ac3911f4 Mon Sep 17 00:00:00 2001 From: Vincent Palatin Date: Wed, 2 Sep 2015 14:45:14 -0700 Subject: update case closed debugging partial mode policy When a debug accessory is connected to the type-C port while the write protection is enabled, put the case closed debugging in "partial" mode rather than "full". Update the "partial" mode to provide read-only access to the AP and EC consoles. Signed-off-by: Vincent Palatin BRANCH=smaug BUG=chrome-os-partner:44700 TEST=check the EC console input/output over USB is still working with SuzyQ on a write-protected system, verify that the console input is disabled. Change-Id: I5baa03d6e738d06437c45469f46b286e76a755a4 Reviewed-on: https://chromium-review.googlesource.com/297141 Commit-Ready: Vincent Palatin Tested-by: Vincent Palatin Reviewed-by: Anton Staaf Reviewed-by: Alec Berg --- board/ryu/board.c | 4 ++++ board/ryu/usb_pd_policy.c | 3 ++- chip/g/usb_console.c | 9 ++++++--- chip/stm32/usb-stream.c | 9 +++++++-- chip/stm32/usb-stream.h | 4 ++++ chip/stm32/usb_console.c | 7 +++++-- common/case_closed_debug.c | 7 ++++--- common/usb_pd_protocol.c | 4 +++- include/usb_console.h | 2 +- 9 files changed, 36 insertions(+), 13 deletions(-) diff --git a/board/ryu/board.c b/board/ryu/board.c index 49a7e1bf0a..24402d42fc 100644 --- a/board/ryu/board.c +++ b/board/ryu/board.c @@ -30,6 +30,7 @@ #include "queue_policies.h" #include "registers.h" #include "spi.h" +#include "system.h" #include "task.h" #include "usb.h" #include "usb_charge.h" @@ -144,6 +145,9 @@ static void board_init(void) queue_init(&ap_usart_to_usb); queue_init(&ap_usb_to_usart); usart_init(&ap_usart); + /* Disable UART input when the Write Protect is enabled */ + if (system_is_locked()) + ap_usb.state->rx_disabled = 1; /* * Enable CC lines after all GPIO have been initialized. Note, it is diff --git a/board/ryu/usb_pd_policy.c b/board/ryu/usb_pd_policy.c index 14e5828f17..ea709a3b53 100644 --- a/board/ryu/usb_pd_policy.c +++ b/board/ryu/usb_pd_policy.c @@ -255,7 +255,8 @@ int pd_custom_vdm(int port, int cnt, uint32_t *payload, #endif /* CONFIG_USB_PD_LOGGING */ #ifdef CONFIG_CASE_CLOSED_DEBUG case VDO_CMD_CCD_EN: - ccd_set_mode(CCD_MODE_ENABLED); + ccd_set_mode(system_is_locked() ? CCD_MODE_PARTIAL + : CCD_MODE_ENABLED); break; #endif } diff --git a/chip/g/usb_console.c b/chip/g/usb_console.c index 19bcf7d243..d075bdac09 100644 --- a/chip/g/usb_console.c +++ b/chip/g/usb_console.c @@ -29,6 +29,7 @@ static int last_tx_ok = 1; static int is_reset; static int is_enabled = 1; +static int is_readonly; /* USB-Serial descriptors */ const struct usb_interface_descriptor USB_IFACE_DESC(USB_IFACE_CONSOLE) = @@ -76,7 +77,7 @@ static void con_ep_tx(void) static void con_ep_rx(void) { int i; - int rx_size = USB_MAX_PACKET_SIZE + int rx_size = is_readonly ? 0 : USB_MAX_PACKET_SIZE - (ep_out_desc.flags & DOEPDMA_RXBYTES_MASK); for (i = 0; i < rx_size; i++) { @@ -94,7 +95,8 @@ static void con_ep_rx(void) GR_USB_DOEPINT(USB_EP_CONSOLE) = 0xffffffff; /* wake-up the console task */ - console_has_input(); + if (!is_readonly) + console_has_input(); } static void ep_reset(void) @@ -254,7 +256,8 @@ int usb_vprintf(const char *format, va_list args) return ret; } -void usb_console_enable(int enabled) +void usb_console_enable(int enabled, int readonly) { is_enabled = enabled; + is_readonly = readonly; } diff --git a/chip/stm32/usb-stream.c b/chip/stm32/usb-stream.c index 256dc829e1..08004dcad4 100644 --- a/chip/stm32/usb-stream.c +++ b/chip/stm32/usb-stream.c @@ -56,6 +56,11 @@ static int rx_valid(struct usb_stream_config const *config) return (STM32_USB_EP(config->endpoint) & EP_RX_MASK) == EP_RX_VALID; } +static int rx_disabled(struct usb_stream_config const *config) +{ + return config->state->rx_disabled; +} + static void usb_read(struct producer const *producer, size_t count) { struct usb_stream_config const *config = @@ -95,7 +100,7 @@ void usb_stream_deferred(struct usb_stream_config const *config) if (!tx_valid(config) && tx_write(config)) STM32_TOGGLE_EP(config->endpoint, EP_TX_MASK, EP_TX_VALID, 0); - if (!rx_valid(config) && rx_read(config)) + if (!rx_valid(config) && !rx_disabled(config) && rx_read(config)) STM32_TOGGLE_EP(config->endpoint, EP_RX_MASK, EP_RX_VALID, 0); } @@ -136,5 +141,5 @@ void usb_stream_reset(struct usb_stream_config const *config) STM32_USB_EP(i) = ((i << 0) | /* Endpoint Addr*/ (2 << 4) | /* TX NAK */ (0 << 9) | /* Bulk EP */ - (3 << 12)); /* RX VALID */ + (rx_disabled(config) ? EP_RX_NAK : EP_RX_VALID)); } diff --git a/chip/stm32/usb-stream.h b/chip/stm32/usb-stream.h index c99fd3e695..da2d677880 100644 --- a/chip/stm32/usb-stream.h +++ b/chip/stm32/usb-stream.h @@ -31,6 +31,10 @@ struct usb_stream_state { * restart USB reception by marking the RX buffer as VALID. */ int rx_waiting; + /* + * Flag indicating that the incoming data on the USB link are discarded. + */ + int rx_disabled; }; /* diff --git a/chip/stm32/usb_console.c b/chip/stm32/usb_console.c index 665568a28a..7688d4af29 100644 --- a/chip/stm32/usb_console.c +++ b/chip/stm32/usb_console.c @@ -29,6 +29,7 @@ static int last_tx_ok = 1; static int is_reset; static int is_enabled = 1; +static int is_readonly; /* USB-Serial descriptors */ const struct usb_interface_descriptor USB_IFACE_DESC(USB_IFACE_CONSOLE) = { @@ -100,7 +101,8 @@ static void ep_reset(void) STM32_USB_EP(USB_EP_CONSOLE) = (USB_EP_CONSOLE | /* Endpoint Addr */ (2 << 4) | /* TX NAK */ (0 << 9) | /* Bulk EP */ - (3 << 12)); /* RX VALID */ + (is_readonly ? EP_RX_NAK + : EP_RX_VALID)); is_reset = 1; } @@ -248,7 +250,8 @@ int usb_vprintf(const char *format, va_list args) return ret; } -void usb_console_enable(int enabled) +void usb_console_enable(int enabled, int readonly) { is_enabled = enabled; + is_readonly = readonly; } diff --git a/common/case_closed_debug.c b/common/case_closed_debug.c index 3adc563c4f..31477b7554 100644 --- a/common/case_closed_debug.c +++ b/common/case_closed_debug.c @@ -41,10 +41,11 @@ void ccd_set_mode(enum ccd_mode new_mode) current_mode = new_mode; /* - * Only enable forwarding the local console over USB if we are now in - * the fully enabled mode. + * The forwarding of the local console over USB is read-only + * if we are not in the fully enabled mode. */ - usb_console_enable(new_mode == CCD_MODE_ENABLED); + usb_console_enable(new_mode != CCD_MODE_DISABLED, + new_mode != CCD_MODE_ENABLED); #if defined(CONFIG_USB_SPI) usb_spi_enable(&ccd_usb_spi, new_mode == CCD_MODE_ENABLED); diff --git a/common/usb_pd_protocol.c b/common/usb_pd_protocol.c index 07ce8189dc..11a1f62c9c 100644 --- a/common/usb_pd_protocol.c +++ b/common/usb_pd_protocol.c @@ -1590,7 +1590,9 @@ void pd_task(void) #ifdef CONFIG_CASE_CLOSED_DEBUG if (new_cc_state == PD_CC_DEBUG_ACC) { - ccd_set_mode(CCD_MODE_ENABLED); + ccd_set_mode(system_is_locked() ? + CCD_MODE_PARTIAL : + CCD_MODE_ENABLED); typec_set_input_current_limit( port, 3000, TYPE_C_VOLTAGE); charge_manager_update_dualrole( diff --git a/include/usb_console.h b/include/usb_console.h index d83fc480b0..08cbbf5491 100644 --- a/include/usb_console.h +++ b/include/usb_console.h @@ -50,7 +50,7 @@ int usb_getc(void); * is not accessible until the USB peripheral is also initialized, which can * be delayed. */ -void usb_console_enable(int enabled); +void usb_console_enable(int enabled, int readonly); #define usb_va_start va_start #define usb_va_end va_end -- cgit v1.2.1