From: Fabio Estevam <festevam@gmail.com>
To: sbabic@denx.de
Cc: eduard@lionizers.com, u-boot@lists.denx.de,
Fabio Estevam <festevam@denx.de>
Subject: [PATCH v5 10/14] smegw01: Add lockdown U-Boot env support
Date: Wed, 26 Apr 2023 13:04:57 -0300 [thread overview]
Message-ID: <20230426160501.1199085-10-festevam@gmail.com> (raw)
In-Reply-To: <20230426160501.1199085-1-festevam@gmail.com>
From: Eduard Strehlau <eduard@lionizers.com>
Add lockdown U-Boot env support so that only certain U-Boot environment
variables are allowed to be modified.
Signed-off-by: Eduard Strehlau <eduard@lionizers.com>
Signed-off-by: Fabio Estevam <festevam@denx.de>
---
Changes since v4:
- None
board/storopack/smegw01/Kconfig | 7 +++++
board/storopack/smegw01/smegw01.c | 17 +++++++++++
configs/smegw01_defconfig | 11 ++++++-
include/configs/smegw01.h | 48 +++++++++++++++++++++++++++++--
4 files changed, 79 insertions(+), 4 deletions(-)
diff --git a/board/storopack/smegw01/Kconfig b/board/storopack/smegw01/Kconfig
index d8f24695d0d2..390214c285bb 100644
--- a/board/storopack/smegw01/Kconfig
+++ b/board/storopack/smegw01/Kconfig
@@ -12,4 +12,11 @@ config SYS_CONFIG_NAME
config IMX_CONFIG
default "board/storopack/smegw01/imximage.cfg"
+config SYS_BOOT_LOCKED
+ bool "Lock boot process to EMMC"
+ default y
+ help
+ Say N here if you want to boot from eMMC and SD.
+ Say Y to boot from eMMC.
+
endif
diff --git a/board/storopack/smegw01/smegw01.c b/board/storopack/smegw01/smegw01.c
index 7d4de9326d6f..e648b196b9d1 100644
--- a/board/storopack/smegw01/smegw01.c
+++ b/board/storopack/smegw01/smegw01.c
@@ -14,6 +14,7 @@
#include <asm/io.h>
#include <common.h>
#include <env.h>
+#include <env_internal.h>
#include <asm/arch/crm_regs.h>
#include <asm/setup.h>
#include <asm/bootm.h>
@@ -103,3 +104,19 @@ uint board_mmc_get_env_part(struct mmc *mmc)
part = 0;
return part;
}
+
+enum env_location env_get_location(enum env_operation op, int prio)
+{
+ if (op == ENVOP_SAVE || op == ENVOP_ERASE)
+ return ENVL_MMC;
+
+ switch (prio) {
+ case 0:
+ return ENVL_NOWHERE;
+
+ case 1:
+ return ENVL_MMC;
+ }
+
+ return ENVL_UNKNOWN;
+}
diff --git a/configs/smegw01_defconfig b/configs/smegw01_defconfig
index 54cf1cfc1f1b..ea25b3b87ce4 100644
--- a/configs/smegw01_defconfig
+++ b/configs/smegw01_defconfig
@@ -7,6 +7,7 @@ CONFIG_ENV_OFFSET=0x100000
CONFIG_DM_GPIO=y
CONFIG_DEFAULT_DEVICE_TREE="imx7d-smegw01"
CONFIG_TARGET_SMEGW01=y
+# CONFIG_SYS_BOOT_LOCKED is not set
CONFIG_ENV_OFFSET_REDUND=0x110000
CONFIG_ARMV7_BOOT_SEC_DEFAULT=y
# CONFIG_ARMV7_VIRT is not set
@@ -17,13 +18,18 @@ CONFIG_SYS_MEMTEST_START=0x80000000
CONFIG_SYS_MEMTEST_END=0xa0000000
CONFIG_FIT=y
CONFIG_FIT_VERBOSE=y
+CONFIG_AUTOBOOT_MENU_SHOW=y
+CONFIG_BOOTMENU_DISABLE_UBOOT_CONSOLE=y
CONFIG_USE_BOOTCOMMAND=y
-CONFIG_BOOTCOMMAND="if test \"${ustate}\" = 1; then setenv upgrade_available 1; saveenv; fi; if run loadimage; then run mmcboot; else run altbootcmd; fi; "
+CONFIG_BOOTCOMMAND="if test \"${ustate}\" = 1; then setenv upgrade_available 1; saveenv; fi; run mmcboot; "
+CONFIG_USE_PREBOOT=y
+CONFIG_PREBOOT="run setup_boot_menu;"
CONFIG_HUSH_PARSER=y
CONFIG_SYS_MAXARGS=32
CONFIG_SYS_PBSIZE=532
# CONFIG_CMD_BOOTD is not set
CONFIG_CMD_BOOTZ=y
+CONFIG_CMD_BOOTMENU=y
# CONFIG_CMD_IMI is not set
# CONFIG_CMD_XIMG is not set
CONFIG_CMD_MEMTEST=y
@@ -43,9 +49,12 @@ CONFIG_CMD_SQUASHFS=y
CONFIG_CMD_FS_GENERIC=y
CONFIG_OF_CONTROL=y
CONFIG_ENV_OVERWRITE=y
+CONFIG_ENV_IS_NOWHERE=y
CONFIG_SYS_REDUNDAND_ENVIRONMENT=y
CONFIG_SYS_RELOC_GD_ENV_ADDR=y
CONFIG_SYS_MMC_ENV_DEV=1
+CONFIG_ENV_WRITEABLE_LIST=y
+CONFIG_ENV_ACCESS_IGNORE_FORCE=y
CONFIG_NET_RANDOM_ETHADDR=y
CONFIG_BOUNCE_BUFFER=y
CONFIG_BOOTCOUNT_LIMIT=y
diff --git a/include/configs/smegw01.h b/include/configs/smegw01.h
index 852188327777..6f373973ab84 100644
--- a/include/configs/smegw01.h
+++ b/include/configs/smegw01.h
@@ -22,6 +22,32 @@
#define EXTRA_BOOTPARAMS
#endif
+#ifdef CONFIG_SYS_BOOT_LOCKED
+#define EXTRA_ENV_FLAGS
+#define SETUP_BOOT_MENU "setup_boot_menu=setenv bootmenu_0 eMMC=run bootcmd\0"
+#else
+#define EXTRA_ENV_FLAGS "mmcdev:dw,"
+#define SETUP_BOOT_MENU "setup_boot_menu=" \
+ "if test \"${mmcdev}\" = 1; then " \
+ "setenv emmc_priority 0;" \
+ "setenv sd_priority 1;" \
+ "else " \
+ "setenv emmc_priority 1;" \
+ "setenv sd_priority 0;" \
+ "fi;" \
+ "setenv bootmenu_${emmc_priority} eMMC=run boot_emmc;" \
+ "setenv bootmenu_${sd_priority} SD=run boot_sd;\0"
+#endif
+
+#define CFG_ENV_FLAGS_LIST_STATIC \
+ "mmcpart:dw," \
+ "mmcpart_committed:dw," \
+ "ustate:dw," \
+ "bootcount:dw," \
+ "bootlimit:dw," \
+ "upgrade_available:dw," \
+ EXTRA_ENV_FLAGS
+
#define CFG_EXTRA_ENV_SETTINGS \
"image=fitImage\0" \
"console=ttymxc0\0" \
@@ -40,13 +66,28 @@
"fi;\0" \
"bootlimit=3\0" \
"fit_addr=0x88000000\0" \
- "loadimage=load mmc ${mmcdev}#rootfs-${mmcpart_committed} ${fit_addr} boot/${image}\0" \
+ "loadimage=load mmc ${mmcdev}:${gpt_partition_entry} ${fit_addr} boot/${image}\0" \
"loadpart=gpt setenv mmc ${mmcdev} rootfs-${mmcpart_committed}\0" \
"loadbootpart=mmc partconf 1 boot_part\0" \
- "mmcboot=echo Booting from mmc ...; " \
+ "boot_sd=setenv mmcdev_wanted 0; run persist_mmcdev; run bootcmd;\0" \
+ "boot_emmc=setenv mmcdev_wanted 1; run persist_mmcdev; run bootcmd;\0" \
+ "persist_mmcdev=" \
+ "if test \"${mmcdev}\" != \"${mmcdev_wanted}\"; then " \
+ "setenv mmcdev \"${mmcdev_wanted}\";" \
+ "saveenv;" \
+ "fi;\0" \
+ "mmcboot=echo Booting...; " \
+ "echo mmcdev: ${mmcdev}; " \
"run commit_mmc; " \
+ "echo mmcpart: ${mmcpart_committed}; " \
"run loadpart; " \
+ "echo gptpart: ${gpt_partition_entry}; " \
"run loadbootpart; " \
+ "if run loadimage; then " \
+ "; " \
+ "else " \
+ "run altbootcmd; " \
+ "fi; " \
"run mmcargs; " \
"if bootm ${fit_addr}; then " \
"; " \
@@ -61,7 +102,8 @@
"setenv mmcpart 1; " \
"setenv mmcpart_committed 1;" \
"fi; setenv bootcount 0; setenv upgrade_available; setenv ustate 3; saveenv; " \
- "run bootcmd;\0"
+ "run bootcmd;\0" \
+ SETUP_BOOT_MENU
/* Physical Memory Map */
#define PHYS_SDRAM MMDC0_ARB_BASE_ADDR
--
2.34.1
next prev parent reply other threads:[~2023-04-26 16:07 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-26 16:04 [PATCH v5 01/14] smegw01: Enable setting additional boot params Fabio Estevam
2023-04-26 16:04 ` [PATCH v5 02/14] smegw01: Select CONFIG_CMD_SQUASHFS Fabio Estevam
2023-05-02 12:46 ` sbabic
2023-04-26 16:04 ` [PATCH v5 03/14] smegw01: Select bootcount support Fabio Estevam
2023-05-02 12:46 ` sbabic
2023-04-26 16:04 ` [PATCH v5 04/14] smegw01: Add altbootcmd Fabio Estevam
2023-05-02 12:47 ` sbabic
2023-04-26 16:04 ` [PATCH v5 05/14] smegw01: Run altbootcmd in the case of failure Fabio Estevam
2023-05-02 12:47 ` sbabic
2023-04-26 16:04 ` [PATCH v5 06/14] smegw01: Only commit to new partition if update was successful Fabio Estevam
2023-05-02 12:47 ` sbabic
2023-04-26 16:04 ` [PATCH v5 07/14] smegw01: Enable EMMC boot from multiple partitions Fabio Estevam
2023-05-02 12:47 ` sbabic
2023-04-26 16:04 ` [PATCH v5 08/14] smegw01: Change default boot device to eMMC Fabio Estevam
2023-05-02 12:46 ` sbabic
2023-04-26 16:04 ` [PATCH v5 09/14] smegw01: Switch to fitImage Fabio Estevam
2023-05-02 12:47 ` sbabic
2023-04-26 16:04 ` Fabio Estevam [this message]
2023-05-02 12:47 ` [PATCH v5 10/14] smegw01: Add lockdown U-Boot env support sbabic
2023-04-26 16:04 ` [PATCH v5 11/14] smegw01: Read the second MAC address Fabio Estevam
2023-05-02 12:46 ` sbabic
2023-04-26 16:04 ` [PATCH v5 12/14] smegw01: Disable additional boot menu options Fabio Estevam
2023-05-02 12:47 ` sbabic
2023-04-26 16:05 ` [PATCH v5 13/14] smegw01: Fix fallback to altbootcmd Fabio Estevam
2023-05-02 12:46 ` sbabic
2023-04-26 16:05 ` [PATCH v5 14/14] smegw01: Convert CFG_EXTRA_ENV_SETTINGS to an env file Fabio Estevam
2023-04-26 17:31 ` Tom Rini
2023-05-02 12:47 ` sbabic
2023-05-02 12:47 ` [PATCH v5 01/14] smegw01: Enable setting additional boot params sbabic
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=20230426160501.1199085-10-festevam@gmail.com \
--to=festevam@gmail.com \
--cc=eduard@lionizers.com \
--cc=festevam@denx.de \
--cc=sbabic@denx.de \
--cc=u-boot@lists.denx.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