mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: Ahmad Fatoum <a.fatoum@pengutronix.de>
Cc: Barebox List <barebox@lists.infradead.org>
Subject: Re: [PATCH 7/8] cdev: Add function to get unallocated start of device
Date: Tue, 12 Oct 2021 10:31:02 +0200	[thread overview]
Message-ID: <20211012083102.GO28453@pengutronix.de> (raw)
In-Reply-To: <05f86cbe-ad12-f957-8e51-58e7d9b3b830@pengutronix.de>

On Tue, Oct 12, 2021 at 09:52:51AM +0200, Ahmad Fatoum wrote:
> On 12.10.21 09:33, Sascha Hauer wrote:
> > On several SoCs barebox is written to the raw device in front of the
> > first partition. So far we blindly trust that there is enough space
> > available for the barebox image. Start changing this by adding a
> > function that retrieves the available space.
> > 
> > Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
> > ---
> >  common/partitions.c | 28 ++++++++++++++++++++++++++++
> >  include/driver.h    |  1 +
> >  2 files changed, 29 insertions(+)
> > 
> > diff --git a/common/partitions.c b/common/partitions.c
> > index d80878e065..e36341fc1e 100644
> > --- a/common/partitions.c
> > +++ b/common/partitions.c
> > @@ -156,3 +156,31 @@ int partition_parser_register(struct partition_parser *p)
> >  
> >  	return 0;
> >  }
> > +
> > +/**
> > + * cdev_unallocated_start - return unallocated space
> > + * @name: The cdev name
> > + *
> > + * This function returns the space that is not allocated by any partition
> > + * at the start of a device.
> > + *
> > + * Return: The unallocated space at the start of the device in bytes
> > + */
> > +loff_t cdev_unallocated_start(const char *name)
> 
> That name is a bit misleading. It's either cdev_allocated_start
> or cdev_unallocated_space. Also cdev_ for a function not taking a cdev
> is unexpected. Perhaps define devpath_to_cdev(s) as
> cdev_by_name(devpath_to_name(s)) and have the caller pass in the cdev?

That's a case of "wow, what a horrible name, let's write the function
first and rethink the name later". That rethinking didn't happen on my
side, thanks for doing this ;)

Sascha

-----------------------------8<-------------------------------

>From 839d934c79aee95a7d67d2f8dceacbfd0e5ea848 Mon Sep 17 00:00:00 2001
From: Sascha Hauer <s.hauer@pengutronix.de>
Date: Tue, 12 Oct 2021 09:33:51 +0200
Subject: [PATCH] cdev: Add function to get unallocated space at start of
 device

On several SoCs barebox is written to the raw device in front of the
first partition. So far we blindly trust that there is enough space
available for the barebox image. Start changing this by adding a
function that retrieves the available space.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Link: https://lore.barebox.org/20211012073352.4071559-8-s.hauer@pengutronix.de
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 common/partitions.c | 27 +++++++++++++++++++++++++++
 include/driver.h    |  1 +
 2 files changed, 28 insertions(+)

diff --git a/common/partitions.c b/common/partitions.c
index d80878e065..b579559672 100644
--- a/common/partitions.c
+++ b/common/partitions.c
@@ -156,3 +156,30 @@ int partition_parser_register(struct partition_parser *p)
 
 	return 0;
 }
+
+/**
+ * cdev_unallocated_space - return unallocated space
+ * cdev: The cdev
+ *
+ * This function returns the space that is not allocated by any partition
+ * at the start of a device.
+ *
+ * Return: The unallocated space at the start of the device in bytes
+ */
+loff_t cdev_unallocated_space(struct cdev *cdev)
+{
+	struct cdev *partcdev;
+	loff_t start;
+
+	if (!cdev)
+		return 0;
+
+	start = cdev->size;
+
+	list_for_each_entry(partcdev, &cdev->partitions, partition_entry) {
+		if (partcdev->offset < start)
+			start = partcdev->offset;
+	}
+
+	return start;
+}
diff --git a/include/driver.h b/include/driver.h
index c7f5903fce..4f6d40e17c 100644
--- a/include/driver.h
+++ b/include/driver.h
@@ -494,6 +494,7 @@ ssize_t cdev_read(struct cdev *cdev, void *buf, size_t count, loff_t offset, ulo
 ssize_t cdev_write(struct cdev *cdev, const void *buf, size_t count, loff_t offset, ulong flags);
 int cdev_ioctl(struct cdev *cdev, int cmd, void *buf);
 int cdev_erase(struct cdev *cdev, loff_t count, loff_t offset);
+loff_t cdev_unallocated_space(struct cdev *cdev);
 
 #define DEVFS_PARTITION_FIXED		(1U << 0)
 #define DEVFS_PARTITION_READONLY	(1U << 1)
-- 
2.30.2

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


  reply	other threads:[~2021-10-12  8:32 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-12  7:33 [PATCH v2 0/8] RK3568 updates Sascha Hauer
2021-10-12  7:33 ` [PATCH 1/8] phy: rockchip: Add dummy driver for child node Sascha Hauer
2021-10-12  7:33 ` [PATCH 2/8] ARM: Rockchip rk3568 EVB: Enable deep probe Sascha Hauer
2021-10-12  7:33 ` [PATCH 3/8] ARM: Rockchip: rk3568 EVB: use 64bit partition sizes Sascha Hauer
2021-10-12  7:33 ` [PATCH 4/8] phy: rockchip-inno-usb2: handle disabled child nodes gracefully Sascha Hauer
2021-10-12  7:33 ` [PATCH 5/8] usb: dwc3: reset controller before using it Sascha Hauer
2021-10-12  7:33 ` [PATCH 6/8] ARM: rk3568: Detect USB boot Sascha Hauer
2021-10-12  7:33 ` [PATCH 7/8] cdev: Add function to get unallocated start of device Sascha Hauer
2021-10-12  7:52   ` Ahmad Fatoum
2021-10-12  8:31     ` Sascha Hauer [this message]
2021-10-12  7:33 ` [PATCH 8/8] ARM: Rockchip: RK3568: implement failsafe barebox update Sascha Hauer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211012083102.GO28453@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox