From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 757ACC5479D for ; Fri, 6 Jan 2023 23:22:39 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 80426854CE; Sat, 7 Jan 2023 00:22:36 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=debian.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; secure) header.d=debian.org header.i=@debian.org header.b="OjzNJysh"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id AFFDF854D1; Sat, 7 Jan 2023 00:22:34 +0100 (CET) Received: from cascadia.aikidev.net (cascadia.aikidev.net [IPv6:2600:3c01:e000:267:0:a171:de7:c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id B8568854D1 for ; Sat, 7 Jan 2023 00:22:31 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=debian.org Authentication-Results: phobos.denx.de; spf=none smtp.mailfrom=vagrant@debian.org Received: from localhost (unknown [IPv6:2600:3c01:e000:21:7:77:0:20]) (Authenticated sender: vagrant@cascadia.debian.net) by cascadia.aikidev.net (Postfix) with ESMTPSA id 585791AB3B; Fri, 6 Jan 2023 15:22:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=debian.org; s=1.vagrant.user; t=1673047348; bh=fSN9o0oVkdgZKOQNXDWsYy9Z6g5N6iifP/cTDZNIMRk=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=OjzNJyshlagA+FozrVJ70A0nZEckiqgIOdBH5okMgUIW7P0PXbrBqCdnvgLYNmWvN H9nki8O7tFD6YeumYyy/Ca2iDaEFCwOHlhkeTQTo8YYxTuLxbk8rrEFsrWlh7Wp7wO V7eg+p2XywBWBGx+nD1Jxw6HQDAYakK+BzEdlqMtb4tZl9KGo9uovoHl6qGnrpUjVc 1XiZwWsMM1sV5X23P/DR0BgWDcC75bB/pKC4sQ9SV6PDFL7h9NG8P3lw8MW4Y3y5s3 PYTV5G/Fwxrbu1hr8ZBWFqCAL+OdXnxc14g7pTK5N14r1SBkcgiOOX8SbAhcDMMvIU Iqgla0GfjRx+w== From: Vagrant Cascadian To: Heinrich Schuchardt , Ilias Apalodimas Cc: Tom Rini , Liviu Dudau , Simon Glass , Stefan Roese , Patrick Delaunay , Jaehoon Chung , Michal Simek , Patrice Chotard , Ashok Reddy Soma , u-boot@lists.denx.de, Heinrich Schuchardt Subject: Re: [PATCH v2 2/3] efi_loader: carve out efi_get_memory_map_alloc() In-Reply-To: <20230105202536.190392-3-heinrich.schuchardt@canonical.com> References: <20230105202536.190392-1-heinrich.schuchardt@canonical.com> <20230105202536.190392-3-heinrich.schuchardt@canonical.com> Date: Fri, 06 Jan 2023 15:22:22 -0800 Message-ID: <87ilhj5jv5.fsf@contorta> MIME-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha512; protocol="application/pgp-signature" X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.6 at phobos.denx.de X-Virus-Status: Clean --=-=-= Content-Type: text/plain Content-Transfer-Encoding: quoted-printable On 2023-01-05, Heinrich Schuchardt wrote: > Carve out code from efidebug command used to read the memory map. > > Signed-off-by: Heinrich Schuchardt Tested on odroid-c2, fixes booting from extlinux.conf and boot.scr using booti, and still works using EFI boot as well. Thanks! Tested-by: Vagrant Cascadian live well, vagrant > --- > v2: > new patch > --- > cmd/efidebug.c | 18 ++++-------------- > include/efi_loader.h | 3 +++ > lib/efi_loader/efi_memory.c | 34 ++++++++++++++++++++++++++++++++++ > 3 files changed, 41 insertions(+), 14 deletions(-) > > diff --git a/cmd/efidebug.c b/cmd/efidebug.c > index 569003ae2e..e6959ede93 100644 > --- a/cmd/efidebug.c > +++ b/cmd/efidebug.c > @@ -591,25 +591,15 @@ static void print_memory_attributes(u64 attributes) > static int do_efi_show_memmap(struct cmd_tbl *cmdtp, int flag, > int argc, char *const argv[]) > { > - struct efi_mem_desc *memmap =3D NULL, *map; > - efi_uintn_t map_size =3D 0; > + struct efi_mem_desc *memmap, *map; > + efi_uintn_t map_size; > const char *type; > int i; > efi_status_t ret; >=20=20 > - ret =3D efi_get_memory_map(&map_size, memmap, NULL, NULL, NULL); > - if (ret =3D=3D EFI_BUFFER_TOO_SMALL) { > - map_size +=3D sizeof(struct efi_mem_desc); /* for my own */ > - ret =3D efi_allocate_pool(EFI_BOOT_SERVICES_DATA, map_size, > - (void *)&memmap); > - if (ret !=3D EFI_SUCCESS) > - return CMD_RET_FAILURE; > - ret =3D efi_get_memory_map(&map_size, memmap, NULL, NULL, NULL); > - } > - if (ret !=3D EFI_SUCCESS) { > - efi_free_pool(memmap); > + ret =3D efi_get_memory_map_alloc(&map_size, &memmap); > + if (ret !=3D EFI_SUCCESS) > return CMD_RET_FAILURE; > - } >=20=20 > printf("Type Start%.*s End%.*s Attributes\n", > EFI_PHYS_ADDR_WIDTH - 5, spc, EFI_PHYS_ADDR_WIDTH - 3, spc); > diff --git a/include/efi_loader.h b/include/efi_loader.h > index 0899e293e5..02d151b715 100644 > --- a/include/efi_loader.h > +++ b/include/efi_loader.h > @@ -734,6 +734,9 @@ efi_status_t efi_allocate_pool(enum efi_memory_type p= ool_type, > efi_uintn_t size, void **buffer); > /* EFI pool memory free function. */ > efi_status_t efi_free_pool(void *buffer); > +/* Allocate and retrieve EFI memory map */ > +efi_status_t efi_get_memory_map_alloc(efi_uintn_t *map_size, > + struct efi_mem_desc **memory_map); > /* Returns the EFI memory map */ > efi_status_t efi_get_memory_map(efi_uintn_t *memory_map_size, > struct efi_mem_desc *memory_map, > diff --git a/lib/efi_loader/efi_memory.c b/lib/efi_loader/efi_memory.c > index 8d347f101f..32254d2433 100644 > --- a/lib/efi_loader/efi_memory.c > +++ b/lib/efi_loader/efi_memory.c > @@ -736,6 +736,40 @@ efi_status_t efi_get_memory_map(efi_uintn_t *memory_= map_size, > return EFI_SUCCESS; > } >=20=20 > +/** > + * efi_get_memory_map_alloc() - allocate map describing memory usage > + * > + * The caller is responsible for calling FreePool() if the call succeeds. > + * > + * @memory_map buffer to which the memory map is written > + * @map_size size of the memory map > + * Return: status code > + */ > +efi_status_t efi_get_memory_map_alloc(efi_uintn_t *map_size, > + struct efi_mem_desc **memory_map) > +{ > + efi_status_t ret; > + > + *memory_map =3D NULL; > + *map_size =3D 0; > + ret =3D efi_get_memory_map(map_size, *memory_map, NULL, NULL, NULL); > + if (ret =3D=3D EFI_BUFFER_TOO_SMALL) { > + *map_size +=3D sizeof(struct efi_mem_desc); /* for the map */ > + ret =3D efi_allocate_pool(EFI_BOOT_SERVICES_DATA, *map_size, > + (void **)memory_map); > + if (ret !=3D EFI_SUCCESS) > + return ret; > + ret =3D efi_get_memory_map(map_size, *memory_map, > + NULL, NULL, NULL); > + if (ret !=3D EFI_SUCCESS) { > + efi_free_pool(*memory_map); > + *memory_map =3D NULL; > + } > + } > + > + return ret; > +} > + > /** > * efi_add_conventional_memory_map() - add a RAM memory area to the map > * --=-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iHUEARYKAB0WIQRlgHNhO/zFx+LkXUXcUY/If5cWqgUCY7itLwAKCRDcUY/If5cW qoi8AP4+LN1BVyReeSJUJ9mVTigMD7+GPm1SrzRxBWhcF5GgbwEA5S2sU22UZT6Y bG+0sfhVMs4uNPUxhr3cLBuIQAZOGwY= =Ra1t -----END PGP SIGNATURE----- --=-=-=--