OpenBIC
OpenSource Bridge-IC
All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
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 FORCE_INIT_FLAG BIT(1)
37#define NO_RESET_FLAG BIT(0)
38
46};
47
48uint8_t fw_update(uint32_t offset, uint16_t msg_len, uint8_t *msg_buf, uint8_t flag,
49 uint8_t flash_position);
50int read_fw_image(uint32_t offset, uint8_t msg_len, uint8_t *msg_buf, uint8_t flash_position);
51uint8_t fw_update_cxl(uint32_t offset, uint16_t msg_len, uint8_t *msg_buf, bool sector_end);
52
53uint8_t get_fw_sha256(uint8_t *msg_buf, uint32_t offset, uint32_t length, uint8_t flash_position);
54
57bool pal_switch_bios_spi_mux(int gpio_status);
59int do_update(const struct device *flash_device, off_t offset, uint8_t *buf, size_t len);
60void set_default_retry_count(int count);
61int ckeck_flash_device_isinit(const struct device *flash_device, uint8_t flash_position);
62char *get_flash_device_string_by_index(uint8_t flash_index);
63
72};
73
74#if DT_NODE_HAS_STATUS(DT_PATH(soc, spi_7e620000), okay)
75#define SPI_fmc
76#endif
77
78#if DT_NODE_HAS_STATUS(DT_PATH(soc, spi_7e630000), okay)
79#define SPI_spi1
80#endif
81
82#if DT_NODE_HAS_STATUS(DT_PATH(soc, spi_7e640000), okay)
83#define SPI_spi2
84#endif
85
86#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:39
@ DEVSPI_SPI1_CS0
Definition: util_spi.h:42
@ DEVSPI_SPI1_CS1
Definition: util_spi.h:43
@ DEVSPI_SPI2_CS0
Definition: util_spi.h:44
@ DEVSPI_FMC_CS0
Definition: util_spi.h:40
@ DEVSPI_FMC_CS1
Definition: util_spi.h:41
@ DEVSPI_SPI2_CS1
Definition: util_spi.h:45
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:64
@ FWUPDATE_NOT_SUPPORT
Definition: util_spi.h:71
@ FWUPDATE_OUT_OF_HEAP
Definition: util_spi.h:66
@ FWUPDATE_REPEATED_UPDATED
Definition: util_spi.h:68
@ FWUPDATE_OVER_LENGTH
Definition: util_spi.h:67
@ FWUPDATE_ERROR_OFFSET
Definition: util_spi.h:70
@ FWUPDATE_UPDATE_FAIL
Definition: util_spi.h:69
@ FWUPDATE_SUCCESS
Definition: util_spi.h:65