u16 onfi_crc16(u16 crc, u8 const *p, size_t len)
{ int i; while (len--) {
crc ^= *p++ << 8; for (i = 0; i < 8; i++)
crc = (crc << 1) ^ ((crc & 0x8000) ? 0x8005 : 0);
}
return crc;
}
/* Parse the Extended Parameter Page. */ staticint nand_flash_detect_ext_param_page(struct nand_chip *chip, struct nand_onfi_params *p)
{ struct nand_device *base = &chip->base; struct nand_ecc_props requirements; struct onfi_ext_param_page *ep; struct onfi_ext_section *s; struct onfi_ext_ecc_info *ecc;
uint8_t *cursor; int ret; int len; int i;
len = le16_to_cpu(p->ext_param_page_length) * 16;
ep = kmalloc(len, GFP_KERNEL); if (!ep) return -ENOMEM;
/* *UsetheChangeReadColumncommandtoskiptheONFIparampagesand *ensurewereadattherightlocation.
*/
ret = nand_change_read_column_op(chip, sizeof(*p) * p->num_of_param_pages,
ep, len, true); if (ret) goto ext_out;
ret = -EINVAL; if ((onfi_crc16(ONFI_CRC_BASE, ((uint8_t *)ep) + 2, len - 2)
!= le16_to_cpu(ep->crc))) {
pr_debug("fail in the CRC.\n"); goto ext_out;
}
/* *Checkthesignature. *DonotstrictlyfollowtheONFIspec,maybechangedinfuture.
*/ if (strncmp(ep->sig, "EPPS", 4)) {
pr_debug("The signature is invalid.\n"); goto ext_out;
}
/* find the ECC section. */
cursor = (uint8_t *)(ep + 1); for (i = 0; i < ONFI_EXT_SECTION_MAX; i++) {
s = ep->sections + i; if (s->type == ONFI_SECTION_TYPE_2) break;
cursor += s->length * 16;
} if (i == ONFI_EXT_SECTION_MAX) {
pr_debug("We can not find the ECC section.\n"); goto ext_out;
}
/* get the info we want. */
ecc = (struct onfi_ext_ecc_info *)cursor;
if (!ecc->codeword_size) {
pr_debug("Invalid codeword size\n"); goto ext_out;
}
/* Try ONFI for unknown chip or LP */
ret = nand_readid_op(chip, 0x20, id, sizeof(id)); if (ret || strncmp(id, "ONFI", 4)) return0;
/* ONFI chip: allocate a buffer to hold its parameter page */
pbuf = kzalloc((sizeof(*pbuf) * ONFI_PARAM_PAGES), GFP_KERNEL); if (!pbuf) return -ENOMEM;
if (!nand_has_exec_op(chip) || chip->controller->supported_op.data_only_read)
use_datain = true;
for (i = 0; i < ONFI_PARAM_PAGES; i++) { if (!i)
ret = nand_read_param_page_op(chip, 0, &pbuf[i], sizeof(*pbuf)); elseif (use_datain)
ret = nand_read_data_op(chip, &pbuf[i], sizeof(*pbuf), true, false); else
ret = nand_change_read_column_op(chip, sizeof(*pbuf) * i,
&pbuf[i], sizeof(*pbuf), true); if (ret) {
ret = 0; goto free_onfi_param_page;
}
crc = onfi_crc16(ONFI_CRC_BASE, (u8 *)&pbuf[i], 254); if (crc == le16_to_cpu(pbuf[i].crc)) {
p = &pbuf[i]; break;
}
}
if (i == ONFI_PARAM_PAGES) { constvoid *srcbufs[ONFI_PARAM_PAGES]; unsignedint j;
/* The Extended Parameter Page is supported since ONFI 2.1. */ if (nand_flash_detect_ext_param_page(chip, p))
pr_warn("Failed to detect ONFI extended param page\n");
} else {
pr_warn("Could not retrieve ONFI ECC requirements\n");
}
/* Save some parameters from the parameter page for future use */ if (le16_to_cpu(p->opt_cmd) & ONFI_OPT_CMD_SET_GET_FEATURES) {
chip->parameters.supports_set_get_features = true;
bitmap_set(chip->parameters.get_feature_list,
ONFI_FEATURE_ADDR_TIMING_MODE, 1);
bitmap_set(chip->parameters.set_feature_list,
ONFI_FEATURE_ADDR_TIMING_MODE, 1);
}
if (le16_to_cpu(p->opt_cmd) & ONFI_OPT_CMD_READ_CACHE)
chip->parameters.supports_read_cache = true;
onfi = kzalloc(sizeof(*onfi), GFP_KERNEL); if (!onfi) {
ret = -ENOMEM; goto free_model;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.