STAR
Cal STAR — firmware, DAQ server, and engine design
Loading...
Searching...
No Matches
test_emmc_card.c
Go to the documentation of this file.
1/* CID / EXT_CSD parsing against the THGBMTG5D1LBAIL datasheet values. */
2#include <stdio.h>
3#include <stdlib.h>
4#include <string.h>
5
6#include "emmc_card.h"
7
8#define CHECK(condition) \
9 do { \
10 if (!(condition)) { \
11 fprintf(stderr, "%s:%d: %s\n", __FILE__, __LINE__, #condition); \
12 exit(1); \
13 } \
14 } while (0)
15
16/* CID as the datasheet's p. 5 table lays it out, serial 0x12345678. */
17static void datasheet_cid(uint32_t cid[4]) {
18 cid[0] = 0x11u << 24 | 0x01u << 16 | 0x00u << 8 | '0'; /* MID CBX OID */
19 cid[1] = (uint32_t)'0' << 24 | (uint32_t)'4' << 16 | 'G' << 8 | 'A';
20 cid[2] = (uint32_t)'1' << 24 | 0x02u << 16 | 0x1234u; /* PRV, PSN hi */
21 cid[3] = 0x5678u << 16 | 0x5Au << 8 | 0x01u; /* PSN lo, MDT */
22}
23
24/* EXT_CSD with the datasheet's shipped values (pp. 7-11). */
25static void datasheet_ext_csd(uint8_t e[512]) {
26 memset(e, 0, 512);
27 e[EMMC_EXT_CSD_SEC_COUNT + 0] = 0x00;
28 e[EMMC_EXT_CSD_SEC_COUNT + 1] = 0x00;
29 e[EMMC_EXT_CSD_SEC_COUNT + 2] = 0x76;
30 e[EMMC_EXT_CSD_SEC_COUNT + 3] = 0x00;
31 e[EMMC_EXT_CSD_REV] = 0x07;
39}
40
41static void test_datasheet_part(void) {
42 uint32_t cid[4];
43 uint8_t e[512];
45 datasheet_cid(cid);
47 emmc_card_parse(cid, e, &info);
48 CHECK(info.mid == 0x11);
49 CHECK(strcmp(info.pnm, "004GA1") == 0);
50 CHECK(info.prv == 0x02);
51 CHECK(info.psn == 0x12345678u);
52 CHECK(info.sec_count == 0x00760000u);
53 CHECK((uint64_t)info.sec_count * 512u == 3959422976u);
54 CHECK(info.ext_csd_rev == 7 && info.device_type == 0x57);
55 CHECK(info.rst_n_function == 0); /* RST_n ignored as shipped */
57}
58
59static void test_each_issue(void) {
60 uint32_t cid[4];
61 uint8_t e[512];
63
64 datasheet_cid(cid);
66 cid[0] = (cid[0] & 0x00FFFFFFu) | 0x15u << 24; /* Samsung */
67 emmc_card_parse(cid, e, &info);
69
70 datasheet_cid(cid);
71 cid[1] ^= 0x01u; /* "004GA0"... */
72 emmc_card_parse(cid, e, &info);
74
75 datasheet_cid(cid);
76 e[EMMC_EXT_CSD_SEC_COUNT + 2] = 0xEC; /* an 8 GB part */
77 emmc_card_parse(cid, e, &info);
79
81 e[EMMC_EXT_CSD_REV] = 6;
82 emmc_card_parse(cid, e, &info);
84
87 emmc_card_parse(cid, e, &info);
91 emmc_card_parse(cid, e, &info);
94 emmc_card_parse(cid, e, &info);
96
99 emmc_card_parse(cid, e, &info);
101
104 emmc_card_parse(cid, e, &info);
106}
107
108int main(void) {
111 puts("2 emmc card test groups passed");
112 return 0;
113}
static board_sleep_info_t info
Definition board_sleep.c:14
uint32_t emmc_card_check(const emmc_card_info_t *info)
Definition emmc_card.c:34
void emmc_card_parse(const uint32_t cid[4], const uint8_t ext_csd[512], emmc_card_info_t *out)
Definition emmc_card.c:5
#define EMMC_EXT_CSD_PRE_EOL_INFO
Definition emmc_card.h:32
#define EMMC_EXT_CSD_CACHE_CTRL
Definition emmc_card.h:24
#define EMMC_EXT_CSD_DEVICE_TYPE
Definition emmc_card.h:30
@ EMMC_CARD_WRONG_SIZE
Definition emmc_card.h:57
@ EMMC_CARD_WRONG_PART
Definition emmc_card.h:56
@ EMMC_CARD_WEAR_WARNING
Definition emmc_card.h:59
@ EMMC_CARD_CACHE_ON
Definition emmc_card.h:61
@ EMMC_CARD_OK
Definition emmc_card.h:54
@ EMMC_CARD_NO_RELIABLE_WRITE
Definition emmc_card.h:60
@ EMMC_CARD_OLD_REVISION
Definition emmc_card.h:58
@ EMMC_CARD_WRONG_MAKER
Definition emmc_card.h:55
#define EMMC_EXT_CSD_SEC_COUNT
Definition emmc_card.h:31
#define EMMC_EXT_CSD_REV
Definition emmc_card.h:29
#define EMMC_EXT_CSD_LIFE_TIME_B
Definition emmc_card.h:34
#define EMMC_EXT_CSD_LIFE_TIME_A
Definition emmc_card.h:33
#define EMMC_EXT_CSD_RST_N_FUNCTION
Definition emmc_card.h:25
#define EMMC_EXT_CSD_WR_REL_SET
Definition emmc_card.h:26
int main()
static void datasheet_ext_csd(uint8_t e[512])
static void test_datasheet_part(void)
#define CHECK(condition)
static void datasheet_cid(uint32_t cid[4])
static void test_each_issue(void)