From patchwork Tue Feb 6 20:30:46 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roman Kagan X-Patchwork-Id: 10204179 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 070FE60247 for ; Tue, 6 Feb 2018 21:30:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id ECA7C27FE4 for ; Tue, 6 Feb 2018 21:30:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E164628842; Tue, 6 Feb 2018 21:30:00 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAD_ENC_HEADER,BAYES_00, DKIM_SIGNED, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 3D41028998 for ; Tue, 6 Feb 2018 21:30:00 +0000 (UTC) Received: from localhost ([::1]:36682 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ejAoR-0007kg-CA for patchwork-qemu-devel@patchwork.kernel.org; Tue, 06 Feb 2018 16:29:59 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45176) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ej9uT-0001c5-QQ for qemu-devel@nongnu.org; Tue, 06 Feb 2018 15:32:11 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ej9uQ-0003Sb-FE for qemu-devel@nongnu.org; Tue, 06 Feb 2018 15:32:09 -0500 Received: from mail-db5eur01on0121.outbound.protection.outlook.com ([104.47.2.121]:11584 helo=EUR01-DB5-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ej9uQ-0003RX-2e for qemu-devel@nongnu.org; Tue, 06 Feb 2018 15:32:06 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=virtuozzo.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=rOacPbvJtrX3vWh/Pafe5jWYNm31oERxcLKkwmJiyjM=; b=TmKwczHrku82TokWFIOja1/ww+jWeLcS0k6NxQB2DkgFVOZKIEooidF2Ch4d2vSRRY4puDpx4G2HamKSEHTpKZj4dfInioWy/UfRanhfNQ4pOPVfMQP3qe3E8AkETCmaviubHdjx9xgRA6UH1A6zO3Z+1YCgU/SJ05twVzV6+sQ= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=rkagan@virtuozzo.com; Received: from rkaganb.sw.ru (195.214.232.6) by VI1PR0801MB1983.eurprd08.prod.outlook.com (2603:10a6:800:8a::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.464.11; Tue, 6 Feb 2018 20:32:02 +0000 From: Roman Kagan To: qemu-devel@nongnu.org Date: Tue, 6 Feb 2018 23:30:46 +0300 Message-Id: <20180206203048.11096-33-rkagan@virtuozzo.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180206203048.11096-1-rkagan@virtuozzo.com> References: <20180206203048.11096-1-rkagan@virtuozzo.com> MIME-Version: 1.0 X-Originating-IP: [195.214.232.6] X-ClientProxiedBy: HE1PR0301CA0008.eurprd03.prod.outlook.com (2603:10a6:3:76::18) To VI1PR0801MB1983.eurprd08.prod.outlook.com (2603:10a6:800:8a::16) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 0bc6b1e3-1f28-4087-5872-08d56da0aeb2 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(4534165)(7168020)(4627221)(201703031133081)(201702281549075)(5600026)(4604075)(2017052603307)(7153060)(7193020); SRVR:VI1PR0801MB1983; X-Microsoft-Exchange-Diagnostics: 1; VI1PR0801MB1983; 3:0+NI36iKkZBamS8mpSgRkH0ugAwZDqyLt1toUZLRgpPtzKVWtfWJAXL4Pa52IdL59Rf5gBqWPfwfJBOUixndbhaWtP4C5XlneNrYD+bNQDV8AzUvqjnQn71Lrvpnn45BLm1KM1mM82j/rwArwXOdbd8f7eNiWKR7miR+Ujvy5GCiSEgPIYnMbB9erWlwghrH9h10xcRLenCuea0PxatrMMVt5txDFYvuMTNYwqE9VGGZKOBRyPduASzIe0iUBP2L; 25:IBge94C7Uk/6DcjzILwFIrZSTb0OgTRUQJBOm5JV9bM4lwjZtk/3f+jcConzzQDHEZyyramaPh35qwOZE5uZRhtgIAauHqbgSRzTE5289UI7q6qcxTGbJzQUiRRbVjoWvDB09Vp7R21C8IaSAXHu6Sexrr2tG1UmK9qTisXJBz9TjhPa5ENZUCRQhJBoefZp3Xwr8HeKoW+4izL0Vk9x4MnMbuD2CM6S7oqn3yepJ2G/p4DIGT0wU7lEuw+WfmmgQF9Voj0slCJA5qbn284VHYgIVYgFTeHqufRtQUek/pfxWMu3Socheg3kJrgIoCg25oOnJ+wk0JD0J4RJA9PGXA==; 31:3s3+cMYF7rabS/hYamZqHg5xDctbDHueO2aO090TsA0rMOaVVRnyzW5J0V1wWV/UtcksLPikbKCQa55gs4rhBNi1DJYfnrRtj33MDZmCuKR1qI3at3aytnehm4YIazx1aezBFVPr4hirjvgnzjgeOzhtlA77nTuCSmv88zIQqoQtBgK82GB1sTM4y0XD/PI2sM7opgPVr1pZILk+0PP5ewA788YG6K2oQd50QNT7RzE= X-MS-TrafficTypeDiagnostic: VI1PR0801MB1983: X-Microsoft-Exchange-Diagnostics: 1; VI1PR0801MB1983; 20:ufjS0htNFSt1AgZKQrPK9VtmbCOUNBoTFF0ZEdvtsWi2rUJE0T+op8tkoCYZtaBkA9+CvHY1ThxW6nVGcpX8oNcI5zDKv3fl65Hr0/fH9YCOoqSYp6+XGUi2bEDAoN8KIT0K9WGbEVsLYpeHx+AiXAhzkx0vaytgso43MtPBIoP/gjJYbj/LN6x+OVyQwiDQzZjOqkQ0vA7ZDiRguVX8mkBWRvXZcn7ETEQhRcjsIa/JxnEcnETBUoJ/uyjfbAsyGViHs7sNkJuhVirqjunEievW1By1KgIThC8oPmFDXvmht0AdhhLNNz972rKWxMvZHC0XKbM1bx4C9AVu3xosWkdC1LkhSs57GuzaOuIWLrr2VK7bz0o4EyGTWwWf6R705UFlr6pgzyDkuAnuA5YPOb2fAFkFt6xKe0EEpbIurxE=; 4:b2kdvUvfqGyn1l0PT7bWCffQbFcuNSvEA/2gVxb6aW26AUY5TDlmB18mFL3ENlO/Rp74wtK4hmgbwgCyUF/NI3Q0ka2xM7VTtqP6iJ1pqbeyBQX/Mk48CRToem3LfGB24/5TCrfpM+tYbyDWHwpe0+DuuphPrdpW/zw6go0w0fQC7Jr5jnQHKOVaMGACzRad+3yusqkqu7LQYdlU168Hxy2ETxRA4btJA6AgzNtCd1GKPHN5hEjTaXzC/eWft85ui9pLcQ5akao/YC53ICNqow== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040501)(2401047)(5005006)(8121501046)(3002001)(93006095)(93001095)(3231101)(2400082)(944501161)(10201501046)(6041288)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123558120)(20161123564045)(20161123562045)(20161123560045)(6072148)(201708071742011); SRVR:VI1PR0801MB1983; BCL:0; PCL:0; RULEID:; SRVR:VI1PR0801MB1983; X-Forefront-PRVS: 0575F81B58 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(1496009)(396003)(366004)(376002)(39380400002)(39850400004)(346002)(189003)(199004)(16586007)(53936002)(305945005)(54906003)(7736002)(3846002)(316002)(105586002)(2361001)(106356001)(2351001)(6116002)(1076002)(50226002)(8936002)(81156014)(5660300001)(8676002)(81166006)(7416002)(2950100002)(6666003)(6916009)(76176011)(575784001)(86362001)(68736007)(66066001)(16526019)(47776003)(50466002)(4326008)(97736004)(26005)(6512007)(51416003)(2906002)(52116002)(386003)(6506007)(59450400001)(48376002)(55236004)(36756003)(53416004)(69596002)(6486002)(478600001)(186003)(25786009)(217873001); DIR:OUT; SFP:1102; SCL:1; SRVR:VI1PR0801MB1983; H:rkaganb.sw.ru; FPR:; SPF:None; PTR:InfoNoRecords; MX:1; A:1; LANG:en; Received-SPF: None (protection.outlook.com: virtuozzo.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; VI1PR0801MB1983; 23:Tp12tQ407/aQnwQ26mdODE6uQi6lxUoQpSn1Ftk?= =?us-ascii?Q?uQcCWiF9t2JvPG9dTCzaLP5REjCFX98pkNwCyBlEw3KTZFq8muExsijaiZFX?= =?us-ascii?Q?MIzj8Ln5RPOUhYQGAvkPHLfQZK/GWBCHQO6z4kKJsLvsY8z0LC1v+mvoyX7s?= =?us-ascii?Q?SZwJBbVnp0MLyazBh721vO36MxbrDavxMmwjI0TYuZQPR+u6dUoTi5y0tcK0?= =?us-ascii?Q?ona3kvUl8zm3pFzXi8+IP1Kn901VAdmZVX90YLwGe7Gp+MtkPCl2YW0sg1FB?= =?us-ascii?Q?2ugAMI/m1CajaRrfap5n/A+nAG+rc77UcXFeukcEfNYCJeP+1ceqmBIO4M0U?= =?us-ascii?Q?+wX2X0imaMa6W1X4Mkx+kzl+shXsX9JpbUYDp5d6HZ0OQMPVWeVt+N00GPy4?= =?us-ascii?Q?YVrFoHIiJNLO7T4NMQ9rwoRYFBXaLHDSnTvtX6V20S+Wog66rp+IhmaWCSRQ?= =?us-ascii?Q?DdLyEj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BibvvIo2?= =?us-ascii?Q?xDtM2SA=3D=3D?= X-Microsoft-Exchange-Diagnostics: 1; VI1PR0801MB1983; 6:jAnObX01pP5AtXzJ9nHPU+lUe9vBWLXsmefSDWwor1o5pZO1B23V70E0s5md97smi/c4v+jUDyBzLdH4scwflh8CEeKapHlKlanofcZJaL7SWmpsg/D++McXGqUhHOVv4p3ChwAMpI7lCRx+imaThqAoeJeGB3XemSG+qVhKonaSwFUxj9F1kHc280dUik4ApOuXgtlEhjKeqn8NOaMdUKr96eLP53xvY84H+yioAd27owMhcurYw6jXsJS3q8oYQ2qRv9eju0W9AvppNVhLxUFkPp2oS+FRAxcczltEBVxMBr0eLTJJipHRMOm9fVozAFscpVhBSMjyYuZ4dDZFRu1Zl+Ux/Als0Iuj1S2nU98=; 5:93n2rKuppn4oCnG1CRv2PxogsSP0+5aY7P881UYX6SHZXfotK8EjsAC/1HhTEwgFQuGbGywLNmgFghp/IcR+l1Haygl0qoAOt0iuXAOkxxgvQrirj7X6Jrw72zTiNJKINb+sFRhzhySLEEEeacIcLHg06bL/9qIgTznoA6Cb55E=; 24:5BuK14owPXhLf4n1DzSsFPnDhe8GtC2v62PNOinsRQX0KsYgWi1P8tFLo/9/2mKTEcYV0J2qsC8ck8Oodd7+ZXf+AA6eaaTc9Yp16I6qkoY=; 7:AQAqWZ0gBRU46AAGubSZZpv9Sx40HCGnvnEZrpSw+H9BelB1mAxttfzwwnBRocqlFKLkSEAaz3k7lp5kQLsVSUOsWtkcyU/SazNFgtLPIazVqzAhscQm8SfQHbt1KXimDtZySLl5jKMuTIPqfzaAYBX9hjSMtJF6Q5/ekGUmeFgXz1A2SDx7RSMaUB5qhtDVQYeaceWeNPHLiNIRkZ+C7THKOEBDxCKHm7UZW9AW+SWmNsrN6LRuqaeCaoZ35Mfk SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; VI1PR0801MB1983; 20:fkWi1Ne+h2E1alj3nl+ZQcM0vRPN651k+JySP0z3feJixaM/LEcEblKKGC1/C/lQedaXBkPWZ2n7b27XCmu925gzuWiTtS8snqeSPiRlS+KjLjdfZxzXpkk+iWxQNezUFIDzYsz22Im4ppuDTUghkliVEY26SWUvo3bqEHH+Wxc= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Feb 2018 20:32:02.3724 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 0bc6b1e3-1f28-4087-5872-08d56da0aeb2 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0801MB1983 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 104.47.2.121 Subject: [Qemu-devel] [RFC PATCH 32/34] loader: allow arbitrary basename for fw_cfg file roms X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ben Warren , Konrad Rzeszutek Wilk , Krish Sadhukhan , "Marcos E. Matsunaga" , Jan Dakinevich , Vadim Rozenfeld , "Denis V. Lunev" , si-wei liu , Paolo Bonzini , Vitaly Kuznetsov , Cathy Avery Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP rom_add_file assumes that the basename of the file roms in fw_cfg should be the same as the original basename of the rom file on the filesystem. However, this is not always convenient: the rom basename may bear certain meaning in the guest firmware context, e.g. contain device ids, while the the filename on the host filesystem may be something more human-readable. [In particular, this is how I'm planning to supply roms for Hyper-V VMBus devices, which don't have a spec-defined way of doing this.] To cater to such usecases, interpret the corresponding argument of rom_add_file as a path which, if ends with a slash, is interpreted as a "directory" to which the basename of the rom file is appended; otherwise this argument is treated as a full fw_cfg path. TODO: it may be a better idea to use separate arguments for "directory" and "filename" instead of interpreting the trailing dash. Signed-off-by: Roman Kagan --- include/hw/loader.h | 2 +- hw/core/loader.c | 43 +++++++++++++++++++++---------------------- 2 files changed, 22 insertions(+), 23 deletions(-) diff --git a/include/hw/loader.h b/include/hw/loader.h index 355fe0f5a2..a309662fa8 100644 --- a/include/hw/loader.h +++ b/include/hw/loader.h @@ -186,7 +186,7 @@ void pstrcpy_targphys(const char *name, extern bool option_rom_has_mr; extern bool rom_file_has_mr; -int rom_add_file(const char *file, const char *fw_dir, +int rom_add_file(const char *file, const char *fw_path, hwaddr addr, int32_t bootindex, bool option_rom, MemoryRegion *mr, AddressSpace *as); MemoryRegion *rom_add_blob(const char *name, const void *blob, size_t len, diff --git a/hw/core/loader.c b/hw/core/loader.c index 91669d65aa..436154de48 100644 --- a/hw/core/loader.c +++ b/hw/core/loader.c @@ -817,7 +817,6 @@ struct Rom { MemoryRegion *mr; AddressSpace *as; int isrom; - char *fw_dir; char *fw_file; hwaddr addr; @@ -882,7 +881,7 @@ static void *rom_set_mr(Rom *rom, Object *owner, const char *name, bool ro) return data; } -int rom_add_file(const char *file, const char *fw_dir, +int rom_add_file(const char *file, const char *fw_path, hwaddr addr, int32_t bootindex, bool option_rom, MemoryRegion *mr, AddressSpace *as) @@ -914,10 +913,6 @@ int rom_add_file(const char *file, const char *fw_dir, goto err; } - if (fw_dir) { - rom->fw_dir = g_strdup(fw_dir); - rom->fw_file = g_strdup(file); - } rom->addr = addr; rom->romsize = lseek(fd, 0, SEEK_END); if (rom->romsize == -1) { @@ -937,20 +932,26 @@ int rom_add_file(const char *file, const char *fw_dir, } close(fd); rom_insert(rom); - if (rom->fw_file && fw_cfg) { + if (fw_path && fw_cfg) { const char *basename; - char fw_file_name[FW_CFG_MAX_FILE_PATH]; void *data; - basename = strrchr(rom->fw_file, '/'); - if (basename) { - basename++; + basename = strrchr(fw_path, '/'); + if (basename && basename[1] == '\0') { + /* given path terminates with '/', append basename(file) */ + basename = strrchr(file, '/'); + if (basename) { + basename++; + } else { + basename = file; + } + + rom->fw_file = g_strdup_printf("%s%s", fw_path, basename); } else { - basename = rom->fw_file; + rom->fw_file = g_strdup(fw_path); } - snprintf(fw_file_name, sizeof(fw_file_name), "%s/%s", rom->fw_dir, - basename); - snprintf(devpath, sizeof(devpath), "/rom@%s", fw_file_name); + + snprintf(devpath, sizeof(devpath), "/rom@%s", rom->fw_file); if ((!option_rom || mc->option_rom_has_mr) && mc->rom_file_has_mr) { data = rom_set_mr(rom, OBJECT(fw_cfg), devpath, true); @@ -958,7 +959,7 @@ int rom_add_file(const char *file, const char *fw_dir, data = rom->data; } - fw_cfg_add_file(fw_cfg, fw_file_name, data, rom->romsize); + fw_cfg_add_file(fw_cfg, rom->fw_file, data, rom->romsize); } else { if (mr) { rom->mr = mr; @@ -978,8 +979,7 @@ err: g_free(rom->data); g_free(rom->path); g_free(rom->name); - if (fw_dir) { - g_free(rom->fw_dir); + if (fw_path) { g_free(rom->fw_file); } g_free(rom); @@ -1052,12 +1052,12 @@ int rom_add_elf_program(const char *name, void *data, size_t datasize, int rom_add_vga(const char *file) { - return rom_add_file(file, "vgaroms", 0, -1, true, NULL, NULL); + return rom_add_file(file, "vgaroms/", 0, -1, true, NULL, NULL); } int rom_add_option(const char *file, int32_t bootindex) { - return rom_add_file(file, "genroms", 0, bootindex, true, NULL, NULL); + return rom_add_file(file, "genroms/", 0, bootindex, true, NULL, NULL); } static void rom_reset(void *unused) @@ -1255,9 +1255,8 @@ void hmp_info_roms(Monitor *mon, const QDict *qdict) rom->isrom ? "rom" : "ram", rom->name); } else { - monitor_printf(mon, "fw=%s/%s" + monitor_printf(mon, "fw=%s" " size=0x%06zx name=\"%s\"\n", - rom->fw_dir, rom->fw_file, rom->romsize, rom->name);