Re: [edk2] How to get BBS_BBS_DEVICE_PATH from BOOTXXXX variable

2016-10-20 Thread Carsey, Jaben
Have you examined the structure EFI_LOAD_OPTION from UefiSpec.h?

I think that you are traversing the structure incorrectly.  I cannot be sure 
since I am not certain what this mGetVariable function does specifically.

I start by getting the correct size (BufferSize is zero at this first call):
Status = gRT->GetVariable(
VariableName,
(EFI_GUID*)&gEfiGlobalVariableGuid,
NULL,
&BufferSize,
Buffer);
if (Status == EFI_BUFFER_TOO_SMALL) {
  Buffer = AllocateZeroPool(BufferSize);
  Status = gRT->GetVariable(
  VariableName,
  (EFI_GUID*)&gEfiGlobalVariableGuid,
  NULL,
  &BufferSize,
  Buffer);
}

To parse the structure I divide it up using the structure.  I think your +3 may 
be causing lots of issues.

LoadOption  = (EFI_LOAD_OPTION *)Buffer;
Description = (CHAR16*)(Buffer + sizeof (EFI_LOAD_OPTION));
DescriptionSize = StrSize (Description);
if (LoadOption->FilePathListLength != 0) {
  FilePathList = (UINT8 *)Description + DescriptionSize;
   }

After this we can calculate the location of optional data.
OptionalDataOffset = sizeof *LoadOption + DescriptionSize +
 LoadOption->FilePathListLength;
The optional data would be found at:
Buffer + OptionalDataOffset

Note that all the pointer math is based on using UINT8* or the raw Buffer 
variable which is a UINT8*.  Otherwise the size in bytes will not work out.

-Jaben


From: Saqib Khan [mailto:saqib.khan2...@gmail.com]
Sent: Thursday, October 20, 2016 12:30 AM
To: Carsey, Jaben 
Cc: Andrew Fish ; edk2-de...@ml01.01.org; Laszlo Ersek 

Subject: Re: [edk2] How to get BBS_BBS_DEVICE_PATH from BOOT variable
Importance: High

BootVariable = mGetVariable(Name, &gEfiGlobalVariableGuid, &BootVariableSize, 
NULL);
Ptr = (BootVariable+3);
 Print(L" %s",(CHAR16 *)(Ptr));
 DevicePath =AllocateZeroPool (*FilePathListLength) ;
 Ptr+= StrSize((CHAR16 *)Ptr);
 CopyMem (DevicePath, Ptr, *FilePathListLength);
As Carsey suggested i used the same Math in order to get DevicePath but in my 
case it is not working
As documentation this data structure is not aligned so i am assuming that just 
after description there should be
FilePathList ,so if i CopyMem (*FilePathListLength) bytes to DevicePath i 
should get the right value but i am getting garbage.

On Thu, Oct 20, 2016 at 1:41 AM, Carsey, Jaben 
mailto:jaben.car...@intel.com>> wrote:
Have you examined the BCFG command in the UEFI Shell?

It does this exact behavior and the code is at: 
ShellPkg\Library\UefiBcfgCommandLib\bcfg.c.

-Jaben

> -Original Message-
> From: edk2-devel 
> [mailto:edk2-devel-boun...@lists.01.org<mailto:edk2-devel-boun...@lists.01.org>]
>  On Behalf Of
> Saqib Khan
> Sent: Wednesday, October 19, 2016 11:18 AM
> To: Andrew Fish mailto:af...@apple.com>>
> Cc: edk2-de...@ml01.01.org<mailto:edk2-de...@ml01.01.org>; Laszlo Ersek 
> mailto:ler...@redhat.com>>
> Subject: Re: [edk2] How to get BBS_BBS_DEVICE_PATH from BOOT
> variable
>
> Hi, so i have parsed the structure as follow :
>
>
>
>
>
>
>
> *BootVariable = mGetVariable(Name, &gEfiGlobalVariableGuid,
> &BootVariableSize, NULL);LDAttr = BootVariable[0];FilePathListLength =
> (BootVariable+2);Ptr = (BootVariable+3); // for description *
>
>
>
> *for FilePathList[] Ptr+= StrSize((CHAR16 *)Ptr); CopyMem (Ptr,
> DevicePath, *FilePathListLength);*
>
>
> I am able to get LDAttr ,FilePathListLength and description but
>
> when i try to check DevicePath->Type it always return 0x01( Hardware Device
> Path) for each device .
>
>
> I have hard drive with legacy OS(BBS_DEVICE_PATH). So it should not always
> return 0x01 .What i am doing wrong in parsing ?
>
> Thanks
>
> On Tue, Oct 18, 2016 at 11:37 PM, Andrew Fish 
> mailto:af...@apple.com>> wrote:
>
> >
> > > On Oct 18, 2016, at 10:40 AM, Laszlo Ersek 
> > > mailto:ler...@redhat.com>> wrote:
> > >
> > > On 10/18/16 19:18, Saqib Khan wrote:
> > >> Hi,
> > >> I can not find structure of BOOT variable, Can any one help how to
> > >> extract device path from BOOT variable.
> > >
> > > In UEFI-related questions, the UEFI specification has a fair chance to
> > > provide useful information.
> > >
> > > Please refer to "3.1.3 Load Options" in the UEFI v2.6 spec, available
> > > for download from <http://www.uefi.org/specifications>.
> > >
> > > Locating the matching structure definition in the edk2 tree is left as
> > > an exercise to the reader ;)
> > >
> >
&g

Re: [edk2] How to get BBS_BBS_DEVICE_PATH from BOOTXXXX variable

2016-10-20 Thread Saqib Khan
*BootVariable = mGetVariable(Name, &gEfiGlobalVariableGuid,
&BootVariableSize, NULL);Ptr = (BootVariable+3); Print(L"
%s",(CHAR16 *)(Ptr)); DevicePath =AllocateZeroPool
(*FilePathListLength) ; Ptr+= StrSize((CHAR16 *)Ptr);
 CopyMem (DevicePath, Ptr, *FilePathListLength);*
As Carsey suggested i used the same Math in order to get DevicePath but in
my case it is not working

As documentation this data structure is not aligned so i am assuming that
just after description there should be
FilePathList ,so if i CopyMem * (**FilePathListLength) bytes to DevicePath
i should get the right value but i am getting garbage.

On Thu, Oct 20, 2016 at 1:41 AM, Carsey, Jaben 
wrote:

> Have you examined the BCFG command in the UEFI Shell?
>
> It does this exact behavior and the code is at: ShellPkg\Library\
> UefiBcfgCommandLib\bcfg.c.
>
> -Jaben
>
> > -Original Message-
> > From: edk2-devel [mailto:edk2-devel-boun...@lists.01.org] On Behalf Of
> > Saqib Khan
> > Sent: Wednesday, October 19, 2016 11:18 AM
> > To: Andrew Fish 
> > Cc: edk2-de...@ml01.01.org; Laszlo Ersek 
> > Subject: Re: [edk2] How to get BBS_BBS_DEVICE_PATH from BOOT
> > variable
> >
> > Hi, so i have parsed the structure as follow :
> >
> >
> >
> >
> >
> >
> >
> > *BootVariable = mGetVariable(Name, &gEfiGlobalVariableGuid,
> > &BootVariableSize, NULL);LDAttr = BootVariable[0];FilePathListLength =
> > (BootVariable+2);Ptr = (BootVariable+3); // for description *
> >
> >
> >
> > *for FilePathList[] Ptr+= StrSize((CHAR16 *)Ptr); CopyMem (Ptr,
> > DevicePath, *FilePathListLength);*
> >
> >
> > I am able to get LDAttr ,FilePathListLength and description but
> >
> > when i try to check DevicePath->Type it always return 0x01( Hardware
> Device
> > Path) for each device .
> >
> >
> > I have hard drive with legacy OS(BBS_DEVICE_PATH). So it should not
> always
> > return 0x01 .What i am doing wrong in parsing ?
> >
> > Thanks
> >
> > On Tue, Oct 18, 2016 at 11:37 PM, Andrew Fish  wrote:
> >
> > >
> > > > On Oct 18, 2016, at 10:40 AM, Laszlo Ersek 
> wrote:
> > > >
> > > > On 10/18/16 19:18, Saqib Khan wrote:
> > > >> Hi,
> > > >> I can not find structure of BOOT variable, Can any one help how
> to
> > > >> extract device path from BOOT variable.
> > > >
> > > > In UEFI-related questions, the UEFI specification has a fair chance
> to
> > > > provide useful information.
> > > >
> > > > Please refer to "3.1.3 Load Options" in the UEFI v2.6 spec, available
> > > > for download from <http://www.uefi.org/specifications>.
> > > >
> > > > Locating the matching structure definition in the edk2 tree is left
> as
> > > > an exercise to the reader ;)
> > > >
> > >
> > > Chapter 3 Boot Manager.
> > >
> > > The structure is EFI_LOAD_OPTION but some of the fields are variable
> > > length so you have to do math to figure stuff out.
> > >
> > > Thanks,
> > >
> > > Andrew Fish
> > >
> > >
> > > > Laszlo
> > > >
> > > > ___
> > > > edk2-devel mailing list
> > > > edk2-devel@lists.01.org
> > > > https://lists.01.org/mailman/listinfo/edk2-devel
> > >
> > >
> >
> >
> > --
> > Regards
> > Saqib Ahmed Khanzada
> > ___
> > edk2-devel mailing list
> > edk2-devel@lists.01.org
> > https://lists.01.org/mailman/listinfo/edk2-devel
>



-- 
Regards
Saqib Ahmed Khanzada
___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


Re: [edk2] How to get BBS_BBS_DEVICE_PATH from BOOTXXXX variable

2016-10-19 Thread Carsey, Jaben
Have you examined the BCFG command in the UEFI Shell?  

It does this exact behavior and the code is at: 
ShellPkg\Library\UefiBcfgCommandLib\bcfg.c.

-Jaben

> -Original Message-
> From: edk2-devel [mailto:edk2-devel-boun...@lists.01.org] On Behalf Of
> Saqib Khan
> Sent: Wednesday, October 19, 2016 11:18 AM
> To: Andrew Fish 
> Cc: edk2-de...@ml01.01.org; Laszlo Ersek 
> Subject: Re: [edk2] How to get BBS_BBS_DEVICE_PATH from BOOT
> variable
> 
> Hi, so i have parsed the structure as follow :
> 
> 
> 
> 
> 
> 
> 
> *BootVariable = mGetVariable(Name, &gEfiGlobalVariableGuid,
> &BootVariableSize, NULL);LDAttr = BootVariable[0];FilePathListLength =
> (BootVariable+2);Ptr = (BootVariable+3); // for description *
> 
> 
> 
> *for FilePathList[] Ptr+= StrSize((CHAR16 *)Ptr); CopyMem (Ptr,
> DevicePath, *FilePathListLength);*
> 
> 
> I am able to get LDAttr ,FilePathListLength and description but
> 
> when i try to check DevicePath->Type it always return 0x01( Hardware Device
> Path) for each device .
> 
> 
> I have hard drive with legacy OS(BBS_DEVICE_PATH). So it should not always
> return 0x01 .What i am doing wrong in parsing ?
> 
> Thanks
> 
> On Tue, Oct 18, 2016 at 11:37 PM, Andrew Fish  wrote:
> 
> >
> > > On Oct 18, 2016, at 10:40 AM, Laszlo Ersek  wrote:
> > >
> > > On 10/18/16 19:18, Saqib Khan wrote:
> > >> Hi,
> > >> I can not find structure of BOOT variable, Can any one help how to
> > >> extract device path from BOOT variable.
> > >
> > > In UEFI-related questions, the UEFI specification has a fair chance to
> > > provide useful information.
> > >
> > > Please refer to "3.1.3 Load Options" in the UEFI v2.6 spec, available
> > > for download from <http://www.uefi.org/specifications>.
> > >
> > > Locating the matching structure definition in the edk2 tree is left as
> > > an exercise to the reader ;)
> > >
> >
> > Chapter 3 Boot Manager.
> >
> > The structure is EFI_LOAD_OPTION but some of the fields are variable
> > length so you have to do math to figure stuff out.
> >
> > Thanks,
> >
> > Andrew Fish
> >
> >
> > > Laszlo
> > >
> > > ___
> > > edk2-devel mailing list
> > > edk2-devel@lists.01.org
> > > https://lists.01.org/mailman/listinfo/edk2-devel
> >
> >
> 
> 
> --
> Regards
> Saqib Ahmed Khanzada
> ___
> edk2-devel mailing list
> edk2-devel@lists.01.org
> https://lists.01.org/mailman/listinfo/edk2-devel
___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


Re: [edk2] How to get BBS_BBS_DEVICE_PATH from BOOTXXXX variable

2016-10-19 Thread Saqib Khan
Hi, so i have parsed the structure as follow :







*BootVariable = mGetVariable(Name, &gEfiGlobalVariableGuid,
&BootVariableSize, NULL);LDAttr = BootVariable[0];FilePathListLength =
(BootVariable+2);Ptr = (BootVariable+3); // for description *



*for FilePathList[] Ptr+= StrSize((CHAR16 *)Ptr); CopyMem (Ptr,
DevicePath, *FilePathListLength);*


I am able to get LDAttr ,FilePathListLength and description but

when i try to check DevicePath->Type it always return 0x01( Hardware Device
Path) for each device .


I have hard drive with legacy OS(BBS_DEVICE_PATH). So it should not always
return 0x01 .What i am doing wrong in parsing ?

Thanks

On Tue, Oct 18, 2016 at 11:37 PM, Andrew Fish  wrote:

>
> > On Oct 18, 2016, at 10:40 AM, Laszlo Ersek  wrote:
> >
> > On 10/18/16 19:18, Saqib Khan wrote:
> >> Hi,
> >> I can not find structure of BOOT variable, Can any one help how to
> >> extract device path from BOOT variable.
> >
> > In UEFI-related questions, the UEFI specification has a fair chance to
> > provide useful information.
> >
> > Please refer to "3.1.3 Load Options" in the UEFI v2.6 spec, available
> > for download from .
> >
> > Locating the matching structure definition in the edk2 tree is left as
> > an exercise to the reader ;)
> >
>
> Chapter 3 Boot Manager.
>
> The structure is EFI_LOAD_OPTION but some of the fields are variable
> length so you have to do math to figure stuff out.
>
> Thanks,
>
> Andrew Fish
>
>
> > Laszlo
> >
> > ___
> > edk2-devel mailing list
> > edk2-devel@lists.01.org
> > https://lists.01.org/mailman/listinfo/edk2-devel
>
>


-- 
Regards
Saqib Ahmed Khanzada
___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


Re: [edk2] How to get BBS_BBS_DEVICE_PATH from BOOTXXXX variable

2016-10-18 Thread Andrew Fish

> On Oct 18, 2016, at 10:40 AM, Laszlo Ersek  wrote:
> 
> On 10/18/16 19:18, Saqib Khan wrote:
>> Hi,
>> I can not find structure of BOOT variable, Can any one help how to
>> extract device path from BOOT variable.
> 
> In UEFI-related questions, the UEFI specification has a fair chance to
> provide useful information.
> 
> Please refer to "3.1.3 Load Options" in the UEFI v2.6 spec, available
> for download from .
> 
> Locating the matching structure definition in the edk2 tree is left as
> an exercise to the reader ;)
> 

Chapter 3 Boot Manager. 

The structure is EFI_LOAD_OPTION but some of the fields are variable length so 
you have to do math to figure stuff out. 

Thanks,

Andrew Fish


> Laszlo
> 
> ___
> edk2-devel mailing list
> edk2-devel@lists.01.org
> https://lists.01.org/mailman/listinfo/edk2-devel

___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


Re: [edk2] How to get BBS_BBS_DEVICE_PATH from BOOTXXXX variable

2016-10-18 Thread Laszlo Ersek
On 10/18/16 19:18, Saqib Khan wrote:
> Hi,
> I can not find structure of BOOT variable, Can any one help how to
> extract device path from BOOT variable.

In UEFI-related questions, the UEFI specification has a fair chance to
provide useful information.

Please refer to "3.1.3 Load Options" in the UEFI v2.6 spec, available
for download from .

Locating the matching structure definition in the edk2 tree is left as
an exercise to the reader ;)

Laszlo

___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


[edk2] How to get BBS_BBS_DEVICE_PATH from BOOTXXXX variable

2016-10-18 Thread Saqib Khan
Hi,
I can not find structure of BOOT variable, Can any one help how to
extract device path from BOOT variable.

here is code  i have attempt (rEFind)

*UINT8 *Value;*












*Status = gRT->GetVariable ((CHAR16 *)Name, &gEfiGlobalVariableGuid, NULL,
&BootVariableSize, Value);//print attribute/*Check if
device boot variable is legacy*/  Ptr = Value; Ptr
+= sizeof (UINT32); DevPathLen = *(UINT16 *) Ptr; Ptr +=
sizeof (UINT16); Ptr += StrSize ((UINT16 *) Ptr);
 DevicePath = (EFI_DEVICE_PATH_PROTOCOL *) Ptr;  Print (L"Paths:
%s\n",ConvertDevicePathToText (DevicePath,TRUE,TRUE));*


-- 
Regards
Saqib
___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel