From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id BA469C433EF for ; Thu, 12 May 2022 08:44:44 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 939E584368; Thu, 12 May 2022 10:44:41 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="vziGq7q4"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id F20E08438D; Thu, 12 May 2022 10:44:38 +0200 (CEST) Received: from mail-pf1-x42b.google.com (mail-pf1-x42b.google.com [IPv6:2607:f8b0:4864:20::42b]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 720C484216 for ; Thu, 12 May 2022 10:44:34 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=takahiro.akashi@linaro.org Received: by mail-pf1-x42b.google.com with SMTP id p8so4175518pfh.8 for ; Thu, 12 May 2022 01:44:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:mail-followup-to:references :mime-version:content-disposition:in-reply-to; bh=pTDKcCYnbRA5FDlGrkReVBRnWQEkJButP0fz5JdlIqk=; b=vziGq7q4KJ6iVtvZUzRfVHmb+7GTBd2tVtNaWftXgBmlFvCQvM3xepr0fv16JEKH0x c2IiMZ7+G1+YjDwxSiUzODRaDlaMt8heMihB00amB39fUYl3FmivmWoKr4z7fV1rFIgY c01o7bBIoka3T/kaN2dRQBjhG3XUWTufmtEB5QCdBBKCY8Cv39I3SSf3o4M+6nv765TE 3Z3jd2wc8p62U5Pg+K52uya/CCu+tGoiB3eUpZPTFginqSTkKR2JY+UUUHJpaD+WbXRd SQkLnQlDcFrLRO6w7yh+H6zp8Ja0LoK8UwNSeudAjFgJ+iZPm0oRFOqTzZckn1241Z7k yDPg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id :mail-followup-to:references:mime-version:content-disposition :in-reply-to; bh=pTDKcCYnbRA5FDlGrkReVBRnWQEkJButP0fz5JdlIqk=; b=hh5Gl5TG6oIGBddHQXUy3bFbR6MjmJEsnobuMUn2leRVz8jlSA0wBJu8fIWKUfDN6g LTw7N4XCjr2m8nDAbEbK27l5Rf9J2BjM+GKERyKx9ipk/j/Uidu2l6rndUa30j70zSdz 89+bGcrXEkn5WWDwceDl/OMaP5qYbr3NOoOVaMS9PGxA46C5h0DQloWoe366k5JMSnjl dQ9+0VgzDHH7iPgntGvMtU0gCOn3tI0kgwMWJJiNBRpEynTm801hHhjv2yeYLx4SyeEL FYLt8IAKKFor4vjYJ0S/Huao8irImjFrvGjgwaJoimHKcaBj7TENGjvgjcQiBsfhWHIY Inbg== X-Gm-Message-State: AOAM531cNI5ugL/dFks61+VfW388AaBHvPSnHyApoOD9f1tABJrcnOwg 4egGfsxOSxCCqip6U7PzAgrHQA== X-Google-Smtp-Source: ABdhPJwgtlVea1HR9f4snpn4Dthuzr/B/SJKOE9e0az0RadkWLLM5b/Nh23sq0q2dKgn8C75AsFSQw== X-Received: by 2002:a63:2317:0:b0:3c1:f437:2e7c with SMTP id j23-20020a632317000000b003c1f4372e7cmr23815657pgj.351.1652345072683; Thu, 12 May 2022 01:44:32 -0700 (PDT) Received: from laputa ([2400:4050:c3e1:100:f5e6:8e26:8fc:a1db]) by smtp.gmail.com with ESMTPSA id y128-20020a62ce86000000b0050dc76281d4sm3257681pfg.174.2022.05.12.01.44.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 May 2022 01:44:32 -0700 (PDT) Date: Thu, 12 May 2022 17:44:28 +0900 From: Takahiro Akashi To: Heinrich Schuchardt Cc: Masahisa Kojima , u-boot@lists.denx.de, Ilias Apalodimas , Simon Glass , Francois Ozog , Mark Kettenis Subject: Re: [PATCH v5 10/17] bootmenu: add distro boot entry Message-ID: <20220512084428.GA90900@laputa> Mail-Followup-To: Takahiro Akashi , Heinrich Schuchardt , Masahisa Kojima , u-boot@lists.denx.de, Ilias Apalodimas , Simon Glass , Francois Ozog , Mark Kettenis References: <20220428080950.23509-1-masahisa.kojima@linaro.org> <20220428080950.23509-11-masahisa.kojima@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.5 at phobos.denx.de X-Virus-Status: Clean On Sun, May 01, 2022 at 11:48:40PM +0200, Heinrich Schuchardt wrote: > On 4/28/22 10:09, Masahisa Kojima wrote: > > This commit adds the distro_boot entries into the bootmenu. > > The bootmenu read the "boot_targets" U-Boot environment variable > > and enumerate it. > > User can select the distro boot entry, then bootmenu executes > > "run bootcmd_xxx" command. > > > > The bootmenu also checks the existing block devices and network > > option("dhcp" and "pxe") availability, then filter out > > the "boot_targets" appeared in bootmenu. > > > > The bootmenu example is as follows, distro boot entry has the > > "distro_boot" prefix. > > > > *** U-Boot Boot Menu *** > > > > distro_boot : usb0 > > distro_boot : scsi0 > > distro_boot : virtio0 > > distro_boot : dhcp > > You will be creating UEFI boot options for all block devices anyway. > We should avoid duplicate entries. Please, drop this patch. Nak A distro entry should work, searching not only for a default UEFI file but also sysboot (extlinux.conf) and boot scripts. > Best regards > > heinrich > > > > > Signed-off-by: Masahisa Kojima > > --- > > Changes in v5: > > - split into the separate patch > > - add function description comment > > - handle the case boot_targets variable is empty > > - filter out the non-exist device entry > > > > cmd/bootmenu.c | 177 +++++++++++++++++++++++++++++++++++++++++++++++++ > > 1 file changed, 177 insertions(+) > > > > diff --git a/cmd/bootmenu.c b/cmd/bootmenu.c > > index da688e6213..afe42b8041 100644 > > --- a/cmd/bootmenu.c > > +++ b/cmd/bootmenu.c > > @@ -7,6 +7,7 @@ > > #include > > #include > > #include > > +#include > > #include > > #include > > #include > > @@ -14,6 +15,7 @@ > > #include > > #include > > #include > > +#include > > #include > > #include > > > > @@ -31,6 +33,7 @@ enum boot_type { > > BOOTMENU_TYPE_NONE = 0, > > BOOTMENU_TYPE_BOOTMENU, > > BOOTMENU_TYPE_UEFI_BOOT_OPTION, > > + BOOTMENU_TYPE_DISTRO_BOOT, > > }; > > > > struct bootmenu_entry { > > @@ -90,6 +93,8 @@ static void bootmenu_print_entry(void *data) > > printf("bootmenu_%02d : %ls", entry->bootorder, entry->title); > > else if (entry->type == BOOTMENU_TYPE_UEFI_BOOT_OPTION) > > printf("UEFI BOOT%04X : %ls", entry->bootorder, entry->title); > > + else if (entry->type == BOOTMENU_TYPE_DISTRO_BOOT) > > + printf("distro_boot : %ls", entry->title); > > else > > printf("%ls", entry->title); > > > > @@ -465,6 +470,172 @@ static int prepare_uefi_bootorder_entry(struct bootmenu_data *menu, > > return 1; > > } > > > > +static int is_blk_device_available(char *token) > > +{ > > + struct driver *d = ll_entry_start(struct driver, driver); > > + const int n_ents = ll_entry_count(struct driver, driver); > > + struct driver *entry; > > + struct udevice *udev; > > + struct uclass *uc; > > + struct blk_desc *desc; > > + int ret, i; > > + const char *if_type_name; > > + > > + ret = uclass_get(UCLASS_BLK, &uc); > > + if (ret) > > + return -ENODEV; > > + > > + for (entry = d; entry < d + n_ents; entry++) { > > + if (entry->id != UCLASS_BLK) > > + continue; > > + i = 0; > > + uclass_foreach_dev(udev, uc) { > > + if (udev->driver != entry) > > + continue; > > + desc = dev_get_uclass_plat(udev); > > + if_type_name = blk_get_if_type_name(desc->if_type); > > + if (strncmp(token, if_type_name, strlen(if_type_name)) == 0) { > > + char *p; > > + int j, len; > > + int devnum = 0; > > + > > + p = token + strlen(if_type_name); > > + len = strlen(p); > > + if (!len) > > + continue; /* no device number */ > > + > > + for (j = 0; j < len; j++) { > > + if (!isdigit(*p)) { > > + /* invalid device number */ > > + devnum = INT_MAX; > > + break; > > + } > > + devnum = (devnum * 10) + (*p++ - '0'); > > + } > > + > > + if (devnum == INT_MAX) > > + continue; > > + > > + if (devnum == desc->devnum) > > + return 1; > > + } > > + } > > + } > > + > > + if (strncmp(token, "dhcp", strlen("dhcp")) == 0) { > > + if (IS_ENABLED(CONFIG_CMD_DHCP)) > > + return 1; > > + } > > + > > + if (strncmp(token, "pxe", strlen("pxe")) == 0) { > > + if (IS_ENABLED(CONFIG_CMD_PXE)) > > + return 1; > > + } > > + > > + return -ENODEV; > > +} > > + > > +/** > > + * prepare_distro_boot_entry() - generate the distro boot entries > > + * > > + * This function read the "boot_targets" U-Boot environment variable > > + * and generate the bootmenu entries. > > + * > > + * @menu: pointer to the bootmenu structure > > + * @current: pointer to the last bootmenu entry list > > + * @index: pointer to the index of the last bootmenu entry, > > + * the number of uefi entry is added by this function > > + * Return: 1 on success, negative value on error > > + */ > > +static int prepare_distro_boot_entry(struct bootmenu_data *menu, > > + struct bootmenu_entry **current, > > + unsigned short int *index) > > +{ > > + char *p; > > + int len; > > + char *token; > > + char *boot_targets; > > + unsigned short int i = *index; > > + struct bootmenu_entry *entry = NULL; > > + struct bootmenu_entry *iter = *current; > > + > > + /* list the distro boot "boot_targets" */ > > + boot_targets = env_get("boot_targets"); > > + if (!boot_targets) > > + return -ENOENT; > > + > > + len = strlen(boot_targets); > > + if (!len) > > + return -ENOENT; > > + > > + p = calloc(1, len + 1); > > + strlcpy(p, boot_targets, len); > > + > > + token = strtok(p, " "); > > + > > + do { > > + u16 *buf; > > + char *command; > > + int command_size; > > + > > + if (is_blk_device_available(token) != 1) { > > + token = strtok(NULL, " "); > > + continue; > > + } > > + > > + entry = malloc(sizeof(struct bootmenu_entry)); > > + if (!entry) { > > + free(p); > > + return -ENOMEM; > > + } > > + > > + len = strlen(token); > > + buf = calloc(1, (len + 1) * sizeof(u16)); > > + entry->title = buf; > > + if (!entry->title) { > > + free(entry); > > + free(p); > > + return -ENOMEM; > > + } > > + utf8_utf16_strncpy(&buf, token, len); > > + sprintf(entry->key, "%d", i); > > + entry->num = i; > > + entry->menu = menu; > > + > > + command_size = sizeof("run bootcmd_") + len; > > + command = calloc(1, command_size); > > + if (!command) { > > + free(entry->title); > > + free(entry); > > + free(p); > > + return -ENOMEM; > > + } > > + snprintf(command, command_size, "run bootcmd_%s", token); > > + entry->command = command; > > + entry->type = BOOTMENU_TYPE_DISTRO_BOOT; > > + entry->next = NULL; > > + > > + if (!iter) > > + menu->first = entry; > > + else > > + iter->next = entry; > > + > > + iter = entry; > > + i++; > > + > > + if (i == MAX_COUNT - 1) > > + break; > > + > > + token = strtok(NULL, " "); > > + } while (token); > > + > > + free(p); > > + *index = i; > > + *current = iter; > > + > > + return 1; > > +} > > + > > static struct bootmenu_data *bootmenu_create(int delay) > > { > > int ret; > > @@ -498,6 +669,12 @@ static struct bootmenu_data *bootmenu_create(int delay) > > } > > } > > > > + if (i < MAX_COUNT - 1) { > > + ret = prepare_distro_boot_entry(menu, &iter, &i); > > + if (ret < 0 && ret != -ENOENT) > > + goto cleanup; > > + } > > + > > /* Add U-Boot console entry at the end */ > > if (i <= MAX_COUNT - 1) { > > entry = malloc(sizeof(struct bootmenu_entry)); >