From: Ahmad Fatoum <ahmad@a3f.at>
To: barebox@lists.infradead.org
Subject: [PATCH 5/6] sandbox: hostfile: allow probing from device tree
Date: Tue, 27 Aug 2019 16:32:38 +0200 [thread overview]
Message-ID: <20190827143239.15682-6-ahmad@a3f.at> (raw)
In-Reply-To: <20190827143239.15682-1-ahmad@a3f.at>
When testing things like barebox state in sandbox, it's nice to be able
to refer to a partition on a hostfile by phandle. Support this by
checking for reading the barebox,filename property.
Signed-off-by: Ahmad Fatoum <ahmad@a3f.at>
---
arch/sandbox/board/hostfile.c | 16 ++++--
arch/sandbox/dts/sandbox-state.dtsi | 50 +++++++++++++++++++
.../sandbox/mach-sandbox/include/mach/linux.h | 1 +
arch/sandbox/os/common.c | 5 ++
4 files changed, 68 insertions(+), 4 deletions(-)
create mode 100644 arch/sandbox/dts/sandbox-state.dtsi
diff --git a/arch/sandbox/board/hostfile.c b/arch/sandbox/board/hostfile.c
index 745f078d1a79..e5a7580d0792 100644
--- a/arch/sandbox/board/hostfile.c
+++ b/arch/sandbox/board/hostfile.c
@@ -84,15 +84,16 @@ static int hf_probe(struct device_d *dev)
if (!dev->device_node)
return -ENODEV;
- err = of_property_read_u32(dev->device_node, "barebox,fd", &priv->fd);
- if (err)
- return err;
+ of_property_read_u32(dev->device_node, "barebox,fd", &priv->fd);
err = of_property_read_string(dev->device_node, "barebox,filename",
&priv->filename);
if (err)
return err;
+ if (!priv->fd)
+ priv->fd = linux_open(priv->filename, true);
+
priv->cdev.name = dev->device_node->name;
priv->cdev.dev = dev;
priv->cdev.ops = &hf_fops;
@@ -101,7 +102,14 @@ static int hf_probe(struct device_d *dev)
dev->info = hf_info;
dev->priv = priv;
- return devfs_create(&priv->cdev);
+ err = devfs_create(&priv->cdev);
+ if (err)
+ return err;
+
+ of_parse_partitions(&priv->cdev, dev->device_node);
+ of_partitions_register_fixup(&priv->cdev);
+
+ return 0;
}
static __maybe_unused struct of_device_id hostfile_dt_ids[] = {
diff --git a/arch/sandbox/dts/sandbox-state.dtsi b/arch/sandbox/dts/sandbox-state.dtsi
new file mode 100644
index 000000000000..fc17bd078899
--- /dev/null
+++ b/arch/sandbox/dts/sandbox-state.dtsi
@@ -0,0 +1,50 @@
+/ {
+ aliases {
+ state = &state;
+ };
+
+ disk {
+ compatible = "barebox,hostfile";
+ barebox,filename = "disk";
+ reg = <0x0 0x0 0x100000>;
+
+ partitions {
+ compatible = "fixed-partitions";
+ #address-cells = <1>;
+ #size-cells = <1>;
+
+ hostfile_state: state@0 {
+ reg = <0x0 0x1000>;
+ label = "state";
+ };
+ };
+ };
+
+ state: state {
+ magic = <0xaa3b86a6>;
+ compatible = "barebox,state";
+ backend-type = "raw";
+ backend = <&hostfile_state>;
+ backend-storage-type = "direct";
+ backend-stridesize = <64>;
+
+ #address-cells = <1>;
+ #size-cells = <1>;
+ vars {
+ #address-cells = <1>;
+ #size-cells = <1>;
+
+ x {
+ reg = <0x0 0x4>;
+ type = "uint32";
+ default = <1>;
+ };
+
+ y {
+ reg = <0x4 0x4>;
+ type = "uint32";
+ default = <3>;
+ };
+ };
+ };
+};
diff --git a/arch/sandbox/mach-sandbox/include/mach/linux.h b/arch/sandbox/mach-sandbox/include/mach/linux.h
index 7d0ed55735e7..c344285473e6 100644
--- a/arch/sandbox/mach-sandbox/include/mach/linux.h
+++ b/arch/sandbox/mach-sandbox/include/mach/linux.h
@@ -10,6 +10,7 @@ struct fb_bitfield;
int linux_register_device(const char *name, void *start, void *end);
int tap_alloc(const char *dev);
uint64_t linux_get_time(void);
+int linux_open(const char *filename, int readwrite);
int linux_read(int fd, void *buf, size_t count);
int linux_read_nonblock(int fd, void *buf, size_t count);
ssize_t linux_write(int fd, const void *buf, size_t count);
diff --git a/arch/sandbox/os/common.c b/arch/sandbox/os/common.c
index a7ea8f2d3b18..86118822a177 100644
--- a/arch/sandbox/os/common.c
+++ b/arch/sandbox/os/common.c
@@ -121,6 +121,11 @@ void __attribute__((noreturn)) linux_exit(void)
exit(0);
}
+int linux_open(const char *filename, int readwrite)
+{
+ return open(filename, readwrite ? O_RDWR : O_RDONLY);
+}
+
int linux_read(int fd, void *buf, size_t count)
{
ssize_t ret;
--
2.20.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
next prev parent reply other threads:[~2019-08-27 14:33 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-08-27 14:32 [PATCH 0/6] sandbox: add HWRNG driver for host /dev/random Ahmad Fatoum
2019-08-27 14:32 ` [PATCH 1/6] sandbox: include header to provide missing prototype Ahmad Fatoum
2019-08-27 14:32 ` [PATCH 2/6] sandbox: remove unused ARCH_LINUX Kconfig symbol Ahmad Fatoum
2019-08-27 14:32 ` [PATCH 3/6] sandbox: redefine optarg and optind to avoid collisions Ahmad Fatoum
2019-08-27 14:32 ` [PATCH 4/6] sandbox: compile with symbol -fvisibility=hidden Ahmad Fatoum
2019-08-27 14:32 ` Ahmad Fatoum [this message]
2019-08-28 11:49 ` [PATCH 5/6] sandbox: hostfile: allow probing from device tree Sascha Hauer
2019-08-28 12:06 ` Ahmad Fatoum
2019-08-27 14:32 ` [PATCH 6/6] hwrng: add sandbox driver interface to host /dev/random Ahmad Fatoum
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=20190827143239.15682-6-ahmad@a3f.at \
--to=ahmad@a3f.at \
--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