mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: Rouven Czerwinski <r.czerwinski@pengutronix.de>,
	barebox@lists.infradead.org
Subject: Re: [PATCH 2/3] blspec: add new blspec.compatible.extra variable
Date: Fri, 22 Sep 2023 07:19:09 +0200	[thread overview]
Message-ID: <df9db1d4-85cf-fae2-96ff-c2594b1d9f73@pengutronix.de> (raw)
In-Reply-To: <44d292e5-729c-f22b-9309-c0c54c7aac71@pengutronix.de>

Hi,

On 21.09.23 14:37, Ahmad Fatoum wrote:
> On 20.09.23 14:37, Rouven Czerwinski wrote:
>> The blspec.compatible.extra variable will be used to specify extra
> 
> As this is only relevant when booting. Maybe prefix with boot.?
> Not sure if that wouldn't be too long..

We may also want to use this for other stuff than blspec in future,
e.g. FIT or matching overlays by compatible, so I think we should do away
with both blspec and boot and call it maybe global.of.compatible.extra?

If you agree, please define the variable in common/misc.c or some other
common location.

> 
>> compatibles that are also used to match during bootloader specification
>> entry parsing. This means that even if your internal barebox device tree
>> machine compatible is "vendor,bareboxcompatible", but your bootloader
>> specification device tree contains "vendor,linuxcompatible", it is
>> possible to boot this entry by setting blspec.compatible.extra to
>> "vendor,linuxcompatible".
>>
>> More than one compatible is possible as well, the compatibles will need
>> to be space separated (since "," is already used for the vendor hardware
>> distinction).
>>
>> Signed-off-by: Rouven Czerwinski <r.czerwinski@pengutronix.de>
>> ---
>>  common/blspec.c | 56 +++++++++++++++++++++++++++++++++++++++++++++++++
>>  1 file changed, 56 insertions(+)
>>
>> diff --git a/common/blspec.c b/common/blspec.c
>> index f8d47f20d2..e361a02333 100644
>> --- a/common/blspec.c
>> +++ b/common/blspec.c
>> @@ -19,10 +19,20 @@
>>  #include <net.h>
>>  #include <fs.h>
>>  #include <of.h>
>> +#include <magicvar.h>
>> +#include <linux/list.h>
>>  #include <linux/stat.h>
>>  #include <linux/err.h>
>>  #include <mtd/ubi-user.h>
>>  
>> +struct list_head *blspec_extra_list;
>> +char *blspec_extra_string;
>> +
>> +struct blspec_extra_entry {
>> +	char *compatible;
>> +	struct list_head list;
>> +};
>> +
>>  /*
>>   * blspec_entry_var_set - set a variable to a value
>>   */
>> @@ -830,8 +840,54 @@ static int blspec_bootentry_provider(struct bootentries *bootentries,
>>  	return found;
>>  }
>>  
>> +static int blspec_extra_set(struct param_d *p, void *priv)
>> +{
>> +	struct blspec_extra_entry *entry, *tmp;
>> +	char *str = blspec_extra_string;
>> +	char *temp = str;
>> +	unsigned int len;
>> +
>> +	if (blspec_extra_list) {
>> +		list_for_each_entry_safe(entry, tmp, blspec_extra_list, list) {
>> +			list_del(&entry->list);
>> +			free(entry->compatible);
>> +			free(entry);
>> +		}
>> +		blspec_extra_list = NULL;
>> +	}
>> +
>> +	while(str++) {
>> +		if (*str == ' ' || *str == 0) {
> 
> Please use strsep (or strsep_unescaped) as elsewhere in blspec.c. 
> 
>> +			len = temp - str;
>> +			if(len > 126) {
>> +				len = 127;
>> +			}
>> +			entry = calloc(1, sizeof(struct blspec_extra_entry));
> 
> xzalloc if you don't check for !NULL.
> 
>> +			entry->compatible = xzalloc(len + 1);
>> +			memcpy(entry->compatible, temp, len);
> 
> But here you could just use xstrdup?
> 
>> +
>> +			if (blspec_extra_list == NULL) {
>> +				INIT_LIST_HEAD(&entry->list);
>> +				blspec_extra_list = &entry->list;
> 
> This is unusal. Why not have blspec_extra_list be a list_head instead of a pointer?
> 
>> +			} else {
>> +				list_add_tail(&entry->list, blspec_extra_list);
>> +			}
>> +
>> +			temp = str + 1;
>> +		}
>> +		if (*str == 0)
>> +			break;
>> +	}
>> +
>> +	return 0;
>> +}
>> +
>>  static int blspec_init(void)
>>  {
>> +	dev_add_param_string(&global_device, "blspec.compatible.extra",
>> +			     blspec_extra_set, NULL, &blspec_extra_string, blspec_extra_list);
>>  	return bootentry_register_provider(blspec_bootentry_provider);
>>  }
>>  device_initcall(blspec_init);
>> +
>> +BAREBOX_MAGICVAR(global.blspec.compatible.extra, "Extra compatible to also match during bootloader entry matching");
> 

-- 
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	other threads:[~2023-09-22  5:20 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-20 12:37 [PATCH 1/3] blspec: take compatible name as argument Rouven Czerwinski
2023-09-20 12:37 ` [PATCH 2/3] blspec: add new blspec.compatible.extra variable Rouven Czerwinski
2023-09-21 12:37   ` Ahmad Fatoum
2023-09-22  5:19     ` Ahmad Fatoum [this message]
2023-09-21 12:57   ` Sascha Hauer
2023-09-20 12:37 ` [PATCH 3/3] blspec: take extra entries into account Rouven Czerwinski
2023-09-21 12:33 ` [PATCH 1/3] blspec: take compatible name as argument Ahmad Fatoum
2023-09-21 12:38 ` 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=df9db1d4-85cf-fae2-96ff-c2594b1d9f73@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    --cc=r.czerwinski@pengutronix.de \
    /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