How to read HDD S.M.A.R.T data?

Post Reply
LeoHsieh
Junior Member
Posts: 3
Joined: Thu Apr 26, 2018 1:59 am

How to read HDD S.M.A.R.T data?

Post by LeoHsieh » Thu Apr 26, 2018 2:14 am

Does anyone know how to read S.M.A.R.T data through gEfiAtaPassThruProtocolGuid?

Here is my code snippet, it will reboot the system after it is executed

Code: Select all

        Status = gBS->HandleProtocol (
                AtaPassThruHandles[Index],
                &gEfiAtaPassThruProtocolGuid,
                (VOID **) &AtaPassThru
                );

        ZeroMem (&AtaPassThruCommandPacket, sizeof(EFI_ATA_PASS_THRU_COMMAND_PACKET));
        ZeroMem (&AtaCommandBlock, sizeof (EFI_ATA_COMMAND_BLOCK));
        ZeroMem (&AtaStatusBlock, sizeof(EFI_ATA_STATUS_BLOCK));
        ZeroMem (&SmartData, 512);
        AtaCommandBlock.AtaCommand      = ATA_CMD_SMART;
        AtaCommandBlock.AtaSectorCount  = 0x01;
        AtaCommandBlock.AtaCylinderLow  = ATA_CONSTANT_4F;
        AtaCommandBlock.AtaCylinderHigh = ATA_CONSTANT_C2;
        AtaCommandBlock.AtaFeatures     = ATA_SMART_READ_DATA;
        AtaCommandBlock.AtaDeviceHead   = 0xA0;

        AtaPassThruCommandPacket.Timeout            = EFI_TIMER_PERIOD_SECONDS (3);
        AtaPassThruCommandPacket.Length             = EFI_ATA_PASS_THRU_LENGTH_BYTES;
        AtaPassThruCommandPacket.Protocol           = EFI_ATA_PASS_THRU_PROTOCOL_PIO_DATA_IN;
        AtaPassThruCommandPacket.OutTransferLength  = 0;
        AtaPassThruCommandPacket.OutDataBuffer      = NULL;
        AtaPassThruCommandPacket.InTransferLength   = 512;
        AtaPassThruCommandPacket.InDataBuffer       = SmartData;
        AtaPassThruCommandPacket.Acb                = &AtaCommandBlock;
        AtaPassThruCommandPacket.Asb                = &AtaStatusBlock;

        Status = AtaPassThru->PassThru (
                AtaPassThru,
                Port,
                PortMultiplierPort,
                &AtaPassThruCommandPacket,
                NULL
                );

User avatar
BobJC
Member
Posts: 21
Joined: Wed Apr 04, 2018 2:07 pm

Re: How to read HDD S.M.A.R.T data?

Post by BobJC » Thu Apr 26, 2018 1:52 pm

After HandleProtocol, you should check the return value to make sure the protocol instance is retrieved correctly.
Or else, invalid protocol pointer will lead to exception or reset.

LeoHsieh
Junior Member
Posts: 3
Joined: Thu Apr 26, 2018 1:59 am

Re: How to read HDD S.M.A.R.T data?

Post by LeoHsieh » Fri Apr 27, 2018 3:24 am

Yes, I have check status is EFI_SUCCESS.

User avatar
BobJC
Member
Posts: 21
Joined: Wed Apr 04, 2018 2:07 pm

Re: How to read HDD S.M.A.R.T data?

Post by BobJC » Fri Apr 27, 2018 11:24 am

Then check the validity of the protocol pointer, and use serial output or XDP/DCI to do live debugging to figure out the exact location of the reset.
We should not debug through the community forum, right? ;)

matt.huang
Enthusiast
Posts: 30
Joined: Fri Apr 20, 2018 12:06 pm

Re: How to read HDD S.M.A.R.T data?

Post by matt.huang » Fri Apr 27, 2018 6:31 pm

Cannot know the context since there is a small amount of snippet, there are couple of steps you need to check:
  • Current system state (DXE / SMM / runtime, etc)
  • Locate the right protocol instance
  • SMART supportive check, long story short, command_set_supported_83
  • If SMART is supported, does it enabled? command_set_supported_82
  • If SMART is supported and enabled, ATA_SMART_RETURN_STATUS / ATA_SMART_READ_DATA, do what you need to do.
If it still fails on you after checking all the above, maybe the hardware piece you're working on doesn't accept SMART under AtaPassThru (e.g. Some Intel RAID drivers), you can check that by filtering out AtaPassThru protocol under LegacyFree GUID.

LeoHsieh
Junior Member
Posts: 3
Joined: Thu Apr 26, 2018 1:59 am

Re: How to read HDD S.M.A.R.T data?

Post by LeoHsieh » Mon May 07, 2018 5:56 am

Hi Sir,

Thanks for your help.
I successfully read S.M.A.R.T. data.

My variable(SmartData) type declares an error and there is no problem after the correction.

User avatar
BobJC
Member
Posts: 21
Joined: Wed Apr 04, 2018 2:07 pm

Re: How to read HDD S.M.A.R.T data?

Post by BobJC » Mon May 07, 2018 1:27 pm

Hmm... buffer overflow... C language's curse. ;)
Anyway, good to hear that it is resolved.

matt.huang
Enthusiast
Posts: 30
Joined: Fri Apr 20, 2018 12:06 pm

Re: How to read HDD S.M.A.R.T data?

Post by matt.huang » Mon May 07, 2018 2:52 pm

lol I think I knew what went wrong, **var and *var, right :D

MichaelClito
Member
Posts: 8
Joined: Thu Jun 14, 2018 10:06 am
Location: Virgin Islands
Contact:

How to read HDD S M A R T data

Post by MichaelClito » Tue Jul 24, 2018 9:27 pm

Hi I am Shahifur Rahman.
I am a new user in WRF-ARW. I would like to read geogrid data. How can i read geogrid data? Please help me.

Post Reply