From nobody Tue Feb 10 19:17:01 2026 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1674886044447926.0429307624736; Fri, 27 Jan 2023 22:07:24 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pLeLc-0002KY-Kb; Sat, 28 Jan 2023 01:05:56 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pLeLa-0002K5-U3; Sat, 28 Jan 2023 01:05:54 -0500 Received: from out1-smtp.messagingengine.com ([66.111.4.25]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pLeLY-0007Vn-Vr; Sat, 28 Jan 2023 01:05:54 -0500 Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id 32A345C06D1; Sat, 28 Jan 2023 01:05:52 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute1.internal (MEProxy); Sat, 28 Jan 2023 01:05:52 -0500 Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sat, 28 Jan 2023 01:05:50 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pjd.dev; h=cc:cc :content-transfer-encoding:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to; s=fm1; t=1674885952; x= 1674972352; bh=jf6ILXzGt4f+cwWOHbp15S/XgmP9rRs79WrjUZM2PIw=; b=j PKHzuHLou4Rn6iwI6KR758dBzhmd5qxRt1YyQMzbeRdiuJT1TuL4Yd3keGGhpQz7 aCv795GJfKSLQBr/SHvw3NCROOWNl/9VgNg4kp7vvQAMqNVCPSahHjlmtzen71wb GB5MCohZ3yneC/iN7MzUQQRCLs8AVSIDXtEfOxBzaPPoB1lEhH+OU7l8Wfz9pfo9 H99VpVtmucjJbdlZAz5bitARhIbNnrfIHO0kWQHdtYP4UAKz9ZjjbRj2LP0sJVWV EHuM9cJU/+aDWMc6835D9nv/xsC2aUkkutnE5013GinaNwq7qRGSMD0GPURai6xx kmVLkBU8EQbJ38ShikLBg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t=1674885952; x= 1674972352; bh=jf6ILXzGt4f+cwWOHbp15S/XgmP9rRs79WrjUZM2PIw=; b=C nHhC4D4XydUoW9j1x0jcKutNY6vH5hUqa2kVBq1iqeiI+zSx+4a/8DXJyYeEWsZJ qrsadKp5FFGqs9De85nrCeiJkSGY6ntLvu+j6C6JsIBtaUvZYIwPrrqdlBBZu0f0 rLcVyEW0TfgP09Lsfz5xHr2DZ9W89FoxI148Fea4jwD2MvQlUSMWEPakTMC12uuf X3+cWJ9N4+Ei4VKSXAGuCyrZAuF3mDx05foDfsxbawJrgH1laTLhu3Oj8DwbkJgF WAp4AqoR6ZJyX6L7hc4cm18d227bFG4BK15djiFNSbbh+aVTrLn5Y8Q3pBBU5NP8 SnaRkA3ze2PY+N7LPJLXQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedruddvjedgledvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenuchmihhsshhinhhgucfvqfcufhhivghlugculdeftd dmnegoteeftdduqddtudculdduhedmnecujfgurhephffvvefufffkofgjfhggtgfgseht keertdertdejnecuhfhrohhmpefrvghtvghrucffvghlvghvohhrhigrshcuoehpvghtvg hrsehpjhgurdguvghvqeenucggtffrrghtthgvrhhnpedvhfevvefhtddvueevudelvedt ieehvdejjeeuvedtudegjeeileetheekgfeggeenucevlhhushhtvghrufhiiigvpedune curfgrrhgrmhepmhgrihhlfhhrohhmpehpvghtvghrsehpjhgurdguvghv X-ME-Proxy: Feedback-ID: i9e814621:Fastmail From: Peter Delevoryas To: Cc: peter@pjd.dev, clg@kaod.org, peter.maydell@linaro.org, andrew@aj.id.au, joel@jms.id.au, hskinnemoen@google.com, kfting@nuvoton.com, qemu-arm@nongnu.org, qemu-devel@nongnu.org, philmd@linaro.org, cminyard@mvista.com Subject: [PATCH v5 3/5] hw/nvram/eeprom_at24c: Add init_rom field and at24c_eeprom_init_rom helper Date: Fri, 27 Jan 2023 22:05:41 -0800 Message-Id: <20230128060543.95582-4-peter@pjd.dev> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230128060543.95582-1-peter@pjd.dev> References: <20230128060543.95582-1-peter@pjd.dev> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=66.111.4.25; envelope-from=peter@pjd.dev; helo=out1-smtp.messagingengine.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZM-MESSAGEID: 1674886046185100005 Allows users to specify binary data to initialize an EEPROM, allowing users= to emulate data programmed at manufacturing time. - Added init_rom and init_rom_size attributes to TYPE_AT24C_EE - Added at24c_eeprom_init_rom helper function to initialize attributes - If -drive property is provided, it overrides init_rom data Signed-off-by: Peter Delevoryas Reviewed-by: Joel Stanley Reviewed-by: Corey Minyard Reviewed-by: C=C3=A9dric Le Goater Tested-by: Ninad Palsule --- hw/nvram/eeprom_at24c.c | 36 ++++++++++++++++++++++++++++----- include/hw/nvram/eeprom_at24c.h | 16 +++++++++++++++ 2 files changed, 47 insertions(+), 5 deletions(-) diff --git a/hw/nvram/eeprom_at24c.c b/hw/nvram/eeprom_at24c.c index 98857e3626b9..05598699dc2b 100644 --- a/hw/nvram/eeprom_at24c.c +++ b/hw/nvram/eeprom_at24c.c @@ -50,6 +50,9 @@ struct EEPROMState { uint8_t *mem; =20 BlockBackend *blk; + + const uint8_t *init_rom; + uint32_t init_rom_size; }; =20 static @@ -131,19 +134,37 @@ int at24c_eeprom_send(I2CSlave *s, uint8_t data) =20 I2CSlave *at24c_eeprom_init(I2CBus *bus, uint8_t address, uint32_t rom_siz= e) { - I2CSlave *i2c_dev =3D i2c_slave_new(TYPE_AT24C_EE, address); - DeviceState *dev =3D DEVICE(i2c_dev); + return at24c_eeprom_init_rom(bus, address, rom_size, NULL, 0); +} + +I2CSlave *at24c_eeprom_init_rom(I2CBus *bus, uint8_t address, uint32_t rom= _size, + const uint8_t *init_rom, uint32_t init_rom= _size) +{ + EEPROMState *s; + + s =3D AT24C_EE(i2c_slave_new(TYPE_AT24C_EE, address)); + + qdev_prop_set_uint32(DEVICE(s), "rom-size", rom_size); =20 - qdev_prop_set_uint32(dev, "rom-size", rom_size); - i2c_slave_realize_and_unref(i2c_dev, bus, &error_abort); + /* TODO: Model init_rom with QOM properties. */ + s->init_rom =3D init_rom; + s->init_rom_size =3D init_rom_size; =20 - return i2c_dev; + i2c_slave_realize_and_unref(I2C_SLAVE(s), bus, &error_abort); + + return I2C_SLAVE(s); } =20 static void at24c_eeprom_realize(DeviceState *dev, Error **errp) { EEPROMState *ee =3D AT24C_EE(dev); =20 + if (ee->init_rom_size > ee->rsize) { + error_setg(errp, "%s: init rom is larger than rom: %u > %u", + TYPE_AT24C_EE, ee->init_rom_size, ee->rsize); + return; + } + if (ee->blk) { int64_t len =3D blk_getlength(ee->blk); =20 @@ -163,6 +184,7 @@ static void at24c_eeprom_realize(DeviceState *dev, Erro= r **errp) } =20 ee->mem =3D g_malloc0(ee->rsize); + } =20 static @@ -176,6 +198,10 @@ void at24c_eeprom_reset(DeviceState *state) =20 memset(ee->mem, 0, ee->rsize); =20 + if (ee->init_rom) { + memcpy(ee->mem, ee->init_rom, MIN(ee->init_rom_size, ee->rsize)); + } + if (ee->blk) { int ret =3D blk_pread(ee->blk, 0, ee->rsize, ee->mem, 0); =20 diff --git a/include/hw/nvram/eeprom_at24c.h b/include/hw/nvram/eeprom_at24= c.h index 196db309d451..acb9857b2add 100644 --- a/include/hw/nvram/eeprom_at24c.h +++ b/include/hw/nvram/eeprom_at24c.h @@ -20,4 +20,20 @@ */ I2CSlave *at24c_eeprom_init(I2CBus *bus, uint8_t address, uint32_t rom_siz= e); =20 + +/* + * Create and realize an AT24C EEPROM device on the heap with initial data. + * @bus: I2C bus to put it on + * @address: I2C address of the EEPROM slave when put on a bus + * @rom_size: size of the EEPROM + * @init_rom: Array of bytes to initialize EEPROM memory with + * @init_rom_size: Size of @init_rom, must be less than or equal to @rom_s= ize + * + * Create the device state structure, initialize it, put it on the specifi= ed + * @bus, and drop the reference to it (the device is realized). Copies the= data + * from @init_rom to the beginning of the EEPROM memory buffer. + */ +I2CSlave *at24c_eeprom_init_rom(I2CBus *bus, uint8_t address, uint32_t rom= _size, + const uint8_t *init_rom, uint32_t init_rom= _size); + #endif --=20 2.39.0