From nobody Sun Feb 8 16:44:11 2026 Received: from fanzine2.igalia.com (fanzine.igalia.com [178.60.130.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3C6B98479 for ; Mon, 20 Jan 2025 19:04:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=178.60.130.6 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737399893; cv=none; b=OQgO3/iF7CE6c6irwPXZhMDZBNocMYo5Y2g/GUlyukXtQBBHYVgR6PPVhcZnPJPBzH9CevYCaEiapR6DpvEPGUIba1i0GI66b/W1UsTAhSxJxCSfdEIzeGJ7k0/5D8P4yC8FQGeC5qWmGiZh36jgJyITQUgFiM5QBCeHEEcPXHk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737399893; c=relaxed/simple; bh=9pqnqNGCYH4fC+UvTrP9wiGSwYDrGNYv2yx8w9neZPw=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=ezSwqehtbKv4SILm4TJ/7rsuznOd/nod0fsjcgmDgLqQN8Aza3/R0isOzmWsfy/tj6xcJzI2irz0dpYoSzwjABY/ANaTCuDI8ZEWmP/GerfiMYsAOophOE2crL+oGx4KMDe3bA3A2WSkaia5NsEg6sOLhvRTBrXxccDHVTBvBRo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com; spf=pass smtp.mailfrom=igalia.com; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b=k45DoV7T; arc=none smtp.client-ip=178.60.130.6 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=igalia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b="k45DoV7T" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:MIME-Version:Message-ID:Date:Subject: Cc:To:From:Sender:Reply-To:Content-Type:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: In-Reply-To:References:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=+odszZeuSWb6g2ASMwhHaKnsJyO21sp81y8PuE5B36o=; b=k45DoV7Tn4d9hqP30bFMTxfUwy eVSSpVVvMorj56Dm1F/z7LeAxoQ1poqcbeeo7rJivJJ4vzPqbqyZjeRDnRTBDzFIQwtfj9BoUeqLs Pjxf33KubIfMK3yGTZ9ka7TfFkslr0E/wyXIgddCSMr42dfM4wHdHFQZByyUiy46U4kV7bnsIUCbP tMQLaKWz2qEVq0R31B9wnSHWyYVHu/n4tTGJargzT9Om6hUKnU9C8eFOjedwKr0kYq9zUyLBnX+M1 CqioiE/9QuDuxXZkkdxJrWPfhC9YzXs/PkFCx5pt+25agkhk/JjMu2XuALNwpW5gykkyiWRc6t6ML hJ+W3gvQ==; Received: from [189.110.51.10] (helo=localhost) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_SECP256R1__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1tZx4m-000zoC-Bu; Mon, 20 Jan 2025 20:04:45 +0100 From: "Guilherme G. Piccoli" To: linux-kernel@vger.kernel.org Cc: mcgrof@kernel.org, russ.weight@linux.dev, dakr@kernel.org, gregkh@linuxfoundation.org, rafael@kernel.org, masahiroy@kernel.org, akpm@linux-foundation.org, nathan@kernel.org, nicolas@fjasle.eu, kernel-dev@igalia.com, kernel@gpiccoli.net, "Guilherme G. Piccoli" , Thadeu Lima de Souza Cascardo Subject: [PATCH] scripts: Add script to extract built-in firmware blobs Date: Mon, 20 Jan 2025 16:04:26 -0300 Message-ID: <20250120190436.127578-1-gpiccoli@igalia.com> X-Mailer: git-send-email 2.47.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Through the options CONFIG_EXTRA_FIRMWARE{_DIR} one is able to build a kernel including firmware blobs in a built-in fashion. This is usually the case of built-in drivers that require some blobs in order to work properly, for example, like in non-initrd based systems. Add hereby a script to extract these blobs from a non-stripped vmlinux, similar to the idea of "extract-ikconfig". The firmware loader interface saves such built-in blobs as rodata entries, having a field for the FW name as "_fw___bin"; the tool extracts files named "_" for each rodata firmware entry detected. It makes use of awk, bash, dd and readelf, pretty standard tooling for Linux development. Suggested-and-reviewed-by: Thadeu Lima de Souza Cascardo Signed-off-by: Guilherme G. Piccoli --- scripts/extract-fwblobs | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100755 scripts/extract-fwblobs diff --git a/scripts/extract-fwblobs b/scripts/extract-fwblobs new file mode 100755 index 000000000000..15e836e47368 --- /dev/null +++ b/scripts/extract-fwblobs @@ -0,0 +1,31 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0 +# +# ------------------------------------------------------------------------= ----- +# Extracts the vmlinux built-in firmware blobs - requires a non-stripped i= mage +# ------------------------------------------------------------------------= ----- + +if [ -z "$1" ]; then + echo "Must provide a non-stripped vmlinux as argument" + exit 1 +fi + +read -r RD_ADDR_HEX RD_OFF_HEX <<< "$( readelf -SW "$1" |\ +grep -w rodata | awk '{print "0x"$5" 0x"$6}' )" + +FW_SYMS=3D"$(readelf -sW "$1" |\ +awk -n '/fw_end/ { end=3D$2 ; print name " 0x" start " 0x" end; } { start= =3D$2; name=3D$8; }')" + +while IFS=3D read -r entry; do + read -r FW_NAME FW_ADDR_ST_HEX FW_ADDR_END_HEX <<< "$entry" + + # Notice kernel prepends _fw_ and appends _bin to the FW name + # in rodata; hence we hereby filter that out. + FW_NAME=3D${FW_NAME:4:-4} + + FW_OFFSET=3D"$(printf "%d" $((FW_ADDR_ST_HEX - RD_ADDR_HEX + RD_OFF_HEX))= )" + FW_SIZE=3D"$(printf "%d" $((FW_ADDR_END_HEX - FW_ADDR_ST_HEX)))" + + dd if=3D"$1" of=3D"./${FW_NAME}" bs=3D"${FW_SIZE}" count=3D1 iflag=3Dskip= _bytes skip=3D"${FW_OFFSET}" +done <<< "${FW_SYMS}" + --=20 2.47.1