Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1oVGko-0002IC-GB for mharc-qemu-riscv@gnu.org; Mon, 05 Sep 2022 14:23:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40870) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oVGkl-0002DF-Ea for qemu-riscv@nongnu.org; Mon, 05 Sep 2022 14:23:24 -0400 Received: from mail-pj1-x102e.google.com ([2607:f8b0:4864:20::102e]:38422) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oVGkc-000277-QX for qemu-riscv@nongnu.org; Mon, 05 Sep 2022 14:23:23 -0400 Received: by mail-pj1-x102e.google.com with SMTP id x1-20020a17090ab00100b001fda21bbc90so12807960pjq.3 for ; Mon, 05 Sep 2022 11:23:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=nOmKJ9C0Ic7pbA3XrY/urXuMZM/kB+XJyZpt6xVFVH4=; b=bILOzOcjQv8WmX5zuZHALcuK+EsBhhAcV3ZAm0jP3WQ/mKzWbGo5kLNGkbrZLSROdY Nhk0CxsYuqHuLLqwg5NEmUUNv4GTsJyf7VIJUWEoVGB6YS2Ak+jfHPh553TZrrsoE5As FJqiG3nPXhvDpUYyeg1ll07f2skCXgkpTyCkNCHOh6/TxCA4oFKEKKUJcbJ6kvYLo3Ry uC2+OH7swqJydrfqmpCHXUWI9q2tJRH7Wg/sQfoVfGPy/g2ZHLcEjzTb86r4Iv0krmCM k65xDxq9dROnYFOsPzcalzuv5oVHIgvBTPQYBt7nHgLfsOEOAbYfOEZL+2TEJGt7Wmb0 SQJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date; bh=nOmKJ9C0Ic7pbA3XrY/urXuMZM/kB+XJyZpt6xVFVH4=; b=GAPN7OaYhWIltPtlhjhvqF0Q530PrV+0cVT0RoaJg8NcsT7z9+NlFSS0NdOHewGgsi EJfJlZ2batAwle5jlNPTFsDxP+obH7L6XiEmd2yqV/wIoULkeGBwkaotHEp06xskQawM DhqmJqgCL0sxKQHLrUuNOEoYTXZ8eMOTM3D3g1/EhmPvH82sUzVU5pTb0oU5JpZ9w5RQ 797SCyMAKzw0kXY/OC1ApkAd4rGq+k6qB2sv8sR40NGSC/oZ9/P2oxWzoiIEk0K+CwnB eSrMXy2lQoevRA3D84g79OAFCmzJCdTQDwC23Opk7m4msSj3RL61/1ago5hoLrGbQIuX INRg== X-Gm-Message-State: ACgBeo33uOer4N9ATEtf2TzBl8flwe8IA8gnm2KAiStxk7mu5NXUjvhd fxpsdN4NomE/8lPbZ8ADgnODmQ== X-Google-Smtp-Source: AA6agR5HupXPoGcDVcmBygebSUOqwt5PpUxRHxcqcWPNj9FYqz2KmtkLKzuw23F1FHiWeK3WjYFe/A== X-Received: by 2002:a17:90b:33d1:b0:1fd:6e9f:548c with SMTP id lk17-20020a17090b33d100b001fd6e9f548cmr21370273pjb.137.1662402192057; Mon, 05 Sep 2022 11:23:12 -0700 (PDT) Received: from localhost.localdomain ([49.206.11.92]) by smtp.gmail.com with ESMTPSA id z7-20020aa79587000000b005321340753fsm8046724pfj.103.2022.09.05.11.23.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Sep 2022 11:23:11 -0700 (PDT) From: Sunil V L To: qemu-arm@nongnu.org, qemu-devel@nongnu.org, qemu-riscv@nongnu.org Cc: Peter Maydell , Xiaojuan Yang , Song Gao , Gerd Hoffmann , Palmer Dabbelt , Alistair Francis , Bin Meng , Andrew Jones , Anup Patel , Atish Kumar Patra , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Sunil V L Subject: [PATCH V2 1/3] hw/arm, loongarch: Move load_image_to_fw_cfg() to common location Date: Mon, 5 Sep 2022 23:52:36 +0530 Message-Id: <20220905182238.374545-2-sunilvl@ventanamicro.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220905182238.374545-1-sunilvl@ventanamicro.com> References: <20220905182238.374545-1-sunilvl@ventanamicro.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=2607:f8b0:4864:20::102e; envelope-from=sunilvl@ventanamicro.com; helo=mail-pj1-x102e.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-riscv@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 05 Sep 2022 18:23:25 -0000 load_image_to_fw_cfg() is duplicated by both arm and loongarch. The same function will be required by riscv too. So, it's time to refactor and move this function to a common path. Signed-off-by: Sunil V L --- hw/arm/boot.c | 49 --------------------------------------- hw/loongarch/virt.c | 33 -------------------------- hw/nvram/fw_cfg.c | 49 +++++++++++++++++++++++++++++++++++++++ include/hw/nvram/fw_cfg.h | 3 +++ 4 files changed, 52 insertions(+), 82 deletions(-) diff --git a/hw/arm/boot.c b/hw/arm/boot.c index ada2717f76..704f368d9c 100644 --- a/hw/arm/boot.c +++ b/hw/arm/boot.c @@ -818,55 +818,6 @@ static void do_cpu_reset(void *opaque) } } -/** - * load_image_to_fw_cfg() - Load an image file into an fw_cfg entry identified - * by key. - * @fw_cfg: The firmware config instance to store the data in. - * @size_key: The firmware config key to store the size of the loaded - * data under, with fw_cfg_add_i32(). - * @data_key: The firmware config key to store the loaded data under, - * with fw_cfg_add_bytes(). - * @image_name: The name of the image file to load. If it is NULL, the - * function returns without doing anything. - * @try_decompress: Whether the image should be decompressed (gunzipped) before - * adding it to fw_cfg. If decompression fails, the image is - * loaded as-is. - * - * In case of failure, the function prints an error message to stderr and the - * process exits with status 1. - */ -static void load_image_to_fw_cfg(FWCfgState *fw_cfg, uint16_t size_key, - uint16_t data_key, const char *image_name, - bool try_decompress) -{ - size_t size = -1; - uint8_t *data; - - if (image_name == NULL) { - return; - } - - if (try_decompress) { - size = load_image_gzipped_buffer(image_name, - LOAD_IMAGE_MAX_GUNZIP_BYTES, &data); - } - - if (size == (size_t)-1) { - gchar *contents; - gsize length; - - if (!g_file_get_contents(image_name, &contents, &length, NULL)) { - error_report("failed to load \"%s\"", image_name); - exit(1); - } - size = length; - data = (uint8_t *)contents; - } - - fw_cfg_add_i32(fw_cfg, size_key, size); - fw_cfg_add_bytes(fw_cfg, data_key, data, size); -} - static int do_arm_linux_init(Object *obj, void *opaque) { if (object_dynamic_cast(obj, TYPE_ARM_LINUX_BOOT_IF)) { diff --git a/hw/loongarch/virt.c b/hw/loongarch/virt.c index 5cc0b05538..eee2c193c0 100644 --- a/hw/loongarch/virt.c +++ b/hw/loongarch/virt.c @@ -542,39 +542,6 @@ static void reset_load_elf(void *opaque) } } -/* Load an image file into an fw_cfg entry identified by key. */ -static void load_image_to_fw_cfg(FWCfgState *fw_cfg, uint16_t size_key, - uint16_t data_key, const char *image_name, - bool try_decompress) -{ - size_t size = -1; - uint8_t *data; - - if (image_name == NULL) { - return; - } - - if (try_decompress) { - size = load_image_gzipped_buffer(image_name, - LOAD_IMAGE_MAX_GUNZIP_BYTES, &data); - } - - if (size == (size_t)-1) { - gchar *contents; - gsize length; - - if (!g_file_get_contents(image_name, &contents, &length, NULL)) { - error_report("failed to load \"%s\"", image_name); - exit(1); - } - size = length; - data = (uint8_t *)contents; - } - - fw_cfg_add_i32(fw_cfg, size_key, size); - fw_cfg_add_bytes(fw_cfg, data_key, data, size); -} - static void fw_cfg_add_kernel_info(FWCfgState *fw_cfg) { /* diff --git a/hw/nvram/fw_cfg.c b/hw/nvram/fw_cfg.c index d605f3f45a..3f68dae5d2 100644 --- a/hw/nvram/fw_cfg.c +++ b/hw/nvram/fw_cfg.c @@ -41,6 +41,7 @@ #include "qapi/error.h" #include "hw/acpi/aml-build.h" #include "hw/pci/pci_bus.h" +#include "hw/loader.h" #define FW_CFG_FILE_SLOTS_DFLT 0x20 @@ -1221,6 +1222,54 @@ FWCfgState *fw_cfg_find(void) return FW_CFG(object_resolve_path_type("", TYPE_FW_CFG, NULL)); } +/** + * load_image_to_fw_cfg() - Load an image file into an fw_cfg entry identified + * by key. + * @fw_cfg: The firmware config instance to store the data in. + * @size_key: The firmware config key to store the size of the loaded + * data under, with fw_cfg_add_i32(). + * @data_key: The firmware config key to store the loaded data under, + * with fw_cfg_add_bytes(). + * @image_name: The name of the image file to load. If it is NULL, the + * function returns without doing anything. + * @try_decompress: Whether the image should be decompressed (gunzipped) before + * adding it to fw_cfg. If decompression fails, the image is + * loaded as-is. + * + * In case of failure, the function prints an error message to stderr and the + * process exits with status 1. + */ +void load_image_to_fw_cfg(FWCfgState *fw_cfg, uint16_t size_key, + uint16_t data_key, const char *image_name, + bool try_decompress) +{ + size_t size = -1; + uint8_t *data; + + if (image_name == NULL) { + return; + } + + if (try_decompress) { + size = load_image_gzipped_buffer(image_name, + LOAD_IMAGE_MAX_GUNZIP_BYTES, &data); + } + + if (size == (size_t)-1) { + gchar *contents; + gsize length; + + if (!g_file_get_contents(image_name, &contents, &length, NULL)) { + error_report("failed to load \"%s\"", image_name); + exit(1); + } + size = length; + data = (uint8_t *)contents; + } + + fw_cfg_add_i32(fw_cfg, size_key, size); + fw_cfg_add_bytes(fw_cfg, data_key, data, size); +} static void fw_cfg_class_init(ObjectClass *klass, void *data) { diff --git a/include/hw/nvram/fw_cfg.h b/include/hw/nvram/fw_cfg.h index 0e7a8bc7af..066c10d279 100644 --- a/include/hw/nvram/fw_cfg.h +++ b/include/hw/nvram/fw_cfg.h @@ -341,5 +341,8 @@ bool fw_cfg_dma_enabled(void *opaque); * key lookup failure. */ const char *fw_cfg_arch_key_name(uint16_t key); +void load_image_to_fw_cfg(FWCfgState *fw_cfg, uint16_t size_key, + uint16_t data_key, const char *image_name, + bool try_decompress); #endif -- 2.25.1