Received: by 2002:a05:6a10:2785:0:0:0:0 with SMTP id ia5csp3325250pxb; Tue, 12 Jan 2021 11:41:01 -0800 (PST) X-Google-Smtp-Source: ABdhPJwlZ9GND1uU0HEFZZi231zmfU2JpW15x1DKitTiPLNNJH+GtM7Pfsx+n1Y3dup7miC6rMqU X-Received: by 2002:a17:906:144e:: with SMTP id q14mr294499ejc.150.1610480461325; Tue, 12 Jan 2021 11:41:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610480461; cv=none; d=google.com; s=arc-20160816; b=Lhn/rq32ismJhfbZ5cReBskxSQdJ640ZA2bVeSOEyf8wJuVohVmyU9eZ7rO4R67qcN PTEBnj5MZUl25AkMtHj71WQuLR7kGVmX/YYaeZ0ktw2+IDxSzrBRDFPy/caKZRAB5B7f 3LryOhJGvsEYU5ZG7exF4WRK5qYM5qe9AfG/U1B1kR1R3iHpNCXozql7QB7EkIqHunW2 WRfVCM1omjVEl76ppm0B4RgOjnelHm/OKCn9rLtsWHaguaw6+AWxo/4bPiK/+0+OHJWT iTqgXtV8xV2XttG4aXmHPkTdH+JZy1p2jnS4pZg+2AqXwR2OAoz+jl/QeX5TCDRfJo7b eGCw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=Tuei7sFWPbUI7nOlvTWJ6kjxJgj733Mcp85h5bxTmL8=; b=Nj26zVnClq51CumszTJjjcCooGpazresyga/3y8lRb6s+ybxee4kJ1eBP0xKFFNRAZ ht1iaCUe3XIRWlEu/Xf7HA0IozviZxUoWKSxfF9VdqUtrmPzDS979zroD7341UxGl5IW lo5lv27VT2Qea7IsDfuvlfTMtjAyZZAbLvojWOsjAvDZ8a/Jr2iQdAwtYeAxRvBOKehz 0J1wme1J4EP3VdulFdR7aepTVke4Rl6qDZogK0uzEcT4KXf0kpsSyHai9i6JRNfl1Lkz yvo3LMs4D5SIb6SeCBifAaC/v5Rud7/pUTtl7gUKtfJp3I+Ca/O19z1Pu4b6OTBqa2Un I+3A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=PX0eYJLe; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r26si1776865edy.318.2021.01.12.11.40.20; Tue, 12 Jan 2021 11:41:01 -0800 (PST) Received-SPF: pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=PX0eYJLe; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2393212AbhALTif (ORCPT + 99 others); Tue, 12 Jan 2021 14:38:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47386 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2393150AbhALTid (ORCPT ); Tue, 12 Jan 2021 14:38:33 -0500 Received: from mail-oi1-x22f.google.com (mail-oi1-x22f.google.com [IPv6:2607:f8b0:4864:20::22f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E995AC061786 for ; Tue, 12 Jan 2021 11:37:52 -0800 (PST) Received: by mail-oi1-x22f.google.com with SMTP id w124so3562304oia.6 for ; Tue, 12 Jan 2021 11:37:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=Tuei7sFWPbUI7nOlvTWJ6kjxJgj733Mcp85h5bxTmL8=; b=PX0eYJLeziJ1W17AjXTWAGKoP40FaIUCcEDnaaXP4GpKrq0e6aExjMvBi29izMFp5Z me5MVzmjjWlHu10lrclhSOFxZVGN8NIxHHzcpCPAqfn0a4T8wzuA+6GXjRILu2FXNq0J WAsEnO9WI7Pl+GFZ3FrcQMkYvD8DmsK1j4AaV21Tdc66ps8Jhy01z4SxJwy0IweDVWSy gqQcAhnPuunKTqHwvfGkfu4iMGRHAOcok5+VLxgMBDs+AacaHtwMBqhhLlQTSYtQthe3 8KngAzwUu+uqanfRQ9lhzRuXY7wSmKR6bp0fvzsz5NiEWP5m8EbLm8unvcDZ9HMnZPIi BVbA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=Tuei7sFWPbUI7nOlvTWJ6kjxJgj733Mcp85h5bxTmL8=; b=WqgNfeqk/jhaPGE/ofTd4aZwLBnIhuImBbm2g3Nj+45yo/WWGISpEEikZ/GwXcUWg3 719K4dYN49jwdkDpvBDm2kezjy/Xh1398+4WSbMuKJ/Jo16WImOUKiCm1Rui7dckvl0t HZ8BHEOwDXRuIM6crFCA0a10M0noK1CaNO7jrGhVWmAAN/1c6umxUGceiilN2Q88Mssa uaRqeB6W+nqal52hMEM2/Vt0qfWT2Pa3i3+j+jaF8KxE1Mk0e9Tp2Gm2VfkS+x66Yalt EvbPH6THxx3VMj843apxd3ddotoeasL6a4iVr+F1TrSIQWub8+pZ6mohsZwJvSzYgRuV sJrA== X-Gm-Message-State: AOAM531DtaintCAIl0H2mLpwH4iVjsGUZfFZh8U3lnEuB0RZfx2urpqA XmrFJuWIETezKztbAQ2TtpiZ8Z+5iPqIR8iO093MxOjPneA= X-Received: by 2002:aca:f456:: with SMTP id s83mr483075oih.58.1610480272215; Tue, 12 Jan 2021 11:37:52 -0800 (PST) MIME-Version: 1.0 References: <20201222124651.101063-1-marcel@holtmann.org> In-Reply-To: From: Luiz Augusto von Dentz Date: Tue, 12 Jan 2021 11:37:40 -0800 Message-ID: Subject: Re: [PATCH] doc/mgmt-api.txt: Introduce Set Runtime Firmware command To: Abhishek Pandit-Subedi Cc: Marcel Holtmann , Bluez mailing list Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org Hi Abhishek, On Tue, Jan 12, 2021 at 10:03 AM Abhishek Pandit-Subedi wrote: > > Hi Luiz, > > On Mon, Jan 11, 2021 at 1:55 PM Luiz Augusto von Dentz > wrote: > > > > Hi Abhishek, > > > > On Mon, Jan 11, 2021 at 11:38 AM Abhishek Pandit-Subedi > > wrote: > > > > > > Hi Marcel, > > > > > > I don't think this solves the original problem we were talking about: > > > the driver should replace the runtime firmware on reload if it doesn't > > > match what's on disk. > > > > > > Some background for the mailing list: > > > - On a ChromeOS laptop, we discovered that the Bluetooth controller > > > wasn't being fully powered down in some reboots. As a result, a new > > > firmware wasn't being applied after an update. > > > - The kernel driver was checking if the bluetooth controller had > > > loaded some firmware already. If it was in bootloader mode, it would > > > download new firmware. If it was not, it would skip downloading new > > > firmware. > > > > > > The useful part of this mgmt command is to force the driver to reset > > > to bootloader (Action = 0 in Set Runtime Firmware). However, without > > > being able to compare the firmware version loaded on the controller, > > > there's no clear signal for when this should be called. Loading the > > > firmware through mgmt may be useful for debugging but you could also > > > just replace the firmware on disk and "reset to bootloader" to achieve > > > the same effect. I would actually expect unloading and reloading the > > > module should do that. > > > > > > Also, moving the firmware loading from the driver to the userspace > > > seems odd to me. Since the comparison is between the controller > > > firmware and disk firmware, there's not much extra that the userspace > > > knows that the kernel does not. > > > > My last suggestion was just to have a MGMT command suggesting the > > kernel to load the firmware from a different location, this could be > > useful for testing purpose so one can set for example an old/beta > > firmware to compare for regressions or test new features that > > otherwise would not be available. That said perhaps we don't actually > > need a new MGMT command for doing this and just by replacing the > > current file would trigger a reload but that may get tricky when if > > the location does get unmonted/remounted etc. > > > > > > > > ---- > > > > > > Coming back to the original problem of when to reload runtime > > > firmware, here are the conditions under which we do and don't want a > > > reload. > > > > > > Do want a reload: > > > - Reboot > > > - Module is unloaded and reloaded > > > > > > Don't want a reload: > > > - Transport disconnection (i.e. usb disconnect; some laptops will > > > power down USB during suspend to save additional power but BT will > > > stay powered up) > > > > Well if the device disappears from the host I'm not really sure how > > you will be able to detect that the firmware was retained, that said > > when the adapter is power up again it should be possible to query it > > what firmware it is currently running and then compare with the one > > from file before attempting to load it, this should also work > > regardless of the underlying transport/bus so it would work regardless > > of the driver in use. > > Generally the device drivers detect whether it's in bootloader mode or > runtime firmware is uploaded. With the runtime firmware, it can also > query what version is running. However, there's currently no way to > read the version on disk because the firmware version isn't stored at > some known location in the firmware blob. That's the crux of the > problem here. Hmm I believe we can extract the build number of the firmware, I mean it is obviously in there and we could possibly start encoding its version/build as part of the filename as well not just the model. https://git.kernel.org/pub/scm/linux/kernel/git/bluetooth/bluetooth-next.git/tree/drivers/bluetooth/btintel.c#n226 https://git.kernel.org/pub/scm/linux/kernel/git/bluetooth/bluetooth-next.git/tree/drivers/bluetooth/btusb.c#n2723 So we just have to figure out where the build number is in the firmware file, so store it somewhere else perhaps using some metadata perhaps.