Micron MT29F NAND driver

This function is used to lock PERMANENTLY a page in the OTP area. Warning! If this function is not called after an OTP data program, you can still perform bit manipulation program in the OTP area!!

Parameters:
[in]none
Returns:
Function returns DRIVER_STATUS_NOT_INITIALIZED, NAND_SUCCESS or NAND_GENERIC_FAIL
Pseudo Code Steps
  1. Check if the device is previously in OTP mode (FEATURE_ARRAY_OTP_OPERATION)
  2. Set the device in protect mode (FEATURE_ARRAY_OTP_PROTECTION) using set_feature
  3. Check if the device is now in protect mode (FEATURE_ARRAY_OTP_PROTECTION)
  4. Send fake program on the OTP page with 0x00 filled buffer
  5. Re-enter in OTP mode

Definition at line 1569 of file nand_MT29F_lld.c.

References ADDR_FEATURE_ARRAY_OPMODE, parameter_page_t::data_bytes_per_page, device_info, driver_status, DRIVER_STATUS_INITIALIZED, DRIVER_STATUS_NOT_INITIALIZED, parameter_page_t::feature, FEATURE_ARRAY_OTP_OPERATION, FEATURE_ARRAY_OTP_PROTECTION, NAND_GENERIC_FAIL, NAND_Get_Feature(), NAND_OTP_Mode_Enter(), NAND_OTP_Page_Program(), NAND_Set_Feature(), NAND_SUCCESS, parameter_page_t::spare_bytes_per_page, and SUPPORTED_16_BIT_DATA_BUS_WIDTH.

                                                 {
   MT_uint8 ret;
   flash_width subfeature;
   flash_width write_buf[device_info.data_bytes_per_page + device_info.spare_bytes_per_page];

   /* check if driver is in a valid state */
   if(DRIVER_STATUS_INITIALIZED != driver_status)
      return DRIVER_STATUS_NOT_INITIALIZED;

   /* check if device is NOT in normal status */
   ret = NAND_Get_Feature(ADDR_FEATURE_ARRAY_OPMODE, &subfeature);

   if(FEATURE_ARRAY_OTP_OPERATION != subfeature)
      return NAND_GENERIC_FAIL;

   /* issue protect OTP area command */
   ret = NAND_Set_Feature(ADDR_FEATURE_ARRAY_OPMODE, FEATURE_ARRAY_OTP_PROTECTION);

   /* return with error if a fail occurs */
   if(NAND_SUCCESS != ret)
      return ret;

   /* check if device is in normal status */
   ret = NAND_Get_Feature(ADDR_FEATURE_ARRAY_OPMODE, &subfeature);

   /* return with error if a fail occurs */
   if(NAND_SUCCESS != ret)
      return ret;

   if(FEATURE_ARRAY_OTP_PROTECTION != subfeature)
      return NAND_GENERIC_FAIL;

   /* issue the PROGRAM command to lock permanently the page */

   /* data buffer is filled with 0x00 */
   memset(write_buf, 0x00, device_info.data_bytes_per_page);

   /* x8 */
   if((device_info.feature & SUPPORTED_16_BIT_DATA_BUS_WIDTH) == 0)
      ret = NAND_OTP_Page_Program(addr, write_buf, device_info.data_bytes_per_page);
   /* x16 */
   else
      ret = NAND_OTP_Page_Program(addr, write_buf, (device_info.data_bytes_per_page>>2));

   if(NAND_SUCCESS != ret) {
      /* in case of program error, exit in OTP mode */
      NAND_OTP_Mode_Enter();
      return NAND_GENERIC_FAIL;
   }

   /* restore OTP mode before return */
   ret = NAND_OTP_Mode_Enter();

   if(NAND_SUCCESS != ret)
      return NAND_GENERIC_FAIL;

   return NAND_SUCCESS;
}