summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
Diffstat (limited to 'common')
-rw-r--r--common/Makefile1
-rw-r--r--common/avb_verify.c89
-rw-r--r--common/bloblist.c85
-rw-r--r--common/board_f.c13
-rw-r--r--common/button_cmd.c83
-rw-r--r--common/log.c5
-rw-r--r--common/main.c3
-rw-r--r--common/spl/spl.c3
-rw-r--r--common/usb_hub.c6
9 files changed, 241 insertions, 47 deletions
diff --git a/common/Makefile b/common/Makefile
index f010c2a1b9b..e9835473420 100644
--- a/common/Makefile
+++ b/common/Makefile
@@ -12,6 +12,7 @@ obj-y += cli_getch.o cli_simple.o cli_readline.o
obj-$(CONFIG_HUSH_OLD_PARSER) += cli_hush.o
obj-$(CONFIG_HUSH_MODERN_PARSER) += cli_hush_modern.o
obj-$(CONFIG_AUTOBOOT) += autoboot.o
+obj-$(CONFIG_BUTTON_CMD) += button_cmd.o
obj-y += version.o
# # boards
diff --git a/common/avb_verify.c b/common/avb_verify.c
index 48ba8db51e5..cff9117d92f 100644
--- a/common/avb_verify.c
+++ b/common/avb_verify.c
@@ -1,7 +1,6 @@
+// SPDX-License-Identifier: GPL-2.0+
/*
* (C) Copyright 2018, Linaro Limited
- *
- * SPDX-License-Identifier: GPL-2.0+
*/
#include <avb_verify.h>
@@ -120,6 +119,55 @@ static const unsigned char avb_root_pub[1032] = {
0xd8, 0x7e,
};
+const char *str_avb_io_error(AvbIOResult res)
+{
+ switch (res) {
+ case AVB_IO_RESULT_OK:
+ return "Requested operation was successful";
+ case AVB_IO_RESULT_ERROR_IO:
+ return "Underlying hardware encountered an I/O error";
+ case AVB_IO_RESULT_ERROR_OOM:
+ return "Unable to allocate memory";
+ case AVB_IO_RESULT_ERROR_NO_SUCH_PARTITION:
+ return "Requested partition does not exist";
+ case AVB_IO_RESULT_ERROR_RANGE_OUTSIDE_PARTITION:
+ return "Bytes requested is outside the range of partition";
+ case AVB_IO_RESULT_ERROR_NO_SUCH_VALUE:
+ return "Named persistent value does not exist";
+ case AVB_IO_RESULT_ERROR_INVALID_VALUE_SIZE:
+ return "Named persistent value size is not supported";
+ case AVB_IO_RESULT_ERROR_INSUFFICIENT_SPACE:
+ return "Buffer is too small for the requested operation";
+ default:
+ return "Unknown AVB error";
+ }
+}
+
+const char *str_avb_slot_error(AvbSlotVerifyResult res)
+{
+ switch (res) {
+ case AVB_SLOT_VERIFY_RESULT_OK:
+ return "Verification passed successfully";
+ case AVB_SLOT_VERIFY_RESULT_ERROR_OOM:
+ return "Allocation of memory failed";
+ case AVB_SLOT_VERIFY_RESULT_ERROR_IO:
+ return "I/O error occurred while trying to load data";
+ case AVB_SLOT_VERIFY_RESULT_ERROR_VERIFICATION:
+ return "Digest didn't match or signature checks failed";
+ case AVB_SLOT_VERIFY_RESULT_ERROR_ROLLBACK_INDEX:
+ return "Rollback index is less than its stored value";
+ case AVB_SLOT_VERIFY_RESULT_ERROR_PUBLIC_KEY_REJECTED:
+ return "Public keys are not accepted";
+ case AVB_SLOT_VERIFY_RESULT_ERROR_INVALID_METADATA:
+ return "Metadata is invalid or inconsistent";
+ case AVB_SLOT_VERIFY_RESULT_ERROR_UNSUPPORTED_VERSION:
+ return "Metadata requires a newer version of libavb";
+ case AVB_SLOT_VERIFY_RESULT_ERROR_INVALID_ARGUMENT:
+ return "Invalid arguments are used";
+ default:
+ return "Unknown AVB slot verification error";
+ }
+}
/**
* ============================================================================
* Boot states support (GREEN, YELLOW, ORANGE, RED) and dm_verity
@@ -280,9 +328,9 @@ static unsigned long mmc_read_and_flush(struct mmc_part *part,
* Reading fails on unaligned buffers, so we have to
* use aligned temporary buffer and then copy to destination
*/
-
if (unaligned) {
- printf("Handling unaligned read buffer..\n");
+ debug("%s: handling unaligned read buffer, addr = 0x%p\n",
+ __func__, buffer);
tmp_buf = get_sector_buf();
buf_size = get_sector_buf_size();
if (sectors > buf_size / part->info.blksz)
@@ -321,7 +369,8 @@ static unsigned long mmc_write(struct mmc_part *part, lbaint_t start,
if (unaligned) {
tmp_buf = get_sector_buf();
buf_size = get_sector_buf_size();
- printf("Handling unaligned wrire buffer..\n");
+ debug("%s: handling unaligned read buffer, addr = 0x%p\n",
+ __func__, buffer);
if (sectors > buf_size / part->info.blksz)
sectors = buf_size / part->info.blksz;
@@ -349,28 +398,35 @@ static struct mmc_part *get_partition(AvbOps *ops, const char *partition)
dev_num = get_boot_device(ops);
part->mmc = find_mmc_device(dev_num);
if (!part->mmc) {
- printf("No MMC device at slot %x\n", dev_num);
+ printf("%s: no MMC device at slot %x\n", __func__, dev_num);
goto err;
}
- if (mmc_init(part->mmc)) {
- printf("MMC initialization failed\n");
+ ret = mmc_init(part->mmc);
+ if (ret) {
+ printf("%s: MMC initialization failed, err = %d\n",
+ __func__, ret);
goto err;
}
- ret = mmc_switch_part(part->mmc, part_num);
- if (ret)
- goto err;
+ if (IS_MMC(part->mmc)) {
+ ret = mmc_switch_part(part->mmc, part_num);
+ if (ret) {
+ printf("%s: MMC part switch failed, err = %d\n",
+ __func__, ret);
+ goto err;
+ }
+ }
mmc_blk = mmc_get_blk_desc(part->mmc);
if (!mmc_blk) {
- printf("Error - failed to obtain block descriptor\n");
+ printf("%s: failed to obtain block descriptor\n", __func__);
goto err;
}
ret = part_get_info_by_name(mmc_blk, partition, &part->info);
if (ret < 0) {
- printf("Can't find partition '%s'\n", partition);
+ printf("%s: can't find partition '%s'\n", __func__, partition);
goto err;
}
@@ -683,7 +739,7 @@ static AvbIOResult read_rollback_index(AvbOps *ops,
{
#ifndef CONFIG_OPTEE_TA_AVB
/* For now we always return 0 as the stored rollback index. */
- printf("%s not supported yet\n", __func__);
+ debug("%s: rollback protection is not implemented\n", __func__);
if (out_rollback_index)
*out_rollback_index = 0;
@@ -729,7 +785,7 @@ static AvbIOResult write_rollback_index(AvbOps *ops,
{
#ifndef CONFIG_OPTEE_TA_AVB
/* For now this is a no-op. */
- printf("%s not supported yet\n", __func__);
+ debug("%s: rollback protection is not implemented\n", __func__);
return AVB_IO_RESULT_OK;
#else
@@ -765,8 +821,7 @@ static AvbIOResult read_is_device_unlocked(AvbOps *ops, bool *out_is_unlocked)
{
#ifndef CONFIG_OPTEE_TA_AVB
/* For now we always return that the device is unlocked. */
-
- printf("%s not supported yet\n", __func__);
+ debug("%s: device locking is not implemented\n", __func__);
*out_is_unlocked = true;
diff --git a/common/bloblist.c b/common/bloblist.c
index 2d373910b6d..ad06d7a1795 100644
--- a/common/bloblist.c
+++ b/common/bloblist.c
@@ -384,7 +384,7 @@ int bloblist_check(ulong addr, uint size)
return log_msg_ret("Bad magic", -ENOENT);
if (hdr->version != BLOBLIST_VERSION)
return log_msg_ret("Bad version", -EPROTONOSUPPORT);
- if (!hdr->total_size || (size && hdr->total_size != size))
+ if (!hdr->total_size || (size && hdr->total_size > size))
return log_msg_ret("Bad total size", -EFBIG);
if (hdr->used_size > hdr->total_size)
return log_msg_ret("Bad used size", -ENOENT);
@@ -472,13 +472,28 @@ void bloblist_show_list(void)
}
}
-void bloblist_reloc(void *to, uint to_size, void *from, uint from_size)
+int bloblist_reloc(void *to, uint to_size)
{
struct bloblist_hdr *hdr;
- memcpy(to, from, from_size);
+ if (to_size < gd->bloblist->total_size)
+ return -ENOSPC;
+
+ memcpy(to, gd->bloblist, gd->bloblist->total_size);
hdr = to;
hdr->total_size = to_size;
+ gd->bloblist = to;
+
+ return 0;
+}
+
+/*
+ * Weak default function for getting bloblist from boot args.
+ */
+int __weak xferlist_from_boot_arg(ulong __always_unused addr,
+ ulong __always_unused size)
+{
+ return -ENOENT;
}
int bloblist_init(void)
@@ -486,32 +501,43 @@ int bloblist_init(void)
bool fixed = IS_ENABLED(CONFIG_BLOBLIST_FIXED);
int ret = -ENOENT;
ulong addr, size;
- bool expected;
-
- /**
- * We don't expect to find an existing bloblist in the first phase of
- * U-Boot that runs. Also we have no way to receive the address of an
- * allocated bloblist from a previous stage, so it must be at a fixed
+ /*
+ * If U-Boot is not in the first phase, an existing bloblist must be
+ * at a fixed address.
+ */
+ bool from_addr = fixed && !u_boot_first_phase();
+ /*
+ * If U-Boot is in the first phase that an arch custom routine should
+ * install the bloblist passed from previous loader to this fixed
* address.
*/
- expected = fixed && !u_boot_first_phase();
+ bool from_boot_arg = fixed && u_boot_first_phase();
+
if (spl_prev_phase() == PHASE_TPL && !IS_ENABLED(CONFIG_TPL_BLOBLIST))
- expected = false;
+ from_addr = false;
if (fixed)
addr = IF_ENABLED_INT(CONFIG_BLOBLIST_FIXED,
CONFIG_BLOBLIST_ADDR);
size = CONFIG_BLOBLIST_SIZE;
- if (expected) {
+
+ if (from_boot_arg)
+ ret = xferlist_from_boot_arg(addr, size);
+ else if (from_addr)
ret = bloblist_check(addr, size);
- if (ret) {
- log_warning("Expected bloblist at %lx not found (err=%d)\n",
- addr, ret);
- } else {
- /* Get the real size, if it is not what we expected */
- size = gd->bloblist->total_size;
- }
- }
+
+ if (ret)
+ log_warning("Bloblist at %lx not found (err=%d)\n",
+ addr, ret);
+ else
+ /* Get the real size */
+ size = gd->bloblist->total_size;
+
if (ret) {
+ /*
+ * If we don't have a bloblist from a fixed address, or the one
+ * in the fixed address is not valid. we must allocate the
+ * memory for it now.
+ */
if (CONFIG_IS_ENABLED(BLOBLIST_ALLOC)) {
void *ptr = memalign(BLOBLIST_ALIGN, size);
@@ -519,7 +545,8 @@ int bloblist_init(void)
return log_msg_ret("alloc", -ENOMEM);
addr = map_to_sysmem(ptr);
} else if (!fixed) {
- return log_msg_ret("!fixed", ret);
+ return log_msg_ret("BLOBLIST_FIXED is not enabled",
+ ret);
}
log_debug("Creating new bloblist size %lx at %lx\n", size,
addr);
@@ -532,6 +559,11 @@ int bloblist_init(void)
return log_msg_ret("ini", ret);
gd->flags |= GD_FLG_BLOBLIST_READY;
+#ifdef DEBUG
+ bloblist_show_stats();
+ bloblist_show_list();
+#endif
+
return 0;
}
@@ -542,3 +574,14 @@ int bloblist_maybe_init(void)
return 0;
}
+
+int bloblist_check_reg_conv(ulong rfdt, ulong rzero, ulong rsig)
+{
+ if (rzero || rsig != (BLOBLIST_MAGIC | BLOBLIST_REGCONV_VER) ||
+ rfdt != (ulong)bloblist_find(BLOBLISTT_CONTROL_FDT, 0)) {
+ gd->bloblist = NULL; /* Reset the gd bloblist pointer */
+ return -EIO;
+ }
+
+ return 0;
+}
diff --git a/common/board_f.c b/common/board_f.c
index 442b8349d08..8bada6ff2ee 100644
--- a/common/board_f.c
+++ b/common/board_f.c
@@ -282,7 +282,9 @@ static int init_func_i2c(void)
static int setup_mon_len(void)
{
-#if defined(__ARM__) || defined(__MICROBLAZE__)
+#if defined(CONFIG_ARCH_NEXELL)
+ gd->mon_len = (ulong)__bss_end - (ulong)__image_copy_start;
+#elif defined(__ARM__) || defined(__MICROBLAZE__)
gd->mon_len = (ulong)__bss_end - (ulong)_start;
#elif defined(CONFIG_SANDBOX) && !defined(__riscv)
gd->mon_len = (ulong)_end - (ulong)_init;
@@ -706,13 +708,10 @@ static int reloc_bloblist(void)
return 0;
}
if (gd->new_bloblist) {
- int size = CONFIG_BLOBLIST_SIZE;
-
debug("Copying bloblist from %p to %p, size %x\n",
- gd->bloblist, gd->new_bloblist, size);
- bloblist_reloc(gd->new_bloblist, CONFIG_BLOBLIST_SIZE_RELOC,
- gd->bloblist, size);
- gd->bloblist = gd->new_bloblist;
+ gd->bloblist, gd->new_bloblist, gd->bloblist->total_size);
+ return bloblist_reloc(gd->new_bloblist,
+ CONFIG_BLOBLIST_SIZE_RELOC);
}
#endif
diff --git a/common/button_cmd.c b/common/button_cmd.c
new file mode 100644
index 00000000000..b6a8434d6f2
--- /dev/null
+++ b/common/button_cmd.c
@@ -0,0 +1,83 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (c) 2023 Linaro Ltd.
+ * Author: Caleb Connolly <caleb.connolly@linaro.org>
+ */
+
+#include <button.h>
+#include <command.h>
+#include <env.h>
+#include <log.h>
+#include <vsprintf.h>
+
+/* Some sane limit "just in case" */
+#define MAX_BTN_CMDS 32
+
+struct button_cmd {
+ bool pressed;
+ const char *btn_name;
+ const char *cmd;
+};
+
+/*
+ * Button commands are set via environment variables, e.g.:
+ * button_cmd_N_name=Volume Up
+ * button_cmd_N=fastboot usb 0
+ *
+ * This function will retrieve the command for the given button N
+ * and populate the cmd struct with the command string and pressed
+ * state of the button.
+ *
+ * Returns 1 if a command was found, 0 otherwise.
+ */
+static int get_button_cmd(int n, struct button_cmd *cmd)
+{
+ const char *cmd_str;
+ struct udevice *btn;
+ char buf[24];
+
+ snprintf(buf, sizeof(buf), "button_cmd_%d_name", n);
+ cmd->btn_name = env_get(buf);
+ if (!cmd->btn_name)
+ return 0;
+
+ button_get_by_label(cmd->btn_name, &btn);
+ if (!btn) {
+ log_err("No button labelled '%s'\n", cmd->btn_name);
+ return 0;
+ }
+
+ cmd->pressed = button_get_state(btn) == BUTTON_ON;
+ /* If the button isn't pressed then cmd->cmd will be unused so don't waste
+ * cycles reading it
+ */
+ if (!cmd->pressed)
+ return 1;
+
+ snprintf(buf, sizeof(buf), "button_cmd_%d", n);
+ cmd_str = env_get(buf);
+ if (!cmd_str) {
+ log_err("No command set for button '%s'\n", cmd->btn_name);
+ return 0;
+ }
+
+ cmd->cmd = cmd_str;
+
+ return 1;
+}
+
+void process_button_cmds(void)
+{
+ struct button_cmd cmd = {0};
+ int i = 0;
+
+ while (get_button_cmd(i++, &cmd) && i < MAX_BTN_CMDS) {
+ if (!cmd.pressed)
+ continue;
+
+ log_info("BTN '%s'> %s\n", cmd.btn_name, cmd.cmd);
+ run_command(cmd.cmd, CMD_FLAG_ENV);
+ /* Don't run commands for multiple buttons */
+ return;
+ }
+}
diff --git a/common/log.c b/common/log.c
index b2de57fcb3b..42d35f04b68 100644
--- a/common/log.c
+++ b/common/log.c
@@ -428,6 +428,11 @@ int log_device_set_enable(struct log_driver *drv, bool enable)
return 0;
}
+void log_fixup_for_gd_move(struct global_data *new_gd)
+{
+ new_gd->log_head.prev->next = &new_gd->log_head;
+}
+
int log_init(void)
{
struct log_driver *drv = ll_entry_start(struct log_driver, log_driver);
diff --git a/common/main.c b/common/main.c
index 6dba6cba144..82d3aafa53c 100644
--- a/common/main.c
+++ b/common/main.c
@@ -8,6 +8,7 @@
#include <common.h>
#include <autoboot.h>
+#include <button.h>
#include <bootstage.h>
#include <bootstd.h>
#include <cli.h>
@@ -62,6 +63,8 @@ void main_loop(void)
efi_launch_capsules();
}
+ process_button_cmds();
+
s = bootdelay_process();
if (cli_process_fdt(&s))
cli_secure_boot_cmd(s);
diff --git a/common/spl/spl.c b/common/spl/spl.c
index b65c439e7aa..e06bc75d36b 100644
--- a/common/spl/spl.c
+++ b/common/spl/spl.c
@@ -909,6 +909,9 @@ ulong spl_relocate_stack_gd(void)
#if CONFIG_IS_ENABLED(DM)
dm_fixup_for_gd_move(new_gd);
#endif
+#if CONFIG_IS_ENABLED(LOG)
+ log_fixup_for_gd_move(new_gd);
+#endif
#if !defined(CONFIG_ARM) && !defined(CONFIG_RISCV)
gd = new_gd;
#endif
diff --git a/common/usb_hub.c b/common/usb_hub.c
index 3fb7e14d106..2e054eb9353 100644
--- a/common/usb_hub.c
+++ b/common/usb_hub.c
@@ -174,8 +174,10 @@ static void usb_hub_power_on(struct usb_hub_device *hub)
debug("enabling power on all ports\n");
for (i = 0; i < dev->maxchild; i++) {
- usb_set_port_feature(dev, i + 1, USB_PORT_FEAT_RESET);
- debug("Reset : port %d returns %lX\n", i + 1, dev->status);
+ if (usb_hub_is_superspeed(dev)) {
+ usb_set_port_feature(dev, i + 1, USB_PORT_FEAT_RESET);
+ debug("Reset : port %d returns %lX\n", i + 1, dev->status);
+ }
usb_set_port_feature(dev, i + 1, USB_PORT_FEAT_POWER);
debug("PowerOn : port %d returns %lX\n", i + 1, dev->status);
}