Hello Sascha,

On 12.08.25 12:29, Sascha Hauer wrote:
> On Mon, Aug 11, 2025 at 02:27:40PM +0200, Ahmad Fatoum wrote:
>> This series does exactly that. Device parameters are now associated
>> with a struct bobject and that bobject can be returned and consumed
>> by commands without requiring association with a device.
>>
>> This mechanism should be able to bring support for the pipe operator
>> to barebox' shell once the critical commands are adapted to use it and
>> there exists a way for commands to report whether they support
>> structured I/O or not. As I am still figuring out how to do that,
>> I did not include a command that captures structured output to
>> a variable, but that would follow in future.
> 
> Very nice!
> 
> How about something along the lines:
> 
> struct device structio_device = {
>       .name = "structio",
>       .id = DEVICE_ID_SINGLE,
> };

bobjects already have a local flag. I think we should rather have a
bobject_export() that clears the flag on an existing object and makes
it available globally. Code will need to be adapted to loop through
global bobjects instead of devices.

Then there is the matter that:

- many commands return lists or a tree of objects (e.g. iomem,
clk_dump, findmnt), so structio should perhaps

- We will probably want an error bobject that not only holds an
error code, but also a message.

(Future teaser: Once we have support for bobject trees, every
 structio command output can be trivially formatted as JSON
 output for test suite consumption!)

> static int do_structio(int argc, char *argv[])
> {
>       int ret;
> 
>       active_capture = &structio_device.bobject;
> 
>       bobject_del(active_capture);
> 
>       /* TODO: merge argv[1-x] to a single string */
>       ret = run_command(argv[1]);

We have strjoin for that used in watch and time, but we should really
have a function that takes argv directly to avoid whitespace issues.

> static int structio_init(void)
> {
>       return register_device(&structio_device);
> }
> late_initcall(structio_init);

I was thinking of a command that you pass in the variable name and the
bobject is exported using that name. That way you can call multiple
commands to collect the results and then operate on them.

Shell variable garbage collection should in this case take care to
free the bobjects.

That command would also check if structio is even supported for the
command to be executed and fail otherwise.

That's all future work though.

Cheers,
Ahmad

> BAREBOX_CMD_START(structio)
>       .cmd            = do_structio,
>       BAREBOX_CMD_DESC("run with structio")
>       BAREBOX_CMD_GROUP(CMD_GRP_INFO)
> BAREBOX_CMD_END
> 
> With this you could do a
> 
> structio cpuinfo; echo $structio.core
> 
> We would have to replace characters like whitespaces and hyphens in the
> variablenames though.
> 
> Sascha
> 


-- 
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 |

Reply via email to