Received: from list by lists.gnu.org with archive (Exim 4.71) id 1glstH-0001CY-Ov for mharc-grub-devel@gnu.org; Tue, 22 Jan 2019 05:02:43 -0500 Received: from eggs.gnu.org ([209.51.188.92]:38597) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1glstA-00015l-8A for grub-devel@gnu.org; Tue, 22 Jan 2019 05:02:42 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1glst9-0007Rg-8a for grub-devel@gnu.org; Tue, 22 Jan 2019 05:02:36 -0500 Received: from mail-wm1-x343.google.com ([2a00:1450:4864:20::343]:54536) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1glst8-0007QD-W0 for grub-devel@gnu.org; Tue, 22 Jan 2019 05:02:35 -0500 Received: by mail-wm1-x343.google.com with SMTP id a62so13478751wmh.4 for ; Tue, 22 Jan 2019 02:02:34 -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=KtVdCRDkcZ2bLNE+UO+9xk0GWmr8Zu93/VsbcJ+LD3I=; b=b6sOmYg5mw6v+wgez7mRJzFB9+Lo9nf7k1sPPZtNnx3JZOT828u/6ITAjaw0K7S/WX 7JrBC1SMPAWCNJYqzSvaUhV7nsqnkKpyy+95+mHr7EH5kLpaXUktZl6k56STDyS+V2yN ZnerDo/5LoNtcbaPkeWnnrsMuZnhwMaDyeWTbgDH//ISs0C0Xi6AJ/ACR7GOjD5iXdFA 96K4pZYeTxEF6iKTikGwCA14234Y/zcw1QKr9zZOjomgNZuHw7aGmoxTYuEPr6Jl3rXE JRMw+J3JyPJ7VCY98hZNPcK09OUsI0JMjz+iPpb7erOICsX3Kc3r58J0w3RngoH9QzBC XjLQ== 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=KtVdCRDkcZ2bLNE+UO+9xk0GWmr8Zu93/VsbcJ+LD3I=; b=Z/zO7AV2NijF+an3kt2pNEdjba6skyCjprDXXso0a2TaJzVlW6VDeKPl5e3aXvNrW0 qIqeMkmiFGYEGI9G5pmkiRh637elc+WvWeIIGXZz+Ror3h2nO97jUb4hQ1k1fWeX3ZCq G2CBlLJT6VUdCykvDwLwcDBgRpGcdqv5LynAe6JFXEQquTcgdFf0vdTVPokV1LbX/tnH 8nx2xDoUgqKQYt3CpqZKSNJtIBrJHNqSqe06scOVHnR21v487ZpaqsHOr97MM+W7sQL4 J3XSVcPP4XRdx+C0Fw4rV7PBHKowSnipZgvvyvq+kyIOB6sv1R24o/+D+1btVY+s87O2 o+pw== X-Gm-Message-State: AJcUukdh/peXNh5HbCpBQqoEzniAknsNxhqLCtoGpNVEZ5FQfnBvYbTg fEBbMf2hMzp+EZSTCBGaNr0glDAADqE= X-Google-Smtp-Source: ALg8bN589CbqfTdmHMRu/H3kA5pNp36QptSMhBr7sYvkitEnT2XSda3e4qyjsdpI1Ghv+gPigw3nkQ== X-Received: by 2002:a1c:7d06:: with SMTP id y6mr2926860wmc.7.1548151352912; Tue, 22 Jan 2019 02:02:32 -0800 (PST) Received: from localhost.localdomain ([79.118.151.254]) by smtp.gmail.com with ESMTPSA id 3sm65914244wmw.46.2019.01.22.02.02.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 22 Jan 2019 02:02:31 -0800 (PST) From: Cristian Ciocaltea To: The development of GNU GRUB Cc: Daniel Kiper , Cristian Ciocaltea Subject: [PATCH v2] uboot: Add the missing disk write operation support Date: Tue, 22 Jan 2019 12:02:10 +0200 Message-Id: <20190122100210.26426-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::343 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, 22 Jan 2019 10:02:42 -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 Reviewed-by: Daniel Kiper --- Changes since v1: * Fix compiler error when building with '-Werror=discarded-qualifiers': passing argument 2 of 'grub_uboot_dev_write' discards 'const' qualifier from pointer target type 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..3631c044e 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, const 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..353ad51c0 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, const 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