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

fby3.5: rf: Impl CXL FW update #521

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 3 additions & 22 deletions common/lib/util_spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ uint8_t fw_update(uint32_t offset, uint16_t msg_len, uint8_t *msg_buf, bool sect
}

if ((buf_offset + msg_len) > SECTOR_SZ_64K) {
printf("spi bus%x recv data %d over sector size %d\n", flash_position,
printf("spi bus%x recv data %u over sector size %d\n", flash_position,
buf_offset + msg_len, SECTOR_SZ_64K);
SAFE_FREE(txbuf);
k_msleep(10);
Expand Down Expand Up @@ -351,18 +351,9 @@ uint8_t fw_update(uint32_t offset, uint16_t msg_len, uint8_t *msg_buf, bool sect
return FWUPDATE_SUCCESS;
}

uint8_t fw_update_cxl(uint8_t flash_position)
__weak uint8_t fw_update_cxl(uint32_t offset, uint16_t msg_len, uint8_t *msg_buf, bool sector_end)
{
int ret = 0;
const struct device *flash_dev;

flash_dev = device_get_binding(flash_device[flash_position]);
ret = spi_nor_re_init(flash_dev);
if (ret != 0) {
return FWUPDATE_UPDATE_FAIL;
}
//TODO: do real update until know CXL fw update format and progress
return FWUPDATE_SUCCESS;
return FWUPDATE_NOT_SUPPORT;
}

__weak int pal_get_bios_flash_position()
Expand All @@ -374,13 +365,3 @@ __weak bool pal_switch_bios_spi_mux(int gpio_status)
{
return true;
}

__weak int pal_get_cxl_flash_position()
{
return -1;
}

__weak bool pal_switch_cxl_spi_mux()
{
return false;
}
4 changes: 2 additions & 2 deletions common/lib/util_spi.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,13 @@ enum DEVICE_POSITIONS {

uint8_t fw_update(uint32_t offset, uint16_t msg_len, uint8_t *msg_buf, bool sector_end,
uint8_t flash_position);
uint8_t fw_update_cxl(uint8_t flash_position);
uint8_t fw_update_cxl(uint32_t offset, uint16_t msg_len, uint8_t *msg_buf, bool sector_end);

uint8_t get_fw_sha256(uint8_t *msg_buf, uint32_t offset, uint32_t length, uint8_t flash_position);

int pal_get_bios_flash_position();
bool pal_switch_bios_spi_mux(int gpio_status);
int pal_get_cxl_flash_position();
bool pal_switch_cxl_spi_mux();

enum FIRMWARE_UPDATE_RETURN_CODE {
FWUPDATE_SUCCESS,
Expand All @@ -42,6 +41,7 @@ enum FIRMWARE_UPDATE_RETURN_CODE {
FWUPDATE_REPEATED_UPDATED,
FWUPDATE_UPDATE_FAIL,
FWUPDATE_ERROR_OFFSET,
FWUPDATE_NOT_SUPPORT,
};

#if DT_NODE_HAS_STATUS(DT_PATH(soc, spi_7e620000), okay)
Expand Down
22 changes: 7 additions & 15 deletions common/service/ipmi/oem_1s_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -231,20 +231,9 @@ __weak void OEM_1S_FW_UPDATE(ipmi_msg *msg)
} else if ((target == CPLD_UPDATE) || (target == (CPLD_UPDATE | IS_SECTOR_END_MASK))) {
status = cpld_altera_max10_fw_update(offset, length, &msg->data[7]);

} else if (target == CXL_UPDATE) {
int pos = pal_get_cxl_flash_position();
if (pos == -1) {
msg->completion_code = CC_INVALID_PARAM;
return;
}

bool ret = pal_switch_cxl_spi_mux();
if (ret == false) {
msg->completion_code = CC_UNSPECIFIED_ERROR;
return;
}

status = fw_update_cxl(pos);
} else if (target == CXL_UPDATE || (target == (CXL_UPDATE | IS_SECTOR_END_MASK))) {
status =
fw_update_cxl(offset, length, &msg->data[7], (target & IS_SECTOR_END_MASK));

} else {
msg->completion_code = CC_INVALID_DATA_FIELD;
Expand Down Expand Up @@ -272,6 +261,9 @@ __weak void OEM_1S_FW_UPDATE(ipmi_msg *msg)
case FWUPDATE_ERROR_OFFSET:
msg->completion_code = CC_PARAM_OUT_OF_RANGE;
break;
case FWUPDATE_NOT_SUPPORT:
msg->completion_code = CC_INVALID_PARAM;
break;
default:
msg->completion_code = CC_UNSPECIFIED_ERROR;
break;
Expand Down Expand Up @@ -977,7 +969,7 @@ __weak void OEM_1S_CONTROL_SENSOR_POLLING(ipmi_msg *msg)
// Enable or Disable sensor polling
sensor_config[control_sensor_index].is_enable_polling =
((operation == DISABLE_SENSOR_POLLING) ? DISABLE_SENSOR_POLLING :
ENABLE_SENSOR_POLLING);
ENABLE_SENSOR_POLLING);
msg->data[return_data_index + 1] =
sensor_config[control_sensor_index].is_enable_polling;
} else {
Expand Down
2 changes: 1 addition & 1 deletion meta-facebook/yv35-rf/boards/ast1030_evb.conf
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ CONFIG_TACH_ASPEED=n
CONFIG_ESPI_ASPEED=n
CONFIG_PECI_ASPEED=n
CONFIG_PECI_ASPEED_INTERRUPT_DRIVEN=n
CONFIG_USB_ASPEED=n
CONFIG_USB_ASPEED=y
CONFIG_I3C_ASPEED=n
CONFIG_CRYPTO=n
CONFIG_CRYPTO_ASPEED=n
Expand Down
2 changes: 1 addition & 1 deletion meta-facebook/yv35-rf/boards/ast1030_evb.overlay
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
&spi1_cs0 {
status = "okay";
spi-max-buswidth = <4>;
spi-max-frequency = <50000000>;
spi-max-frequency = <3125000>;
re-init-support;
};

Expand Down
6 changes: 3 additions & 3 deletions meta-facebook/yv35-rf/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ CONFIG_I3C_SLAVE=n
CONFIG_I3C_SLAVE_MQUEUE=n
CONFIG_WATCHDOG=y
#USB
CONFIG_USB=n
CONFIG_USB_DEVICE_STACK=n
CONFIG_USB=y
CONFIG_USB_DEVICE_STACK=y
CONFIG_USB_DEVICE_PRODUCT="Zephyr CDC ACM"
CONFIG_USB_CDC_ACM=n
CONFIG_USB_CDC_ACM=y
CONFIG_USB_CDC_ACM_RINGBUF_SIZE=576
CONFIG_USB_DEVICE_VID=0x1d6b
CONFIG_USB_DEVICE_PID=0x0104
Expand Down
85 changes: 76 additions & 9 deletions meta-facebook/yv35-rf/src/lib/plat_spi.c
Original file line number Diff line number Diff line change
@@ -1,24 +1,91 @@
#include <stdio.h>
#include <plat_power_seq.h>

#include "hal_gpio.h"
#include "util_spi.h"
#include "util_sys.h"
#include "plat_gpio.h"

bool pal_switch_cxl_spi_mux()
#define CXL_FLASH_TO_BIC 1
#define CXL_FLASH_TO_CXL 0

#define CXL_UPDATE_MAX_OFFSET 0x2000000

static bool switch_cxl_spi_mux(int gpio_status)
{
// Switch CXL MUX selection pin to BIC
int ret = gpio_set(SPI_MASTER_SEL, GPIO_HIGH);
if (ret != 0) {
if (gpio_status != CXL_FLASH_TO_BIC && gpio_status != CXL_FLASH_TO_CXL) {
printf("[%s] Invalid argument\n", __func__);
return false;
}

// Enable CXL MUX
ret = gpio_set(FM_SPI_MUX_OE_CTL_N, GPIO_LOW);
if (ret != 0) {
if (gpio_set(SPI_MASTER_SEL, gpio_status)) {
printf("Fail to switch the flash to %s\n",
(gpio_status == CXL_FLASH_TO_BIC) ? "BIC" : "PIONEER");
return false;
}

return true;
}

int pal_get_cxl_flash_position()
static bool control_flash_power(int power_state)
{
int control_mode = 0;

switch (power_state) {
case POWER_OFF:
control_mode = DISABLE_POWER_MODE;
break;
case POWER_ON:
control_mode = ENABLE_POWER_MODE;
break;
default:
return false;
}

for (int retry = 3;; retry--) {
if (gpio_get(P1V8_ASIC_PG_R) == power_state) {
return true;
}

if (!retry) {
break;
}

control_power_stage(control_mode, P1V8_ASIC_EN_R);
k_msleep(CHKPWR_DELAY_MSEC);
}

printf("Fail to %s the ASIC_1V8\n", (power_state == POWER_OFF) ? "disable" : "enable");

return false;
}

uint8_t fw_update_cxl(uint32_t offset, uint16_t msg_len, uint8_t *msg_buf, bool sector_end)
{
return DEVSPI_SPI1_CS0;
uint8_t ret = FWUPDATE_UPDATE_FAIL;
bool last = ((offset + msg_len) == CXL_UPDATE_MAX_OFFSET);

if (offset > CXL_UPDATE_MAX_OFFSET) {
return FWUPDATE_OVER_LENGTH;
}

// Enable the P1V8_ASCI to power the flash
if (control_flash_power(POWER_ON) == false) {
return FWUPDATE_UPDATE_FAIL;
}

// Set high to choose the BIC as the host
if (switch_cxl_spi_mux(CXL_FLASH_TO_BIC) == false) {
printf("Fail to switch PIONEER flash to BIC\n");
return FWUPDATE_UPDATE_FAIL;
}

ret = fw_update(offset, msg_len, msg_buf, sector_end, DEVSPI_SPI1_CS0);

if (last || ret != FWUPDATE_SUCCESS) {
control_flash_power(POWER_OFF);
switch_cxl_spi_mux(CXL_FLASH_TO_CXL);
}

return ret;
}
2 changes: 2 additions & 0 deletions meta-facebook/yv35-rf/src/platform/plat_def.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#ifndef PLAT_DEF_H
#define PLAT_DEF_H

#define BMC_USB_PORT "CDC_ACM_0"

#endif