OpenBIC
OpenSource Bridge-IC
util_spi.h
Go to the documentation of this file.
1/*
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef UTIL_SPI_H
18#define UTIL_SPI_H
19
20#include <zephyr.h>
21#include <stdbool.h>
22#include <stdint.h>
23#include <drivers/spi_nor.h>
24
25#define NUM_SPI_DEV 3
26#define SECTOR_SZ_64K 0x10000
27#define SECTOR_SZ_32K 0x08000
28#define SECTOR_SZ_16K 0x04000
29#define SECTOR_SZ_4K 0x01000
30#define SECTOR_SZ_1K 0x00400
31#define SECTOR_SZ_256 0x00100
32
33#define SHA256_DIGEST_SIZE 32
34
35#define SECTOR_END_FLAG BIT(7)
36#define NO_RESET_FLAG BIT(0)
37
45};
46
47uint8_t fw_update(uint32_t offset, uint16_t msg_len, uint8_t *msg_buf, uint8_t flag,
48 uint8_t flash_position);
49int read_fw_image(uint32_t offset, uint8_t msg_len, uint8_t *msg_buf, uint8_t flash_position);
50uint8_t fw_update_cxl(uint32_t offset, uint16_t msg_len, uint8_t *msg_buf, bool sector_end);
51
52uint8_t get_fw_sha256(uint8_t *msg_buf, uint32_t offset, uint32_t length, uint8_t flash_position);
53
56bool pal_switch_bios_spi_mux(int gpio_status);
58int do_update(const struct device *flash_device, off_t offset, uint8_t *buf, size_t len);
59void set_default_retry_count(int count);
60int ckeck_flash_device_isinit(const struct device *flash_device, uint8_t flash_position);
61char *get_flash_device_string_by_index(uint8_t flash_index);
62
71};
72
73#if DT_NODE_HAS_STATUS(DT_PATH(soc, spi_7e620000), okay)
74#define SPI_fmc
75#endif
76
77#if DT_NODE_HAS_STATUS(DT_PATH(soc, spi_7e630000), okay)
78#define SPI_spi1
79#endif
80
81#if DT_NODE_HAS_STATUS(DT_PATH(soc, spi_7e640000), okay)
82#define SPI_spi2
83#endif
84
85#endif
uint32_t offset
Definition: pldm_firmware_update.h:0
uint32_t length
Definition: pldm_firmware_update.h:1
uint8_t fw_update_cxl(uint32_t offset, uint16_t msg_len, uint8_t *msg_buf, bool sector_end)
Definition: util_spi.c:479
uint8_t fw_update(uint32_t offset, uint16_t msg_len, uint8_t *msg_buf, uint8_t flag, uint8_t flash_position)
Definition: util_spi.c:319
int pal_get_bios_flash_position()
Definition: util_spi.c:484
bool pal_switch_bios_spi_mux(int gpio_status)
Definition: util_spi.c:494
int do_update(const struct device *flash_device, off_t offset, uint8_t *buf, size_t len)
Definition: util_spi.c:132
int ckeck_flash_device_isinit(const struct device *flash_device, uint8_t flash_position)
Definition: util_spi.c:111
int pal_get_cxl_flash_position()
DEVICE_POSITIONS
Definition: util_spi.h:38
@ DEVSPI_SPI1_CS0
Definition: util_spi.h:41
@ DEVSPI_SPI1_CS1
Definition: util_spi.h:42
@ DEVSPI_SPI2_CS0
Definition: util_spi.h:43
@ DEVSPI_FMC_CS0
Definition: util_spi.h:39
@ DEVSPI_FMC_CS1
Definition: util_spi.h:40
@ DEVSPI_SPI2_CS1
Definition: util_spi.h:44
uint8_t get_fw_sha256(uint8_t *msg_buf, uint32_t offset, uint32_t length, uint8_t flash_position)
int read_fw_image(uint32_t offset, uint8_t msg_len, uint8_t *msg_buf, uint8_t flash_position)
Definition: util_spi.c:447
void set_default_retry_count(int count)
Definition: util_spi.c:474
char * get_flash_device_string_by_index(uint8_t flash_index)
Definition: util_spi.c:127
int pal_get_prot_flash_position()
Definition: util_spi.c:489
FIRMWARE_UPDATE_RETURN_CODE
Definition: util_spi.h:63
@ FWUPDATE_NOT_SUPPORT
Definition: util_spi.h:70
@ FWUPDATE_OUT_OF_HEAP
Definition: util_spi.h:65
@ FWUPDATE_REPEATED_UPDATED
Definition: util_spi.h:67
@ FWUPDATE_OVER_LENGTH
Definition: util_spi.h:66
@ FWUPDATE_ERROR_OFFSET
Definition: util_spi.h:69
@ FWUPDATE_UPDATE_FAIL
Definition: util_spi.h:68
@ FWUPDATE_SUCCESS
Definition: util_spi.h:64