lib/sw_services/xilflash/src/xilflash_amd.c
static int CheckBlockProtection(XFlash * InstancePtr, u32 Offset)
{
	u8 Mode;
	u8 AddrMul;
	u16 Region;
	u16 Block;
	u32 Dummy;
	u32 BlockAddress;
	u32 CmdAddress;
	u32 ProtStatus;
	int Status = (int)XST_FAILURE;
	XFlashGeometry *GeomPtr;
	XFlashVendorData_Amd *DevDataPtr;

	/*
	 * Verify inputs are valid.
	 */
	if(InstancePtr == NULL) {
		return (XST_FAILURE);
	}

	GeomPtr = &InstancePtr->Geometry;

	DevDataPtr = GET_PARTDATA(InstancePtr);

	Mode = (InstancePtr->Geometry.MemoryLayout &
			XFL_LAYOUT_PART_MODE_MASK) >> 8;
	if (Mode == 2) {
		AddrMul = 1;
	}
	else if (Mode == 1) {
		AddrMul = 2;
	}
	else {
		return (XST_FAILURE);
	}

	/*
	 * Convert the starting address to block coordinates. This also verifies
	 * the starting address is within the instance's address space.
	 */
	Status = XFlashGeometry_ToBlock(GeomPtr, Offset, &Region, &Block,
						&Dummy);
	if (Status != XST_SUCCESS) {
		return (XFLASH_ADDRESS_ERROR);
	}

	/*
	 * Get the physical address to write the command to and send command.
	 */
	(void) XFlashGeometry_ToAbsolute(GeomPtr, Region, Block, 0,
				 &BlockAddress);

	CmdAddress = BlockAddress | ((XFL_AMD_CMD1_ADDR * AddrMul) + !(
					XFL_AMD_CMD1_ADDR & 0x1));

	/*
	 * Send the command.
	 */
	DevDataPtr->SendCmdSeq(GeomPtr->BaseAddress,
				XFL_AMD_CMD1_ADDR, XFL_AMD_CMD2_ADDR,
				XFL_AMD_CMD1_DATA, XFL_AMD_CMD2_DATA);

	DevDataPtr->WriteFlash(InstancePtr->Geometry.BaseAddress,
				CmdAddress, XFL_AMD_CMD_AUTO_SELECT);

	/*
	 * Retrieve Protection Status located at word offset 2.
	 */
	CmdAddress = BlockAddress + (XFL_AMD_PROT_STATUS_OFFSET * AddrMul);

	ProtStatus = DevDataPtr->GetStatus(GeomPtr->BaseAddress, CmdAddress);
	if(ProtStatus == XFL_AMD_GROUP_UNPROTECTED) {
		Status = XST_SUCCESS;
	}
	else if(ProtStatus == XFL_AMD_GROUP_PROTECTED) {
		Status = XFLASH_BLOCK_PROTECTED;
	}
	else {
		Status = XST_FAILURE;
	}

	/*
	 * Return to Read mode.
	 */
	(void) XFlashAmd_Reset(InstancePtr);

	return (Status);
}
/*****************************************************************************/
/**
*
* This function reads the protection status of a block group.
*
* @param	InstancePtr is the pointer to the XFlash instance.
* @param	Offset is the offset into the device(s) address space from where
* 		to read protection status.
*
* @return
*		- XST_SUCCESS if block is not protected.
*		- XFLASH_BLOCK_PROTECTED if block is protected.
*		- XFLASH_ADDRESS_ERROR if the destination address range is
*		  not completely within the addressable areas of the device(s).
*		- XST_FAILURE if block protection is unclear.
*
* @note		None.
*
******************************************************************************/
This function reads the protection status of a block group.
This function reads the protection status of a block group .
static int CheckBlockProtection(XFlash * InstancePtr, u32 Offset)
{
	u8 Mode;
	u8 AddrMul;
	u16 Region;
	u16 Block;
	u32 Dummy;
	u32 BlockAddress;
	u32 CmdAddress;
	u32 ProtStatus;
	int Status = (int)XST_FAILURE;
	XFlashGeometry *GeomPtr;
	XFlashVendorData_Amd *DevDataPtr;
	if(InstancePtr == NULL) {
		return (XST_FAILURE);
	}
	GeomPtr = &InstancePtr->Geometry;
	DevDataPtr = GET_PARTDATA(InstancePtr);
	Mode = (InstancePtr->Geometry.MemoryLayout &
			XFL_LAYOUT_PART_MODE_MASK) >> 8;
	if (Mode == 2) {
		AddrMul = 1;
	}
	else if (Mode == 1) {
		AddrMul = 2;
	}
	else {
		return (XST_FAILURE);
	}
	Status = XFlashGeometry_ToBlock(GeomPtr, Offset, &Region, &Block,
						&Dummy);
	if (Status != XST_SUCCESS) {
		return (XFLASH_ADDRESS_ERROR);
	}
	(void) XFlashGeometry_ToAbsolute(GeomPtr, Region, Block, 0,
				 &BlockAddress);
	CmdAddress = BlockAddress | ((XFL_AMD_CMD1_ADDR * AddrMul) + !(
					XFL_AMD_CMD1_ADDR & 0x1));
	DevDataPtr->SendCmdSeq(GeomPtr->BaseAddress,
				XFL_AMD_CMD1_ADDR, XFL_AMD_CMD2_ADDR,
				XFL_AMD_CMD1_DATA, XFL_AMD_CMD2_DATA);
	DevDataPtr->WriteFlash(InstancePtr->Geometry.BaseAddress,
				CmdAddress, XFL_AMD_CMD_AUTO_SELECT);
	CmdAddress = BlockAddress + (XFL_AMD_PROT_STATUS_OFFSET * AddrMul);
	ProtStatus = DevDataPtr->GetStatus(GeomPtr->BaseAddress, CmdAddress);
	if(ProtStatus == XFL_AMD_GROUP_UNPROTECTED) {
		Status = XST_SUCCESS;
	}
	else if(ProtStatus == XFL_AMD_GROUP_PROTECTED) {
		Status = XFLASH_BLOCK_PROTECTED;
	}
	else {
		Status = XST_FAILURE;
	}
	(void) XFlashAmd_Reset(InstancePtr);
	return (Status);
}
static int CheckBlockProtection ( XFlash * InstancePtr , u32 Offset ) { u8 Mode ; u8 AddrMul ; u16 Region ; u16 Block ; u32 Dummy ; u32 BlockAddress ; u32 CmdAddress ; u32 ProtStatus ; int Status = ( int ) XST_FAILURE ; XFlashGeometry * GeomPtr ; XFlashVendorData_Amd * DevDataPtr ; if ( InstancePtr == NULL ) { return ( XST_FAILURE ) ; } GeomPtr = & InstancePtr -> Geometry ; DevDataPtr = GET_PARTDATA ( InstancePtr ) ; Mode = ( InstancePtr -> Geometry . MemoryLayout & XFL_LAYOUT_PART_MODE_MASK ) >> 8 ; if ( Mode == 2 ) { AddrMul = 1 ; } else if ( Mode == 1 ) { AddrMul = 2 ; } else { return ( XST_FAILURE ) ; } Status = XFlashGeometry_ToBlock ( GeomPtr , Offset , & Region , & Block , & Dummy ) ; if ( Status != XST_SUCCESS ) { return ( XFLASH_ADDRESS_ERROR ) ; } ( void ) XFlashGeometry_ToAbsolute ( GeomPtr , Region , Block , 0 , & BlockAddress ) ; CmdAddress = BlockAddress | ( ( XFL_AMD_CMD1_ADDR * AddrMul ) + ! ( XFL_AMD_CMD1_ADDR & 0x1 ) ) ; DevDataPtr -> SendCmdSeq ( GeomPtr -> BaseAddress , XFL_AMD_CMD1_ADDR , XFL_AMD_CMD2_ADDR , XFL_AMD_CMD1_DATA , XFL_AMD_CMD2_DATA ) ; DevDataPtr -> WriteFlash ( InstancePtr -> Geometry . BaseAddress , CmdAddress , XFL_AMD_CMD_AUTO_SELECT ) ; CmdAddress = BlockAddress + ( XFL_AMD_PROT_STATUS_OFFSET * AddrMul ) ; ProtStatus = DevDataPtr -> GetStatus ( GeomPtr -> BaseAddress , CmdAddress ) ; if ( ProtStatus == XFL_AMD_GROUP_UNPROTECTED ) { Status = XST_SUCCESS ; } else if ( ProtStatus == XFL_AMD_GROUP_PROTECTED ) { Status = XFLASH_BLOCK_PROTECTED ; } else { Status = XST_FAILURE ; } ( void ) XFlashAmd_Reset ( InstancePtr ) ; return ( Status ) ; }
This function reads the protection status of a block group.
This function reads the protection status of a block group .
/*
	 * Verify inputs are valid.
	 */ /*
	 * Convert the starting address to block coordinates. This also verifies
	 * the starting address is within the instance's address space.
	 */ /*
	 * Get the physical address to write the command to and send command.
	 */ /*
	 * Send the command.
	 */ /*
	 * Retrieve Protection Status located at word offset 2.
	 */ /*
	 * Return to Read mode.
	 */