Created
March 8, 2020 12:23
-
-
Save z4yx/ba5db1227be96cadb3b5d450a7b1a5b8 to your computer and use it in GitHub Desktop.
kernel driver code snippet to read unique ID of W25Q128
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <linux/random.h> | |
int spi_nor_scan(struct spi_nor *nor, const char *name, enum read_mode mode) { | |
// ... | |
// after mutex_init(&nor->lock); | |
if(memcmp(info->id, "\xef\x40\x18", 3) == 0) { | |
int ret; | |
u8 buf[4+8]; // 4 dummy + 64-bit ID | |
dev_warn(dev, "reading unique ID\n"); | |
ret = nor->read_reg(nor, 0x4B, buf, sizeof(buf)); // Read Unique ID number | |
if (ret < 0) { | |
pr_err("error %d reading unique ID\n", (int) ret); | |
} else { | |
pr_info("Unique ID:"); | |
for ( ret = 0; ret < 8; ret++) | |
pr_info(" %02x", buf[4+ret]); | |
pr_info("\n"); | |
add_device_randomness(buf+4, 8); | |
pr_info("random added\n"); | |
} | |
} | |
// ... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment