From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj1-f42.google.com (mail-pj1-f42.google.com [209.85.216.42]) by mx.groups.io with SMTP id smtpd.web10.14155.1667437146433058363 for ; Wed, 02 Nov 2022 17:59:06 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@gmail.com header.s=20210112 header.b=lJ82vLGl; spf=pass (domain: gmail.com, ip: 209.85.216.42, mailfrom: pedro.falcato@gmail.com) Received: by mail-pj1-f42.google.com with SMTP id d13-20020a17090a3b0d00b00213519dfe4aso385014pjc.2 for ; Wed, 02 Nov 2022 17:59:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :from:to:cc:subject:date:message-id:reply-to; bh=muR+duwbg+a458TDrao70vaBM1j21T5uADarzFnkRX4=; b=lJ82vLGl+ja1RkJl9R9x6Y7AKLdvrhhkM/1DqjDgqe8LGVjNFgmHu77dbGg9Z75rfV mmpkXIw4xA+OZuh6SmJVvZxy4LbJio7hQMdwrAseuAfcJlf/59+KQV6HMjfAa7V8JCLn TT3ySPc1J2lI7ctIi5e6NSHo23eyRxGy9Bbo6YPHSD0wDJZZt7IAv0qAqDfl9FdipwVB uyZN2ySGq7uwHQJuKR8io3iUO7L31DMeNNNesLa1+Lt26u6rN7cMt8rvBgJMbGLEJZ9w Owbpk0JLmRJ8hQPm7qFxmRNifgyRYmEQHD266K+5NHSax6o+iP5KPjhyTrjNO9mVJNeL plMg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=muR+duwbg+a458TDrao70vaBM1j21T5uADarzFnkRX4=; b=lGtRyBTPkLXRHYuzgh16WPxMpyYyhThELnHjWhNOZawhIyHx+mWLWQqqMeAWPdvF8c hk0RINpIVpmRxuWQyndsmSblEhyBbNc+DbZ2Nh8VxSvZZB8X3/u/oHoNYZ3UgJ5dL7AF OO7YJNFSKsBaZLNOgdU/+OwMcfcFNXszXIRwTsgTmNhU5ajj2BGWoSe61mJu72Mig0N1 k4VD2pB0M7c/l3gg93XPG0Acc01FWMu3EjokYbcUgbEbWOvf5/W4ZGGagvC027AEjmdj jZ22NKkDWHXqdxwfBHw1U+1BQj9C2N7TgAH3NWBNymIikUMJprb4rNKwCR7GgNkLvvst /PDg== X-Gm-Message-State: ACrzQf1QS0BMPv58MwAlexNA7evrcDvh+og1/n0u2+4s8k3ZfHeekR/l OJlEK51ojbgDspC1GSKMsfLEBAL+uB2SOlppFcKZtpkrUtteBw== X-Google-Smtp-Source: AMsMyM4TYH5OvTS+w1+4hX95ZLQvgkDKtCHWE8Zyk2FsWwkEDvOolHzmbajKLy/WNuq1vcpnJA1qwOCMWID/sKj9F68= X-Received: by 2002:a17:902:f685:b0:186:fa9c:2fdc with SMTP id l5-20020a170902f68500b00186fa9c2fdcmr27780002plg.25.1667437145252; Wed, 02 Nov 2022 17:59:05 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: "Pedro Falcato" Date: Thu, 3 Nov 2022 00:58:53 +0000 Message-ID: Subject: Re: [edk2-devel] How to add a DXE driver to an OVMF image? To: devel@edk2.groups.io, d.meneses@softi9.pt Content-Type: multipart/alternative; boundary="000000000000ba688605ec86766a" --000000000000ba688605ec86766a Content-Type: text/plain; charset="UTF-8" Hi! If I recall correctly, UEFI drivers are not guaranteed to have a valid ConOut and ConIn, and you're not supposed to use those. They are (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.log -global isa-debugcon.iobase=0x402" to QEMU to keep them. The rest of your procedure looks mostly OK as far as I can tell. Crash theory: ConOut was garbage, so you tried to jump into a random address. Random address had random data/instructions in there, which caused you an int 6 -> Invalid opcode. Thanks, Pedro 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 with edk2. Nobody 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 probably missing something. > > So far what I have done is: > > - create the simplest DXE driver I managed > > In folder *MdeModulePkg/Application/Hello*, I have: > *Hello.c* : > include > > ... > > while (1) > SystemTable->ConOut->OutputString(SystemTable->ConOut, > L"It works!\n"); > return EFI_SUCCESS; > > > *Hello.inf* : > [Defines] > INF_VERSION = 0x00010005 > BASE_NAME = Hello > FILE_GUID = ... > MODULE_TYPE = DXE_DRIVER > VERSION_STRING = 1.0 > ENTRY_POINT = UefiMain > > > [Sources] > Hello.c > > [Packages] > MdePkg/MdePkg.dec > MdeModulePkg/MdeModulePkg.dec > > [LibraryClasses] > UefiDriverEntryPoint > UefiLib > > [Depex] > TRUE > > - Set *OvmfPkg/OvmfPkgX64.dsc* as my target platform with *GCC5* as > the toolchain > - 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* file. > - Add *Mde**ModulePkg/Application/Hello/Hello.inf* to the end of the > *[FV.DXEFV**]* section in *OvmfPkgX64.fdf* (I have also tried to add > it after other certain 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=fat:rw:bootdrv,format=raw* > - *QEMU* hangs with message *"Guest has not initialized display (yet)"* > - *log.txt* has one log: *check_exception old: 0xffffffff new 0x6* > > > > > -- Pedro Falcato --000000000000ba688605ec86766a Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi!

If I recall correctly, U= EFI drivers are not guaranteed to have a valid ConOut and ConIn, and you= 9;re not supposed to use those. They are (always?) valid in UEFI apps.
Can you try to use DebugLib (don't forget to place DebugLib in Li= braryClasses) and DEBUG((DEBUG_INFO, "Blah\n")); ? That should pr= etty much work. Note that OVMF will send those debug messages to a special = device, so you can pass "-debugcon file:debug.log -global isa-de= bugcon.iobase=3D0x402" to QEMU to keep them. The rest of your p= rocedure looks mostly OK as far as I can tell.

Cra= sh theory: ConOut was garbage, so you tried to jump into a random address. = Random address had random data/instructions in there, which caused you an i= nt 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=C2=A0= this post on Super = User,=C2=A0I am trying to add a DXE driver to an OVMF image I'm building with edk2. Nobody was able to help me there so I tur= n here for your help.
=C2=A0
I haven't found any proper documentati= on on exactly what I'm trying to achieve so I am probably missing somet= hing.
=C2=A0
So far what I have done is:
  • create the simplest DXE driver I managed=
In folder MdeModulePkg/Application/He= llo, I have:
Hello.c :=C2=A0
= include
= =C2=A0
...
=C2=A0
= while=C2=A0(1)
=C2= =A0 =C2=A0 =C2=A0 =C2=A0 SystemTable->ConOut->OutputString(SystemTable->ConOut,
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 L= "It works!\n");
return=C2=A0EFI_SUCCESS;

=
=C2=A0<= /div>
Hello.= inf :=C2=A0
= [Defines]
=C2= =A0=C2=A0INF_VERSION<= span style=3D"border:0px none;font:inherit;margin:0px;padding:0px;vertical-= align:baseline;color:inherit">=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =3D 0x00010005
=C2= =A0=C2=A0BASE_NAME=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =3D Hello
=C2= =A0=C2=A0FILE_GUID=C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =3D= =C2=A0...
=C2= =A0=C2=A0MODULE_TYPE<= span style=3D"border:0px none;font:inherit;margin:0px;padding:0px;vertical-= align:baseline;color:inherit">=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =3D=C2=A0DXE_DRIVER
=C2= =A0=C2=A0VERSION_STRING=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0=3D 1.0
=C2= =A0=C2=A0ENTRY_POINT<= span style=3D"border:0px none;font:inherit;margin:0px;padding:0px;vertical-= align:baseline;color:inherit">=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =3D UefiMain


[Sources]
=C2= =A0=C2=A0Hello.c
[Packages]
=C2= =A0=C2=A0MdePkg/MdePkg.dec
=C2= =A0=C2=A0MdeModulePkg/MdeMod= ulePkg.dec

[LibraryClasses]
=C2= =A0 UefiDriverEntryPoint
=C2= =A0 UefiLib

[Depex]
=C2= =A0 =C2=A0=C2=A0TRUE
  • S= et OvmfPkg/Ov= mfPkgX64.dsc=C2=A0as my target platform with GCC5=C2=A0as 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/Application/Hello/Hello.inf=C2=A0to the end of the component section (I have tried to add it af= ter other certain drivers) in the .dsc=C2=A0file.
  • Add MdeModulePkg/Application/Hello/Hello.inf to the end = of the [FV.DXEFV]=C2=A0section in OvmfPkgX64.fdf=C2=A0(I have also tried to add it after other certain drivers)
  • Run=C2=A0bui= ld
  • Run QE= MU with the resulting OVMF=C2=A0image: qemu-system-x86_64<= /span>=C2=A0-d int -D lo= g.txt=C2=A0=C2=A0-bios OVMF.fd -net none -= drive file=3Dfat:rw:bootdrv,format=3D= raw
  • QEMU hangs with message = "Guest has not initialized display (yet)"
  • log.txt=C2=A0has one log: check_exception old: 0xffffffff new 0x6
=C2=A0
=20



--
Pedro Falcato
--000000000000ba688605ec86766a--