* [PATCH v2 01/20] ARM: k3: Add function to enable 32k crystal
2025-02-12 14:09 [PATCH v2 00/20] ARM: K3 updates Sascha Hauer
@ 2025-02-12 14:09 ` Sascha Hauer
2025-02-12 14:09 ` [PATCH v2 02/20] ARM: k3: add function to detect eMMC boot Sascha Hauer
` (19 subsequent siblings)
20 siblings, 0 replies; 22+ messages in thread
From: Sascha Hauer @ 2025-02-12 14:09 UTC (permalink / raw)
To: open list:BAREBOX
The external 32k crystal is optional and by default LFOSC0 is sourced
by a RC oscillator. This adds a function to be called by board code
when the 32k crystal is present and shall be used to source LFOSC0
from the crystal.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
arch/arm/mach-k3/common.c | 20 ++++++++++++++++++++
include/mach/k3/common.h | 1 +
2 files changed, 21 insertions(+)
diff --git a/arch/arm/mach-k3/common.c b/arch/arm/mach-k3/common.c
index 3922a0ff19..c779e873c9 100644
--- a/arch/arm/mach-k3/common.c
+++ b/arch/arm/mach-k3/common.c
@@ -170,6 +170,26 @@ static void of_delete_node_path(struct device_node *root, const char *path)
of_delete_node(np);
}
+#define MCU_CTRL_MMR0_BASE 0x04500000
+#define MCU_CTRL_LFXOSC_CTRL (MCU_CTRL_MMR0_BASE + 0x8038)
+#define MCU_CTRL_LFXOSC_32K_DISABLE_VAL BIT(7)
+#define MCU_CTRL_DEVICE_CLKOUT_LFOSC_SELECT_VAL (0x3)
+#define MCU_CTRL_DEVICE_CLKOUT_32K_CTRL (MCU_CTRL_MMR0_BASE + 0x8058)
+
+void am625_enable_32k_crystal(void)
+{
+ u32 val;
+
+ /* Enable 32k crystal */
+ val = readl(MCU_CTRL_LFXOSC_CTRL);
+ val &= ~(MCU_CTRL_LFXOSC_32K_DISABLE_VAL);
+ writel(val, MCU_CTRL_LFXOSC_CTRL);
+
+ /* select 32k clock from LFOSC0 */
+ writel(MCU_CTRL_DEVICE_CLKOUT_LFOSC_SELECT_VAL,
+ MCU_CTRL_DEVICE_CLKOUT_32K_CTRL);
+}
+
#define CTRLMMR_WKUP_JTAG_DEVICE_ID (AM625_WKUP_CTRL_MMR0_BASE + 0x18)
#define JTAG_DEV_CORE_NR GENMASK(21, 19)
diff --git a/include/mach/k3/common.h b/include/mach/k3/common.h
index d7ceea51d7..3377dc8895 100644
--- a/include/mach/k3/common.h
+++ b/include/mach/k3/common.h
@@ -6,5 +6,6 @@
void am625_get_bootsource(enum bootsource *src, int *instance);
u64 am625_sdram_size(void);
void am625_register_dram(void);
+void am625_enable_32k_crystal(void);
#endif /* __MACH_K3_COMMON_H */
--
2.39.5
^ permalink raw reply [flat|nested] 22+ messages in thread
* [PATCH v2 02/20] ARM: k3: add function to detect eMMC boot
2025-02-12 14:09 [PATCH v2 00/20] ARM: K3 updates Sascha Hauer
2025-02-12 14:09 ` [PATCH v2 01/20] ARM: k3: Add function to enable 32k crystal Sascha Hauer
@ 2025-02-12 14:09 ` Sascha Hauer
2025-02-12 14:09 ` [PATCH v2 03/20] ARM: k3: do not mount /boot when booting from eMMC Sascha Hauer
` (18 subsequent siblings)
20 siblings, 0 replies; 22+ messages in thread
From: Sascha Hauer @ 2025-02-12 14:09 UTC (permalink / raw)
To: open list:BAREBOX
Booting from eMMC on K3 SoCs requires some special handling. With SD
card boot we put the environment in the boot FAT partition whereas with
eMMC boot we want to put it into the raw eMMC device. Also with eMMC
boot we have to load the subsequent stages from the eMMC boot partitions
and from the boot FAT otherwise. Add a function to detect eMMC boot
to base these decisions on.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
arch/arm/mach-k3/common.c | 13 +++++++++++++
include/mach/k3/common.h | 1 +
2 files changed, 14 insertions(+)
diff --git a/arch/arm/mach-k3/common.c b/arch/arm/mach-k3/common.c
index c779e873c9..7ded1f3f04 100644
--- a/arch/arm/mach-k3/common.c
+++ b/arch/arm/mach-k3/common.c
@@ -162,6 +162,19 @@ void am625_get_bootsource(enum bootsource *src, int *instance)
k3_get_bootsource(devstat, src, instance);
}
+bool k3_boot_is_emmc(void)
+{
+ u32 bootmode = readl(AM625_BOOT_PARAM_TABLE_INDEX_OCRAM);
+ u32 devstat = readl(AM625_CTRLMMR_MAIN_DEVSTAT);
+
+ if (bootmode != K3_PRIMARY_BOOTMODE)
+ return false;
+ if (FIELD_GET(MAIN_DEVSTAT_PRIMARY_BOOTMODE, devstat) != BOOT_DEVICE_EMMC)
+ return false;
+
+ return true;
+}
+
static void of_delete_node_path(struct device_node *root, const char *path)
{
struct device_node *np;
diff --git a/include/mach/k3/common.h b/include/mach/k3/common.h
index 3377dc8895..7f0796f7f4 100644
--- a/include/mach/k3/common.h
+++ b/include/mach/k3/common.h
@@ -4,6 +4,7 @@
#include <bootsource.h>
void am625_get_bootsource(enum bootsource *src, int *instance);
+bool k3_boot_is_emmc(void);
u64 am625_sdram_size(void);
void am625_register_dram(void);
void am625_enable_32k_crystal(void);
--
2.39.5
^ permalink raw reply [flat|nested] 22+ messages in thread
* [PATCH v2 03/20] ARM: k3: do not mount /boot when booting from eMMC
2025-02-12 14:09 [PATCH v2 00/20] ARM: K3 updates Sascha Hauer
2025-02-12 14:09 ` [PATCH v2 01/20] ARM: k3: Add function to enable 32k crystal Sascha Hauer
2025-02-12 14:09 ` [PATCH v2 02/20] ARM: k3: add function to detect eMMC boot Sascha Hauer
@ 2025-02-12 14:09 ` Sascha Hauer
2025-02-12 14:09 ` [PATCH v2 04/20] fip: drop typedefs Sascha Hauer
` (17 subsequent siblings)
20 siblings, 0 replies; 22+ messages in thread
From: Sascha Hauer @ 2025-02-12 14:09 UTC (permalink / raw)
To: open list:BAREBOX
When booting from eMMC we load the subsequent stages from eMMC boot
partitions, so we do not need a boot FAT partition on eMMC. We can
use an unpartitioned area in the eMMC user area in this case, so
bail out from mounting /boot when eMMC boot is detected.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
arch/arm/mach-k3/common.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/arch/arm/mach-k3/common.c b/arch/arm/mach-k3/common.c
index 7ded1f3f04..97cb46d58e 100644
--- a/arch/arm/mach-k3/common.c
+++ b/arch/arm/mach-k3/common.c
@@ -275,6 +275,9 @@ static int omap_env_init(void)
if (bootsource_get() != BOOTSOURCE_MMC)
return 0;
+ if (k3_boot_is_emmc())
+ return 0;
+
instance = bootsource_get_instance();
cdevname = xasprintf("mmc%d", instance);
--
2.39.5
^ permalink raw reply [flat|nested] 22+ messages in thread
* [PATCH v2 04/20] fip: drop typedefs
2025-02-12 14:09 [PATCH v2 00/20] ARM: K3 updates Sascha Hauer
` (2 preceding siblings ...)
2025-02-12 14:09 ` [PATCH v2 03/20] ARM: k3: do not mount /boot when booting from eMMC Sascha Hauer
@ 2025-02-12 14:09 ` Sascha Hauer
2025-02-12 14:09 ` [PATCH v2 05/20] fip: use linux list implementation Sascha Hauer
` (16 subsequent siblings)
20 siblings, 0 replies; 22+ messages in thread
From: Sascha Hauer @ 2025-02-12 14:09 UTC (permalink / raw)
To: open list:BAREBOX
Do not typedef struct types.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
commands/fiptool.c | 28 ++++++++++++++--------------
include/fiptool.h | 26 +++++++++++++-------------
lib/fip.c | 44 ++++++++++++++++++++++----------------------
3 files changed, 49 insertions(+), 49 deletions(-)
diff --git a/commands/fiptool.c b/commands/fiptool.c
index 2d766f895b..a4370c9eef 100644
--- a/commands/fiptool.c
+++ b/commands/fiptool.c
@@ -31,7 +31,7 @@ typedef struct cmd {
} cmd_t;
-static int write_image_to_file(const image_t *image, const char *filename)
+static int write_image_to_file(const struct fip_image *image, const char *filename)
{
int fd;
@@ -53,7 +53,7 @@ static int write_image_to_file(const image_t *image, const char *filename)
static int info_cmd(struct fip_state *fip, int argc, char *argv[])
{
- image_desc_t *desc;
+ struct fip_image_desc *desc;
fip_toc_header_t toc_header;
int ret;
@@ -74,7 +74,7 @@ static int info_cmd(struct fip_state *fip, int argc, char *argv[])
(unsigned long long)toc_header.flags);
for (desc = fip->image_desc_head; desc != NULL; desc = desc->next) {
- image_t *image = desc->image;
+ struct fip_image *image = desc->image;
if (image == NULL)
continue;
@@ -193,7 +193,7 @@ static __maybe_unused int create_cmd(struct fip_state *fip, int argc, char *argv
while ((opt = getopt(argc, argv, "e:p:a:b:")) > 0) {
switch (opt) {
case 'e': {
- image_desc_t *desc;
+ struct fip_image_desc *desc;
desc = lookup_image_desc_from_opt(fip, &optarg);
if (!desc)
@@ -214,7 +214,7 @@ static __maybe_unused int create_cmd(struct fip_state *fip, int argc, char *argv
char name[UUID_STRING_LEN + 1];
char filename[PATH_MAX] = { 0 };
uuid_t uuid = uuid_null;
- image_desc_t *desc;
+ struct fip_image_desc *desc;
parse_blob_opt(optarg, &uuid,
filename, sizeof(filename));
@@ -264,7 +264,7 @@ static __maybe_unused int update_cmd(struct fip_state *fip, int argc, char *argv
while ((opt = getopt(argc, argv, "e:p:b:a:o:")) > 0) {
switch (opt) {
case 'e': {
- image_desc_t *desc;
+ struct fip_image_desc *desc;
desc = lookup_image_desc_from_opt(fip, &optarg);
if (!desc)
@@ -281,7 +281,7 @@ static __maybe_unused int update_cmd(struct fip_state *fip, int argc, char *argv
char name[UUID_STRING_LEN + 1];
char filename[PATH_MAX] = { 0 };
uuid_t uuid = uuid_null;
- image_desc_t *desc;
+ struct fip_image_desc *desc;
parse_blob_opt(optarg, &uuid,
filename, sizeof(filename));
@@ -339,7 +339,7 @@ static __maybe_unused int update_cmd(struct fip_state *fip, int argc, char *argv
static int unpack_cmd(struct fip_state *fip, int argc, char *argv[])
{
char outdir[PATH_MAX] = { 0 };
- image_desc_t *desc;
+ struct fip_image_desc *desc;
int fflag = 0;
int unpack_all = 1;
int ret, opt;
@@ -350,7 +350,7 @@ static int unpack_cmd(struct fip_state *fip, int argc, char *argv[])
while ((opt = getopt(argc, argv, "e:b:fo:")) > 0) {
switch (opt) {
case 'e': {
- image_desc_t *desc;
+ struct fip_image_desc *desc;
desc = lookup_image_desc_from_opt(fip, &optarg);
if (!desc)
@@ -363,7 +363,7 @@ static int unpack_cmd(struct fip_state *fip, int argc, char *argv[])
char name[UUID_STRING_LEN + 1];
char filename[PATH_MAX] = { 0 };
uuid_t uuid = uuid_null;
- image_desc_t *desc;
+ struct fip_image_desc *desc;
parse_blob_opt(optarg, &uuid,
filename, sizeof(filename));
@@ -411,7 +411,7 @@ static int unpack_cmd(struct fip_state *fip, int argc, char *argv[])
/* Unpack all specified images. */
for (desc = fip->image_desc_head; desc != NULL; desc = desc->next) {
char file[PATH_MAX];
- image_t *image = desc->image;
+ struct fip_image *image = desc->image;
if (!unpack_all && desc->action != DO_UNPACK)
continue;
@@ -447,7 +447,7 @@ static __maybe_unused int remove_cmd(struct fip_state *fip, int argc, char *argv
{
char outfile[PATH_MAX] = { 0 };
fip_toc_header_t toc_header;
- image_desc_t *desc;
+ struct fip_image_desc *desc;
long align = 1;
int ret, opt, fflag = 0;
@@ -457,7 +457,7 @@ static __maybe_unused int remove_cmd(struct fip_state *fip, int argc, char *argv
while ((opt = getopt(argc, argv, "e:a:b:fo:")) > 0) {
switch (opt) {
case 'e': {
- image_desc_t *desc;
+ struct fip_image_desc *desc;
desc = lookup_image_desc_from_opt(fip, &optarg);
if (!desc)
@@ -473,7 +473,7 @@ static __maybe_unused int remove_cmd(struct fip_state *fip, int argc, char *argv
case 'b': {
char name[UUID_STRING_LEN + 1], filename[PATH_MAX];
uuid_t uuid = uuid_null;
- image_desc_t *desc;
+ struct fip_image_desc *desc;
parse_blob_opt(optarg, &uuid,
filename, sizeof(filename));
diff --git a/include/fiptool.h b/include/fiptool.h
index 704845f456..6f1d69d178 100644
--- a/include/fiptool.h
+++ b/include/fiptool.h
@@ -16,23 +16,23 @@ enum {
DO_REMOVE = 3
};
-typedef struct image_desc {
+struct fip_image_desc {
uuid_t uuid;
char *name;
char *cmdline_name;
int action;
char *action_arg;
- struct image *image;
- struct image_desc *next;
-} image_desc_t;
+ struct fip_image *image;
+ struct fip_image_desc *next;
+};
-typedef struct image {
+struct fip_image {
struct fip_toc_entry toc_e;
void *buffer;
-} image_t;
+};
struct fip_state {
- image_desc_t *image_desc_head;
+ struct fip_image_desc *image_desc_head;
size_t nr_image_descs;
int verbose;
};
@@ -45,24 +45,24 @@ struct fip_state {
} \
} while (0)
-image_desc_t *new_image_desc(const uuid_t *uuid,
+struct fip_image_desc *new_image_desc(const uuid_t *uuid,
const char *name, const char *cmdline_name);
-void set_image_desc_action(image_desc_t *desc, int action,
+void set_image_desc_action(struct fip_image_desc *desc, int action,
const char *arg);
-void free_image_desc(image_desc_t *desc);
+void free_image_desc(struct fip_image_desc *desc);
-void add_image_desc(struct fip_state *fip, image_desc_t *desc);
+void add_image_desc(struct fip_state *fip, struct fip_image_desc *desc);
void free_image_descs(struct fip_state *fip);
void fill_image_descs(struct fip_state *fip);
-image_desc_t *lookup_image_desc_from_uuid(struct fip_state *fip,
+struct fip_image_desc *lookup_image_desc_from_uuid(struct fip_state *fip,
const uuid_t *uuid);
-image_desc_t *lookup_image_desc_from_opt(struct fip_state *fip, char **arg);
+struct fip_image_desc *lookup_image_desc_from_opt(struct fip_state *fip, char **arg);
int parse_fip(struct fip_state *fip,
const char *filename, fip_toc_header_t *toc_header_out);
diff --git a/lib/fip.c b/lib/fip.c
index ae7ff8b3ad..e7589ff4c2 100644
--- a/lib/fip.c
+++ b/lib/fip.c
@@ -26,10 +26,10 @@
#include <fip.h>
#include <fiptool.h>
-image_desc_t *new_image_desc(const uuid_t *uuid,
+struct fip_image_desc *new_image_desc(const uuid_t *uuid,
const char *name, const char *cmdline_name)
{
- image_desc_t *desc;
+ struct fip_image_desc *desc;
desc = xzalloc(sizeof(*desc));
memcpy(&desc->uuid, uuid, sizeof(uuid_t));
@@ -39,7 +39,7 @@ image_desc_t *new_image_desc(const uuid_t *uuid,
return desc;
}
-void set_image_desc_action(image_desc_t *desc, int action,
+void set_image_desc_action(struct fip_image_desc *desc, int action,
const char *arg)
{
ASSERT(desc != NULL);
@@ -52,7 +52,7 @@ void set_image_desc_action(image_desc_t *desc, int action,
desc->action_arg = xstrdup(arg);
}
-void free_image_desc(image_desc_t *desc)
+void free_image_desc(struct fip_image_desc *desc)
{
free(desc->name);
free(desc->cmdline_name);
@@ -64,9 +64,9 @@ void free_image_desc(image_desc_t *desc)
free(desc);
}
-void add_image_desc(struct fip_state *fip, image_desc_t *desc)
+void add_image_desc(struct fip_state *fip, struct fip_image_desc *desc)
{
- image_desc_t **p = &fip->image_desc_head;
+ struct fip_image_desc **p = &fip->image_desc_head;
while (*p)
p = &(*p)->next;
@@ -78,7 +78,7 @@ void add_image_desc(struct fip_state *fip, image_desc_t *desc)
void free_image_descs(struct fip_state *fip)
{
- image_desc_t *desc = fip->image_desc_head, *tmp;
+ struct fip_image_desc *desc = fip->image_desc_head, *tmp;
while (desc != NULL) {
tmp = desc->next;
@@ -96,7 +96,7 @@ void fill_image_descs(struct fip_state *fip)
for (toc_entry = toc_entries;
toc_entry->cmdline_name != NULL;
toc_entry++) {
- image_desc_t *desc;
+ struct fip_image_desc *desc;
desc = new_image_desc(&toc_entry->uuid,
toc_entry->name,
@@ -106,7 +106,7 @@ void fill_image_descs(struct fip_state *fip)
for (toc_entry = plat_def_toc_entries;
toc_entry->cmdline_name != NULL;
toc_entry++) {
- image_desc_t *desc;
+ struct fip_image_desc *desc;
desc = new_image_desc(&toc_entry->uuid,
toc_entry->name,
@@ -115,10 +115,10 @@ void fill_image_descs(struct fip_state *fip)
}
}
-image_desc_t *lookup_image_desc_from_uuid(struct fip_state *fip,
+struct fip_image_desc *lookup_image_desc_from_uuid(struct fip_state *fip,
const uuid_t *uuid)
{
- image_desc_t *desc;
+ struct fip_image_desc *desc;
for (desc = fip->image_desc_head; desc != NULL; desc = desc->next)
if (memcmp(&desc->uuid, uuid, sizeof(uuid_t)) == 0)
@@ -126,10 +126,10 @@ image_desc_t *lookup_image_desc_from_uuid(struct fip_state *fip,
return NULL;
}
-image_desc_t *lookup_image_desc_from_opt(struct fip_state *fip, char **arg)
+struct fip_image_desc *lookup_image_desc_from_opt(struct fip_state *fip, char **arg)
{
int len = 0;
- image_desc_t *desc;
+ struct fip_image_desc *desc;
char *eq;
eq = strchrnul(*arg, '=');
@@ -200,8 +200,8 @@ int parse_fip(struct fip_state *fip,
/* Walk through each ToC entry in the file. */
while ((char *)toc_entry + sizeof(*toc_entry) - 1 < bufend) {
- image_t *image;
- image_desc_t *desc;
+ struct fip_image *image;
+ struct fip_image_desc *desc;
/* Found the ToC terminator, we are done. */
if (memcmp(&toc_entry->uuid, &uuid_null, sizeof(uuid_t)) == 0) {
@@ -260,10 +260,10 @@ int parse_fip(struct fip_state *fip,
return 0;
}
-static image_t *read_image_from_file(const uuid_t *uuid, const char *filename)
+static struct fip_image *read_image_from_file(const uuid_t *uuid, const char *filename)
{
struct stat st;
- image_t *image;
+ struct fip_image *image;
int fd;
ASSERT(uuid != NULL);
@@ -298,7 +298,7 @@ int pack_images(struct fip_state *fip,
uint64_t toc_flags, unsigned long align)
{
int fd;
- image_desc_t *desc;
+ struct fip_image_desc *desc;
fip_toc_header_t *toc_header;
fip_toc_entry_t *toc_entry;
char *buf;
@@ -325,7 +325,7 @@ int pack_images(struct fip_state *fip,
entry_offset = buf_size;
for (desc = fip->image_desc_head; desc != NULL; desc = desc->next) {
- image_t *image = desc->image;
+ struct fip_image *image = desc->image;
if (image == NULL || (image->toc_e.size == 0ULL))
continue;
@@ -361,7 +361,7 @@ int pack_images(struct fip_state *fip,
pr_verbose("Payload size: %llu bytes\n", payload_size);
for (desc = fip->image_desc_head; desc != NULL; desc = desc->next) {
- image_t *image = desc->image;
+ struct fip_image *image = desc->image;
if (image == NULL)
continue;
@@ -396,11 +396,11 @@ int pack_images(struct fip_state *fip,
*/
int update_fip(struct fip_state *fip)
{
- image_desc_t *desc;
+ struct fip_image_desc *desc;
/* Add or replace images in the FIP file. */
for (desc = fip->image_desc_head; desc != NULL; desc = desc->next) {
- image_t *image;
+ struct fip_image *image;
if (desc->action != DO_PACK)
continue;
--
2.39.5
^ permalink raw reply [flat|nested] 22+ messages in thread
* [PATCH v2 05/20] fip: use linux list implementation
2025-02-12 14:09 [PATCH v2 00/20] ARM: K3 updates Sascha Hauer
` (3 preceding siblings ...)
2025-02-12 14:09 ` [PATCH v2 04/20] fip: drop typedefs Sascha Hauer
@ 2025-02-12 14:09 ` Sascha Hauer
2025-02-12 14:09 ` [PATCH v2 06/20] fip: use uuid_equal() and uuid_is_null() Sascha Hauer
` (15 subsequent siblings)
20 siblings, 0 replies; 22+ messages in thread
From: Sascha Hauer @ 2025-02-12 14:09 UTC (permalink / raw)
To: open list:BAREBOX
Replace open coded list handling with Linux list implementation.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
commands/fiptool.c | 16 ++++++++--------
include/fiptool.h | 16 ++++++++++++----
lib/fip.c | 40 +++++++++++++++++++++++-----------------
3 files changed, 43 insertions(+), 29 deletions(-)
diff --git a/commands/fiptool.c b/commands/fiptool.c
index a4370c9eef..45d534e470 100644
--- a/commands/fiptool.c
+++ b/commands/fiptool.c
@@ -73,7 +73,7 @@ static int info_cmd(struct fip_state *fip, int argc, char *argv[])
pr_verbose("toc_header[flags]: 0x%llX\n",
(unsigned long long)toc_header.flags);
- for (desc = fip->image_desc_head; desc != NULL; desc = desc->next) {
+ fip_for_each_desc(fip, desc) {
struct fip_image *image = desc->image;
if (image == NULL)
@@ -409,7 +409,7 @@ static int unpack_cmd(struct fip_state *fip, int argc, char *argv[])
}
/* Unpack all specified images. */
- for (desc = fip->image_desc_head; desc != NULL; desc = desc->next) {
+ fip_for_each_desc(fip, desc) {
char file[PATH_MAX];
struct fip_image *image = desc->image;
@@ -517,7 +517,7 @@ static __maybe_unused int remove_cmd(struct fip_state *fip, int argc, char *argv
if (ret)
return ret;
- for (desc = fip->image_desc_head; desc != NULL; desc = desc->next) {
+ fip_for_each_desc(fip, desc) {
if (desc->action != DO_REMOVE)
continue;
@@ -548,7 +548,7 @@ static cmd_t cmds[] = {
static int do_fiptool(int argc, char *argv[])
{
int i, opt, ret = 0;
- struct fip_state fip = {};
+ struct fip_state *fip = fip_new();
/*
* Set POSIX mode so getopt stops at the first non-option
@@ -557,7 +557,7 @@ static int do_fiptool(int argc, char *argv[])
while ((opt = getopt(argc, argv, "+v")) > 0) {
switch (opt) {
case 'v':
- fip.verbose = 1;
+ fip->verbose = 1;
break;
default:
return COMMAND_ERROR_USAGE;
@@ -569,14 +569,14 @@ static int do_fiptool(int argc, char *argv[])
if (argc == 0)
return COMMAND_ERROR_USAGE;
- fill_image_descs(&fip);
+ fill_image_descs(fip);
for (i = 0; i < ARRAY_SIZE(cmds); i++) {
if (strcmp(cmds[i].name, argv[0]) == 0) {
struct getopt_context gc;
getopt_context_store(&gc);
- ret = cmds[i].handler(&fip, argc, argv);
+ ret = cmds[i].handler(fip, argc, argv);
getopt_context_restore(&gc);
break;
@@ -585,7 +585,7 @@ static int do_fiptool(int argc, char *argv[])
if (i == ARRAY_SIZE(cmds))
return COMMAND_ERROR_USAGE;
- free_image_descs(&fip);
+ fip_free(fip);
return ret;
}
diff --git a/include/fiptool.h b/include/fiptool.h
index 6f1d69d178..5a3fdee6e0 100644
--- a/include/fiptool.h
+++ b/include/fiptool.h
@@ -8,6 +8,7 @@
#include <linux/uuid.h>
#include <fip.h>
+#include <linux/list.h>
enum {
DO_UNSPEC = 0,
@@ -23,7 +24,7 @@ struct fip_image_desc {
int action;
char *action_arg;
struct fip_image *image;
- struct fip_image_desc *next;
+ struct list_head list;
};
struct fip_image {
@@ -32,7 +33,7 @@ struct fip_image {
};
struct fip_state {
- struct fip_image_desc *image_desc_head;
+ struct list_head descs;
size_t nr_image_descs;
int verbose;
};
@@ -45,6 +46,9 @@ struct fip_state {
} \
} while (0)
+struct fip_state *fip_new(void);
+void fip_free(struct fip_state *fip);
+
struct fip_image_desc *new_image_desc(const uuid_t *uuid,
const char *name, const char *cmdline_name);
@@ -55,8 +59,6 @@ void free_image_desc(struct fip_image_desc *desc);
void add_image_desc(struct fip_state *fip, struct fip_image_desc *desc);
-void free_image_descs(struct fip_state *fip);
-
void fill_image_descs(struct fip_state *fip);
struct fip_image_desc *lookup_image_desc_from_uuid(struct fip_state *fip,
@@ -84,4 +86,10 @@ typedef struct toc_entry {
extern toc_entry_t toc_entries[];
extern toc_entry_t plat_def_toc_entries[];
+#define fip_for_each_desc(fip, e) \
+ list_for_each_entry(e, &(fip)->descs, list)
+
+#define fip_for_each_desc_safe(fip, e, tmp) \
+ list_for_each_entry_safe(e, tmp, &(fip)->descs, list)
+
#endif /* FIPTOOL_H */
diff --git a/lib/fip.c b/lib/fip.c
index e7589ff4c2..63f1469086 100644
--- a/lib/fip.c
+++ b/lib/fip.c
@@ -66,27 +66,33 @@ void free_image_desc(struct fip_image_desc *desc)
void add_image_desc(struct fip_state *fip, struct fip_image_desc *desc)
{
- struct fip_image_desc **p = &fip->image_desc_head;
+ list_add_tail(&desc->list, &fip->descs);
+ fip->nr_image_descs++;
+}
- while (*p)
- p = &(*p)->next;
+struct fip_state *fip_new(void)
+{
+ struct fip_state *fip;
- ASSERT(*p == NULL);
- *p = desc;
- fip->nr_image_descs++;
+ fip = xzalloc(sizeof(*fip));
+
+ INIT_LIST_HEAD(&fip->descs);
+
+ return fip;
}
-void free_image_descs(struct fip_state *fip)
+void fip_free(struct fip_state *fip)
{
- struct fip_image_desc *desc = fip->image_desc_head, *tmp;
+ struct fip_image_desc *desc, *tmp;
- while (desc != NULL) {
- tmp = desc->next;
+ fip_for_each_desc_safe(fip, desc, tmp) {
free_image_desc(desc);
- desc = tmp;
fip->nr_image_descs--;
}
+
ASSERT(fip->nr_image_descs == 0);
+
+ free(fip);
}
void fill_image_descs(struct fip_state *fip)
@@ -120,7 +126,7 @@ struct fip_image_desc *lookup_image_desc_from_uuid(struct fip_state *fip,
{
struct fip_image_desc *desc;
- for (desc = fip->image_desc_head; desc != NULL; desc = desc->next)
+ fip_for_each_desc(fip, desc)
if (memcmp(&desc->uuid, uuid, sizeof(uuid_t)) == 0)
return desc;
return NULL;
@@ -135,7 +141,7 @@ struct fip_image_desc *lookup_image_desc_from_opt(struct fip_state *fip, char **
eq = strchrnul(*arg, '=');
len = eq - *arg;
- for (desc = fip->image_desc_head; desc != NULL; desc = desc->next) {
+ fip_for_each_desc(fip, desc) {
if (strncmp(desc->cmdline_name, *arg, len) == 0) {
if (*eq)
*arg = eq + 1;
@@ -305,7 +311,7 @@ int pack_images(struct fip_state *fip,
uint64_t entry_offset, buf_size, payload_size = 0, pad_size;
size_t nr_images = 0;
- for (desc = fip->image_desc_head; desc != NULL; desc = desc->next)
+ fip_for_each_desc(fip, desc)
if (desc->image != NULL)
nr_images++;
@@ -324,7 +330,7 @@ int pack_images(struct fip_state *fip,
toc_entry = (fip_toc_entry_t *)(toc_header + 1);
entry_offset = buf_size;
- for (desc = fip->image_desc_head; desc != NULL; desc = desc->next) {
+ fip_for_each_desc(fip, desc) {
struct fip_image *image = desc->image;
if (image == NULL || (image->toc_e.size == 0ULL))
@@ -360,7 +366,7 @@ int pack_images(struct fip_state *fip,
pr_verbose("Payload size: %llu bytes\n", payload_size);
- for (desc = fip->image_desc_head; desc != NULL; desc = desc->next) {
+ fip_for_each_desc(fip, desc) {
struct fip_image *image = desc->image;
if (image == NULL)
@@ -399,7 +405,7 @@ int update_fip(struct fip_state *fip)
struct fip_image_desc *desc;
/* Add or replace images in the FIP file. */
- for (desc = fip->image_desc_head; desc != NULL; desc = desc->next) {
+ fip_for_each_desc(fip, desc) {
struct fip_image *image;
if (desc->action != DO_PACK)
--
2.39.5
^ permalink raw reply [flat|nested] 22+ messages in thread
* [PATCH v2 06/20] fip: use uuid_equal() and uuid_is_null()
2025-02-12 14:09 [PATCH v2 00/20] ARM: K3 updates Sascha Hauer
` (4 preceding siblings ...)
2025-02-12 14:09 ` [PATCH v2 05/20] fip: use linux list implementation Sascha Hauer
@ 2025-02-12 14:09 ` Sascha Hauer
2025-02-12 14:09 ` [PATCH v2 07/20] fiptool: do not typedef structs Sascha Hauer
` (14 subsequent siblings)
20 siblings, 0 replies; 22+ messages in thread
From: Sascha Hauer @ 2025-02-12 14:09 UTC (permalink / raw)
To: open list:BAREBOX
We have uuid_equal() and uuid_is_null(), use that rather than open coded
memcmp().
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
commands/fiptool.c | 10 ++++------
lib/fip.c | 4 ++--
2 files changed, 6 insertions(+), 8 deletions(-)
diff --git a/commands/fiptool.c b/commands/fiptool.c
index 45d534e470..b917c62a97 100644
--- a/commands/fiptool.c
+++ b/commands/fiptool.c
@@ -219,8 +219,7 @@ static __maybe_unused int create_cmd(struct fip_state *fip, int argc, char *argv
parse_blob_opt(optarg, &uuid,
filename, sizeof(filename));
- if (memcmp(&uuid, &uuid_null, sizeof(uuid_t)) == 0 ||
- filename[0] == '\0')
+ if (uuid_is_null(&uuid) || filename[0] == '\0')
return COMMAND_ERROR_USAGE;
desc = lookup_image_desc_from_uuid(fip, &uuid);
@@ -286,7 +285,7 @@ static __maybe_unused int update_cmd(struct fip_state *fip, int argc, char *argv
parse_blob_opt(optarg, &uuid,
filename, sizeof(filename));
- if (memcmp(&uuid, &uuid_null, sizeof(uuid_t)) == 0 ||
+ if (uuid_is_null(&uuid) ||
filename[0] == '\0')
return COMMAND_ERROR_USAGE;
@@ -368,8 +367,7 @@ static int unpack_cmd(struct fip_state *fip, int argc, char *argv[])
parse_blob_opt(optarg, &uuid,
filename, sizeof(filename));
- if (memcmp(&uuid, &uuid_null, sizeof(uuid_t)) == 0 ||
- filename[0] == '\0')
+ if (uuid_is_null(&uuid) || filename[0] == '\0')
return COMMAND_ERROR_USAGE;
desc = lookup_image_desc_from_uuid(fip, &uuid);
@@ -478,7 +476,7 @@ static __maybe_unused int remove_cmd(struct fip_state *fip, int argc, char *argv
parse_blob_opt(optarg, &uuid,
filename, sizeof(filename));
- if (memcmp(&uuid, &uuid_null, sizeof(uuid_t)) == 0)
+ if (uuid_is_null(&uuid))
return COMMAND_ERROR_USAGE;
desc = lookup_image_desc_from_uuid(fip, &uuid);
diff --git a/lib/fip.c b/lib/fip.c
index 63f1469086..774de2ad1d 100644
--- a/lib/fip.c
+++ b/lib/fip.c
@@ -127,7 +127,7 @@ struct fip_image_desc *lookup_image_desc_from_uuid(struct fip_state *fip,
struct fip_image_desc *desc;
fip_for_each_desc(fip, desc)
- if (memcmp(&desc->uuid, uuid, sizeof(uuid_t)) == 0)
+ if (uuid_equal(&desc->uuid, uuid))
return desc;
return NULL;
}
@@ -210,7 +210,7 @@ int parse_fip(struct fip_state *fip,
struct fip_image_desc *desc;
/* Found the ToC terminator, we are done. */
- if (memcmp(&toc_entry->uuid, &uuid_null, sizeof(uuid_t)) == 0) {
+ if (uuid_is_null(&toc_entry->uuid)) {
terminated = 1;
break;
}
--
2.39.5
^ permalink raw reply [flat|nested] 22+ messages in thread
* [PATCH v2 07/20] fiptool: do not typedef structs
2025-02-12 14:09 [PATCH v2 00/20] ARM: K3 updates Sascha Hauer
` (5 preceding siblings ...)
2025-02-12 14:09 ` [PATCH v2 06/20] fip: use uuid_equal() and uuid_is_null() Sascha Hauer
@ 2025-02-12 14:09 ` Sascha Hauer
2025-02-12 14:09 ` [PATCH v2 08/20] fip: add fip_ prefix Sascha Hauer
` (13 subsequent siblings)
20 siblings, 0 replies; 22+ messages in thread
From: Sascha Hauer @ 2025-02-12 14:09 UTC (permalink / raw)
To: open list:BAREBOX
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
commands/fiptool.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/commands/fiptool.c b/commands/fiptool.c
index b917c62a97..eb7d9b5ac7 100644
--- a/commands/fiptool.c
+++ b/commands/fiptool.c
@@ -24,11 +24,11 @@
#include <fip.h>
#include <fiptool.h>
-typedef struct cmd {
+struct cmd {
char *name;
int (*handler)(struct fip_state *fip, int, char **);
void (*usage)(int);
-} cmd_t;
+};
static int write_image_to_file(const struct fip_image *image, const char *filename)
@@ -532,7 +532,7 @@ static __maybe_unused int remove_cmd(struct fip_state *fip, int argc, char *argv
}
/* Available subcommands. */
-static cmd_t cmds[] = {
+static struct cmd cmds[] = {
{ .name = "info", .handler = info_cmd, },
{ .name = "uuid", .handler = uuid_cmd, },
{ .name = "unpack", .handler = unpack_cmd, },
--
2.39.5
^ permalink raw reply [flat|nested] 22+ messages in thread
* [PATCH v2 08/20] fip: add fip_ prefix
2025-02-12 14:09 [PATCH v2 00/20] ARM: K3 updates Sascha Hauer
` (6 preceding siblings ...)
2025-02-12 14:09 ` [PATCH v2 07/20] fiptool: do not typedef structs Sascha Hauer
@ 2025-02-12 14:09 ` Sascha Hauer
2025-02-12 14:09 ` [PATCH v2 09/20] fip: add fip_image_open() Sascha Hauer
` (12 subsequent siblings)
20 siblings, 0 replies; 22+ messages in thread
From: Sascha Hauer @ 2025-02-12 14:09 UTC (permalink / raw)
To: open list:BAREBOX
Many functions of the FIP library do not have an indication what
they are about. Add a fip_ prefix to all FIP related functions.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
commands/fiptool.c | 68 +++++++++++++++++++++++++++---------------------------
include/fiptool.h | 20 ++++++++--------
lib/fip.c | 40 ++++++++++++++++----------------
3 files changed, 64 insertions(+), 64 deletions(-)
diff --git a/commands/fiptool.c b/commands/fiptool.c
index eb7d9b5ac7..46b5ed29c3 100644
--- a/commands/fiptool.c
+++ b/commands/fiptool.c
@@ -62,7 +62,7 @@ static int info_cmd(struct fip_state *fip, int argc, char *argv[])
argc--, argv++;
- ret = parse_fip(fip, argv[0], &toc_header);
+ ret = fip_parse(fip, argv[0], &toc_header);
if (ret)
return ret;
@@ -195,10 +195,10 @@ static __maybe_unused int create_cmd(struct fip_state *fip, int argc, char *argv
case 'e': {
struct fip_image_desc *desc;
- desc = lookup_image_desc_from_opt(fip, &optarg);
+ desc = fip_lookup_image_desc_from_opt(fip, &optarg);
if (!desc)
return COMMAND_ERROR;
- set_image_desc_action(desc, DO_PACK, optarg);
+ fip_set_image_desc_action(desc, DO_PACK, optarg);
break;
}
case 'p':
@@ -222,13 +222,13 @@ static __maybe_unused int create_cmd(struct fip_state *fip, int argc, char *argv
if (uuid_is_null(&uuid) || filename[0] == '\0')
return COMMAND_ERROR_USAGE;
- desc = lookup_image_desc_from_uuid(fip, &uuid);
+ desc = fip_lookup_image_desc_from_uuid(fip, &uuid);
if (desc == NULL) {
snprintf(name, sizeof(name), "%pU", &uuid);
- desc = new_image_desc(&uuid, name, "blob");
- add_image_desc(fip, desc);
+ desc = fip_new_image_desc(&uuid, name, "blob");
+ fip_add_image_desc(fip, desc);
}
- set_image_desc_action(desc, DO_PACK, filename);
+ fip_set_image_desc_action(desc, DO_PACK, filename);
break;
}
default:
@@ -241,10 +241,10 @@ static __maybe_unused int create_cmd(struct fip_state *fip, int argc, char *argv
if (argc == 0)
return COMMAND_ERROR_USAGE;
- if (update_fip(fip))
+ if (fip_update(fip))
return COMMAND_ERROR;
- return pack_images(fip, argv[0], toc_flags, align);
+ return fip_pack_images(fip, argv[0], toc_flags, align);
}
@@ -265,10 +265,10 @@ static __maybe_unused int update_cmd(struct fip_state *fip, int argc, char *argv
case 'e': {
struct fip_image_desc *desc;
- desc = lookup_image_desc_from_opt(fip, &optarg);
+ desc = fip_lookup_image_desc_from_opt(fip, &optarg);
if (!desc)
return COMMAND_ERROR;
- set_image_desc_action(desc, DO_PACK, optarg);
+ fip_set_image_desc_action(desc, DO_PACK, optarg);
break;
}
case 'p':
@@ -289,13 +289,13 @@ static __maybe_unused int update_cmd(struct fip_state *fip, int argc, char *argv
filename[0] == '\0')
return COMMAND_ERROR_USAGE;
- desc = lookup_image_desc_from_uuid(fip, &uuid);
+ desc = fip_lookup_image_desc_from_uuid(fip, &uuid);
if (desc == NULL) {
snprintf(name, sizeof(name), "%pU", &uuid);
- desc = new_image_desc(&uuid, name, "blob");
- add_image_desc(fip, desc);
+ desc = fip_new_image_desc(&uuid, name, "blob");
+ fip_add_image_desc(fip, desc);
}
- set_image_desc_action(desc, DO_PACK, filename);
+ fip_set_image_desc_action(desc, DO_PACK, filename);
break;
}
case 'a':
@@ -320,7 +320,7 @@ static __maybe_unused int update_cmd(struct fip_state *fip, int argc, char *argv
snprintf(outfile, sizeof(outfile), "%s", argv[0]);
if (file_exists(argv[0])) {
- ret = parse_fip(fip, argv[0], &toc_header);
+ ret = fip_parse(fip, argv[0], &toc_header);
if (ret)
return ret;
}
@@ -329,10 +329,10 @@ static __maybe_unused int update_cmd(struct fip_state *fip, int argc, char *argv
toc_header.flags &= ~(0xffffULL << 32);
toc_flags = (toc_header.flags |= toc_flags);
- if (update_fip(fip))
+ if (fip_update(fip))
return COMMAND_ERROR;
- return pack_images(fip, outfile, toc_flags, align);
+ return fip_pack_images(fip, outfile, toc_flags, align);
}
static int unpack_cmd(struct fip_state *fip, int argc, char *argv[])
@@ -351,10 +351,10 @@ static int unpack_cmd(struct fip_state *fip, int argc, char *argv[])
case 'e': {
struct fip_image_desc *desc;
- desc = lookup_image_desc_from_opt(fip, &optarg);
+ desc = fip_lookup_image_desc_from_opt(fip, &optarg);
if (!desc)
return COMMAND_ERROR;
- set_image_desc_action(desc, DO_UNPACK, optarg);
+ fip_set_image_desc_action(desc, DO_UNPACK, optarg);
unpack_all = 0;
break;
}
@@ -370,13 +370,13 @@ static int unpack_cmd(struct fip_state *fip, int argc, char *argv[])
if (uuid_is_null(&uuid) || filename[0] == '\0')
return COMMAND_ERROR_USAGE;
- desc = lookup_image_desc_from_uuid(fip, &uuid);
+ desc = fip_lookup_image_desc_from_uuid(fip, &uuid);
if (desc == NULL) {
snprintf(name, sizeof(name), "%pU", &uuid);
- desc = new_image_desc(&uuid, name, "blob");
- add_image_desc(fip, desc);
+ desc = fip_new_image_desc(&uuid, name, "blob");
+ fip_add_image_desc(fip, desc);
}
- set_image_desc_action(desc, DO_UNPACK, filename);
+ fip_set_image_desc_action(desc, DO_UNPACK, filename);
unpack_all = 0;
break;
}
@@ -396,7 +396,7 @@ static int unpack_cmd(struct fip_state *fip, int argc, char *argv[])
if (argc == 0)
return COMMAND_ERROR_USAGE;
- ret = parse_fip(fip, argv[0], NULL);
+ ret = fip_parse(fip, argv[0], NULL);
if (ret)
return ret;
@@ -457,10 +457,10 @@ static __maybe_unused int remove_cmd(struct fip_state *fip, int argc, char *argv
case 'e': {
struct fip_image_desc *desc;
- desc = lookup_image_desc_from_opt(fip, &optarg);
+ desc = fip_lookup_image_desc_from_opt(fip, &optarg);
if (!desc)
return COMMAND_ERROR;
- set_image_desc_action(desc, DO_REMOVE, NULL);
+ fip_set_image_desc_action(desc, DO_REMOVE, NULL);
break;
}
case 'a':
@@ -479,13 +479,13 @@ static __maybe_unused int remove_cmd(struct fip_state *fip, int argc, char *argv
if (uuid_is_null(&uuid))
return COMMAND_ERROR_USAGE;
- desc = lookup_image_desc_from_uuid(fip, &uuid);
+ desc = fip_lookup_image_desc_from_uuid(fip, &uuid);
if (desc == NULL) {
snprintf(name, sizeof(name), "%pU", &uuid);
- desc = new_image_desc(&uuid, name, "blob");
- add_image_desc(fip, desc);
+ desc = fip_new_image_desc(&uuid, name, "blob");
+ fip_add_image_desc(fip, desc);
}
- set_image_desc_action(desc, DO_REMOVE, NULL);
+ fip_set_image_desc_action(desc, DO_REMOVE, NULL);
break;
}
case 'f':
@@ -511,7 +511,7 @@ static __maybe_unused int remove_cmd(struct fip_state *fip, int argc, char *argv
if (outfile[0] == '\0')
snprintf(outfile, sizeof(outfile), "%s", argv[0]);
- ret = parse_fip(fip, argv[0], &toc_header);
+ ret = fip_parse(fip, argv[0], &toc_header);
if (ret)
return ret;
@@ -528,7 +528,7 @@ static __maybe_unused int remove_cmd(struct fip_state *fip, int argc, char *argv
}
}
- return pack_images(fip, outfile, toc_header.flags, align);
+ return fip_pack_images(fip, outfile, toc_header.flags, align);
}
/* Available subcommands. */
@@ -567,7 +567,7 @@ static int do_fiptool(int argc, char *argv[])
if (argc == 0)
return COMMAND_ERROR_USAGE;
- fill_image_descs(fip);
+ fip_fill_image_descs(fip);
for (i = 0; i < ARRAY_SIZE(cmds); i++) {
if (strcmp(cmds[i].name, argv[0]) == 0) {
struct getopt_context gc;
diff --git a/include/fiptool.h b/include/fiptool.h
index 5a3fdee6e0..6a12466c29 100644
--- a/include/fiptool.h
+++ b/include/fiptool.h
@@ -49,31 +49,31 @@ struct fip_state {
struct fip_state *fip_new(void);
void fip_free(struct fip_state *fip);
-struct fip_image_desc *new_image_desc(const uuid_t *uuid,
+struct fip_image_desc *fip_new_image_desc(const uuid_t *uuid,
const char *name, const char *cmdline_name);
-void set_image_desc_action(struct fip_image_desc *desc, int action,
+void fip_set_image_desc_action(struct fip_image_desc *desc, int action,
const char *arg);
-void free_image_desc(struct fip_image_desc *desc);
+void fip_free_image_desc(struct fip_image_desc *desc);
-void add_image_desc(struct fip_state *fip, struct fip_image_desc *desc);
+void fip_add_image_desc(struct fip_state *fip, struct fip_image_desc *desc);
-void fill_image_descs(struct fip_state *fip);
+void fip_fill_image_descs(struct fip_state *fip);
-struct fip_image_desc *lookup_image_desc_from_uuid(struct fip_state *fip,
+struct fip_image_desc *fip_lookup_image_desc_from_uuid(struct fip_state *fip,
const uuid_t *uuid);
-struct fip_image_desc *lookup_image_desc_from_opt(struct fip_state *fip, char **arg);
+struct fip_image_desc *fip_lookup_image_desc_from_opt(struct fip_state *fip, char **arg);
-int parse_fip(struct fip_state *fip,
+int fip_parse(struct fip_state *fip,
const char *filename, fip_toc_header_t *toc_header_out);
-int pack_images(struct fip_state *fip,
+int fip_pack_images(struct fip_state *fip,
const char *filename,
uint64_t toc_flags, unsigned long align);
-int update_fip(struct fip_state *fip);
+int fip_update(struct fip_state *fip);
#define TOC_HEADER_SERIAL_NUMBER 0x12345678
diff --git a/lib/fip.c b/lib/fip.c
index 774de2ad1d..075cd0e1e6 100644
--- a/lib/fip.c
+++ b/lib/fip.c
@@ -26,7 +26,7 @@
#include <fip.h>
#include <fiptool.h>
-struct fip_image_desc *new_image_desc(const uuid_t *uuid,
+struct fip_image_desc *fip_new_image_desc(const uuid_t *uuid,
const char *name, const char *cmdline_name)
{
struct fip_image_desc *desc;
@@ -39,7 +39,7 @@ struct fip_image_desc *new_image_desc(const uuid_t *uuid,
return desc;
}
-void set_image_desc_action(struct fip_image_desc *desc, int action,
+void fip_set_image_desc_action(struct fip_image_desc *desc, int action,
const char *arg)
{
ASSERT(desc != NULL);
@@ -52,7 +52,7 @@ void set_image_desc_action(struct fip_image_desc *desc, int action,
desc->action_arg = xstrdup(arg);
}
-void free_image_desc(struct fip_image_desc *desc)
+void fip_free_image_desc(struct fip_image_desc *desc)
{
free(desc->name);
free(desc->cmdline_name);
@@ -64,7 +64,7 @@ void free_image_desc(struct fip_image_desc *desc)
free(desc);
}
-void add_image_desc(struct fip_state *fip, struct fip_image_desc *desc)
+void fip_add_image_desc(struct fip_state *fip, struct fip_image_desc *desc)
{
list_add_tail(&desc->list, &fip->descs);
fip->nr_image_descs++;
@@ -86,7 +86,7 @@ void fip_free(struct fip_state *fip)
struct fip_image_desc *desc, *tmp;
fip_for_each_desc_safe(fip, desc, tmp) {
- free_image_desc(desc);
+ fip_free_image_desc(desc);
fip->nr_image_descs--;
}
@@ -95,7 +95,7 @@ void fip_free(struct fip_state *fip)
free(fip);
}
-void fill_image_descs(struct fip_state *fip)
+void fip_fill_image_descs(struct fip_state *fip)
{
toc_entry_t *toc_entry;
@@ -104,24 +104,24 @@ void fill_image_descs(struct fip_state *fip)
toc_entry++) {
struct fip_image_desc *desc;
- desc = new_image_desc(&toc_entry->uuid,
+ desc = fip_new_image_desc(&toc_entry->uuid,
toc_entry->name,
toc_entry->cmdline_name);
- add_image_desc(fip, desc);
+ fip_add_image_desc(fip, desc);
}
for (toc_entry = plat_def_toc_entries;
toc_entry->cmdline_name != NULL;
toc_entry++) {
struct fip_image_desc *desc;
- desc = new_image_desc(&toc_entry->uuid,
+ desc = fip_new_image_desc(&toc_entry->uuid,
toc_entry->name,
toc_entry->cmdline_name);
- add_image_desc(fip, desc);
+ fip_add_image_desc(fip, desc);
}
}
-struct fip_image_desc *lookup_image_desc_from_uuid(struct fip_state *fip,
+struct fip_image_desc *fip_lookup_image_desc_from_uuid(struct fip_state *fip,
const uuid_t *uuid)
{
struct fip_image_desc *desc;
@@ -132,7 +132,7 @@ struct fip_image_desc *lookup_image_desc_from_uuid(struct fip_state *fip,
return NULL;
}
-struct fip_image_desc *lookup_image_desc_from_opt(struct fip_state *fip, char **arg)
+struct fip_image_desc *fip_lookup_image_desc_from_opt(struct fip_state *fip, char **arg)
{
int len = 0;
struct fip_image_desc *desc;
@@ -153,7 +153,7 @@ struct fip_image_desc *lookup_image_desc_from_opt(struct fip_state *fip, char **
return NULL;
}
-int parse_fip(struct fip_state *fip,
+int fip_parse(struct fip_state *fip,
const char *filename, fip_toc_header_t *toc_header_out)
{
struct stat st;
@@ -238,17 +238,17 @@ int parse_fip(struct fip_state *fip,
toc_entry->size);
/* If this is an unknown image, create a descriptor for it. */
- desc = lookup_image_desc_from_uuid(fip, &toc_entry->uuid);
+ desc = fip_lookup_image_desc_from_uuid(fip, &toc_entry->uuid);
if (desc == NULL) {
char name[UUID_STRING_LEN + 1], filename[PATH_MAX];
snprintf(name, sizeof(name), "%pU", &toc_entry->uuid);
snprintf(filename, sizeof(filename), "%s%s",
name, ".bin");
- desc = new_image_desc(&toc_entry->uuid, name, "blob");
+ desc = fip_new_image_desc(&toc_entry->uuid, name, "blob");
desc->action = DO_UNPACK;
desc->action_arg = xstrdup(filename);
- add_image_desc(fip, desc);
+ fip_add_image_desc(fip, desc);
}
ASSERT(desc->image == NULL);
@@ -266,7 +266,7 @@ int parse_fip(struct fip_state *fip,
return 0;
}
-static struct fip_image *read_image_from_file(const uuid_t *uuid, const char *filename)
+static struct fip_image *fip_read_image_from_file(const uuid_t *uuid, const char *filename)
{
struct stat st;
struct fip_image *image;
@@ -299,7 +299,7 @@ static struct fip_image *read_image_from_file(const uuid_t *uuid, const char *fi
return image;
}
-int pack_images(struct fip_state *fip,
+int fip_pack_images(struct fip_state *fip,
const char *filename,
uint64_t toc_flags, unsigned long align)
{
@@ -400,7 +400,7 @@ int pack_images(struct fip_state *fip,
* in update_fip() creating the new FIP file from scratch because the
* internal image table is not populated.
*/
-int update_fip(struct fip_state *fip)
+int fip_update(struct fip_state *fip)
{
struct fip_image_desc *desc;
@@ -411,7 +411,7 @@ int update_fip(struct fip_state *fip)
if (desc->action != DO_PACK)
continue;
- image = read_image_from_file(&desc->uuid,
+ image = fip_read_image_from_file(&desc->uuid,
desc->action_arg);
if (!image)
return -1;
--
2.39.5
^ permalink raw reply [flat|nested] 22+ messages in thread
* [PATCH v2 09/20] fip: add fip_image_open()
2025-02-12 14:09 [PATCH v2 00/20] ARM: K3 updates Sascha Hauer
` (7 preceding siblings ...)
2025-02-12 14:09 ` [PATCH v2 08/20] fip: add fip_ prefix Sascha Hauer
@ 2025-02-12 14:09 ` Sascha Hauer
2025-02-12 14:09 ` [PATCH v2 10/20] ARM: k3: r5: add USB DFU and eMMC boot support Sascha Hauer
` (11 subsequent siblings)
20 siblings, 0 replies; 22+ messages in thread
From: Sascha Hauer @ 2025-02-12 14:09 UTC (permalink / raw)
To: open list:BAREBOX
This adds a fip_image_open() function as an alternative to fip_parse().
Unline fip_parse() the new function:
- Allows to specify an offset with the file for reading a FIP image from
partitions
- Does not read past the image when the FIP image is on a partition
which is bigger than the FIP image
- less memory consumption
fip_image_open() is mainly useful for reading a FIP image without the
intent of modifying it.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
include/fiptool.h | 4 ++
lib/fip.c | 132 +++++++++++++++++++++++++++++++++++++++++++++++++++++-
2 files changed, 135 insertions(+), 1 deletion(-)
diff --git a/include/fiptool.h b/include/fiptool.h
index 6a12466c29..bc42f7edd6 100644
--- a/include/fiptool.h
+++ b/include/fiptool.h
@@ -30,12 +30,14 @@ struct fip_image_desc {
struct fip_image {
struct fip_toc_entry toc_e;
void *buffer;
+ bool buf_no_free;
};
struct fip_state {
struct list_head descs;
size_t nr_image_descs;
int verbose;
+ void *buffer;
};
#define pr_verbose(...) do { \
@@ -92,4 +94,6 @@ extern toc_entry_t plat_def_toc_entries[];
#define fip_for_each_desc_safe(fip, e, tmp) \
list_for_each_entry_safe(e, tmp, &(fip)->descs, list)
+struct fip_state *fip_image_open(const char *filename, size_t offset);
+
#endif /* FIPTOOL_H */
diff --git a/lib/fip.c b/lib/fip.c
index 075cd0e1e6..39b0fd20aa 100644
--- a/lib/fip.c
+++ b/lib/fip.c
@@ -58,7 +58,8 @@ void fip_free_image_desc(struct fip_image_desc *desc)
free(desc->cmdline_name);
free(desc->action_arg);
if (desc->image) {
- free(desc->image->buffer);
+ if (!desc->image->buf_no_free)
+ free(desc->image->buffer);
free(desc->image);
}
free(desc);
@@ -92,6 +93,7 @@ void fip_free(struct fip_state *fip)
ASSERT(fip->nr_image_descs == 0);
+ free(fip->buffer);
free(fip);
}
@@ -430,3 +432,131 @@ int fip_update(struct fip_state *fip)
return 0;
}
+
+/*
+ * fip_image_open - open a FIP image for readonly access
+ * @filename: The filename of the FIP image
+ * @offset: The offset of the FIP image in the file
+ *
+ * This opens a FIP image for readonly access. This is an alternative
+ * implementation for fip_parse() with these differences:
+ * - suitable for reading FIP images from raw partitions. This function
+ * only reads the FIP image, even when the partition is bigger than the
+ * image
+ * - Allows to specify an offset within the partition where the FIP image
+ * starts
+ * - Do not memdup the images from the full FIP image
+ *
+ * This function is for easy readonly access to the images within the FIP
+ * image. Do not call any of the above FIP manipulation functions other than
+ * fip_free() on an image opened with this function.
+ */
+struct fip_state *fip_image_open(const char *filename, size_t offset)
+{
+ fip_toc_header_t toc_header;
+ int ret;
+ int fd;
+ struct fip_state *fip_state;
+ LIST_HEAD(entries);
+ size_t fip_headers_size, total = 0;
+ struct fip_image_desc *desc;
+ off_t pos;
+ int n_entries = 0;
+
+ fd = open(filename, O_RDONLY);
+ if (fd < 0)
+ return ERR_PTR(fd);
+
+ fip_state = fip_new();
+
+ pos = lseek(fd, offset, SEEK_SET);
+ if (pos != offset) {
+ ret = -EINVAL;
+ goto err;
+ }
+
+ ret = read_full(fd, &toc_header, sizeof(toc_header));
+ if (ret < 0)
+ goto err;
+
+ if (ret < sizeof(toc_header)) {
+ ret = -ENODATA;
+ goto err;
+ }
+
+ if (toc_header.name != TOC_HEADER_NAME) {
+ pr_err("%s is not a FIP file: unknown magic = 0x%08x\n",
+ filename, toc_header.name);
+ ret = -EINVAL;
+ goto err;
+ }
+
+ /* read all toc entries */
+ while (1) {
+ struct fip_image_desc *desc = xzalloc(sizeof(*desc));
+ struct fip_image *image = xzalloc(sizeof(*image));
+ struct fip_toc_entry *toc_entry = &image->toc_e;
+
+ desc->image = image;
+
+ ret = read_full(fd, toc_entry, sizeof(*toc_entry));
+ if (ret < 0)
+ goto err;
+ if (ret < sizeof(*toc_entry)) {
+ ret = -ENODATA;
+ goto err;
+ }
+
+ list_add_tail(&desc->list, &fip_state->descs);
+
+ pr_debug("Read TOC entry %pU %llu %llu\n", &toc_entry->uuid,
+ toc_entry->offset_address, toc_entry->size);
+
+ /* Found the ToC terminator, we are done. */
+ if (uuid_is_null(&toc_entry->uuid))
+ break;
+ }
+
+ /* determine buffer size */
+ fip_for_each_desc(fip_state, desc) {
+ uint64_t this_end = desc->image->toc_e.offset_address + desc->image->toc_e.size;
+
+ if (this_end > total)
+ total = this_end;
+ n_entries++;
+ }
+
+ fip_headers_size = n_entries * sizeof(struct fip_toc_entry) + sizeof(fip_toc_header_t);
+
+ total -= fip_headers_size;
+
+ fip_state->buffer = malloc(total);
+ if (!fip_state->buffer) {
+ ret = -ENOMEM;
+ goto err;
+ }
+
+ ret = read_full(fd, fip_state->buffer, total);
+ if (ret < 0)
+ goto err;
+
+ if (ret < total) {
+ ret = -ENODATA;
+ goto err;
+ }
+
+ close(fd);
+
+ fip_for_each_desc(fip_state, desc) {
+ desc->image->buffer = fip_state->buffer +
+ desc->image->toc_e.offset_address - fip_headers_size;
+ desc->image->buf_no_free = true;
+ }
+
+ return fip_state;
+err:
+ close(fd);
+ fip_free(fip_state);
+
+ return ERR_PTR(ret);
+}
--
2.39.5
^ permalink raw reply [flat|nested] 22+ messages in thread
* [PATCH v2 10/20] ARM: k3: r5: add USB DFU and eMMC boot support
2025-02-12 14:09 [PATCH v2 00/20] ARM: K3 updates Sascha Hauer
` (8 preceding siblings ...)
2025-02-12 14:09 ` [PATCH v2 09/20] fip: add fip_image_open() Sascha Hauer
@ 2025-02-12 14:09 ` Sascha Hauer
2025-02-12 14:09 ` [PATCH v2 11/20] ARM: am625-sk: enable 32k crystal Sascha Hauer
` (10 subsequent siblings)
20 siblings, 0 replies; 22+ messages in thread
From: Sascha Hauer @ 2025-02-12 14:09 UTC (permalink / raw)
To: open list:BAREBOX
This patch adds USB DFU and eMMC boot support for the k3 SoCs.
DFU mode is entered when the SoC is booted from USB. For continuing the
boot we need several binaries (bl31, OP-TEE, barebox, ti-dm firmware),
these can be uploaded as distinct files or combined together as a FIP
image. This patch also adds the possibility to put a FIP image on the
SD/eMMC card which is then preferred over the distinct files which were
previously expected on SD/eMMC cards.
Also the K3 SoCs have a boot mode to boot from eMMC boot partitions for
which this patch adds support. When this bootmode is selected the
tiboot3.bin file is loaded from the active boot partition. We then need
to load the FIP image from the same boot partition. This image is
expected to be at offset 1MiB in the boot partition.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
Documentation/boards/ti-k3.rst | 47 +++++++++
arch/arm/mach-k3/Kconfig | 1 +
arch/arm/mach-k3/r5.c | 232 +++++++++++++++++++++++++++++++++++------
include/mach/k3/common.h | 7 ++
4 files changed, 256 insertions(+), 31 deletions(-)
diff --git a/Documentation/boards/ti-k3.rst b/Documentation/boards/ti-k3.rst
index a1bf0b92e8..4b3822c020 100644
--- a/Documentation/boards/ti-k3.rst
+++ b/Documentation/boards/ti-k3.rst
@@ -69,6 +69,9 @@ OP-TEE is built from https://github.com/OP-TEE/optee_os.git::
PLATFORM=k3-am62x
cp out/arm-plat-k3/core/tee-raw.bin $TI_BOOT/optee.bin
+OP-TEE is optional. barebox will continue without ``optee.bin`` when the file
+does not exist.
+
Copying ti-dm.bin
-----------------
@@ -77,3 +80,47 @@ copied to the eMMC/SD as well::
cp $TI_LINUX_FIRMWARE/ti-dm/am62xx/ipc_echo_testb_mcu1_0_release_strip.xer5f $TI_BOOT/ti-dm.bin
+Combining binaries into a FIP image
+-----------------------------------
+
+Alternatively to putting the different binaries (``barebox.bin``, ``bl31.bin``, ``optee.bin``
+and ``ti-dm.bin``) into the FAT image the files can be combined into a FIP image named
+``k3.fip``.::
+
+ fiptool create --soc-fw bl31.bin \
+ --tos-fw optee.bin \
+ --nt-fw barebox-beagleplay.img \
+ --blob uuid=9e8c2017-8b94-4e2b-a7b3-a0f88eabb8ae,file=ti-dm.bin k3.fip
+
+USB DFU boot
+------------
+K3 Boards can be booted via USB DFU. When in USB boot mode the initial stage can be uploaded
+using ``dfu-util``::
+
+ dfu-util -D barebox-beagleplay-r5.img -a bootloader
+
+This will start the initial stage which then expects the following stages which can
+be uploaded with ``dfu-util`` as well, either as FIP image::
+
+ dfu-util -D k3.fip -a fip
+
+or as separate files::
+
+ dfu-util -D blb31.bin -a tfa
+ dfu-util -D optee.bin -a optee
+ dfu-util -D ti-dm.bin -a ti-dm
+ dfu-util -D barebox-beagleplay.img -a barebox
+
+Uploading optee.bin can be skipped in case it's not needed.
+
+eMMC boot
+---------
+K3 boards can boot from eMMC boot partitions. In this mode the ROM reads the tiboot3.bin
+raw from the active boot partition. In this mode barebox expects the FIP image with the
+following stages in the same boot partition at offset 1MiB. There is a barebox update handler
+which takes a combined image consisting of tiboot3.bin and the FIP image to allow for a
+failsafe update. This image can't be generated by the barebox build system though. It has
+to be generated by a build system or manually::
+
+ dd if=images/barebox-beagleplay-r5.img of=barebox-beagleplay-emmc.img
+ dd if=k3.fip of=barebox-beagleplay-emmc.img bs=1024 seek=1024
diff --git a/arch/arm/mach-k3/Kconfig b/arch/arm/mach-k3/Kconfig
index 51b02b697c..50919dc7e3 100644
--- a/arch/arm/mach-k3/Kconfig
+++ b/arch/arm/mach-k3/Kconfig
@@ -15,6 +15,7 @@ config MACH_K3_CORTEX_R5
select ARMV7R_MPU
select ELF
select K3_DDRSS
+ select FIP
depends on 32BIT
select ARM_USE_COMPRESSED_DTB
default y
diff --git a/arch/arm/mach-k3/r5.c b/arch/arm/mach-k3/r5.c
index 32d98fe89a..ced1eb2856 100644
--- a/arch/arm/mach-k3/r5.c
+++ b/arch/arm/mach-k3/r5.c
@@ -6,6 +6,7 @@
#include <init.h>
#include <libfile.h>
#include <fs.h>
+#include <fip.h>
#include <firmware.h>
#include <linux/remoteproc.h>
#include <soc/ti/ti_sci_protocol.h>
@@ -14,6 +15,11 @@
#include <asm/cache.h>
#include <linux/sizes.h>
#include <barebox.h>
+#include <bootsource.h>
+#include <linux/usb/gadget-multi.h>
+#include <mach/k3/common.h>
+#include <mci.h>
+#include <fiptool.h>
#define RTC_BASE_ADDRESS 0x2b1f0000
#define K3RTC_KICK0_UNLOCK_VALUE 0x83e70b13
@@ -217,38 +223,143 @@ void am625_early_init(void)
ti_pd_wait(pd_base, 0);
}
+#if IN_PROPER
+
/*
* The bl31 and optee binaries are relocatable, but these addresses
* are hardcoded as reserved mem regions in the upstream device trees.
*/
-#define BL31_ADDRESS 0x9e780000
-#define OPTEE_ADDRESS 0x9e800000
+#define BL31_ADDRESS (void *)0x9e780000
+#define BL32_ADDRESS (void *)0x9e800000
+#define BAREBOX_ADDRESS (void *)0x80080000
-static int k3_r5_start_image(void)
+static void *k3_ti_dm;
+
+static bool have_bl31;
+static bool have_bl32;
+static bool have_bl33;
+
+static uuid_t uuid_bl31 = UUID_EL3_RUNTIME_FIRMWARE_BL31;
+static uuid_t uuid_ti_dm_fw = UUID_TI_DM_FW;
+static uuid_t uuid_bl33 = UUID_NON_TRUSTED_FIRMWARE_BL33;
+static uuid_t uuid_bl32 = UUID_SECURE_PAYLOAD_BL32;
+
+static int load_fip(const char *filename, off_t offset)
{
- int err;
- void *ti_dm_buf;
- ssize_t size;
- struct firmware fw;
- const struct ti_sci_handle *ti_sci;
- void *bl31 = (void *)BL31_ADDRESS;
- void *barebox = (void *)0x80080000;
- void *optee = (void *)OPTEE_ADDRESS;
- struct elf_image *elf;
- void __noreturn (*ti_dm)(void);
- struct rproc *arm64_rproc;
+ struct fip_state *fip;
+ struct fip_image_desc *desc;
- ti_sci = ti_sci_get_handle(NULL);
- if (IS_ERR(ti_sci))
- return -EINVAL;
+ fip = fip_image_open(filename, offset);
+ if (IS_ERR(fip)) {
+ pr_err("Cannot open FIP image: %pe\n", fip);
+ return PTR_ERR(fip);
+ }
- arm64_rproc = ti_k3_am64_get_handle();
- if (!arm64_rproc) {
- pr_err("Cannot get rproc handle\n");
- return -EINVAL;
+ fip_for_each_desc(fip, desc) {
+ struct fip_toc_entry *toc_entry = &desc->image->toc_e;
+
+ if (uuid_equal(&toc_entry->uuid, &uuid_bl31)) {
+ memcpy(BL31_ADDRESS, desc->image->buffer, toc_entry->size);
+ have_bl31 = true;
+ }
+
+ if (uuid_equal(&toc_entry->uuid, &uuid_bl33)) {
+ memcpy(BAREBOX_ADDRESS, desc->image->buffer, toc_entry->size);
+ have_bl33 = true;
+ }
+
+ if (uuid_equal(&toc_entry->uuid, &uuid_bl32)) {
+ memcpy(BL32_ADDRESS, desc->image->buffer, toc_entry->size);
+ have_bl32 = true;
+ }
+
+ if (uuid_equal(&toc_entry->uuid, &uuid_ti_dm_fw)) {
+ k3_ti_dm = xmemdup(desc->image->buffer, toc_entry->size);
+ }
}
- size = read_file_into_buf("/boot/optee.bin", optee, SZ_32M);
+ fip_free(fip);
+
+ return 0;
+}
+
+static void do_dfu(void)
+{
+ struct usbgadget_funcs funcs = {};
+ int ret;
+ struct stat s;
+ ssize_t size;
+
+ funcs.flags |= USBGADGET_DFU;
+ funcs.dfu_opts = "/optee.bin(optee)c,"
+ "/bl31.bin(tfa)c,"
+ "/ti-dm.bin(ti-dm)c,"
+ "/barebox.bin(barebox)cs,"
+ "/fip.img(fip)cs";
+
+ ret = usbgadget_prepare_register(&funcs);
+ if (ret)
+ goto err;
+
+ while (1) {
+ if (!have_bl32) {
+ size = read_file_into_buf("/optee.bin", BL32_ADDRESS, SZ_32M);
+ if (size > 0) {
+ printf("Downloaded OP-TEE\n");
+ have_bl32 = true;
+ }
+ }
+
+ if (!have_bl31) {
+ size = read_file_into_buf("/bl31.bin", BL31_ADDRESS, SZ_32M);
+ if (size > 0) {
+ printf("Downloaded TF-A\n");
+ have_bl31 = true;
+ }
+ }
+
+ if (!k3_ti_dm) {
+ ret = read_file_2("/ti-dm.bin", &size, &k3_ti_dm, FILESIZE_MAX);
+ if (!ret) {
+ printf("Downloaded TI-DM\n");
+ }
+ }
+
+ size = read_file_into_buf("/barebox.bin", BAREBOX_ADDRESS, SZ_32M);
+ if (size > 0) {
+ have_bl33 = true;
+ printf("Downloaded barebox image, DFU done\n");
+ break;
+ }
+
+ ret = stat("/fip.img", &s);
+ if (!ret) {
+ printf("Downloaded FIP image, DFU done\n");
+ load_fip("/fip.img", 0);
+ break;
+ }
+
+ command_slice_release();
+ mdelay(50);
+ command_slice_acquire();
+ };
+
+ return;
+
+err:
+ pr_err("DFU failed with: %pe\n", ERR_PTR(ret));
+}
+
+static int load_images(void)
+{
+ ssize_t size;
+ int err;
+
+ err = load_fip("/boot/k3.fip", 0);
+ if (!err)
+ return 0;
+
+ size = read_file_into_buf("/boot/optee.bin", BL32_ADDRESS, SZ_32M);
if (size < 0) {
if (size != -ENOENT) {
pr_err("Cannot load optee.bin: %pe\n", ERR_PTR(size));
@@ -256,31 +367,89 @@ static int k3_r5_start_image(void)
}
pr_info("optee.bin not found, continue without\n");
} else {
- pr_debug("Loaded optee.bin (size %u) to 0x%p\n", size, optee);
+ pr_debug("Loaded optee.bin (size %u) to 0x%p\n", size, BL32_ADDRESS);
}
- size = read_file_into_buf("/boot/barebox.bin", barebox, optee - barebox);
+ size = read_file_into_buf("/boot/barebox.bin", BAREBOX_ADDRESS, SZ_32M);
if (size < 0) {
pr_err("Cannot load barebox.bin: %pe\n", ERR_PTR(size));
return size;
}
- pr_debug("Loaded barebox.bin (size %u) to 0x%p\n", size, barebox);
+ pr_debug("Loaded barebox.bin (size %u) to 0x%p\n", size, BAREBOX_ADDRESS);
- size = read_file_into_buf("/boot/bl31.bin", bl31, barebox - optee);
+ size = read_file_into_buf("/boot/bl31.bin", BL31_ADDRESS, SZ_32M);
if (size < 0) {
pr_err("Cannot load bl31.bin: %pe\n", ERR_PTR(size));
return size;
}
- pr_debug("Loaded bl31.bin (size %u) to 0x%p\n", size, bl31);
+ pr_debug("Loaded bl31.bin (size %u) to 0x%p\n", size, BL31_ADDRESS);
- err = read_file_2("/boot/ti-dm.bin", &size, &ti_dm_buf, FILESIZE_MAX);
+ err = read_file_2("/boot/ti-dm.bin", &size, &k3_ti_dm, FILESIZE_MAX);
if (err) {
pr_err("Cannot load ti-dm.bin: %pe\n", ERR_PTR(err));
return err;
}
pr_debug("Loaded ti-dm.bin (size %u)\n", size);
- elf = elf_open_binary(ti_dm_buf);
+ return 0;
+}
+
+static int load_fip_emmc(void)
+{
+ int bootpart;
+ struct mci *mci;
+ char *fname;
+ const char *mmcdev = "mmc0";
+
+ device_detect_by_name(mmcdev);
+
+ mci = mci_get_device_by_name(mmcdev);
+ if (!mci)
+ return -EINVAL;
+
+ bootpart = mci->bootpart;
+
+ if (bootpart != 1 && bootpart != 2) {
+ pr_err("Unexpected bootpart value %d\n", bootpart);
+ bootpart = 1;
+ }
+
+ fname = xasprintf("/dev/%s.boot%d", mmcdev, bootpart - 1);
+
+ load_fip(fname, K3_EMMC_BOOTPART_TIBOOT3_BIN_SIZE);
+
+ free(fname);
+
+ return 0;
+}
+
+static int k3_r5_start_image(void)
+{
+ int err;
+ struct firmware fw;
+ const struct ti_sci_handle *ti_sci;
+ struct elf_image *elf;
+ void __noreturn (*ti_dm)(void);
+ struct rproc *arm64_rproc;
+
+ if (IS_ENABLED(CONFIG_USB_GADGET_DFU) && bootsource_get() == BOOTSOURCE_SERIAL)
+ do_dfu();
+ else if (k3_boot_is_emmc())
+ load_fip_emmc();
+ else
+ load_images();
+
+ ti_sci = ti_sci_get_handle(NULL);
+ if (IS_ERR(ti_sci))
+ return -EINVAL;
+
+ arm64_rproc = ti_k3_am64_get_handle();
+ if (!arm64_rproc) {
+ pr_err("Cannot get rproc handle\n");
+ return -EINVAL;
+ }
+
+ elf = elf_open_binary(k3_ti_dm);
if (IS_ERR(elf)) {
pr_err("Cannot open ELF image %pe\n", elf);
return PTR_ERR(elf);
@@ -292,9 +461,9 @@ static int k3_r5_start_image(void)
elf_close(elf);
}
- free(ti_dm_buf);
+ free(k3_ti_dm);
- fw.data = bl31;
+ fw.data = BL31_ADDRESS;
/* Release all the exclusive devices held by SPL before starting ATF */
pr_info("Starting TF-A on A53 core\n");
@@ -324,3 +493,4 @@ static int xload(void)
hang();
}
postenvironment_initcall(xload);
+#endif /* IN_PROPER */
diff --git a/include/mach/k3/common.h b/include/mach/k3/common.h
index 7f0796f7f4..14dfc4a28a 100644
--- a/include/mach/k3/common.h
+++ b/include/mach/k3/common.h
@@ -2,6 +2,11 @@
#define __MACH_K3_COMMON_H
#include <bootsource.h>
+#include <linux/sizes.h>
+#include <linux/uuid.h>
+
+#define UUID_TI_DM_FW \
+ UUID_INIT(0x9e8c2017, 0x8b94, 0x4e2b, 0xa7, 0xb3, 0xa0, 0xf8, 0x8e, 0xab, 0xb8, 0xae)
void am625_get_bootsource(enum bootsource *src, int *instance);
bool k3_boot_is_emmc(void);
@@ -9,4 +14,6 @@ u64 am625_sdram_size(void);
void am625_register_dram(void);
void am625_enable_32k_crystal(void);
+#define K3_EMMC_BOOTPART_TIBOOT3_BIN_SIZE SZ_1M
+
#endif /* __MACH_K3_COMMON_H */
--
2.39.5
^ permalink raw reply [flat|nested] 22+ messages in thread
* [PATCH v2 11/20] ARM: am625-sk: enable 32k crystal
2025-02-12 14:09 [PATCH v2 00/20] ARM: K3 updates Sascha Hauer
` (9 preceding siblings ...)
2025-02-12 14:09 ` [PATCH v2 10/20] ARM: k3: r5: add USB DFU and eMMC boot support Sascha Hauer
@ 2025-02-12 14:09 ` Sascha Hauer
2025-02-12 14:09 ` [PATCH v2 12/20] mci: am654: parse generic mmc node properties Sascha Hauer
` (9 subsequent siblings)
20 siblings, 0 replies; 22+ messages in thread
From: Sascha Hauer @ 2025-02-12 14:09 UTC (permalink / raw)
To: open list:BAREBOX
The am625-sk board has the 32k crystal equipped. Enable it to source the
RTC from the crystal rather than from the imprecise RC oscillator.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
arch/arm/boards/am625-sk/Makefile | 1 +
arch/arm/boards/am625-sk/board.c | 30 ++++++++++++++++++++++++++++++
2 files changed, 31 insertions(+)
diff --git a/arch/arm/boards/am625-sk/Makefile b/arch/arm/boards/am625-sk/Makefile
index 1ff9e75a00..8c45b1e154 100644
--- a/arch/arm/boards/am625-sk/Makefile
+++ b/arch/arm/boards/am625-sk/Makefile
@@ -1,3 +1,4 @@
pbl-y += lowlevel.o
+obj-y += board.o
pbl-$(CONFIG_MACH_K3_CORTEX_A) += entry.o
pbl-$(CONFIG_MACH_K3_CORTEX_R5) += entry-r5.o am625-sk-ddr.o am625sip-sk-ddr.o
diff --git a/arch/arm/boards/am625-sk/board.c b/arch/arm/boards/am625-sk/board.c
new file mode 100644
index 0000000000..fd3bcdeac6
--- /dev/null
+++ b/arch/arm/boards/am625-sk/board.c
@@ -0,0 +1,30 @@
+// SPDX-License-Identifier: GPL-2.0-only
+
+#define pr_fmt(fmt) "am625-sk: " fmt
+
+#include <linux/kernel.h>
+#include <mach/k3/common.h>
+#include <driver.h>
+#include <bbu.h>
+
+static int am625_sk_probe(struct device *dev)
+{
+ am625_enable_32k_crystal();
+
+ return 0;
+}
+
+static __maybe_unused struct of_device_id am625_sk_ids[] = {
+ {
+ .compatible = "ti,am625-sk",
+ }, {
+ /* sentinel */
+ }
+};
+
+static struct driver am625_sk_driver = {
+ .name = "am625-sk",
+ .probe = am625_sk_probe,
+ .of_compatible = am625_sk_ids,
+};
+coredevice_platform_driver(am625_sk_driver);
--
2.39.5
^ permalink raw reply [flat|nested] 22+ messages in thread
* [PATCH v2 12/20] mci: am654: parse generic mmc node properties
2025-02-12 14:09 [PATCH v2 00/20] ARM: K3 updates Sascha Hauer
` (10 preceding siblings ...)
2025-02-12 14:09 ` [PATCH v2 11/20] ARM: am625-sk: enable 32k crystal Sascha Hauer
@ 2025-02-12 14:09 ` Sascha Hauer
2025-02-12 14:09 ` [PATCH v2 13/20] ARM: k3: limit eMMC frequency to 26MHz Sascha Hauer
` (8 subsequent siblings)
20 siblings, 0 replies; 22+ messages in thread
From: Sascha Hauer @ 2025-02-12 14:09 UTC (permalink / raw)
To: open list:BAREBOX
Call mci_of_parse_node() to parse generic node properties like
max-frequency to lower the maximum allowed frequency.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
drivers/mci/am654-sdhci.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/mci/am654-sdhci.c b/drivers/mci/am654-sdhci.c
index 9787642011..2c1fa5d804 100644
--- a/drivers/mci/am654-sdhci.c
+++ b/drivers/mci/am654-sdhci.c
@@ -594,6 +594,7 @@ static int am654_sdhci_probe(struct device *dev)
mci = &plat->mci;
mci->f_max = clk_get_rate(plat->clk);
mci->f_min = 50000000 / 256;
+ mci_of_parse_node(mci, np);
if (plat->soc_data->flags & DLL_PRESENT) {
ret = of_property_read_u32(np, "ti,trm-icp", &plat->trm_icp);
--
2.39.5
^ permalink raw reply [flat|nested] 22+ messages in thread
* [PATCH v2 13/20] ARM: k3: limit eMMC frequency to 26MHz
2025-02-12 14:09 [PATCH v2 00/20] ARM: K3 updates Sascha Hauer
` (11 preceding siblings ...)
2025-02-12 14:09 ` [PATCH v2 12/20] mci: am654: parse generic mmc node properties Sascha Hauer
@ 2025-02-12 14:09 ` Sascha Hauer
2025-02-12 14:09 ` [PATCH v2 14/20] ARM: k3: add eMMC barebox update handler Sascha Hauer
` (7 subsequent siblings)
20 siblings, 0 replies; 22+ messages in thread
From: Sascha Hauer @ 2025-02-12 14:09 UTC (permalink / raw)
To: open list:BAREBOX
The eMMCs on am625 currently only work reliably with 26MHz. Until this
issue is sorted out limit them to 26MHz on the affected boards
(beagleplay and am625-sk).
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
arch/arm/dts/k3-am625-beagleplay.dts | 4 ++++
arch/arm/dts/k3-am625-sk.dts | 4 ++++
2 files changed, 8 insertions(+)
diff --git a/arch/arm/dts/k3-am625-beagleplay.dts b/arch/arm/dts/k3-am625-beagleplay.dts
index 60340ab8ca..73ac950414 100644
--- a/arch/arm/dts/k3-am625-beagleplay.dts
+++ b/arch/arm/dts/k3-am625-beagleplay.dts
@@ -29,3 +29,7 @@ AM62X_IOPAD(0x0224, PIN_INPUT, 0) /* (D22) MMC1_DAT3 */
AM62X_IOPAD(0x0240, PIN_INPUT, 0) /* (D17) MMC1_SDCD */
>;
};
+
+&sdhci0 {
+ max-frequency = <26000000>;
+};
diff --git a/arch/arm/dts/k3-am625-sk.dts b/arch/arm/dts/k3-am625-sk.dts
index 1982c34388..56d5681519 100644
--- a/arch/arm/dts/k3-am625-sk.dts
+++ b/arch/arm/dts/k3-am625-sk.dts
@@ -7,3 +7,7 @@
* DRAM size differs between board variants. Real size is read from DDRSS
*/
/delete-node/ &{/memory@80000000};
+
+&sdhci0 {
+ max-frequency = <26000000>;
+};
--
2.39.5
^ permalink raw reply [flat|nested] 22+ messages in thread
* [PATCH v2 14/20] ARM: k3: add eMMC barebox update handler
2025-02-12 14:09 [PATCH v2 00/20] ARM: K3 updates Sascha Hauer
` (12 preceding siblings ...)
2025-02-12 14:09 ` [PATCH v2 13/20] ARM: k3: limit eMMC frequency to 26MHz Sascha Hauer
@ 2025-02-12 14:09 ` Sascha Hauer
2025-02-12 14:09 ` [PATCH v2 15/20] ARM: am625-sk: put environment on eMMC when booting from it Sascha Hauer
` (6 subsequent siblings)
20 siblings, 0 replies; 22+ messages in thread
From: Sascha Hauer @ 2025-02-12 14:09 UTC (permalink / raw)
To: open list:BAREBOX
This adds a barebox update handler to write a barebox image to the
eMMC boot partitions. The image is written to the currently inactive
boot partition which is made active after a successful write thus
enabling a failsafe update.
The update handler expects an image which has the tiboot3.bin right
at the start of the image and a FIP image containing the next stages
at offset 1MiB. This image can't be generated by barebox itself (as
it requires two barebox images built for different architectures). It
must be generated by an external build system.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
arch/arm/mach-k3/Makefile | 1 +
arch/arm/mach-k3/bbu.c | 77 +++++++++++++++++++++++++++++++++++++++++++++++
include/mach/k3/common.h | 13 ++++++++
3 files changed, 91 insertions(+)
diff --git a/arch/arm/mach-k3/Makefile b/arch/arm/mach-k3/Makefile
index 8120c6fd35..b1dfb66d74 100644
--- a/arch/arm/mach-k3/Makefile
+++ b/arch/arm/mach-k3/Makefile
@@ -1,6 +1,7 @@
obj-y += common.o
obj-pbl-$(CONFIG_MACH_K3_CORTEX_R5) += r5.o
obj-pbl-y += ddrss.o
+obj-$(CONFIG_BAREBOX_UPDATE) += bbu.o
extra-$(CONFIG_MACH_K3_CORTEX_R5) += combined-dm-cfg-am625.k3cfg combined-sysfw-cfg-am625.k3cfg
diff --git a/arch/arm/mach-k3/bbu.c b/arch/arm/mach-k3/bbu.c
new file mode 100644
index 0000000000..815af086e8
--- /dev/null
+++ b/arch/arm/mach-k3/bbu.c
@@ -0,0 +1,77 @@
+// SPDX-License-Identifier: GPL-2.0-only
+
+#define pr_fmt(fmt) "k3-bbu: " fmt
+
+#include <bbu.h>
+#include <xfuncs.h>
+#include <fcntl.h>
+#include <filetype.h>
+#include <linux/printk.h>
+#include <unistd.h>
+#include <mach/k3/common.h>
+#include <linux/sizes.h>
+#include <libfile.h>
+
+static int k3_bbu_mmc_update(struct bbu_handler *handler,
+ struct bbu_data *data)
+{
+ int fd, ret;
+ enum filetype type;
+
+ if (data->len < K3_EMMC_BOOTPART_TIBOOT3_BIN_SIZE + SZ_1K) {
+ pr_err("Image is too small\n");
+ return -EINVAL;
+ }
+
+ type = file_detect_type(data->image + K3_EMMC_BOOTPART_TIBOOT3_BIN_SIZE, SZ_1K);
+
+ if (type != filetype_fip) {
+ pr_err("Cannot find FIP image at offset 1M\n");
+ return -EINVAL;
+ }
+
+ pr_debug("Attempting eMMC boot partition update\n");
+
+ ret = bbu_confirm(data);
+ if (ret)
+ return ret;
+
+ fd = open(data->devicefile, O_RDWR);
+ if (fd < 0)
+ return fd;
+
+ ret = pwrite_full(fd, data->image, data->len, 0);
+ if (ret < 0)
+ pr_err("writing to %s failed with %pe\n", data->devicefile, ERR_PTR(ret));
+
+ close(fd);
+
+ return ret < 0 ? ret : 0;
+}
+
+static int k3_bbu_mmc_fip_handler(struct bbu_handler *handler,
+ struct bbu_data *data)
+{
+ return bbu_mmcboot_handler(handler, data, k3_bbu_mmc_update);
+}
+
+int k3_bbu_emmc_register(const char *name,
+ const char *devicefile,
+ unsigned long flags)
+{
+ struct bbu_handler *handler;
+ int ret;
+
+ handler = xzalloc(sizeof(*handler));
+
+ handler->flags = flags | BBU_HANDLER_FLAG_MMC_BOOT_ACK;
+ handler->devicefile = devicefile;
+ handler->name = name;
+ handler->handler = k3_bbu_mmc_fip_handler;
+
+ ret = bbu_register_handler(handler);
+ if (ret)
+ free(handler);
+
+ return ret;
+}
diff --git a/include/mach/k3/common.h b/include/mach/k3/common.h
index 14dfc4a28a..871e9f39e3 100644
--- a/include/mach/k3/common.h
+++ b/include/mach/k3/common.h
@@ -16,4 +16,17 @@ void am625_enable_32k_crystal(void);
#define K3_EMMC_BOOTPART_TIBOOT3_BIN_SIZE SZ_1M
+#ifdef CONFIG_BAREBOX_UPDATE
+int k3_bbu_emmc_register(const char *name,
+ const char *devicefile,
+ unsigned long flags);
+#else
+static inline int k3_bbu_emmc_register(const char *name,
+ const char *devicefile,
+ unsigned long flags)
+{
+ return 0;
+}
+#endif
+
#endif /* __MACH_K3_COMMON_H */
--
2.39.5
^ permalink raw reply [flat|nested] 22+ messages in thread
* [PATCH v2 15/20] ARM: am625-sk: put environment on eMMC when booting from it
2025-02-12 14:09 [PATCH v2 00/20] ARM: K3 updates Sascha Hauer
` (13 preceding siblings ...)
2025-02-12 14:09 ` [PATCH v2 14/20] ARM: k3: add eMMC barebox update handler Sascha Hauer
@ 2025-02-12 14:09 ` Sascha Hauer
2025-02-12 14:09 ` [PATCH v2 16/20] serial: omap: Use ttyS as Linux console name Sascha Hauer
` (5 subsequent siblings)
20 siblings, 0 replies; 22+ messages in thread
From: Sascha Hauer @ 2025-02-12 14:09 UTC (permalink / raw)
To: open list:BAREBOX
When booting from eMMC put the environment on the eMMC as well.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
arch/arm/boards/am625-sk/board.c | 5 +++++
arch/arm/dts/k3-am625-sk.dts | 15 +++++++++++++++
2 files changed, 20 insertions(+)
diff --git a/arch/arm/boards/am625-sk/board.c b/arch/arm/boards/am625-sk/board.c
index fd3bcdeac6..c716f30e69 100644
--- a/arch/arm/boards/am625-sk/board.c
+++ b/arch/arm/boards/am625-sk/board.c
@@ -11,6 +11,11 @@ static int am625_sk_probe(struct device *dev)
{
am625_enable_32k_crystal();
+ k3_bbu_emmc_register("emmc", "/dev/mmc0", BBU_HANDLER_FLAG_DEFAULT);
+
+ if (k3_boot_is_emmc())
+ of_device_enable_path("/chosen/environment-emmc");
+
return 0;
}
diff --git a/arch/arm/dts/k3-am625-sk.dts b/arch/arm/dts/k3-am625-sk.dts
index 56d5681519..8d7a73babf 100644
--- a/arch/arm/dts/k3-am625-sk.dts
+++ b/arch/arm/dts/k3-am625-sk.dts
@@ -3,6 +3,16 @@
#include <arm64/ti/k3-am625-sk.dts>
#include "k3-am625.dtsi"
+/ {
+ chosen {
+ environment-emmc {
+ compatible = "barebox,environment";
+ device-path = &env_emmc;
+ status = "disabled";
+ };
+ };
+};
+
/*
* DRAM size differs between board variants. Real size is read from DDRSS
*/
@@ -10,4 +20,9 @@
&sdhci0 {
max-frequency = <26000000>;
+
+ env_emmc: partition@e0000 {
+ label = "barebox-environment";
+ reg = <0x0 0xe0000 0x0 0x20000>;
+ };
};
--
2.39.5
^ permalink raw reply [flat|nested] 22+ messages in thread
* [PATCH v2 16/20] serial: omap: Use ttyS as Linux console name
2025-02-12 14:09 [PATCH v2 00/20] ARM: K3 updates Sascha Hauer
` (14 preceding siblings ...)
2025-02-12 14:09 ` [PATCH v2 15/20] ARM: am625-sk: put environment on eMMC when booting from it Sascha Hauer
@ 2025-02-12 14:09 ` Sascha Hauer
2025-02-12 14:09 ` [PATCH v2 17/20] ARM: k3: remove beagleplay FIT image Sascha Hauer
` (4 subsequent siblings)
20 siblings, 0 replies; 22+ messages in thread
From: Sascha Hauer @ 2025-02-12 14:09 UTC (permalink / raw)
To: open list:BAREBOX
Traditionally Linux used ttyO as console name for Omap devices. This has
been changed to ttyS in 2014. Since then ttyO gets translated to ttyS by
the Kernel. Use ttyS directly to avoid the translation in the Kernel.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
drivers/serial/serial_ns16550.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/serial/serial_ns16550.c b/drivers/serial/serial_ns16550.c
index 45341d1c9b..56a1c6c6b9 100644
--- a/drivers/serial/serial_ns16550.c
+++ b/drivers/serial/serial_ns16550.c
@@ -402,13 +402,13 @@ static struct ns16550_drvdata ns16550_drvdata = {
static __maybe_unused struct ns16550_drvdata omap_drvdata = {
.init_port = ns16550_omap_init_port,
- .linux_console_name = "ttyO",
+ .linux_console_name = "ttyS",
.linux_earlycon_name = "omap8250",
};
static __maybe_unused struct ns16550_drvdata omap_clk48m_drvdata = {
.init_port = ns16550_omap_init_port,
- .linux_console_name = "ttyO",
+ .linux_console_name = "ttyS",
.clk_default = 48000000,
};
--
2.39.5
^ permalink raw reply [flat|nested] 22+ messages in thread
* [PATCH v2 17/20] ARM: k3: remove beagleplay FIT image
2025-02-12 14:09 [PATCH v2 00/20] ARM: K3 updates Sascha Hauer
` (15 preceding siblings ...)
2025-02-12 14:09 ` [PATCH v2 16/20] serial: omap: Use ttyS as Linux console name Sascha Hauer
@ 2025-02-12 14:09 ` Sascha Hauer
2025-02-12 14:09 ` [PATCH v2 18/20] ARM: am625-sk: cleanup board entry Sascha Hauer
` (3 subsequent siblings)
20 siblings, 0 replies; 22+ messages in thread
From: Sascha Hauer @ 2025-02-12 14:09 UTC (permalink / raw)
To: open list:BAREBOX
Remove beagleplay FIT image to avoid the dependency to U-Boot mkimage.
We can still build a FIT image using the generic-dt-2nd support.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
images/Makefile.k3 | 4 ----
images/k3-am625-beagleplay.its | 29 -----------------------------
2 files changed, 33 deletions(-)
diff --git a/images/Makefile.k3 b/images/Makefile.k3
index 466a84af99..b27b3dfcc5 100644
--- a/images/Makefile.k3
+++ b/images/Makefile.k3
@@ -15,10 +15,6 @@ pblb-$(CONFIG_MACH_BEAGLEPLAY) += start_beagleplay
FILE_barebox-beagleplay.img = start_beagleplay.pblb
image-$(CONFIG_MACH_BEAGLEPLAY) += barebox-beagleplay.img
-$(obj)/k3-am625-beagleplay.itb: $(obj)/barebox-beagleplay.img
-FILE_barebox-beagleplay-fit.img = k3-am625-beagleplay.itb
-image-$(CONFIG_MACH_BEAGLEPLAY) += barebox-beagleplay-fit.img
-
endif
ifdef CONFIG_MACH_K3_CORTEX_R5
diff --git a/images/k3-am625-beagleplay.its b/images/k3-am625-beagleplay.its
deleted file mode 100644
index 987d4d1660..0000000000
--- a/images/k3-am625-beagleplay.its
+++ /dev/null
@@ -1,29 +0,0 @@
-
-/dts-v1/;
-
-/ {
- description = "barebox for BeaglePlay board";
-
- images {
- barebox {
- description = "barebox for BeaglePlay board";
- type = "firmware";
- os = "linux";
- arch = "arm";
- compression = "none";
- load = <0x80800000>;
- entry = <0x80800000>;
- data = /incbin/("barebox-beagleplay.img");
- };
- };
-
- configurations {
- default = "conf-0";
-
- conf-0 {
- description = "barebox for BeaglePlay board";
- firmware = "barebox";
- loadables = "barebox";
- };
- };
-};
--
2.39.5
^ permalink raw reply [flat|nested] 22+ messages in thread
* [PATCH v2 18/20] ARM: am625-sk: cleanup board entry
2025-02-12 14:09 [PATCH v2 00/20] ARM: K3 updates Sascha Hauer
` (16 preceding siblings ...)
2025-02-12 14:09 ` [PATCH v2 17/20] ARM: k3: remove beagleplay FIT image Sascha Hauer
@ 2025-02-12 14:09 ` Sascha Hauer
2025-02-12 14:09 ` [PATCH v2 19/20] ARM: beagleplay: " Sascha Hauer
` (2 subsequent siblings)
20 siblings, 0 replies; 22+ messages in thread
From: Sascha Hauer @ 2025-02-12 14:09 UTC (permalink / raw)
To: open list:BAREBOX
We used to genrate a Linux Kernel compatible image that can be started
from U-Boot. This is no longer necessary as we have full 1st stage
support now in barebox. A FIT image to be started from U-Boot can still
be generated with BOARD_GENERIC_FIT.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
arch/arm/boards/am625-sk/Makefile | 1 -
arch/arm/boards/am625-sk/entry.S | 29 -----------------------------
arch/arm/boards/am625-sk/lowlevel.c | 13 +++----------
3 files changed, 3 insertions(+), 40 deletions(-)
diff --git a/arch/arm/boards/am625-sk/Makefile b/arch/arm/boards/am625-sk/Makefile
index 8c45b1e154..8cba450528 100644
--- a/arch/arm/boards/am625-sk/Makefile
+++ b/arch/arm/boards/am625-sk/Makefile
@@ -1,4 +1,3 @@
pbl-y += lowlevel.o
obj-y += board.o
-pbl-$(CONFIG_MACH_K3_CORTEX_A) += entry.o
pbl-$(CONFIG_MACH_K3_CORTEX_R5) += entry-r5.o am625-sk-ddr.o am625sip-sk-ddr.o
diff --git a/arch/arm/boards/am625-sk/entry.S b/arch/arm/boards/am625-sk/entry.S
deleted file mode 100644
index 5fc9297d50..0000000000
--- a/arch/arm/boards/am625-sk/entry.S
+++ /dev/null
@@ -1,29 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0-or-later */
-#include <linux/linkage.h>
-#include <asm/barebox-arm64.h>
-#include <asm/image.h>
-
-#define IMAGE_FLAGS \
- (ARM64_IMAGE_FLAG_PAGE_SIZE_4K << ARM64_IMAGE_FLAG_PAGE_SIZE_SHIFT) | \
- (ARM64_IMAGE_FLAG_PHYS_BASE << ARM64_IMAGE_FLAG_PHYS_BASE_SHIFT)
-
-.section .text_head_entry_start_vivavis_cu33d
-ENTRY("start_am625_sk")
- adr x1, 0 /* code0 */
- b 2f /* code1 */
- .xword 0x80000 /* Image load offset */
- .xword _barebox_image_size /* Effective Image size */
- .xword IMAGE_FLAGS /* Kernel flags */
- .xword 0 /* reserved */
- .xword 0 /* reserved */
- .xword 0 /* reserved */
- .ascii ARM64_IMAGE_MAGIC /* magic number */
- .int 0 /* reserved (PE-COFF offset) */
- .asciz "barebox" /* unused for now */
-2:
- mov sp, x1
- /* Stack now grows into the 0x80000 image load offset specified
- * above. This is more than enough until FDT /memory is decoded.
- */
- b am625_sk
-ENTRY_PROC_END(start_am625_sk)
diff --git a/arch/arm/boards/am625-sk/lowlevel.c b/arch/arm/boards/am625-sk/lowlevel.c
index 5c1c38e325..10da8731ca 100644
--- a/arch/arm/boards/am625-sk/lowlevel.c
+++ b/arch/arm/boards/am625-sk/lowlevel.c
@@ -14,14 +14,10 @@
#include "ddr.h"
-/* Called from assembly */
-void am625_sk(void *dtb);
-
-static noinline void am625_sk_continue(void *dtb)
+static noinline void am625_sk_continue(void)
{
unsigned long membase = 0x80000000, memsize;
extern char __dtb_z_k3_am625_sk_start[];
- unsigned int size;
memsize = am625_sdram_size();
@@ -33,13 +29,10 @@ static noinline void am625_sk_continue(void *dtb)
if (memsize == SZ_512M)
memsize = SZ_512M - 0x04000000; /* substract space needed for TF-A, OP-TEE, ... */
- if (blob_is_valid_fdt_ptr(dtb, membase, memsize, &size))
- handoff_data_add(HANDOFF_DATA_EXTERNAL_DT, dtb, size);
-
barebox_arm_entry(membase, memsize, __dtb_z_k3_am625_sk_start);
}
-void am625_sk(void *dtb)
+ENTRY_FUNCTION_WITHSTACK(start_am625_sk, 0x80800000, r0, r1, r2)
{
putc_ll('>');
@@ -49,7 +42,7 @@ void am625_sk(void *dtb)
setup_c();
- am625_sk_continue(dtb);
+ am625_sk_continue();
}
static noinline void am625_sk_r5_continue(void)
--
2.39.5
^ permalink raw reply [flat|nested] 22+ messages in thread
* [PATCH v2 19/20] ARM: beagleplay: cleanup board entry
2025-02-12 14:09 [PATCH v2 00/20] ARM: K3 updates Sascha Hauer
` (17 preceding siblings ...)
2025-02-12 14:09 ` [PATCH v2 18/20] ARM: am625-sk: cleanup board entry Sascha Hauer
@ 2025-02-12 14:09 ` Sascha Hauer
2025-02-12 14:09 ` [PATCH v2 20/20] ARM: k3: Add k3-r5_defconfig Sascha Hauer
2025-02-17 11:14 ` [PATCH v2 00/20] ARM: K3 updates Sascha Hauer
20 siblings, 0 replies; 22+ messages in thread
From: Sascha Hauer @ 2025-02-12 14:09 UTC (permalink / raw)
To: open list:BAREBOX
We used to genrate a Linux Kernel compatible image that can be started
from U-Boot. This is no longer necessary as we have full 1st stage
support now in barebox. A FIT image to be started from U-Boot can still
be generated with BOARD_GENERIC_FIT.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
arch/arm/boards/beagleplay/Makefile | 1 -
arch/arm/boards/beagleplay/entry.S | 29 -----------------------------
arch/arm/boards/beagleplay/lowlevel.c | 18 ++++++------------
3 files changed, 6 insertions(+), 42 deletions(-)
diff --git a/arch/arm/boards/beagleplay/Makefile b/arch/arm/boards/beagleplay/Makefile
index 396dff29a2..a8c7320bdb 100644
--- a/arch/arm/boards/beagleplay/Makefile
+++ b/arch/arm/boards/beagleplay/Makefile
@@ -1,3 +1,2 @@
pbl-y += lowlevel.o
-pbl-$(CONFIG_MACH_K3_CORTEX_A) += entry.o
pbl-$(CONFIG_MACH_K3_CORTEX_R5) += entry-r5.o ddr.o
diff --git a/arch/arm/boards/beagleplay/entry.S b/arch/arm/boards/beagleplay/entry.S
deleted file mode 100644
index 6e4c7196f3..0000000000
--- a/arch/arm/boards/beagleplay/entry.S
+++ /dev/null
@@ -1,29 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0-or-later */
-#include <linux/linkage.h>
-#include <asm/barebox-arm64.h>
-#include <asm/image.h>
-
-#define IMAGE_FLAGS \
- (ARM64_IMAGE_FLAG_PAGE_SIZE_4K << ARM64_IMAGE_FLAG_PAGE_SIZE_SHIFT) | \
- (ARM64_IMAGE_FLAG_PHYS_BASE << ARM64_IMAGE_FLAG_PHYS_BASE_SHIFT)
-
-.section .text_head_entry_start_beagleplay
-ENTRY("start_beagleplay")
- adr x1, 0 /* code0 */
- b 2f /* code1 */
- .xword 0x80000 /* Image load offset */
- .xword _barebox_image_size /* Effective Image size */
- .xword IMAGE_FLAGS /* Kernel flags */
- .xword 0 /* reserved */
- .xword 0 /* reserved */
- .xword 0 /* reserved */
- .ascii ARM64_IMAGE_MAGIC /* magic number */
- .int 0 /* reserved (PE-COFF offset) */
- .asciz "barebox" /* unused for now */
-2:
- mov sp, x1
- /* Stack now grows into the 0x80000 image load offset specified
- * above. This is more than enough until FDT /memory is decoded.
- */
- b beagleplay
-ENTRY_PROC_END(start_beagleplay)
diff --git a/arch/arm/boards/beagleplay/lowlevel.c b/arch/arm/boards/beagleplay/lowlevel.c
index 744f78d009..9430017568 100644
--- a/arch/arm/boards/beagleplay/lowlevel.c
+++ b/arch/arm/boards/beagleplay/lowlevel.c
@@ -10,27 +10,21 @@
#include <compressed-dtb.h>
#include <cache.h>
#include <mach/k3/r5.h>
+#include <mach/k3/common.h>
#include "ddr.h"
-/* Called from assembly */
-void beagleplay(void *dtb);
-
-static noinline void beagleplay_continue(void *dtb)
+static noinline void beagleplay_continue(void)
{
- unsigned long membase, memsize;
+ unsigned long membase = 0x80000000, memsize;
extern char __dtb_k3_am625_beagleplay_start[];
- unsigned int size;
-
- fdt_find_mem(__dtb_k3_am625_beagleplay_start, &membase, &memsize);
- if (blob_is_valid_fdt_ptr(dtb, membase, memsize, &size))
- handoff_data_add(HANDOFF_DATA_EXTERNAL_DT, dtb, size);
+ memsize = am625_sdram_size();
barebox_arm_entry(membase, memsize, __dtb_k3_am625_beagleplay_start);
}
-void beagleplay(void *dtb)
+ENTRY_FUNCTION_WITHSTACK(start_beagleplay, 0x80800000, r0, r1, r2)
{
putc_ll('>');
@@ -40,7 +34,7 @@ void beagleplay(void *dtb)
setup_c();
- beagleplay_continue(dtb);
+ beagleplay_continue();
}
extern char __dtb_k3_am625_r5_beagleplay_start[];
--
2.39.5
^ permalink raw reply [flat|nested] 22+ messages in thread
* [PATCH v2 20/20] ARM: k3: Add k3-r5_defconfig
2025-02-12 14:09 [PATCH v2 00/20] ARM: K3 updates Sascha Hauer
` (18 preceding siblings ...)
2025-02-12 14:09 ` [PATCH v2 19/20] ARM: beagleplay: " Sascha Hauer
@ 2025-02-12 14:09 ` Sascha Hauer
2025-02-17 11:14 ` [PATCH v2 00/20] ARM: K3 updates Sascha Hauer
20 siblings, 0 replies; 22+ messages in thread
From: Sascha Hauer @ 2025-02-12 14:09 UTC (permalink / raw)
To: open list:BAREBOX
This adds a defconfig for the initial stage of K3 Socs.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
arch/arm/configs/k3-r5_defconfig | 43 ++++++++++++++++++++++++++++++++++++++++
1 file changed, 43 insertions(+)
diff --git a/arch/arm/configs/k3-r5_defconfig b/arch/arm/configs/k3-r5_defconfig
new file mode 100644
index 0000000000..59b3aa5a6e
--- /dev/null
+++ b/arch/arm/configs/k3-r5_defconfig
@@ -0,0 +1,43 @@
+CONFIG_ARCH_K3=y
+CONFIG_MACH_AM625_SK=y
+CONFIG_MACH_BEAGLEPLAY=y
+CONFIG_AEABI=y
+CONFIG_ARM_OPTIMZED_STRING_FUNCTIONS=y
+# CONFIG_BOARD_GENERIC_DT is not set
+# CONFIG_MEMINFO is not set
+CONFIG_ENVIRONMENT_VARIABLES=y
+CONFIG_IMAGE_COMPRESSION_XZKERN=y
+CONFIG_BAREBOX_MAX_IMAGE_SIZE=0x10000000
+CONFIG_MALLOC_SIZE=0x0
+CONFIG_MALLOC_TLSF=y
+CONFIG_KALLSYMS=y
+CONFIG_PROMPT="MLO>"
+CONFIG_SHELL_NONE=y
+# CONFIG_ERRNO_MESSAGES is not set
+CONFIG_CONSOLE_ACTIVATE_NONE=y
+CONFIG_PBL_CONSOLE=y
+CONFIG_BTHREAD=y
+CONFIG_DEBUG_LL=y
+CONFIG_DRIVER_SERIAL_NS16550=y
+# CONFIG_SPI is not set
+CONFIG_I2C=y
+CONFIG_I2C_OMAP=y
+CONFIG_USB_HOST=y
+CONFIG_USB_DWC3=y
+CONFIG_USB_DWC3_GADGET=y
+# CONFIG_USB_DWC3_OF_SIMPLE is not set
+CONFIG_USB_GADGET=y
+CONFIG_USB_GADGET_DFU=y
+CONFIG_MCI=y
+# CONFIG_MCI_WRITE is not set
+CONFIG_MCI_AM654=y
+# CONFIG_TI_SCI_CLK is not set
+CONFIG_MFD_SYSCON=y
+CONFIG_MFD_TPS65219=y
+CONFIG_PINCTRL_SINGLE=y
+CONFIG_REGULATOR=y
+CONFIG_REGULATOR_FIXED=y
+CONFIG_REGULATOR_TPS65219=y
+# CONFIG_VIRTIO_MENU is not set
+CONFIG_MAILBOX=y
+CONFIG_FS_FAT=y
--
2.39.5
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [PATCH v2 00/20] ARM: K3 updates
2025-02-12 14:09 [PATCH v2 00/20] ARM: K3 updates Sascha Hauer
` (19 preceding siblings ...)
2025-02-12 14:09 ` [PATCH v2 20/20] ARM: k3: Add k3-r5_defconfig Sascha Hauer
@ 2025-02-17 11:14 ` Sascha Hauer
20 siblings, 0 replies; 22+ messages in thread
From: Sascha Hauer @ 2025-02-17 11:14 UTC (permalink / raw)
To: open list:BAREBOX, Sascha Hauer
On Wed, 12 Feb 2025 15:09:13 +0100, Sascha Hauer wrote:
> This series has some updates for the TI K3 architecture.
>
> We add support for bootstrapping boards via USB DFU. This has been sent
> earlier, this time booting from eMMC is added as well.
>
> On K3 SoCs we need a bunch of images after the first stage has been
> loaded: OP-TEE, ti-dm firmware, TF-A binary and finally a barebox
> binary. Until now these are expected as distinct images on the SD cards
> FAT partition. This is impractical for booting from eMMC boot partitions
> and also DFU boot, so this series adds support for handling a FIP image
> containing these binaries.
>
> [...]
Applied, thanks!
[01/20] ARM: k3: Add function to enable 32k crystal
https://git.pengutronix.de/cgit/barebox/commit/?id=f8488603862b (link may not be stable)
[02/20] ARM: k3: add function to detect eMMC boot
https://git.pengutronix.de/cgit/barebox/commit/?id=4a3eac7dbaa1 (link may not be stable)
[03/20] ARM: k3: do not mount /boot when booting from eMMC
https://git.pengutronix.de/cgit/barebox/commit/?id=def806a40287 (link may not be stable)
[04/20] fip: drop typedefs
https://git.pengutronix.de/cgit/barebox/commit/?id=30c35fedb7ba (link may not be stable)
[05/20] fip: use linux list implementation
https://git.pengutronix.de/cgit/barebox/commit/?id=bc79141e65cc (link may not be stable)
[06/20] fip: use uuid_equal() and uuid_is_null()
https://git.pengutronix.de/cgit/barebox/commit/?id=e8074b140a14 (link may not be stable)
[07/20] fiptool: do not typedef structs
https://git.pengutronix.de/cgit/barebox/commit/?id=d58d0997b8b7 (link may not be stable)
[08/20] fip: add fip_ prefix
https://git.pengutronix.de/cgit/barebox/commit/?id=33ac1e970bc0 (link may not be stable)
[09/20] fip: add fip_image_open()
https://git.pengutronix.de/cgit/barebox/commit/?id=72d281a4711b (link may not be stable)
[10/20] ARM: k3: r5: add USB DFU and eMMC boot support
https://git.pengutronix.de/cgit/barebox/commit/?id=9124e7c0b563 (link may not be stable)
[11/20] ARM: am625-sk: enable 32k crystal
https://git.pengutronix.de/cgit/barebox/commit/?id=63a39df42e94 (link may not be stable)
[12/20] mci: am654: parse generic mmc node properties
https://git.pengutronix.de/cgit/barebox/commit/?id=10870f73f2fe (link may not be stable)
[13/20] ARM: k3: limit eMMC frequency to 26MHz
https://git.pengutronix.de/cgit/barebox/commit/?id=b6099d814075 (link may not be stable)
[14/20] ARM: k3: add eMMC barebox update handler
https://git.pengutronix.de/cgit/barebox/commit/?id=e7fc40adf484 (link may not be stable)
[15/20] ARM: am625-sk: put environment on eMMC when booting from it
https://git.pengutronix.de/cgit/barebox/commit/?id=4458a181046d (link may not be stable)
[16/20] serial: omap: Use ttyS as Linux console name
https://git.pengutronix.de/cgit/barebox/commit/?id=6ed7c03d3fb3 (link may not be stable)
[17/20] ARM: k3: remove beagleplay FIT image
https://git.pengutronix.de/cgit/barebox/commit/?id=874477b04d02 (link may not be stable)
[18/20] ARM: am625-sk: cleanup board entry
https://git.pengutronix.de/cgit/barebox/commit/?id=57e67d421450 (link may not be stable)
[19/20] ARM: beagleplay: cleanup board entry
https://git.pengutronix.de/cgit/barebox/commit/?id=b4f14eebf1ec (link may not be stable)
[20/20] ARM: k3: Add k3-r5_defconfig
https://git.pengutronix.de/cgit/barebox/commit/?id=49556447bca7 (link may not be stable)
Best regards,
--
Sascha Hauer <s.hauer@pengutronix.de>
^ permalink raw reply [flat|nested] 22+ messages in thread