Skip to content

Instantly share code, notes, and snippets.

@z4yx
Created March 8, 2020 12:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save z4yx/ba5db1227be96cadb3b5d450a7b1a5b8 to your computer and use it in GitHub Desktop.
Save z4yx/ba5db1227be96cadb3b5d450a7b1a5b8 to your computer and use it in GitHub Desktop.
kernel driver code snippet to read unique ID of W25Q128
#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