diff options
author | Ahmad Fatoum <ahmad@a3f.at> | 2023-04-24 14:18:05 +0200 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2023-05-02 11:34:00 +0200 |
commit | bf680962fb8622fb11455eec493a87c8a190e5f4 (patch) | |
tree | 300c859699ec5b0721b9394657e5a52e6b2e1bd1 /arch/sandbox | |
parent | ddd65721ff2ba691facdbd651b341a97edb3bc71 (diff) | |
download | barebox-bf680962fb8622fb11455eec493a87c8a190e5f4.tar.gz barebox-bf680962fb8622fb11455eec493a87c8a190e5f4.tar.xz |
sandbox: hostfile: add feature controller support
Keeping the tradition of making the sandbox more complex than it needs
to in order to exercise more parts of barebox, let's allow hostfiles to
be feature controllers: This allows specifying optional hostfiles in the
DT: If the hostfile is unavailable, the nodes pointing at the hostfile
can be gated by it, so they behave as if they were disabled.
This is useful for the stickypage, which results in a number of ugly
errors whenever it's unavailable.
Signed-off-by: Ahmad Fatoum <ahmad@a3f.at>
Link: https://lore.barebox.org/20230424121805.150434-7-ahmad@a3f.at
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'arch/sandbox')
-rw-r--r-- | arch/sandbox/board/hostfile.c | 30 | ||||
-rw-r--r-- | arch/sandbox/configs/sandbox_defconfig | 2 | ||||
-rw-r--r-- | arch/sandbox/dts/sandbox.dts | 4 |
3 files changed, 33 insertions, 3 deletions
diff --git a/arch/sandbox/board/hostfile.c b/arch/sandbox/board/hostfile.c index 424f16acd5..d0f400787d 100644 --- a/arch/sandbox/board/hostfile.c +++ b/arch/sandbox/board/hostfile.c @@ -24,6 +24,7 @@ #include <errno.h> #include <linux/err.h> #include <mach/hostfile.h> +#include <featctrl.h> #include <xfuncs.h> struct hf_priv { @@ -33,6 +34,7 @@ struct hf_priv { }; const char *filename; int fd; + struct feature_controller feat; }; static ssize_t hf_read(struct hf_priv *priv, void *buf, size_t count, loff_t offset, ulong flags) @@ -96,18 +98,41 @@ static void hf_info(struct device *dev) printf("file: %s\n", priv->filename); } +static int hostfile_feat_check(struct feature_controller *feat, int idx) +{ + struct hf_priv *priv = container_of(feat, struct hf_priv, feat); + + return priv->fd >= 0 ? FEATCTRL_OKAY : FEATCTRL_GATED; +} + static int hf_probe(struct device *dev) { struct device_node *np = dev->of_node; struct hf_priv *priv = xzalloc(sizeof(*priv)); struct cdev *cdev; - bool is_blockdev; + bool is_featctrl = false, is_blockdev; u64 reg[2]; int err; if (!np) return -ENODEV; + dev->priv = priv; + priv->fd = -1; + + if (IS_ENABLED(CONFIG_FEATURE_CONTROLLER) && + of_property_read_bool(np, "barebox,feature-controller")) { + priv->feat.dev = dev; + priv->feat.check = hostfile_feat_check; + + err = feature_controller_register(&priv->feat); + if (err) + return err; + + is_featctrl = true; + } + + err = of_property_read_u64_array(np, "reg", reg, ARRAY_SIZE(reg)); if (err) return err; @@ -120,10 +145,9 @@ static int hf_probe(struct device *dev) return err; if (priv->fd < 0) - return priv->fd; + return is_featctrl ? 0 : priv->fd; dev->info = hf_info; - dev->priv = priv; is_blockdev = of_property_read_bool(np, "barebox,blockdev"); diff --git a/arch/sandbox/configs/sandbox_defconfig b/arch/sandbox/configs/sandbox_defconfig index 16138d9274..1bb98c550c 100644 --- a/arch/sandbox/configs/sandbox_defconfig +++ b/arch/sandbox/configs/sandbox_defconfig @@ -96,7 +96,9 @@ CONFIG_NET_NFS=y CONFIG_NET_NETCONSOLE=y CONFIG_NET_SNTP=y CONFIG_NET_FASTBOOT=y +CONFIG_FEATURE_CONTROLLER=y CONFIG_OFDEVICE=y +# CONFIG_FEATURE_CONTROLLER_FIXUP is not set CONFIG_OF_BAREBOX_DRIVERS=y CONFIG_OF_BAREBOX_ENV_IN_FS=y CONFIG_OF_OVERLAY_LIVE=y diff --git a/arch/sandbox/dts/sandbox.dts b/arch/sandbox/dts/sandbox.dts index 5b2cab219e..75c633c590 100644 --- a/arch/sandbox/dts/sandbox.dts +++ b/arch/sandbox/dts/sandbox.dts @@ -31,6 +31,8 @@ backend = <&part_state>; backend-storage-type = "direct"; backend-stridesize = <64>; + /* suppres sandbox warnings when stickypage is missing */ + barebox,feature-gates = <&stickypage>; #address-cells = <1>; #size-cells = <1>; @@ -58,6 +60,8 @@ barebox,filename = "$build/stickypage.bin"; reg = <0 0 0 4096>; barebox,cdev; /* no caching allowed */ + barebox,feature-controller; + #feature-cells = <0>; bmode: reboot-mode { compatible = "nvmem-reboot-mode"; |