From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from ma1-aaemail-dr-lapp03.apple.com (ma1-aaemail-dr-lapp03.apple.com [17.171.2.72]) by mx.groups.io with SMTP id smtpd.web12.14508.1667437690162638199 for ; Wed, 02 Nov 2022 18:08:10 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@apple.com header.s=20180706 header.b=VKwAnemL; spf=pass (domain: apple.com, ip: 17.171.2.72, mailfrom: afish@apple.com) Received: from pps.filterd (ma1-aaemail-dr-lapp03.apple.com [127.0.0.1]) by ma1-aaemail-dr-lapp03.apple.com (8.16.0.42/8.16.0.42) with SMTP id 2A311LAD015818; Wed, 2 Nov 2022 18:08:09 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=apple.com; h=from : message-id : content-type : mime-version : subject : date : in-reply-to : cc : to : references; s=20180706; bh=TEgNq6DhraS4xnanhzFIgRhJ7MSao7ccg7eaXTAjDeY=; b=VKwAnemLk/2m4+opiaYu8HrUZZQd7J8KKUGF+uGrxvqXazdUeBuadePk9Uwib8wGit7d 6YWGvbmm37QblPCv1o1oSie83LpT5L/ht9SrAhzEx7d1rNm+8jOr9qlskWCkaGo/+1xN KzRS/iPzKr4dU5hIo4pRMiZDWVnmjvwB4TpoMByrAtJ6duDc7DkxlHZwMFIuvJCMW0un 7LuwVh+B6hjDNqsMUka9hFMRAHB0Xln+OMMHHAty3KMbsrPu9REcQ5GFbqF/aHSlkLwA iNbGRqgsyr+yo4MSWKgIWQLXuolEZrkhq55O1UKsdgYR1VCp+jldBUgWiMiHQolhe0Fx pw== Received: from rn-mailsvcp-mta-lapp04.rno.apple.com (rn-mailsvcp-mta-lapp04.rno.apple.com [10.225.203.152]) by ma1-aaemail-dr-lapp03.apple.com with ESMTP id 3kh35ugcxb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NO); Wed, 02 Nov 2022 18:08:09 -0700 Received: from rn-mailsvcp-mmp-lapp01.rno.apple.com (rn-mailsvcp-mmp-lapp01.rno.apple.com [17.179.253.14]) by rn-mailsvcp-mta-lapp04.rno.apple.com (Oracle Communications Messaging Server 8.1.0.20.20220923 64bit (built Sep 23 2022)) with ESMTPS id <0RKQ00S1WZ5KZFE0@rn-mailsvcp-mta-lapp04.rno.apple.com>; Wed, 02 Nov 2022 18:08:08 -0700 (PDT) Received: from process_milters-daemon.rn-mailsvcp-mmp-lapp01.rno.apple.com by rn-mailsvcp-mmp-lapp01.rno.apple.com (Oracle Communications Messaging Server 8.1.0.19.20220711 64bit (built Jul 11 2022)) id <0RKQ00Y00Z3I9800@rn-mailsvcp-mmp-lapp01.rno.apple.com>; Wed, 02 Nov 2022 18:08:08 -0700 (PDT) X-Va-A: X-Va-T-CD: fb9ca77e010fb2e9e052c364a80d126f X-Va-E-CD: ec9cc94c51167e28e069118bb1fce29d X-Va-R-CD: ce3ffbac7fc5b1e5f0bf2f56a281a21d X-Va-CD: 0 X-Va-ID: c0aeeda1-22cb-403e-920a-beb74014a9dc X-V-A: X-V-T-CD: fb9ca77e010fb2e9e052c364a80d126f X-V-E-CD: ec9cc94c51167e28e069118bb1fce29d X-V-R-CD: ce3ffbac7fc5b1e5f0bf2f56a281a21d X-V-CD: 0 X-V-ID: 06b4c3d2-c675-49be-8b95-469af70f3757 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.545,18.0.895 definitions=2022-11-02_15:2022-11-02,2022-11-02 signatures=0 Received: from smtpclient.apple (unknown [17.11.238.203]) by rn-mailsvcp-mmp-lapp01.rno.apple.com (Oracle Communications Messaging Server 8.1.0.19.20220711 64bit (built Jul 11 2022)) with ESMTPSA id <0RKQ00Z1TZ5J7700@rn-mailsvcp-mmp-lapp01.rno.apple.com>; Wed, 02 Nov 2022 18:08:08 -0700 (PDT) From: "Andrew Fish" Message-id: <3519C852-1306-4986-92F2-D5B2C4531D00@apple.com> MIME-version: 1.0 (Mac OS X Mail 16.0 \(3731.200.22\)) Subject: Re: [edk2-devel] How to add a DXE driver to an OVMF image? Date: Wed, 02 Nov 2022 18:07:56 -0700 In-reply-to: Cc: d.meneses@softi9.pt To: edk2-devel-groups-io , Pedro Falcato References: X-Mailer: Apple Mail (2.3731.200.22) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.545,18.0.895 definitions=2022-11-02_15:2022-11-02,2022-11-02 signatures=0 Content-type: multipart/alternative; boundary="Apple-Mail=_D337BC90-D566-4095-8B41-1F26F162DAAD" --Apple-Mail=_D337BC90-D566-4095-8B41-1F26F162DAAD Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 If you are building with the firmware use the DebugLib in the INF and DEBUG= (); macros. DEBUG((DEBUG_ERROR, =E2=80=9CIt works\n=E2=80=9D)); Also by setting your Depex to TRUE you are basically asking to run before t= he console is available. If you want to depend on all UEFI Services being p= resent don=E2=80=99t set a dependency expression. The Depex is for ordering= the early drivers that don=E2=80=99t follow the UEFI Driver Model. So for = example you have to configure your chipset, and SPI driver to get UEFI NVRA= M working etc.=20 Thanks, Andrew Fish > On Nov 2, 2022, at 5:58 PM, Pedro Falcato wrote= : >=20 > Hi! >=20 > If I recall correctly, UEFI drivers are not guaranteed to have a valid Co= nOut and ConIn, and you're not supposed to use those. They are (always?) va= lid in UEFI apps. > Can you try to use DebugLib (don't forget to place DebugLib in LibraryCla= sses) and DEBUG((DEBUG_INFO, "Blah\n")); ? That should pretty much work. No= te that OVMF will send those debug messages to a special device, so you can= pass "-debugcon file:debug.log -global isa-debugcon.iobase=3D0x402" to QEM= U to keep them. The rest of your procedure looks mostly OK as far as I can = tell. >=20 > Crash theory: ConOut was garbage, so you tried to jump into a random addr= ess. Random address had random data/instructions in there, which caused you= an int 6 -> Invalid opcode. >=20 > Thanks, > Pedro >=20 > On Wed, Nov 2, 2022 at 2:02 PM d.meneses via groups.io > wrote: >> As detailed on this post on Super User , I am trying to add a DXE driver to an OVMF image I'm building wit= h edk2. Nobody was able to help me there so I turn here for your help. >> =20 >> I haven't found any proper documentation on exactly what I'm trying to a= chieve so I am probably missing something. >> =20 >> So far what I have done is: >> create the simplest DXE driver I managed >> In folder MdeModulePkg/Application/Hello, I have: >> Hello.c :=20 >> include >> =20 >> ... >> =20 >> while (1) >> SystemTable->ConOut->OutputString(SystemTable->ConOut, >> L"It works!\n"); >> return EFI_SUCCESS; >>=20 >> =20 >> Hello.inf :=20 >> [Defines] >> INF_VERSION =3D 0x00010005 >> BASE_NAME =3D Hello >> FILE_GUID =3D ... >> MODULE_TYPE =3D DXE_DRIVER >> VERSION_STRING =3D 1.0 >> ENTRY_POINT =3D UefiMain >>=20 >>=20 >> [Sources] >> Hello.c >>=20 >> [Packages] >> MdePkg/MdePkg.dec >> MdeModulePkg/MdeModulePkg.dec >>=20 >> [LibraryClasses] >> UefiDriverEntryPoint >> UefiLib >>=20 >> [Depex] >> TRUE >> Set OvmfPkg/OvmfPkgX64.dsc as my target platform with GCC5 as the toolch= ain >> Add MdeModulePkg/Application/Hello/Hello.inf to the end of the component= section (I have tried to add it after other certain drivers) in the .dsc f= ile. >> Add MdeModulePkg/Application/Hello/Hello.inf to the end of the [FV.DXEFV= ] section in OvmfPkgX64.fdf (I have also tried to add it after other certai= n drivers) >> Run build >> Run QEMU with the resulting OVMF image: qemu-system-x86_64 -d int -D log= .txt -bios OVMF.fd -net none -drive file=3Dfat:rw:bootdrv,format=3Draw >> QEMU hangs with message "Guest has not initialized display (yet)" >> log.txt has one log: check_exception old: 0xffffffff new 0x6 >> =20 >>=20 >>=20 >=20 >=20 > --=20 > Pedro Falcato >=20 --Apple-Mail=_D337BC90-D566-4095-8B41-1F26F162DAAD Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=utf-8 If you are building with the firm= ware use the DebugLib in the INF and DEBUG(); macros.

DE= BUG((DEBUG_ERROR, =E2=80=9CIt works\n=E2=80=9D));

= Also by setting your Depex to TRUE you are basically asking to run before t= he console is available. If you want to depend on all UEFI Services being p= resent don=E2=80=99t set a dependency expression. The Depex is for ordering= the early drivers that don=E2=80=99t follow the UEFI Driver Model. So for = example you have to configure your chipset, and SPI driver to get UEFI NVRA= M working etc. 

Thanks,

<= div>Andrew Fish

On Nov 2, 2022, = at 5:58 PM, Pedro Falcato <pedro.falcato@gmail.com> wrote:

Hi!

If I recall correctly, UEFI drivers are not guaranteed to h= ave a valid ConOut and ConIn, and you're not supposed to use those. They ar= e (always?) valid in UEFI apps.
Can you try to use DebugLib (don'= t forget to place DebugLib in LibraryClasses) and DEBUG((DEBUG_INFO, "Blah\= n")); ? That should pretty much work. Note that OVMF will send those debug = messages to a special device, so you can pass "-debugcon file:debug.l= og -global isa-debugcon.iobase=3D0x402" to QEMU to keep them. The re= st of your procedure looks mostly OK as far as I can tell.

Crash theory: ConOut was garbage, so you tried to jump into a rand= om address. Random address had random data/instructions in there, which cau= sed you an int 6 -> Invalid opcode.

Thanks,
Pedro

On Wed, Nov 2, 2022 at 2:02 PM d.meneses via groups.io <d.meneses=3Dsofti9.pt@groups.io> wrote:
As detailed on this post on Super User, I am trying to add a DXE driver to an OVMF image I'm building with edk2. Nobo= dy was able to help me there so I turn here for your help.
 
I haven't found= any proper documentation on exactly what I'm trying to achieve so I am pro= bably missing something.
 
So far what I h= ave done is:
  • create the simplest DXE driver I managed=
In folder MdeModulePkg/Application/He= llo, I have:
Hello.c=
= include
=  
...
 
= while (1)
 = ;       SystemTable->ConOut->OutputString(SystemTable->ConOut,
                    &nb= sp;                     L= "It works!= \n");
return EFI_SUCCESS;

=
 <= /div>
Hello.= inf
= [Defines]
 = ; INF_VERSION             = ;       =3D 0x00010005
 = ; BASE_NAME              =         =3D Hello
 = ; FILE_GUID  &nb= sp;                   =3D = ;...
 = ; MODULE_TYPE             = ;       =3D DXE_DRIVER
 = ; VERSION_STRING=             &n= bsp;    =3D 1.0
 = ; ENTRY_POINT             = ;       =3D UefiMain


[Sources]
 = ; Hello.c

[Packages]
 = ; MdePkg/MdePkg.dec
 = ; MdeModulePkg/MdeModul= ePkg.dec

[LibraryClasses]
 = ; UefiDriverEntryPoint
 = ; UefiLib

[Depex]
&nbs= p;   TRUE
  • S= et OvmfPkg/Ov= mfPkgX64.dsc as my target platform with GCC5 as the toolchain
  • <= span style=3D"border:0px none;font-style:inherit;font-variant:inherit;font-= weight:inherit;font-stretch:inherit;line-height:inherit;margin:0px;padding:= 0px;vertical-align:baseline;color:inherit">Add MdeModulePkg/Applicati= on/Hello/Hello.inf to the end of the component section (I hav= e tried to add it after other certain drivers) in the .dsc=  file.
  • Add MdeModulePkg/Applicat= ion/Hello/Hello.inf to the end of the [FV.DXEFV] section in Ov= mfPkgX64.fdf (I have also tried to add it after other certain= drivers)
  • Run build
  • Run QE= MU with the resulting OVMF image: qemu-sys= tem-x86_64 -d int -D log.txt  -bios OVMF.fd -net none -drive file=3Dfat:rw:bootdrv,format=3Draw
  • QEMU hangs with message = "Guest has not initialized display (yet)"
  • log.txt has one log: check_exception old: 0xffffffff new 0x6
 




-- =
Pedro Falca= to
=20

--Apple-Mail=_D337BC90-D566-4095-8B41-1F26F162DAAD--