![]() |
coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
|
#include <stdint.h>
#include <string.h>
#include <spi-generic.h>
#include <spi_sdcard.h>
#include <crc_byte.h>
#include <commonlib/helpers.h>
#include <console/console.h>
Go to the source code of this file.
Functions | |
static unsigned long long | extract_bits (uint8_t *buff, int width, int start, int end) |
static void | spi_sdcard_enable_cs (const struct spi_sdcard *card) |
static void | spi_sdcard_disable_cs (const struct spi_sdcard *card) |
static void | spi_sdcard_sendbyte (const struct spi_sdcard *card, uint8_t b) |
static uint8_t | spi_sdcard_recvbyte (const struct spi_sdcard *card) |
static uint8_t | spi_sdcard_calculate_command_crc (uint8_t cmd, uint32_t argument) |
static int | lookup_cmd_response_type (uint8_t cmd) |
static int | lookup_acmd_response_type (uint8_t cmd) |
static int | lookup_response_length (int response_type) |
static int | response_resolve (int response_type, uint8_t *response, uint32_t *out_register) |
static int | spi_sdcard_do_command_help (const struct spi_sdcard *card, int is_acmd, uint8_t cmd, uint32_t argument, uint32_t *out_register) |
static int | spi_sdcard_do_command (const struct spi_sdcard *card, uint8_t cmd, uint32_t argument, uint32_t *out_register) |
static int | spi_sdcard_do_app_command (const struct spi_sdcard *card, uint8_t cmd, uint32_t argument, uint32_t *out_register) |
size_t | spi_sdcard_size (const struct spi_sdcard *card) |
int | spi_sdcard_init (struct spi_sdcard *card, const unsigned int bus, const unsigned int cs) |
int | spi_sdcard_single_read (const struct spi_sdcard *card, size_t block_address, void *buff) |
int | spi_sdcard_multiple_read (const struct spi_sdcard *card, size_t start_block_address, size_t end_block_address, void *buff) |
int | spi_sdcard_read (const struct spi_sdcard *card, void *dest, size_t offset, size_t count) |
int | spi_sdcard_single_write (const struct spi_sdcard *card, size_t block_address, void *buff) |
int | spi_sdcard_multiple_write (const struct spi_sdcard *card, size_t start_block_address, size_t end_block_address, void *buff) |
int | spi_sdcard_erase (const struct spi_sdcard *card, size_t start_block_address, size_t end_block_address) |
int | spi_sdcard_erase_all (const struct spi_sdcard *card) |
#define APP_CMD 55 |
Definition at line 46 of file spi_sdcard.c.
#define BLOCK_SIZE 512 |
Definition at line 93 of file spi_sdcard.c.
#define CLR_WRITE_PROT 29 |
Definition at line 40 of file spi_sdcard.c.
#define CRC_ON_OFF 59 |
Definition at line 49 of file spi_sdcard.c.
#define CT_BLOCK_START 0xfe |
Definition at line 60 of file spi_sdcard.c.
#define CT_MULTIPLE_BLOCK_START 0xfc |
Definition at line 61 of file spi_sdcard.c.
#define CT_MULTIPLE_BLOCK_STOP 0xfd |
Definition at line 62 of file spi_sdcard.c.
#define CT_RESPONSE_ACCEPTED 0x05 |
Definition at line 64 of file spi_sdcard.c.
#define CT_RESPONSE_MASK 0x1f |
Definition at line 63 of file spi_sdcard.c.
#define CT_RESPONSE_REJECTED_CRC 0x0b |
Definition at line 65 of file spi_sdcard.c.
#define CT_RESPONSE_REJECTED_WRITE_ERR 0x0d |
Definition at line 66 of file spi_sdcard.c.
#define dprintk | ( | fmt, | |
args... | |||
) | do {} while (0) |
Definition at line 16 of file spi_sdcard.c.
#define ERASE 38 |
Definition at line 44 of file spi_sdcard.c.
#define ERASE_WR_BLK_END_ADDR 33 |
Definition at line 43 of file spi_sdcard.c.
#define ERASE_WR_BLK_START_ADDR 32 |
Definition at line 42 of file spi_sdcard.c.
#define GEN_CMD 56 |
Definition at line 47 of file spi_sdcard.c.
#define GO_IDLE_STATE 0 |
Definition at line 25 of file spi_sdcard.c.
#define LOCK_UNLOCK 42 |
Definition at line 45 of file spi_sdcard.c.
#define PROGRAM_CSD 27 |
Definition at line 38 of file spi_sdcard.c.
#define READ_MULTIPLEBLOCK 18 |
Definition at line 35 of file spi_sdcard.c.
#define READ_OCR 58 |
Definition at line 48 of file spi_sdcard.c.
#define READ_SINGLE_BLOCK 17 |
Definition at line 34 of file spi_sdcard.c.
#define RSP_ERR_ADDRESS (1 << 13) |
Definition at line 90 of file spi_sdcard.c.
#define RSP_ERR_CARD_IS_LOCKED (1 << 0) |
Definition at line 77 of file spi_sdcard.c.
#define RSP_ERR_CC (1 << 3) |
Definition at line 80 of file spi_sdcard.c.
#define RSP_ERR_COM_CRC (1 << 11) |
Definition at line 88 of file spi_sdcard.c.
#define RSP_ERR_ECC (1 << 4) |
Definition at line 81 of file spi_sdcard.c.
#define RSP_ERR_ERASE_PARAM (1 << 6) |
Definition at line 83 of file spi_sdcard.c.
#define RSP_ERR_ERASE_RESET (1 << 9) |
Definition at line 86 of file spi_sdcard.c.
#define RSP_ERR_ERASE_SEQUENCE (1 << 12) |
Definition at line 89 of file spi_sdcard.c.
#define RSP_ERR_GENERAL (1 << 2) |
Definition at line 79 of file spi_sdcard.c.
#define RSP_ERR_ILLEGAL_COMMAND (1 << 10) |
Definition at line 87 of file spi_sdcard.c.
#define RSP_ERR_IN_IDLE (1 << 8) |
Definition at line 85 of file spi_sdcard.c.
#define RSP_ERR_OUT_OF_RANGE (1 << 7) |
Definition at line 84 of file spi_sdcard.c.
#define RSP_ERR_PARAMETER (1 << 14) |
Definition at line 91 of file spi_sdcard.c.
#define RSP_ERR_WP_ERASE_SKIP (1 << 1) |
Definition at line 78 of file spi_sdcard.c.
#define RSP_ERR_WP_VIOLATION (1 << 5) |
Definition at line 82 of file spi_sdcard.c.
#define RSP_R1 0 |
Definition at line 69 of file spi_sdcard.c.
#define RSP_R1b 1 |
Definition at line 70 of file spi_sdcard.c.
#define RSP_R2 2 |
Definition at line 71 of file spi_sdcard.c.
#define RSP_R3 3 |
Definition at line 72 of file spi_sdcard.c.
#define RSP_R4 4 |
Definition at line 73 of file spi_sdcard.c.
#define RSP_R5 5 |
Definition at line 74 of file spi_sdcard.c.
#define RSP_R7 7 |
Definition at line 75 of file spi_sdcard.c.
#define SD_SEND_OP_COND 41 |
Definition at line 55 of file spi_sdcard.c.
#define SD_STATUS 13 |
Definition at line 52 of file spi_sdcard.c.
#define SDCARD_TYPE_SDHC 2 |
Definition at line 21 of file spi_sdcard.c.
#define SDCARD_TYPE_SDSC 1 |
Definition at line 20 of file spi_sdcard.c.
#define SDCARD_TYPE_SDXC 3 |
Definition at line 22 of file spi_sdcard.c.
#define SEND_CID 10 |
Definition at line 30 of file spi_sdcard.c.
#define SEND_CSD 9 |
Definition at line 29 of file spi_sdcard.c.
#define SEND_IF_COND 8 |
Definition at line 28 of file spi_sdcard.c.
#define SEND_NUM_WR_BLOCKS 22 |
Definition at line 53 of file spi_sdcard.c.
#define SEND_OP_COND 1 |
Definition at line 26 of file spi_sdcard.c.
#define SEND_SCR 51 |
Definition at line 57 of file spi_sdcard.c.
#define SEND_STATUS 13 |
Definition at line 32 of file spi_sdcard.c.
#define SEND_WRITE_PROT 30 |
Definition at line 41 of file spi_sdcard.c.
#define SET_BLOCKLEN 16 |
Definition at line 33 of file spi_sdcard.c.
#define SET_CLR_CARD_DETECT 42 |
Definition at line 56 of file spi_sdcard.c.
#define SET_WR_BLK_ERASE_COUNT 23 |
Definition at line 54 of file spi_sdcard.c.
#define SET_WRITE_PROT 28 |
Definition at line 39 of file spi_sdcard.c.
#define STOP_TRANSMISSION 12 |
Definition at line 31 of file spi_sdcard.c.
#define SWITCH_FUNC 6 |
Definition at line 27 of file spi_sdcard.c.
#define WRITE_BLOCK 24 |
Definition at line 36 of file spi_sdcard.c.
#define WRITE_MULTIPLEBLOCK 25 |
Definition at line 37 of file spi_sdcard.c.
Definition at line 95 of file spi_sdcard.c.
References width.
Referenced by spi_sdcard_size().
|
static |
Definition at line 180 of file spi_sdcard.c.
References RSP_R1, RSP_R2, SD_SEND_OP_COND, SD_STATUS, SEND_NUM_WR_BLOCKS, SEND_SCR, SET_CLR_CARD_DETECT, and SET_WR_BLK_ERASE_COUNT.
Referenced by spi_sdcard_do_command_help().
|
static |
Definition at line 143 of file spi_sdcard.c.
References APP_CMD, CLR_WRITE_PROT, CRC_ON_OFF, ERASE, ERASE_WR_BLK_END_ADDR, ERASE_WR_BLK_START_ADDR, GEN_CMD, GO_IDLE_STATE, LOCK_UNLOCK, PROGRAM_CSD, READ_MULTIPLEBLOCK, READ_OCR, READ_SINGLE_BLOCK, RSP_R1, RSP_R1b, RSP_R2, RSP_R3, RSP_R7, SEND_CID, SEND_CSD, SEND_IF_COND, SEND_OP_COND, SEND_STATUS, SEND_WRITE_PROT, SET_BLOCKLEN, SET_WRITE_PROT, STOP_TRANSMISSION, SWITCH_FUNC, WRITE_BLOCK, and WRITE_MULTIPLEBLOCK.
Referenced by spi_sdcard_do_command_help().
|
static |
Definition at line 195 of file spi_sdcard.c.
References RSP_R1, RSP_R1b, RSP_R2, RSP_R3, and RSP_R7.
Referenced by spi_sdcard_do_command_help().
Definition at line 132 of file spi_sdcard.c.
References crc7_byte().
Referenced by spi_sdcard_do_command_help().
|
static |
Definition at line 113 of file spi_sdcard.c.
References card, spi_sdcard::slave, and spi_release_bus().
Referenced by spi_sdcard_do_command_help(), spi_sdcard_init(), spi_sdcard_multiple_read(), spi_sdcard_multiple_write(), spi_sdcard_single_read(), spi_sdcard_single_write(), and spi_sdcard_size().
|
static |
Definition at line 351 of file spi_sdcard.c.
References APP_CMD, card, NULL, spi_sdcard_do_command(), and spi_sdcard_do_command_help().
Referenced by spi_sdcard_init().
|
static |
Definition at line 343 of file spi_sdcard.c.
References card, and spi_sdcard_do_command_help().
Referenced by spi_sdcard_do_app_command(), spi_sdcard_erase(), spi_sdcard_init(), spi_sdcard_multiple_read(), spi_sdcard_multiple_write(), spi_sdcard_single_read(), spi_sdcard_single_write(), and spi_sdcard_size().
|
static |
Definition at line 266 of file spi_sdcard.c.
References c, card, dprintk, length, lookup_acmd_response_type(), lookup_cmd_response_type(), lookup_response_length(), response_resolve(), RSP_R1b, spi_sdcard_calculate_command_crc(), spi_sdcard_disable_cs(), spi_sdcard_enable_cs(), spi_sdcard_recvbyte(), spi_sdcard_sendbyte(), type, and wait().
Referenced by spi_sdcard_do_app_command(), and spi_sdcard_do_command().
|
static |
Definition at line 108 of file spi_sdcard.c.
References card, spi_sdcard::slave, and spi_claim_bus().
Referenced by spi_sdcard_do_command_help(), spi_sdcard_multiple_read(), spi_sdcard_multiple_write(), spi_sdcard_single_read(), spi_sdcard_single_write(), and spi_sdcard_size().
int spi_sdcard_erase | ( | const struct spi_sdcard * | card, |
size_t | start_block_address, | ||
size_t | end_block_address | ||
) |
Definition at line 772 of file spi_sdcard.c.
References card, ERASE, ERASE_WR_BLK_END_ADDR, ERASE_WR_BLK_START_ADDR, NULL, SDCARD_TYPE_SDSC, spi_sdcard_do_command(), and spi_sdcard::type.
Referenced by spi_sdcard_erase_all().
int spi_sdcard_erase_all | ( | const struct spi_sdcard * | card | ) |
Definition at line 798 of file spi_sdcard.c.
References BLOCK_SIZE, card, spi_sdcard_erase(), and spi_sdcard_size().
int spi_sdcard_init | ( | struct spi_sdcard * | card, |
const unsigned int | bus, | ||
const unsigned int | cs | ||
) |
Definition at line 421 of file spi_sdcard.c.
References card, GO_IDLE_STATE, NULL, READ_OCR, RSP_ERR_ILLEGAL_COMMAND, RSP_ERR_IN_IDLE, SD_SEND_OP_COND, SDCARD_TYPE_SDHC, SDCARD_TYPE_SDSC, SDCARD_TYPE_SDXC, SEND_IF_COND, SEND_OP_COND, SET_BLOCKLEN, spi_sdcard::slave, spi_sdcard_disable_cs(), spi_sdcard_do_app_command(), spi_sdcard_do_command(), spi_sdcard_sendbyte(), spi_sdcard_size(), spi_setup_slave(), spi_sdcard::type, and wait().
Referenced by boot_device_init().
int spi_sdcard_multiple_read | ( | const struct spi_sdcard * | card, |
size_t | start_block_address, | ||
size_t | end_block_address, | ||
void * | buff | ||
) |
Definition at line 544 of file spi_sdcard.c.
References c, card, crc16_byte(), CT_BLOCK_START, NULL, READ_MULTIPLEBLOCK, SDCARD_TYPE_SDSC, SEND_STATUS, spi_sdcard_disable_cs(), spi_sdcard_do_command(), spi_sdcard_enable_cs(), spi_sdcard_recvbyte(), STOP_TRANSMISSION, spi_sdcard::type, and wait().
Referenced by spi_sdcard_read().
int spi_sdcard_multiple_write | ( | const struct spi_sdcard * | card, |
size_t | start_block_address, | ||
size_t | end_block_address, | ||
void * | buff | ||
) |
Definition at line 707 of file spi_sdcard.c.
References c, card, crc16_byte(), CT_MULTIPLE_BLOCK_START, CT_MULTIPLE_BLOCK_STOP, CT_RESPONSE_ACCEPTED, CT_RESPONSE_MASK, NULL, SDCARD_TYPE_SDSC, SEND_STATUS, spi_sdcard_disable_cs(), spi_sdcard_do_command(), spi_sdcard_enable_cs(), spi_sdcard_recvbyte(), spi_sdcard_sendbyte(), STOP_TRANSMISSION, spi_sdcard::type, wait(), and WRITE_MULTIPLEBLOCK.
int spi_sdcard_read | ( | const struct spi_sdcard * | card, |
void * | dest, | ||
size_t | offset, | ||
size_t | count | ||
) |
Definition at line 603 of file spi_sdcard.c.
References BLOCK_SIZE, card, count, memcpy(), offset, spi_sdcard_multiple_read(), and spi_sdcard_single_read().
|
static |
Definition at line 124 of file spi_sdcard.c.
References card, dprintk, spi_sdcard::slave, and spi_xfer().
Referenced by spi_sdcard_do_command_help(), spi_sdcard_multiple_read(), spi_sdcard_multiple_write(), spi_sdcard_single_read(), spi_sdcard_single_write(), and spi_sdcard_size().
|
static |
Definition at line 118 of file spi_sdcard.c.
References card, dprintk, NULL, spi_sdcard::slave, and spi_xfer().
Referenced by spi_sdcard_do_command_help(), spi_sdcard_init(), spi_sdcard_multiple_write(), and spi_sdcard_single_write().
int spi_sdcard_single_read | ( | const struct spi_sdcard * | card, |
size_t | block_address, | ||
void * | buff | ||
) |
Definition at line 496 of file spi_sdcard.c.
References c, card, crc16_byte(), CT_BLOCK_START, NULL, READ_SINGLE_BLOCK, SDCARD_TYPE_SDSC, spi_sdcard_disable_cs(), spi_sdcard_do_command(), spi_sdcard_enable_cs(), spi_sdcard_recvbyte(), spi_sdcard::type, and wait().
Referenced by spi_sdcard_read().
int spi_sdcard_single_write | ( | const struct spi_sdcard * | card, |
size_t | block_address, | ||
void * | buff | ||
) |
Definition at line 658 of file spi_sdcard.c.
References c, card, crc16_byte(), CT_BLOCK_START, CT_RESPONSE_ACCEPTED, CT_RESPONSE_MASK, NULL, SDCARD_TYPE_SDSC, spi_sdcard_disable_cs(), spi_sdcard_do_command(), spi_sdcard_enable_cs(), spi_sdcard_recvbyte(), spi_sdcard_sendbyte(), spi_sdcard::type, wait(), and WRITE_BLOCK.
size_t spi_sdcard_size | ( | const struct spi_sdcard * | card | ) |
Definition at line 363 of file spi_sdcard.c.
References c, card, crc16_byte(), CT_BLOCK_START, extract_bits(), NULL, SEND_CSD, spi_sdcard_disable_cs(), spi_sdcard_do_command(), spi_sdcard_enable_cs(), spi_sdcard_recvbyte(), and wait().
Referenced by spi_sdcard_erase_all(), and spi_sdcard_init().