From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CEB6720AF67; Mon, 16 Jun 2025 16:09:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750090190; cv=none; b=SKiQ/FLt+8wHE52yLqUccZ89pwyfQCOTopSdNYtPjkFvhwiGISOVqY9U8i4bEy/cVHBLK//KuylabeP8dQdcZ0raEX53NC5bfZkR7t29FrFP2KeE0hsDgdQdPjfcu28f+YMhKdvK+fcI0j2xpNuA2vPV6KFChULEGHp0odj1Z9A= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750090190; c=relaxed/simple; bh=hupPpB5C7hsOujbd0CaSC1f/KBFOevySlxxsM3jXnA8=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=DyWF7bVxGjkWUKCWxaU6wp3JvkhSy2k8sYq8QmMvzuKviJjF3naOg8Sp72HcxThAi4fkpNbJqgLd8Hfvzcv4YJPVTk0O0+XpV4VYB2bACAA5yFllgLqMzVh36sX7OolPPEqcy2bZrdVLCSY0+BRPMh7QDY2AFfKwdEe8sCYo0G0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id B05A6150C; Mon, 16 Jun 2025 09:09:26 -0700 (PDT) Received: from [192.168.20.57] (usa-sjc-mx-foss1.foss.arm.com [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id C883B3F673; Mon, 16 Jun 2025 09:09:47 -0700 (PDT) Message-ID: <14f2329f-e110-4f3f-976b-acb38d255798@arm.com> Date: Mon, 16 Jun 2025 11:07:08 -0500 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] scripts: add zboot support to extract-vmlinux To: Masahiro Yamada Cc: linux-kbuild@vger.kernel.org, nathan@kernel.org, nicolas.schier@linux.dev, linux-kernel@vger.kernel.org, Ard Biesheuvel References: <20250522172941.1669424-1-jeremy.linton@arm.com> Content-Language: en-US From: Jeremy Linton In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Hi, Thanks for looking at this. On 6/7/25 11:04 AM, Masahiro Yamada wrote: > On Fri, May 23, 2025 at 2:29 AM Jeremy Linton wrote: >> >> Zboot compressed kernel images are used for arm kernels on various >> distros. > > Are you talking about arm 32 bit here? > (arch/arm/boot/zImage) No, it should be arm64. > >> extract-vmlinux fails with those kernels because the wrapped image is >> another PE. While this could be a bit confusing, the tools primary >> purpose of unwrapping and decompressing the contained vmlinux image >> makes it the obvious place for this functionality. >> >> Add a 'file' check in check_vmlinux() that detects a contained PE >> image before trying readelf. Recent file implementations output >> something like: >> >> "Linux kernel ARM64 boot executable Image, little-endian, 4K pages" > > Are you talking about arm64 here? > > I am confused, as arm64 adopts a simple-compressed image. No, there is a CONFIG_EFI_ZBOOT, which is a EFI/PE image which self decompresses a contained kernel similar to x86, but is for !x86 EFI architectures. This patch extends this utility to work for those images as well. > > > Apparently, this patch did not work for me. > > $ ./scripts/extract-vmlinux arch/arm/boot/zImage > extract-vmlinux: Cannot find vmlinux. > > The 'file' command says, it is "data". > Is my 'file' command too old? > > $ file arch/arm/boot/Image > arch/arm/boot/Image: data > > >> Which is also a stronger statement than readelf provides so drop that >> part of the comment. At the same time this means that kernel images >> which don't appear to contain a compressed image will be returned >> rather than reporting an error. Which matches the behavior for >> existing ELF files. >> >> Signed-off-by: Jeremy Linton >> Cc: Ard Biesheuvel >> --- >> scripts/extract-vmlinux | 9 +++++---- >> 1 file changed, 5 insertions(+), 4 deletions(-) >> >> diff --git a/scripts/extract-vmlinux b/scripts/extract-vmlinux >> index 8995cd304e6e..edda1abe226c 100755 >> --- a/scripts/extract-vmlinux >> +++ b/scripts/extract-vmlinux >> @@ -12,10 +12,11 @@ >> >> check_vmlinux() >> { >> - # Use readelf to check if it's a valid ELF >> - # TODO: find a better to way to check that it's really vmlinux >> - # and not just an elf >> - readelf -h $1 > /dev/null 2>&1 || return 1 >> + file $1 |grep 'Linux kernel.*boot executable Image' > /dev/null >> + if [ "$?" -ne "0" ]; then >> + # Use readelf to check if it's a valid ELF, if 'file' fails >> + readelf -h $1 > /dev/null 2>&1 || return 1 >> + fi >> >> cat $1 >> exit 0 >> -- >> 2.49.0 >> > >