Received: from list by lists.gnu.org with archive (Exim 4.71) id 1gjQCh-0002Hi-NZ for mharc-grub-devel@gnu.org; Tue, 15 Jan 2019 10:00:35 -0500 Received: from eggs.gnu.org ([209.51.188.92]:48356) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gjQCW-0002CW-5Q for grub-devel@gnu.org; Tue, 15 Jan 2019 10:00:34 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gjQCU-0007eI-T7 for grub-devel@gnu.org; Tue, 15 Jan 2019 10:00:24 -0500 Received: from mail-wm1-x342.google.com ([2a00:1450:4864:20::342]:34869) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gjQCU-0007dB-Ik for grub-devel@gnu.org; Tue, 15 Jan 2019 10:00:22 -0500 Received: by mail-wm1-x342.google.com with SMTP id t200so3562984wmt.0 for ; Tue, 15 Jan 2019 07:00:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=adU48kzI/WMzGVk6Clze9mkcPwGyemohIifsjEh45u8=; b=OHFFXVLQBQX6p4q884qo5jTUyK2e9VhoYRoy+CeKz6UTth4HPdu7mhIeINpgIKJKlT 7dPqO4yyfLMfD8t+txEKddWKCVzSNCSjd7O33NghRfv6G5HZLZzyqxdi3UC5ghfbGQJc WAcAVfRx6kTApwOuxcY38uhJQJqFvyxYcy3FmsQCHQnhaKk8AYUdY36z2IQ5jxZDCApG uhe70kKQWwON5A0L2fZKBQtoVpD6W4b+F6iA1pZocEO75aBqcNMamQ9Ex+moNfkkgTV2 HqAITeNq++N3vvIaZ4q4aUQ6DVTaqVEuooaP1/vtP19zy234pd+JDqw4wqtKQcY5SmTd T+TA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=adU48kzI/WMzGVk6Clze9mkcPwGyemohIifsjEh45u8=; b=VwfHn1jXmUGXTKuTbyIQTO3SiKZqbt2OYk3Zt4LCTHHmf9CiIS/M9FnzXn/W/mNx7p gWCLiah4Dp+BX6EPxjHc8kV/c4gH2NLdIGQGZwQgoh9ndZjialvctXQiv7FoLpQAqEv7 5UuNGG+h37z1jqR+FYYRNtiSNqNJpiNXj90vh7gESHgHB0ikx0me1OQtbMX44f7uEIsl u/YFDog0Tp0wSkzKDVhCqlzILWlTLzv2p4vfbrldRT7c9AxWGUPirFSaHnYwKKaDp9rt A96ZU16mpyo6Dlyjjs8kLpenyHfeBTkR/maqjl+ugWLyipiAEYwhddeCCkaXVdPKNxwM HCWw== X-Gm-Message-State: AJcUukcXk9QhSeUPJfua9JsLaOQrgAS1dcSZ4b7Q2m+/afJ15PBumfQA wW5CZDaa6wmsZxuAjGand9zMe18Ps7k= X-Google-Smtp-Source: ALg8bN7sk1krACVJLlcjTZZLzVCHRluzgn0Wwxm0bnZjtbzu1c8PAkuZym3+3vtAGTDxBRwpYMoLRg== X-Received: by 2002:a1c:2d4b:: with SMTP id t72mr3444719wmt.99.1547564420354; Tue, 15 Jan 2019 07:00:20 -0800 (PST) Received: from localhost.localdomain ([79.118.151.254]) by smtp.gmail.com with ESMTPSA id l6sm76463243wrv.70.2019.01.15.07.00.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 15 Jan 2019 07:00:19 -0800 (PST) From: Cristian Ciocaltea To: The development of GNU GRUB Cc: Cristian Ciocaltea Subject: [PATCH] uboot: Add the missing disk write operation support Date: Tue, 15 Jan 2019 16:59:56 +0200 Message-Id: <20190115145956.21088-1-cristian.ciocaltea@gmail.com> X-Mailer: git-send-email 2.17.1 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::342 X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 15 Jan 2019 15:00:34 -0000 uboot_disk_write() is currently lacking the write support to storage devices because, historically, those devices did not implement block_write() in U-Boot. The solution has been tested using a patched U-Boot loading and booting GRUB in a QEMU vexpress-a9 environment. The disk write operations were triggered with GRUB's save_env command. Signed-off-by: Cristian Ciocaltea --- grub-core/disk/uboot/ubootdisk.c | 22 ++++++++++++++++------ grub-core/kern/uboot/uboot.c | 16 ++++++++++++++++ include/grub/uboot/uboot.h | 3 ++- 3 files changed, 34 insertions(+), 7 deletions(-) diff --git a/grub-core/disk/uboot/ubootdisk.c b/grub-core/disk/uboot/ubootdisk.c index a5ce07a99..584a9cbdf 100644 --- a/grub-core/disk/uboot/ubootdisk.c +++ b/grub-core/disk/uboot/ubootdisk.c @@ -264,13 +264,23 @@ uboot_disk_read (struct grub_disk *disk, } static grub_err_t -uboot_disk_write (struct grub_disk *disk __attribute__ ((unused)), - grub_disk_addr_t sector __attribute__ ((unused)), - grub_size_t size __attribute__ ((unused)), - const char *buf __attribute__ ((unused))) +uboot_disk_write (struct grub_disk *disk, + grub_disk_addr_t offset, grub_size_t numblocks, const char *buf) { - return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET, - "attempt to write (not supported)"); + struct ubootdisk_data *d; + int retval; + + d = disk->data; + + retval = grub_uboot_dev_write (d->dev, buf, numblocks, offset); + grub_dprintf ("ubootdisk", + "retval=%d, numblocks=%d, sector=%llu\n", + retval, numblocks, (grub_uint64_t) offset); + + if (retval != 0) + return grub_error (GRUB_ERR_IO, "U-Boot disk write error"); + + return GRUB_ERR_NONE; } static struct grub_disk_dev grub_ubootdisk_dev = { diff --git a/grub-core/kern/uboot/uboot.c b/grub-core/kern/uboot/uboot.c index cf0168e62..bb236bcdf 100644 --- a/grub-core/kern/uboot/uboot.c +++ b/grub-core/kern/uboot/uboot.c @@ -243,6 +243,22 @@ grub_uboot_dev_read (struct device_info *dev, void *buf, grub_size_t blocks, return retval; } +int +grub_uboot_dev_write (struct device_info *dev, void *buf, grub_size_t blocks, + grub_uint32_t start) +{ + int retval; + + if (!OPEN_DEV (dev)) + return -1; + + if (!grub_uboot_syscall (API_DEV_WRITE, &retval, dev, buf, + &blocks, &start)) + return -1; + + return retval; +} + int grub_uboot_dev_recv (struct device_info *dev, void *buf, int size, int *real_size) diff --git a/include/grub/uboot/uboot.h b/include/grub/uboot/uboot.h index c122de6ab..5aba7c35e 100644 --- a/include/grub/uboot/uboot.h +++ b/include/grub/uboot/uboot.h @@ -72,7 +72,8 @@ int EXPORT_FUNC (grub_uboot_dev_enum) (void); struct device_info * EXPORT_FUNC (grub_uboot_dev_get) (int index); int EXPORT_FUNC (grub_uboot_dev_open) (struct device_info *dev); int EXPORT_FUNC (grub_uboot_dev_close) (struct device_info *dev); -int grub_uboot_dev_write (struct device_info *dev, void *buf, int *len); +int grub_uboot_dev_write (struct device_info *dev, void *buf, grub_size_t blocks, + grub_uint32_t start); int grub_uboot_dev_read (struct device_info *dev, void *buf, grub_size_t blocks, grub_uint32_t start, grub_size_t * real_blocks); int EXPORT_FUNC (grub_uboot_dev_recv) (struct device_info *dev, void *buf, -- 2.17.1