/* Write a data buffer to eNVM. Note that we need for this function to reside in RAM since it will be used to self-upgrade U-boot in eNMV.  */
u32 __attribute__((section(".ramcode")))
/* Write a data buffer to eNVM. Note that we need for this function to reside in RAM since it will be used to self-upgrade U-boot in eNMV.  */
u32 __attribute__((section(".ramcode")))
{
	addr &= MSS_ENVM_PAGE_ADDR_MASK;
	MSS_ENVM->status = 0xFFFFFFFF;
	MSS_ENVM->control = addr | cmd;
	while (MSS_ENVM->status & MSS_ENVM_STATUS_BUSY)
		;
	if (MSS_ENVM->status & MSS_ENVM_STATUS_ERROR_MASK) {
		if ((MSS_ENVM->status & 0x180) == 0x180)  {
			return 0;
		}
		return -1;
	}
	return 0;
}