Ejemplo n.º 1
0
/*FUNCTION*-------------------------------------------------------------------
* 
* Function Name    : _mcf5282_cfm_sect_check
* Returned Value   : 
* Comments         : This function blank check the sector
* 
*END*----------------------------------------------------------------------*/
uint_32 _mcf5282_cfm_sect_check
    (  
      /* [IN] the base address of the flash */
      uint_32  handle_ptr,

      /* [IN] sector number to check */
      uint_32  sector   
    )
{ /* Body */

   uint_32_ptr temp_ptr;
   uint_32 sect_offset,end_offset;
   volatile int i;
   
   if((sector < 0) || (sector >= MCF5282_CFM_SECTOR_NUM))
      return CFM_INVALID_SECTOR_NUMBER;

   sect_offset =  GetSectorOffset(sector);
   if(sect_offset == -1)
      return CFM_INVALID_SECTOR_NUMBER;

   for(i=0; i<100; i++){}
   end_offset = sect_offset + MCF5282_CFM_SECTOR_SIZE;
   temp_ptr = (uint_32_ptr)(handle_ptr + sect_offset);

   while(sect_offset < end_offset){
      if(*temp_ptr != MCF5282_CFM_SECTOR_BLANK_CHECK)
         return 1;
      temp_ptr++;
      sect_offset+=4;
   }

   return CFM_OK;
}
Ejemplo n.º 2
0
void CD16Image::InitImage()
{
	if (bam != NULL)
		delete bam;
    bam = GetSector(1, 1);					// Bam of an HD Image seems to start at $100
    bamStart = GetSectorOffset(1, 1);
}
Ejemplo n.º 3
0
void CD16Image::InitBAM(int track, int sector)
{
	if (bam != NULL)
		delete bam;
	bam = NULL;
	bam = GetSector(track, sector);
	bamStart = GetSectorOffset(track, sector);
}
Ejemplo n.º 4
0
CCbmSector *CCbmImageBase::GetSector(int track, int sector)
{
    byte sectorBuffer[256];
    int offset = GetSectorOffset(track, sector);
    if (imageLength <= offset)
	{
		sprintf(msg, "Illegal Track or Sector (%d, %d)", track, sector);
        throw msg;
	}

	memcpy(sectorBuffer, image + offset, 256);
    CCbmSector *sec = new CCbmSector(sectorBuffer);
    sec->SetTrack(track);
    sec->SetSector(sector);
    return sec;
}
Ejemplo n.º 5
0
//----- (0800149E) --------------------------------------------------------
NTSTATUS 
DMReadWrite(
	PDEVICE_OBJECT	DeviceObject, 
	PIRP			Irp
	)
{
	PDEVICE_ENTRY		DevEntry;
	ULONG				SectorNum;
	ULONGLONG			ByteOffset;
	ULONGLONG			SectorOffset;
	PIO_STACK_LOCATION	IrpStack;
	NTSTATUS			status;
	LARGE_INTEGER		PerfCount;
	LARGE_INTEGER		CurrentTime;
	ULONG				seq;

	IrpStack = IoGetCurrentIrpStackLocation(Irp);
	if ( g_bUsePerfCounter )
	{
		PerfCount = KeQueryPerformanceCounter(NULL);
		CurrentTime.QuadPart = 0;
	}
	else
	{
		KeQuerySystemTime(&CurrentTime);
		PerfCount.QuadPart = 0;
	}

	seq = InterlockedIncrement(&Sequence);

	DevEntry = LookupEntryByDevObj(DeviceObject);
	if ( DevEntry )
	{
		SectorNum		= IrpStack->Parameters.Read.Length >> 9;
		ByteOffset		= IrpStack->Parameters.Read.ByteOffset.QuadPart;
		SectorOffset	= GetSectorOffset(ByteOffset, 512);

		LogRecord(
			seq,
			&CurrentTime,
			DevEntry->DiskNumber,
			"%s\t%I64d\t%d",
			IrpStack->MajorFunction == IRP_MJ_READ ? "IRP_MJ_READ" : "IRP_MJ_WRITE", SectorOffset, SectorNum);
	}

	return DefaultDispatch(DeviceObject, Irp, seq, g_bUsePerfCounter, &PerfCount);
}
Ejemplo n.º 6
0
/*FUNCTION*-------------------------------------------------------------------
* 
* Function Name    : _mcf5282_cfm_read
* Returned Value   : 
* Comments         : This function reads from flash at specified sector and 
*                    copy the data to a buffer.
* 
*END*----------------------------------------------------------------------*/
uint_32 _mcf5282_cfm_read
    (  
      /* [IN] the base address of the flash */
      MCF5282_CFM_STRUCT_PTR  handle_ptr,

      /* [IN/OUT] start address of buffer to store the data */
      uint_32_ptr   buff_ptr,

      /* [IN] where to copy data from */
      uint_32       from_sector,
      
      /* [IN] size to read in byte */
      uint_32       size
   )
{ /* Body */
   pointer from;
   uint_32 sect_offset;

   sect_offset = GetSectorOffset(from_sector);
   from = (pointer)MCF5282_CFM_BACKDOOR(sect_offset);
   _mem_copy((pointer)from,(pointer)buff_ptr,(_mem_size)size);
   
   return CFM_OK;
}
Ejemplo n.º 7
0
/*FUNCTION*-------------------------------------------------------------------
* 
* Function Name    : _mcf5282_cfm_verify_mass_erase
* Returned Value   : 
* Comments         : This function verifies entier erase of Flash.
* 
*END*----------------------------------------------------------------------*/
uint_32 _mcf5282_cfm_verify_mass_erase
   (
      /* [IN] the base address of the flash */
      MCF5282_CFM_STRUCT_PTR  handle_ptr
   )
{ /* Body */
   int i;
   uint_32 sector_offset,
           end_offset,
           result;
   uint_32 wait_time = INTFLASH_TIMEOUT;

   result = _mcf5282_cfm_reset(handle_ptr);
   if(result != CFM_OK)
      return result;
   
   for(i=0; i < MCF5282_CFM_SECTOR_NUM ; i+=16){
      sector_offset = GetSectorOffset(i);   
      if(sector_offset == -1)
         return CFM_INVALID_SECTOR_NUMBER;
      handle_ptr->CFMPROT = 0x00000000;
      if( (handle_ptr->CFMCLKD & MCF5282_CFM_CFMCLKD_DIVLD) == 0)
         handle_ptr->CFMCLKD = MCF5282_CFM_CFMCLKD_DIVLD_VALUE;   
      while ((wait_time > 0) && ((handle_ptr->CFMUSTAT & MCF5282_CFM_CFMUSTAT_CBEIF) == 0)){
         handle_ptr->CFMUSTAT = MCF5282_CFM_CFMUSTAT_CBEIF;
         wait_time--;
      }
      if(wait_time <= 0)
         return CFM_TIMED_OUT;
      end_offset = sector_offset + (MCF5282_CFM_SECTOR_SIZE * 16);
      while ( sector_offset <   end_offset) {
         /* Write program data to array address */
         MCF5282_CFM_BACKDOOR(sector_offset) = (uint_32)0x00000000;
         /* Write program command */
         handle_ptr->CFMCMD = MCF5282_CFM_MASS_ERASE_VERIFY;
         /* Clear CBELF bit */
         handle_ptr->CFMUSTAT = MCF5282_CFM_CFMUSTAT_CBEIF;
         /* Protection violation check */
         if((handle_ptr->CFMUSTAT & MCF5282_CFM_CFMUSTAT_PVIOL) != 0){
            handle_ptr->CFMUSTAT = MCF5282_CFM_CFMUSTAT_PVIOL;
            MCF5282_CFM_BACKDOOR(sector_offset) = (uint_32)0x00000000;
            handle_ptr->CFMCMD = MCF5282_CFM_MASS_ERASE_VERIFY;
            handle_ptr->CFMUSTAT = MCF5282_CFM_CFMUSTAT_CBEIF;
         }
         /* Access error check */
         if((handle_ptr->CFMUSTAT & MCF5282_CFM_CFMUSTAT_ACCERR) != 0){
            handle_ptr->CFMUSTAT = MCF5282_CFM_CFMUSTAT_ACCERR;
            MCF5282_CFM_BACKDOOR(sector_offset) = (uint_32)0x00000000;
            handle_ptr->CFMCMD = MCF5282_CFM_MASS_ERASE_VERIFY;
            handle_ptr->CFMUSTAT = MCF5282_CFM_CFMUSTAT_CBEIF;
         } 
         /* Buffer empty check */
         if((handle_ptr->CFMUSTAT & MCF5282_CFM_CFMUSTAT_CBEIF) != 0){
            while((wait_time > 0) && ((handle_ptr->CFMUSTAT & MCF5282_CFM_CFMUSTAT_CCIF) == 0)){
               handle_ptr->CFMUSTAT = MCF5282_CFM_CFMUSTAT_CCIF;
               wait_time--;
            }
            if(wait_time <= 0)
               return CFM_TIMED_OUT;
            else{
               handle_ptr->CFMPROT = 0x00000000;
               if((handle_ptr->CFMCLKD & MCF5282_CFM_CFMCLKD_DIVLD) == 0)
                  handle_ptr->CFMCLKD = MCF5282_CFM_CFMCLKD_DIVLD_VALUE;

               while((wait_time > 0) && ((handle_ptr->CFMUSTAT & MCF5282_CFM_CFMUSTAT_CBEIF) == 0)){
                  handle_ptr->CFMUSTAT = MCF5282_CFM_CFMUSTAT_CBEIF;
                  wait_time--;
               }
               if(wait_time <= 0)
                  return CFM_TIMED_OUT;        
            }
         }   
      sector_offset += 0x40000;
      }
   }
   return CFM_OK;
   
}
Ejemplo n.º 8
0
/*FUNCTION*-------------------------------------------------------------------
* 
* Function Name    : _mcf5282_cfm_sect_erase
* Returned Value   : 
* Comments         : This function erases sectors of internal flash.
* 
*END*----------------------------------------------------------------------*/
uint_32 _mcf5282_cfm_sect_erase
   (
      /* [IN] the base address of the flash */
      MCF5282_CFM_STRUCT_PTR  handle_ptr,

      /* [IN] from sector number to erase */
      uint_32  sect_from,

      /* [IN] erase to sector */
      uint_32  sect_to
   )
{ /* Body */
   int i;
   uint_32 sector_offset,
           end_offset,
           result;
   uint_32 wait_time = INTFLASH_TIMEOUT;

   if((sect_from < 0) || (sect_from >= MCF5282_CFM_SECTOR_NUM) || 
      (sect_to < 0) || (sect_to >= MCF5282_CFM_SECTOR_NUM))
      return CFM_INVALID_SECTOR_NUMBER;
   
   result = _mcf5282_cfm_reset(handle_ptr);
   if(result != CFM_OK)
      return result;
   
   for(i=sect_from; i < sect_to ; i++){
      sector_offset = GetSectorOffset(i);   
      if(sector_offset == -1)
         return CFM_INVALID_SECTOR_NUMBER;
      handle_ptr->CFMPROT = 0x00000000;
      if( (handle_ptr->CFMCLKD & MCF5282_CFM_CFMCLKD_DIVLD) == 0)
         handle_ptr->CFMCLKD = MCF5282_CFM_CFMCLKD_DIVLD_VALUE;   
      while ((wait_time > 0) && ((handle_ptr->CFMUSTAT & MCF5282_CFM_CFMUSTAT_CBEIF) == 0)){
         handle_ptr->CFMUSTAT = MCF5282_CFM_CFMUSTAT_CBEIF;
         wait_time--;
      }
      if(wait_time <= 0)
         return CFM_TIMED_OUT;
      end_offset = sector_offset + MCF5282_CFM_SECTOR_SIZE;
      while ( sector_offset <   end_offset) {
         /* Write program data to array address */
         MCF5282_CFM_BACKDOOR(sector_offset) = (uint_32)0x00000000;
         /* Write program command */
         handle_ptr->CFMCMD = MCF5282_CFM_PAGE_ERASE;
         /* Clear CBELF bit */
         handle_ptr->CFMUSTAT = MCF5282_CFM_CFMUSTAT_CBEIF;
         /* Protection violation check */
         if((handle_ptr->CFMUSTAT & MCF5282_CFM_CFMUSTAT_PVIOL) != 0){
            handle_ptr->CFMUSTAT = MCF5282_CFM_CFMUSTAT_PVIOL;
            MCF5282_CFM_BACKDOOR(sector_offset) = (uint_32)0x00000000;
            handle_ptr->CFMCMD = MCF5282_CFM_PAGE_ERASE;
            handle_ptr->CFMUSTAT = MCF5282_CFM_CFMUSTAT_CBEIF;
         }
         /* Access error check */
         if((handle_ptr->CFMUSTAT & MCF5282_CFM_CFMUSTAT_ACCERR) != 0){
            handle_ptr->CFMUSTAT = MCF5282_CFM_CFMUSTAT_ACCERR;
            MCF5282_CFM_BACKDOOR(sector_offset) = (uint_32)0x00000000;
            handle_ptr->CFMCMD = MCF5282_CFM_PAGE_ERASE;
            handle_ptr->CFMUSTAT = MCF5282_CFM_CFMUSTAT_CBEIF;
         } 
         /* Buffer empty check */
         if((handle_ptr->CFMUSTAT & MCF5282_CFM_CFMUSTAT_CBEIF) != 0){
            while((wait_time > 0) && ((handle_ptr->CFMUSTAT & MCF5282_CFM_CFMUSTAT_CCIF) == 0)){
               handle_ptr->CFMUSTAT = MCF5282_CFM_CFMUSTAT_CCIF;
               wait_time--;
            }
            if(wait_time <= 0)
               return CFM_TIMED_OUT;
            else{
               handle_ptr->CFMPROT = 0x00000000;
               if((handle_ptr->CFMCLKD & MCF5282_CFM_CFMCLKD_DIVLD) == 0)
                  handle_ptr->CFMCLKD = MCF5282_CFM_CFMCLKD_DIVLD_VALUE;

               while((wait_time > 0) && ((handle_ptr->CFMUSTAT & MCF5282_CFM_CFMUSTAT_CBEIF) == 0)){
                  handle_ptr->CFMUSTAT = MCF5282_CFM_CFMUSTAT_CBEIF;
                  wait_time--;
               }
               if(wait_time <= 0)
                  return CFM_TIMED_OUT;        
            }
         }   
      sector_offset += 0x800;
      }
   }
   return CFM_OK;
}
Ejemplo n.º 9
0
/*FUNCTION*-------------------------------------------------------------------
* 
* Function Name    : _mcf5282_cfm_program_32bit
* Returned Value   : 
* Comments         : This function programs the internal flash
* 
*END*----------------------------------------------------------------------*/
uint_32 _mcf5282_cfm_program_32bit
    (  
      /* [IN] the base address of the flash */
      MCF5282_CFM_STRUCT_PTR  handle_ptr,

      /* [IN] where to copy data from */
      uint_32_ptr from_ptr,
      
      /* [IN] sector number to start program */
      uint_32     from_sector, 
    
      /* [IN] data size in byte */
      uint_32     size
    )
{ /* Body */

   uint_32  sect_num,
            i, j,
            sector_offset,
            end_offset,
            count;

   uchar_ptr end_ptr;
   uint_32   wait_time = INTFLASH_TIMEOUT;

   if((size > MCF5282_CFM_MAX_SIZE))
      return CFM_INVALID_DATA_SIZE;
   /* calculate number of sectors from data size */
   count = 0;
   sect_num = 0;
   for(j=from_sector; j<=MCF5282_CFM_SECTOR_NUM; j++){
      count++;
      if(size <= (count * MCF5282_CFM_SECTOR_SIZE)){
         sect_num = count + from_sector;
         break;
      }
   }
   if(sect_num == 0)
      return CFM_INVALID_SECTOR_NUMBER;
   
   end_ptr = (uchar_ptr)from_ptr + size;

   for(i=from_sector; i<sect_num; i++){
      /* Read CFMUSTAT for CBEIF */
      if((handle_ptr->CFMUSTAT & MCF5282_CFM_CFMUSTAT_CBEIF) == 0){
         while((wait_time > 0) && (handle_ptr->CFMUSTAT & MCF5282_CFM_CFMUSTAT_CBEIF) == 0){
            handle_ptr->CFMUSTAT &= MCF5282_CFM_CFMUSTAT_CBEIF;
            wait_time--;
         }
      }
      if(wait_time <= 0)
         return CFM_TIMED_OUT;
      handle_ptr->CFMPROT = 0x00000000;
      sector_offset = GetSectorOffset(i);
      end_offset = sector_offset + MCF5282_CFM_SECTOR_SIZE;
      if(sector_offset != -1){
         while((sector_offset < end_offset) && (from_ptr < (uint_32_ptr)end_ptr)){
            /* Write program data to array address */
            MCF5282_CFM_BACKDOOR(sector_offset) = (uint_32)*from_ptr;
            /* Write program command */
            handle_ptr->CFMCMD = MCF5282_CFM_PROGRAM;
            /* Clear CBELF bit */
            handle_ptr->CFMUSTAT = MCF5282_CFM_CFMUSTAT_CBEIF;
        
            /* Protection violation check */
            if((handle_ptr->CFMUSTAT & MCF5282_CFM_CFMUSTAT_PVIOL) != 0){
               handle_ptr->CFMUSTAT = MCF5282_CFM_CFMUSTAT_PVIOL;
               MCF5282_CFM_BACKDOOR(sector_offset) = (uint_32)*from_ptr;
               handle_ptr->CFMCMD = MCF5282_CFM_PROGRAM;
               handle_ptr->CFMUSTAT = MCF5282_CFM_CFMUSTAT_CBEIF;
           }
           /* Access error check */
           if((handle_ptr->CFMUSTAT & MCF5282_CFM_CFMUSTAT_ACCERR) != 0){
               handle_ptr->CFMUSTAT = MCF5282_CFM_CFMUSTAT_ACCERR;
               MCF5282_CFM_BACKDOOR(sector_offset) = (uint_32)*from_ptr;
               handle_ptr->CFMCMD = MCF5282_CFM_PROGRAM;
               handle_ptr->CFMUSTAT = MCF5282_CFM_CFMUSTAT_CBEIF;
           }
           /* Buffer empty check */
           if((handle_ptr->CFMUSTAT & MCF5282_CFM_CFMUSTAT_CBEIF) != 0){
              while((wait_time > 0) && ((handle_ptr->CFMUSTAT & MCF5282_CFM_CFMUSTAT_CCIF) == 0)){
                 handle_ptr->CFMUSTAT = MCF5282_CFM_CFMUSTAT_CCIF;
                 wait_time--;
              }
              if(wait_time <= 0)
                 return CFM_TIMED_OUT;
              else{
                 handle_ptr->CFMPROT = 0x00000000;
                 if((handle_ptr->CFMCLKD & MCF5282_CFM_CFMCLKD_DIVLD) == 0)
                    handle_ptr->CFMCLKD = MCF5282_CFM_CFMCLKD_DIVLD_VALUE;

                 while((wait_time > 0) && ((handle_ptr->CFMUSTAT & MCF5282_CFM_CFMUSTAT_CBEIF) == 0)){
                    handle_ptr->CFMUSTAT = MCF5282_CFM_CFMUSTAT_CBEIF;
                    wait_time--;
                 }
                 if(wait_time <= 0)
                    return CFM_TIMED_OUT;          
              }
           }     
           /* Update sector offset buy 4 bytes */
           sector_offset += sizeof(uint_32);
           /* Update data */
           from_ptr++;
         }
      } else 
         return CFM_INVALID_SECTOR_NUMBER;
   }
   return CFM_OK;
}
Ejemplo n.º 10
0
void CCbmImageBase::WriteSector(CCbmSector *sector)
{
    int offset = GetSectorOffset(sector->GetTrack(), sector->GetSector());		// Get offset of Sector
	memcpy(image + offset, sector->GetRawSector(), 256);						// Write data to Image
}