On Jun 23, 2014, at 4:59 AM, vijaikumar k <vijaikuma...@mistralsolutions.com> 
wrote:

> Hi All, 
>          When I try to read my BLK device using DBLK command, I get 0 always. 
> There are some data in Nor Flash though.
> Output of DBLK:
> 2.0 Shell> dblk blk8 0 1
> LBA 0000000000000000 Size 00000080 bytes BlkIo 7DDC2730
>   00: 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00  *................*
>   10: 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00  *................*
>   20: 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00  *................*
>   30: 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00  *................*
>   40: 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00  *................*
>   50: 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00  *................*
>   60: 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00  *................*
>   70: 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00  *................*
> dblk command uses AllocateZeroPool to allocate the buffer. I changed it to 
> AllocatePool to make sure that it is reading from my block device.

Do you get some kind of error? It sounds like the data is not being copied into 
the callers buffer? 

> After making it AllocatePool, I get some junk values in dblk command. I dont 
> think my read blocks function is correctly called.

Well your code is new, so it is more likely it has an error.

> I am suspecting something related to device path protocol. Dblk finds the 
> BlockIoprotocol based on device path. In my NOR Flash private data structure 
> should I use EFI_DEVICE_PATH_PROTOCOL??? Here is my Nor flash data structure
> 

You are not installing a device path as you are using the device path on the 
PCI IO handle. It looks like you are installing the Block IO protocol on the 
PCI IO handle. Which is OK, as your code is a device driver, not  a bus driver. 
Bus drivers create child handles. 

If you do a dh in the shell you should see a Block IO protocol on a handle with 
PCI IO. 

Thanks,

Andrew Fish

> NOR_FLASH_INSTANCE  mNorFlashInstanceTemplate = {
>   NOR_FLASH_SIGNATURE, // Signature
>   NULL, // Handle ... NEED TO BE FILLED
> 
>   FALSE, // Initialized
>   NULL, // Initialize
>   0, // Size ... NEED TO BE FILLED
>   0, // StartLba
> 
>   {
>   EFI_BLOCK_IO_PROTOCOL_REVISION3,             // Revision
>   NULL,                // Media
>   (EFI_BLOCK_RESET)NorFlashBlockIoReset, // Reset
>   NorFlashBlockIoReadBlocks,             // ReadBlocks
>   NorFlashBlockIoWriteBlocks,            // WriteBlocks
>   NorFlashBlockIoFlushBlocks             // FlushBlocks
> },// BlockIoProtocol
> 
>   {
>      0,      // MediaId
>   FALSE,  // RemovableMedia
>   TRUE,  // MediaPresent
>   TRUE,   // LogicalPartition
>   FALSE,  // ReadOnly
>   FALSE,  // WriteCaching
>   512,    // BlockSize
>   0,      // IoAlign
>   0,      // LastBlock
>   0,      // LowestAlignedLba
>   0,      // LogicalBlocksPerPhysicalBlock
>   0       // OptimalTransferLengthGranularity
>   }, //Media;
> NULL, //For PCI Access 
> NULL, //Device Path
> };
> 
> Start routine:
> EFI_STATUS
> EFIAPI
> NorFlashDriverBindingStart (
>   IN EFI_DRIVER_BINDING_PROTOCOL  *This,
>   IN EFI_HANDLE                   ControllerHandle,
>   IN EFI_DEVICE_PATH_PROTOCOL     *RemainingDevicePath OPTIONAL
>   )
> {
>   EFI_STATUS                  Status;
>   EFI_PCI_IO_PROTOCOL         *PciIo;
>   EFI_DEVICE_PATH_PROTOCOL    *ParentDevicePath;
>   NOR_FLASH_INSTANCE *Instance;
>   UINT8                            CmdSts;
>   Instance=NULL;
>   //CpuBreakpoint();
>   Print(L"\nInside Start of NorFlash");
>   Status = gBS->OpenProtocol(
>                       ControllerHandle,
>                       &gEfiPciIoProtocolGuid,
>                       (VOID **)&PciIo,
>                       This->DriverBindingHandle,
>                       ControllerHandle,
>                       EFI_OPEN_PROTOCOL_BY_DRIVER
>                       );
>   if (EFI_ERROR (Status)) {
>     goto Error;
>   }
>    Print(L"\nPCI IO Protocol opened successfully");
> 
>   Status = gBS->OpenProtocol (
>                   ControllerHandle,
>                   &gEfiDevicePathProtocolGuid,
>                   (VOID **) &ParentDevicePath,
>                   This->DriverBindingHandle,
>                   ControllerHandle,
>                   EFI_OPEN_PROTOCOL_BY_DRIVER
>                   );
>   if (EFI_ERROR (Status)) {
>          Print(L"\nDevice Path Protocol Failed to register");
>     goto Error;
>   }
>    Print(L"\nDevice Path Protocol Registered Successfully");
> Instance = AllocateCopyPool 
> (sizeof(NOR_FLASH_INSTANCE),&mNorFlashInstanceTemplate);
>   if (Instance == NULL) {
>     return EFI_OUT_OF_RESOURCES;
>   }
>   Print(L"\nResource Pool has been allocated");
> 
>   Instance->Handle=ControllerHandle;
>   Instance->Signature=NOR_FLASH_SIGNATURE;
>   Instance->Size = NOR_SIZE;
>   //Instance->PciIo=PciIo;
>   
>   Instance->BlockIoProtocol.Media = &Instance->Media;
>   Instance->Media.MediaId = NOR_MEDIA_ID; 
>   Instance->Media.BlockSize = NOR_BLOCK_SIZE;
>   Instance->Media.LastBlock = (NOR_SIZE / NOR_BLOCK_SIZE)-1;
>   //Mistral:06/23/2014
>   Instance->PciIo=PciIo;
> 
>     Instance->Initialized = TRUE;
> Print(L"\nBefore Installing multiple protocols");
> //Set Command register to enable Bus Master and MemorySpace
> PciIo->Pci.Read (
>                PciIo,
>                EfiPciIoWidthUint8,
>                PCI_COMMAND_OFFSET,
>                sizeof (UINT8),
>                &CmdSts
>                ); 
>   
>   CmdSts |= EFI_PCI_COMMAND_MEMORY_SPACE |
>             EFI_PCI_COMMAND_BUS_MASTER;
>   
>   PciIo->Pci.Write(
>                PciIo,
>                EfiPciIoWidthUint8,
>                PCI_COMMAND_OFFSET,
>                sizeof (UINT8),
>                &CmdSts
>                );   
> //Removed Device path as already there is a device path associated with 
> PCIIO: by Andrew Fish    
> Status = gBS->InstallMultipleProtocolInterfaces (
>                     &Instance->Handle,
>                     &gEfiBlockIoProtocolGuid,  &Instance->BlockIoProtocol,
>                                       //&gEfiDevicePathProtocolGuid, 
> Instance->DevPath,
>                     NULL
>                     );
> 
>     if (EFI_ERROR(Status)) {
>               Print(L"\nFailedInstalling multiple protocols");  
>       FreePool(Instance);
>       return Status;
>     }
>       Print(L"\nAfter Installing multiple protocols");
> return Status;
> 
> Error:
>   
>   gBS->CloseProtocol (
>          ControllerHandle,
>          &gEfiDevicePathProtocolGuid,
>          This->DriverBindingHandle,
>          ControllerHandle
>          );
>   gBS->CloseProtocol (
>          ControllerHandle,
>          &gEfiPciIoProtocolGuid,
>          This->DriverBindingHandle,
>          ControllerHandle
>          );
> if (Instance->DevPath != NULL) {
>       FreePool (Instance->DevPath);
>     }
>     FreePool (Instance);
> return Status;
> }
> 
> Regards
> Vijai Kumar K

------------------------------------------------------------------------------
HPCC Systems Open Source Big Data Platform from LexisNexis Risk Solutions
Find What Matters Most in Your Big Data with HPCC Systems
Open Source. Fast. Scalable. Simple. Ideal for Dirty Data.
Leverages Graph Analysis for Fast Processing & Easy Data Exploration
http://p.sf.net/sfu/hpccsystems
_______________________________________________
edk2-devel mailing list
edk2-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/edk2-devel

Reply via email to