From 0bfa031b5f024ce57b3fc5988c0f09b0446e29ad Mon Sep 17 00:00:00 2001 From: Jonas Blixt Date: Tue, 17 Sep 2024 11:22:38 +0200 Subject: [PATCH 1/8] pbstate: Add invalidate API To allow resetting the enable and verified bits of a system. --- tools/pbstate/src/pbstate.c | 37 +++++++++++++++++++++++++++++++++++++ tools/pbstate/src/pbstate.h | 10 ++++++++++ 2 files changed, 47 insertions(+) diff --git a/tools/pbstate/src/pbstate.c b/tools/pbstate/src/pbstate.c index 48df6a75..636997f7 100644 --- a/tools/pbstate/src/pbstate.c +++ b/tools/pbstate/src/pbstate.c @@ -418,6 +418,43 @@ int pbstate_switch_system(pbstate_system_t system, uint32_t boot_attempts) return preserved_rc; } +int pbstate_invalidate_system(pbstate_system_t system) +{ + int rc; + int preserved_rc; + int fd = open_and_load_state(true); + + if (fd < 0) + return fd; + + switch (system) { + case PBSTATE_SYSTEM_A: + state.enable &= ~PB_STATE_A_ENABLED; + state.verified &= ~PB_STATE_A_VERIFIED; + break; + case PBSTATE_SYSTEM_B: + state.enable &= ~PB_STATE_B_ENABLED; + state.verified &= ~PB_STATE_B_VERIFIED; + break; + default: + rc = -EINVAL; + goto err_close_release_no_save_out; + break; + } + + return close_and_save_state(fd, true); + +err_close_release_no_save_out: + preserved_rc = rc; + + rc = close_and_save_state(fd, false); + + if (rc < 0) + return rc; + + return preserved_rc; +} + int pbstate_set_system_verified(pbstate_system_t system) { int rc; diff --git a/tools/pbstate/src/pbstate.h b/tools/pbstate/src/pbstate.h index fdc38b12..26fe7fe3 100644 --- a/tools/pbstate/src/pbstate.h +++ b/tools/pbstate/src/pbstate.h @@ -99,6 +99,16 @@ int pbstate_clear_error(uint32_t mask); */ int pbstate_switch_system(pbstate_system_t system, uint32_t boot_attempts); +/** + * Invalidate and disable a system. This will clear the verified bit and + * enabled bit. + * + * @param[in] system System to invalidate + * + * @return 0 on success or -EINVAL on bad parameter + */ +int pbstate_invalidate_system(pbstate_system_t system); + /** * Set system verified bit * From ac58e89cb52df0712e38b3d14ca4492814d22103 Mon Sep 17 00:00:00 2001 From: Jonas Blixt Date: Tue, 17 Sep 2024 13:30:08 +0200 Subject: [PATCH 2/8] cm: Disconnect transport for all boot commands Without this USB device might linger on the host system. In cmd_boot_bpak we must use the lower level API instead of calling boot directly as this function uses callbacks that will need the transport up. By using the lower level API we can perform all the loading and then disconnect transport just before jumping to the image. --- src/cm/cm_main.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/cm/cm_main.c b/src/cm/cm_main.c index 5585d240..37710fd5 100644 --- a/src/cm/cm_main.c +++ b/src/cm/cm_main.c @@ -578,7 +578,15 @@ static int cmd_boot_bpak(void) boot_set_source(BOOT_SOURCE_CB); boot_configure_load_cb(bpak_boot_read_f, bpak_boot_result_f); - return boot(bpak_boot_cmd->uuid); + rc = boot_load(bpak_boot_cmd->uuid); + if (rc != PB_OK) + return rc; + + if (cfg->tops.disconnect) { + cfg->tops.disconnect(); + } + + return boot_jump(); } static int cmd_slc_read(void) @@ -756,6 +764,10 @@ static int pb_command_parse(void) pb_wire_init_result(&result, error_to_wire(rc)); cm_write(&result, sizeof(result)); + if (cfg->tops.disconnect) { + cfg->tops.disconnect(); + } + if (rc == PB_OK) { rc = boot_jump(); /* Should not return */ From 3f21fc54e5cb9b9c2b24ecafeff82d0d23480d18 Mon Sep 17 00:00:00 2001 From: Jonas Blixt Date: Wed, 18 Sep 2024 08:14:32 +0200 Subject: [PATCH 3/8] drivers: usb: imx_ci_udc: Set RS to 0 before stopping This prevents additional attachevent and is necessary before we start flushing endpoints and reseting the controller. --- src/drivers/usb/imx_ci_udc.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/drivers/usb/imx_ci_udc.c b/src/drivers/usb/imx_ci_udc.c index 1d6a7925..d5f5e3ff 100644 --- a/src/drivers/usb/imx_ci_udc.c +++ b/src/drivers/usb/imx_ci_udc.c @@ -571,6 +571,7 @@ static int imx_ci_udc_set_address(uint16_t addr) static int imx_ci_udc_stop(void) { + mmio_clrsetbits_32(imx_ci_udc_base + IMX_CI_UDC_CMD, CMD_RS, 0); imx_ci_udc_reset_queues(); imx_ci_udc_reset(); mmio_write_32(imx_ci_udc_base + IMX_CI_UDC_DEVICEADDR, 0); From d6dc34b86199c8cc689a7f9d5790637e9465dd2b Mon Sep 17 00:00:00 2001 From: Jonas Blixt Date: Tue, 17 Sep 2024 13:33:26 +0200 Subject: [PATCH 4/8] drivers: mmc_core: Fix compiler/loglevel warning --- src/drivers/mmc/mmc_core.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/drivers/mmc/mmc_core.c b/src/drivers/mmc/mmc_core.c index 7bdaf367..0b213cd2 100644 --- a/src/drivers/mmc/mmc_core.c +++ b/src/drivers/mmc/mmc_core.c @@ -845,12 +845,14 @@ int mmc_write(unsigned int lba, size_t length, const uintptr_t buf) int mmc_part_switch(enum mmc_part part) { uint8_t value = 0; +#if LOGLEVEL >= 3 const char *part_names[] = { "User", "Boot0", "Boot1", "RPMB", }; +#endif switch (part) { case MMC_PART_BOOT0: From c2de0642146f260d3daeb715cb62b345489d2669 Mon Sep 17 00:00:00 2001 From: Jonas Blixt Date: Tue, 17 Sep 2024 13:35:34 +0200 Subject: [PATCH 5/8] drivers: mmc: imx_usdhc: Fix compiler loglevel warnings --- src/drivers/mmc/imx_usdhc.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/drivers/mmc/imx_usdhc.c b/src/drivers/mmc/imx_usdhc.c index 16d1b3b2..3790f83b 100644 --- a/src/drivers/mmc/imx_usdhc.c +++ b/src/drivers/mmc/imx_usdhc.c @@ -27,7 +27,6 @@ static int imx_usdhc_set_bus_clock(unsigned int clk_hz) { int div = 1; int pre_div = 1; - unsigned int actual_clk_hz; LOG_DBG("Trying to set bus clock to %u kHz", clk_hz / 1000); @@ -43,7 +42,6 @@ static int imx_usdhc_set_bus_clock(unsigned int clk_hz) while (input_clock_hz / div > clk_hz && div < 16) div++; - actual_clk_hz = input_clock_hz / (pre_div * div); pre_div >>= 1; div -= 1; uint16_t clk_reg = (pre_div << 8) | (div << 4); @@ -60,7 +58,7 @@ static int imx_usdhc_set_bus_clock(unsigned int clk_hz) mmio_setbits_32(usdhc->base + USDHC_VEND_SPEC, VENDSPEC_PER_CLKEN | VENDSPEC_CARD_CLKEN); pb_delay_us(100); - LOG_DBG("Actual bus rate = %d kHz", actual_clk_hz / 1000); + LOG_DBG("Actual bus rate = %d kHz", (input_clock_hz / (pre_div * div)) / 1000); return PB_OK; } @@ -273,9 +271,11 @@ static int imx_usdhc_send_cmd(uint16_t idx, uint32_t arg, uint16_t resp_type, mm static int imx_usdhc_set_bus_width(enum mmc_bus_width width) { +#if LOGLEVEL >= 3 const char *bus_widths[] = { "Invalid", "1-Bit", "4-Bit", "8-Bit", "4-Bit DDR", "8-Bit DDR", "8-Bit DDR + Strobe", }; +#endif LOG_DBG("Width = %s", bus_widths[width]); bus_ddr_enable = false; From ef74af2c3e56901051d559b1cec73adc3689a4ff Mon Sep 17 00:00:00 2001 From: Jonas Blixt Date: Tue, 17 Sep 2024 13:37:32 +0200 Subject: [PATCH 6/8] plat: imx8x: sci: Add missing prototype --- include/plat/imx8x/sci/svc/timer/sci_timer_api.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/plat/imx8x/sci/svc/timer/sci_timer_api.h b/include/plat/imx8x/sci/svc/timer/sci_timer_api.h index ac28d3d1..522dd489 100755 --- a/include/plat/imx8x/sci/svc/timer/sci_timer_api.h +++ b/include/plat/imx8x/sci/svc/timer/sci_timer_api.h @@ -78,6 +78,8 @@ typedef uint32_t sc_timer_wdog_time_t; */ sc_err_t sc_timer_set_wdog_timeout(sc_ipc_t ipc, sc_timer_wdog_time_t timeout); +sc_err_t sc_timer_set_wdog_window(sc_ipc_t ipc, sc_timer_wdog_time_t window); + /*! * This function sets the watchdog pre-timeout in milliseconds. If not * set then the pre-timeout defaults to the max. Once locked this value From b33e0248a398517d8b238df424ce93b1625b5d33 Mon Sep 17 00:00:00 2001 From: Jonas Blixt Date: Wed, 18 Sep 2024 12:32:09 +0200 Subject: [PATCH 7/8] pbstate: close_and_save_state has no return code when wr is false Don't try to propagate rc from close_and_save_state when wr is false. --- tools/pbstate/src/pbstate.c | 64 ++++++++++--------------------------- 1 file changed, 17 insertions(+), 47 deletions(-) diff --git a/tools/pbstate/src/pbstate.c b/tools/pbstate/src/pbstate.c index 636997f7..1fb64822 100644 --- a/tools/pbstate/src/pbstate.c +++ b/tools/pbstate/src/pbstate.c @@ -221,7 +221,6 @@ int pbstate_init(const char *p_device, const char *b_device, pbstate_printfunc_t int pbstate_is_system_active(pbstate_system_t system) { - int rc; int result = 0; int fd = open_and_load_state(false); @@ -242,17 +241,12 @@ int pbstate_is_system_active(pbstate_system_t system) break; } - rc = close_and_save_state(fd, false); - - if (rc < 0) - return rc; - + close_and_save_state(fd, false); return result; } int pbstate_is_system_verified(pbstate_system_t system) { - int rc; int result = 0; int fd = open_and_load_state(false); @@ -273,11 +267,7 @@ int pbstate_is_system_verified(pbstate_system_t system) break; } - rc = close_and_save_state(fd, false); - - if (rc < 0) - return rc; - + close_and_save_state(fd, false); return result; } @@ -293,13 +283,13 @@ int pbstate_get_remaining_boot_attempts(unsigned int *boot_attempts) (*boot_attempts) = state.remaining_boot_attempts; - return close_and_save_state(fd, false); + close_and_save_state(fd, false); + return 0; } int pbstate_force_rollback(void) { int rc; - int preserved_rc = 0; int fd = open_and_load_state(true); if (fd < 0) @@ -326,13 +316,9 @@ int pbstate_force_rollback(void) return 0; err_close_release_no_save_out: - preserved_rc = rc; - rc = close_and_save_state(fd, false); - - if (rc < 0) - return rc; + close_and_save_state(fd, false); - return preserved_rc; + return rc; } int pbstate_get_errors(uint32_t *error) @@ -344,7 +330,8 @@ int pbstate_get_errors(uint32_t *error) (*error) = state.error; - return close_and_save_state(fd, false); + close_and_save_state(fd, false); + return 0; } int pbstate_clear_error(uint32_t mask) @@ -362,7 +349,6 @@ int pbstate_clear_error(uint32_t mask) int pbstate_switch_system(pbstate_system_t system, uint32_t boot_attempts) { int rc; - int preserved_rc; int fd = open_and_load_state(true); if (fd < 0) @@ -408,20 +394,13 @@ int pbstate_switch_system(pbstate_system_t system, uint32_t boot_attempts) return close_and_save_state(fd, true); err_close_release_no_save_out: - preserved_rc = rc; - - rc = close_and_save_state(fd, false); - - if (rc < 0) - return rc; - - return preserved_rc; + close_and_save_state(fd, false); + return rc; } int pbstate_invalidate_system(pbstate_system_t system) { int rc; - int preserved_rc; int fd = open_and_load_state(true); if (fd < 0) @@ -445,20 +424,14 @@ int pbstate_invalidate_system(pbstate_system_t system) return close_and_save_state(fd, true); err_close_release_no_save_out: - preserved_rc = rc; - - rc = close_and_save_state(fd, false); - - if (rc < 0) - return rc; + close_and_save_state(fd, false); - return preserved_rc; + return rc; } int pbstate_set_system_verified(pbstate_system_t system) { int rc; - int preserved_rc; int fd = open_and_load_state(true); if (fd < 0) @@ -484,14 +457,9 @@ int pbstate_set_system_verified(pbstate_system_t system) return close_and_save_state(fd, true); err_close_release_no_save_out: - preserved_rc = rc; - - rc = close_and_save_state(fd, false); - - if (rc < 0) - return rc; + close_and_save_state(fd, false); - return preserved_rc; + return rc; } int pbstate_read_board_reg(unsigned int index, uint32_t *value) @@ -506,7 +474,9 @@ int pbstate_read_board_reg(unsigned int index, uint32_t *value) *value = state.board_regs[PB_STATE_NO_OF_BOARD_REGS - index - 1]; - return close_and_save_state(fd, false); + close_and_save_state(fd, false); + + return 0; } int pbstate_write_board_reg(unsigned int index, uint32_t value) From d1c33299ce41748eae6f93fa4eeb97152306dc55 Mon Sep 17 00:00:00 2001 From: Jonas Blixt Date: Tue, 17 Sep 2024 13:31:37 +0200 Subject: [PATCH 8/8] version: 2.3.0 --- version.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version.txt b/version.txt index ccbccc3d..276cbf9e 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -2.2.0 +2.3.0