* [PATCH 0/4] Layerscape LS1028a pblimage support
@ 2023-12-19 13:00 Sascha Hauer
2023-12-19 13:00 ` [PATCH 1/4] pblimage: drop PowerPC support Sascha Hauer
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Sascha Hauer @ 2023-12-19 13:00 UTC (permalink / raw)
To: Barebox List
The pblimage tool can be re-used for upcoming LS1028a support. This
series contains the necessary changes for the tool.
Sascha Hauer (4):
pblimage: drop PowerPC support
pblimage: simplify a bit
pblimage: use roundup() from kernel.h
pblimage: Add LS1028a support
images/Makefile.layerscape | 16 ++--
scripts/pblimage.c | 149 ++++++++++++++++++++++++++++---------
2 files changed, 120 insertions(+), 45 deletions(-)
--
2.39.2
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 1/4] pblimage: drop PowerPC support
2023-12-19 13:00 [PATCH 0/4] Layerscape LS1028a pblimage support Sascha Hauer
@ 2023-12-19 13:00 ` Sascha Hauer
2023-12-19 13:00 ` [PATCH 2/4] pblimage: simplify a bit Sascha Hauer
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Sascha Hauer @ 2023-12-19 13:00 UTC (permalink / raw)
To: Barebox List
PowerPC support has never been tested in the pblimage tool and will
hopefully be never needed. Drop its support from pblimage
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
scripts/pblimage.c | 22 +++++-----------------
1 file changed, 5 insertions(+), 17 deletions(-)
diff --git a/scripts/pblimage.c b/scripts/pblimage.c
index df5d7aef69..9489c52b18 100644
--- a/scripts/pblimage.c
+++ b/scripts/pblimage.c
@@ -60,12 +60,6 @@ static uint32_t pbl_cmd_initaddr;
static uint32_t pbi_crc_cmd1;
static uint32_t pbi_crc_cmd2;
-enum arch {
- ARCH_ARM,
- ARCH_POWERPC,
-};
-
-enum arch architecture = ARCH_ARM;
static char *rcwfile;
static char *pbifile;
static char *outfile;
@@ -253,17 +247,11 @@ static int pblimage_check_params(void)
exit(EXIT_FAILURE);
}
- if (architecture == ARCH_ARM) {
- pbi_crc_cmd1 = 0x61;
- pbi_crc_cmd2 = 0;
- pbl_cmd_initaddr = loadaddr & PBL_ADDR_24BIT_MASK;
- pbl_cmd_initaddr |= PBL_ACS_CONT_CMD;
- pbl_cmd_initaddr += image_size;
- } else {
- pbi_crc_cmd1 = 0x13;
- pbi_crc_cmd2 = 0x80;
- pbl_cmd_initaddr = 0x82000000;
- }
+ pbi_crc_cmd1 = 0x61;
+ pbi_crc_cmd2 = 0;
+ pbl_cmd_initaddr = loadaddr & PBL_ADDR_24BIT_MASK;
+ pbl_cmd_initaddr |= PBL_ACS_CONT_CMD;
+ pbl_cmd_initaddr += image_size;
next_pbl_cmd = pbl_cmd_initaddr;
return 0;
--
2.39.2
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 2/4] pblimage: simplify a bit
2023-12-19 13:00 [PATCH 0/4] Layerscape LS1028a pblimage support Sascha Hauer
2023-12-19 13:00 ` [PATCH 1/4] pblimage: drop PowerPC support Sascha Hauer
@ 2023-12-19 13:00 ` Sascha Hauer
2023-12-19 13:00 ` [PATCH 3/4] pblimage: use roundup() from kernel.h Sascha Hauer
2023-12-19 13:00 ` [PATCH 4/4] pblimage: Add LS1028a support Sascha Hauer
3 siblings, 0 replies; 5+ messages in thread
From: Sascha Hauer @ 2023-12-19 13:00 UTC (permalink / raw)
To: Barebox List
next_pbl_cmd is a global static variable that is initialized multiple
times, but used in a single function only. Instead of obfuscating its
usage, just pass its value as a parameter to generate_pbl_cmd().
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
scripts/pblimage.c | 23 ++++++++---------------
1 file changed, 8 insertions(+), 15 deletions(-)
diff --git a/scripts/pblimage.c b/scripts/pblimage.c
index 9489c52b18..d0a589f2fe 100644
--- a/scripts/pblimage.c
+++ b/scripts/pblimage.c
@@ -39,10 +39,6 @@
*/
#define BAREBOX_START (128 * 1024)
-/*
- * Initialize to an invalid value.
- */
-static uint32_t next_pbl_cmd = 0x82000000;
/*
* need to store all bytes in memory for calculating crc32, then write the
* bytes to image file for PBL boot.
@@ -56,7 +52,6 @@ static int out_fd;
static int in_fd;
static int spiimage;
-static uint32_t pbl_cmd_initaddr;
static uint32_t pbi_crc_cmd1;
static uint32_t pbi_crc_cmd2;
@@ -77,10 +72,8 @@ static uint32_t pbl_crc32(uint32_t in_crc, const char *buf, uint32_t len)
* "xxxxxx" is the offset. Calculate the start offset by subtracting the size of
* the image from the top of the allowable 24-bit range.
*/
-static void generate_pbl_cmd(void)
+static void generate_pbl_cmd(uint32_t val)
{
- uint32_t val = next_pbl_cmd;
- next_pbl_cmd += 0x40;
int i;
for (i = 3; i >= 0; i--) {
@@ -186,6 +179,7 @@ static void add_end_cmd(void)
static void pbl_load_image(void)
{
int size;
+ unsigned int n;
uint64_t *buf64 = (void *)mem_buf;
/* parse the rcw.cfg file. */
@@ -195,9 +189,12 @@ static void pbl_load_image(void)
if (pbifile)
pbl_parser(pbifile);
- next_pbl_cmd = pbl_cmd_initaddr - image_size;
- while (next_pbl_cmd < pbl_cmd_initaddr) {
- generate_pbl_cmd();
+ for (n = 0; n < image_size; n += 0x40) {
+ uint32_t pbl_cmd;
+
+ pbl_cmd = (loadaddr & PBL_ADDR_24BIT_MASK) | PBL_ACS_CONT_CMD;
+ pbl_cmd += n;
+ generate_pbl_cmd(pbl_cmd);
pbl_fget(64, in_fd);
}
@@ -249,11 +246,7 @@ static int pblimage_check_params(void)
pbi_crc_cmd1 = 0x61;
pbi_crc_cmd2 = 0;
- pbl_cmd_initaddr = loadaddr & PBL_ADDR_24BIT_MASK;
- pbl_cmd_initaddr |= PBL_ACS_CONT_CMD;
- pbl_cmd_initaddr += image_size;
- next_pbl_cmd = pbl_cmd_initaddr;
return 0;
};
--
2.39.2
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 3/4] pblimage: use roundup() from kernel.h
2023-12-19 13:00 [PATCH 0/4] Layerscape LS1028a pblimage support Sascha Hauer
2023-12-19 13:00 ` [PATCH 1/4] pblimage: drop PowerPC support Sascha Hauer
2023-12-19 13:00 ` [PATCH 2/4] pblimage: simplify a bit Sascha Hauer
@ 2023-12-19 13:00 ` Sascha Hauer
2023-12-19 13:00 ` [PATCH 4/4] pblimage: Add LS1028a support Sascha Hauer
3 siblings, 0 replies; 5+ messages in thread
From: Sascha Hauer @ 2023-12-19 13:00 UTC (permalink / raw)
To: Barebox List
We already have roundup() defined in linux/kernel.h, so use it instead
of adding a local definition.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
scripts/pblimage.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/scripts/pblimage.c b/scripts/pblimage.c
index d0a589f2fe..e8108bbb17 100644
--- a/scripts/pblimage.c
+++ b/scripts/pblimage.c
@@ -14,12 +14,12 @@
#include <getopt.h>
#include <endian.h>
#include <byteswap.h>
+#include <linux/kernel.h>
#include "common.h"
#include "common.c"
#include "../crypto/crc32.c"
-#define roundup(x, y) ((((x) + ((y) - 1)) / (y)) * (y))
#define PBL_ACS_CONT_CMD 0x81000000
#define PBL_ADDR_24BIT_MASK 0x00ffffff
--
2.39.2
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 4/4] pblimage: Add LS1028a support
2023-12-19 13:00 [PATCH 0/4] Layerscape LS1028a pblimage support Sascha Hauer
` (2 preceding siblings ...)
2023-12-19 13:00 ` [PATCH 3/4] pblimage: use roundup() from kernel.h Sascha Hauer
@ 2023-12-19 13:00 ` Sascha Hauer
3 siblings, 0 replies; 5+ messages in thread
From: Sascha Hauer @ 2023-12-19 13:00 UTC (permalink / raw)
To: Barebox List
The PBL images for the LS1028a are a bit different from the ones for the
LS1046a, but can be supported in the same pblimage tool. This adds
support for the LS1028a. To accomplish this the SoC type has to be
passed on the command line, so adjust the Makefiles calling pblimage
accordingly.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
images/Makefile.layerscape | 16 ++---
scripts/pblimage.c | 122 ++++++++++++++++++++++++++++++++-----
2 files changed, 116 insertions(+), 22 deletions(-)
diff --git a/images/Makefile.layerscape b/images/Makefile.layerscape
index 062e7263b5..e36dc5000a 100644
--- a/images/Makefile.layerscape
+++ b/images/Makefile.layerscape
@@ -13,30 +13,30 @@ quiet_cmd_lspbl_image = LSPBL-IMG $@
cmd_lspbl_image = $(CPP) $(lspbl_cfg_cpp_flags) -o $(lspbl-rcw-tmp) $(word 2,$^) ; \
$(CPP) $(lspbl_cfg_cpp_flags) -o $(lspbl-pbi-tmp) $(word 3,$^) ; \
$(objtree)/scripts/pblimage -o $@ -r $(lspbl-rcw-tmp) \
- -m $($(patsubst $(obj)/%.pblb,PBL_CODE_SIZE_%,$<)) -p $(lspbl-pbi-tmp) -i $<
+ -c $(2) -m $($(patsubst $(obj)/%.pblb,PBL_CODE_SIZE_%,$<)) -p $(lspbl-pbi-tmp) -i $<
quiet_cmd_lspbl_spi_image = LSPBL-SPI-IMG $@
cmd_lspbl_spi_image = $(CPP) $(lspbl_cfg_cpp_flags) -o $(lspbl-rcw-tmp) $(word 2,$^) ; \
$(CPP) $(lspbl_cfg_cpp_flags) -o $(lspbl-pbi-tmp) $(word 3,$^) ; \
$(objtree)/scripts/pblimage -o $@ -r $(lspbl-rcw-tmp) -s \
- -m $($(patsubst $(obj)/%.pblb,PBL_CODE_SIZE_%,$<)) -p $(lspbl-pbi-tmp) -i $<
+ -c $(2) -m $($(patsubst $(obj)/%.pblb,PBL_CODE_SIZE_%,$<)) -p $(lspbl-pbi-tmp) -i $<
pbl-$(CONFIG_MACH_LS1046ARDB) += start_ls1046ardb.pbl
$(obj)/barebox-ls1046ardb-sd.image: $(obj)/start_ls1046ardb.pblb \
$(board)/ls1046ardb/ls1046ardb_rcw_sd.cfg \
$(board)/ls1046ardb/ls1046ardb_pbi.cfg
- $(call if_changed,lspbl_image)
+ $(call if_changed,lspbl_image,ls1046a)
$(obj)/barebox-ls1046ardb-emmc.image: $(obj)/start_ls1046ardb.pblb \
$(board)/ls1046ardb/ls1046ardb_rcw_emmc.cfg \
$(board)/ls1046ardb/ls1046ardb_pbi.cfg
- $(call if_changed,lspbl_image)
+ $(call if_changed,lspbl_image,ls1046a)
$(obj)/barebox-ls1046ardb-qspi.image: $(obj)/start_ls1046ardb.pblb \
$(board)/ls1046ardb/ls1046ardb_rcw_qspi.cfg \
$(board)/ls1046ardb/ls1046ardb_pbi.cfg
- $(call if_changed,lspbl_spi_image)
+ $(call if_changed,lspbl_spi_image,ls1046a)
image-$(CONFIG_MACH_LS1046ARDB) += barebox-ls1046ardb-sd.image barebox-ls1046ardb-qspi.image \
barebox-ls1046ardb-emmc.image
@@ -46,12 +46,12 @@ pbl-$(CONFIG_MACH_TQMLS1046A) += start_tqmls1046a.pbl
$(obj)/barebox-tqmls1046a-sd.image: $(obj)/start_tqmls1046a.pblb \
$(board)/tqmls1046a/tqmls1046a_rcw_sd_3333_5559.cfg \
$(board)/tqmls1046a/tqmls1046a_pbi.cfg
- $(call if_changed,lspbl_image)
+ $(call if_changed,lspbl_image,ls1046a)
$(obj)/barebox-tqmls1046a-qspi.image: $(obj)/start_tqmls1046a.pblb \
$(board)/tqmls1046a/tqmls1046a_rcw_qspi_3333_5559.cfg \
$(board)/tqmls1046a/tqmls1046a_pbi.cfg
- $(call if_changed,lspbl_spi_image)
+ $(call if_changed,lspbl_spi_image,ls1046a)
image-$(CONFIG_MACH_TQMLS1046A) += barebox-tqmls1046a-sd.image \
barebox-tqmls1046a-qspi.image
@@ -61,6 +61,6 @@ pbl-$(CONFIG_MACH_LS1021AIOT) += start_ls1021aiot.pbl
$(obj)/barebox-ls1021aiot-qspi.image: $(obj)/start_ls1021aiot.pblb \
$(board)/ls1021aiot/ls102xa_rcw_sd_qspi.cfg \
$(board)/ls1021aiot/ls102xa_pbi.cfg
- $(call if_changed,lspbl_spi_image)
+ $(call if_changed,lspbl_spi_image,ls1046a)
image-$(CONFIG_MACH_LS1021AIOT) += barebox-ls1021aiot-qspi.image
diff --git a/scripts/pblimage.c b/scripts/pblimage.c
index e8108bbb17..8cb473d5bc 100644
--- a/scripts/pblimage.c
+++ b/scripts/pblimage.c
@@ -14,6 +14,7 @@
#include <getopt.h>
#include <endian.h>
#include <byteswap.h>
+#include <stdbool.h>
#include <linux/kernel.h>
#include "common.h"
@@ -55,6 +56,32 @@ static int spiimage;
static uint32_t pbi_crc_cmd1;
static uint32_t pbi_crc_cmd2;
+enum soc_type {
+ SOC_TYPE_INVALID,
+ SOC_TYPE_LS1046A,
+ SOC_TYPE_LS1028A,
+};
+
+struct soc_type_entry {
+ const char *name;
+ enum soc_type soc;
+ bool big_endian;
+};
+
+static struct soc_type_entry socs[] = {
+ {
+ .name = "ls1046a",
+ .soc = SOC_TYPE_LS1046A,
+ .big_endian = true,
+ }, {
+ .name = "ls1028a",
+ .soc = SOC_TYPE_LS1028A,
+ .big_endian = false,
+ },
+};
+
+static enum soc_type soc_type;
+
static char *rcwfile;
static char *pbifile;
static char *outfile;
@@ -113,9 +140,16 @@ static void check_get_hexval(const char *filename, int lineno, char *token)
exit(EXIT_FAILURE);
}
- for (i = 3; i >= 0; i--) {
- *pmem_buf++ = (hexval >> (i * 8)) & 0xff;
- pbl_size++;
+ if (socs[soc_type].big_endian) {
+ for (i = 3; i >= 0; i--) {
+ *pmem_buf++ = (hexval >> (i * 8)) & 0xff;
+ pbl_size++;
+ }
+ } else {
+ for (i = 0; i < 4; i++) {
+ *pmem_buf++ = (hexval >> (i * 8)) & 0xff;
+ pbl_size++;
+ }
}
}
@@ -181,24 +215,55 @@ static void pbl_load_image(void)
int size;
unsigned int n;
uint64_t *buf64 = (void *)mem_buf;
+ uint32_t *buf32 = (void *)mem_buf;
/* parse the rcw.cfg file. */
pbl_parser(rcwfile);
+ if (soc_type == SOC_TYPE_LS1028A) {
+ uint32_t chksum = 0;
+ int i;
+
+ for (i = 0; i < 34; i++)
+ chksum += buf32[i];
+
+ buf32[0x22] = chksum;
+ pbl_size += 4;
+ pmem_buf += 4;
+ }
+
/* parse the pbi.cfg file. */
if (pbifile)
pbl_parser(pbifile);
- for (n = 0; n < image_size; n += 0x40) {
- uint32_t pbl_cmd;
+ if (soc_type == SOC_TYPE_LS1046A) {
+ for (n = 0; n < image_size; n += 0x40) {
+ uint32_t pbl_cmd;
- pbl_cmd = (loadaddr & PBL_ADDR_24BIT_MASK) | PBL_ACS_CONT_CMD;
- pbl_cmd += n;
- generate_pbl_cmd(pbl_cmd);
- pbl_fget(64, in_fd);
- }
+ pbl_cmd = (loadaddr & PBL_ADDR_24BIT_MASK) | PBL_ACS_CONT_CMD;
+ pbl_cmd += n;
+ generate_pbl_cmd(pbl_cmd);
+ pbl_fget(64, in_fd);
+ }
- add_end_cmd();
+ add_end_cmd();
+ } else if (soc_type == SOC_TYPE_LS1028A) {
+ buf32 = (void *)pmem_buf;
+
+ buf32[0] = 0x80000008;
+ buf32[1] = 0x2000;
+ buf32[2] = 0x18010000;
+ buf32[3] = image_size;
+ buf32[4] = 0x80ff0000;
+ pbl_size += 20;
+ pmem_buf += 20;
+
+ read(in_fd, mem_buf + 0x1000, image_size);
+ pbl_size = 0x1000 + image_size;
+ printf("%s imagesize: %d\n", rcwfile, image_size);
+ } else {
+ exit(EXIT_FAILURE);
+ }
if (spiimage) {
int i;
@@ -236,7 +301,12 @@ static int pblimage_check_params(void)
}
/* For the variable size, pad it to 64 byte boundary */
- image_size = roundup(pbl_end, 64);
+ if (soc_type == SOC_TYPE_LS1046A)
+ image_size = roundup(pbl_end, 64);
+ else if (soc_type == SOC_TYPE_LS1028A)
+ image_size = roundup(pbl_end, 512);
+ else
+ exit(EXIT_FAILURE);
if (image_size > MAX_PBL_SIZE) {
fprintf(stderr, "Error: pbl size %d in %s exceeds maximum size %d\n",
@@ -289,10 +359,11 @@ static int copy_fd(int in, int out)
int main(int argc, char *argv[])
{
- int opt, ret;
+ int opt, ret, i;
off_t pos;
+ char *cputypestr = NULL;
- while ((opt = getopt(argc, argv, "i:r:p:o:m:s")) != -1) {
+ while ((opt = getopt(argc, argv, "i:r:p:o:m:sc:")) != -1) {
switch (opt) {
case 'i':
infile = optarg;
@@ -312,6 +383,9 @@ int main(int argc, char *argv[])
case 's':
spiimage = 1;
break;
+ case 'c':
+ cputypestr = optarg;
+ break;
default:
exit(EXIT_FAILURE);
}
@@ -332,6 +406,26 @@ int main(int argc, char *argv[])
exit(EXIT_FAILURE);
}
+ if (!cputypestr) {
+ fprintf(stderr, "No CPU type given\n");
+ exit(EXIT_FAILURE);
+ }
+
+ for (i = 0; i < ARRAY_SIZE(socs); i++) {
+ if (!strcmp(socs[i].name, cputypestr)) {
+ soc_type = socs[i].soc;
+ break;
+ }
+ }
+
+ if (soc_type == SOC_TYPE_INVALID) {
+ fprintf(stderr, "Invalid CPU type %s. Valid types are:\n", cputypestr);
+ for (i = 0; i < ARRAY_SIZE(socs); i++)
+ printf(" %s\n", socs[i].name);
+
+ exit(EXIT_FAILURE);
+ }
+
pblimage_check_params();
out_fd = open(outfile, O_WRONLY | O_CREAT | O_TRUNC, 0644);
--
2.39.2
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2023-12-19 13:02 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-12-19 13:00 [PATCH 0/4] Layerscape LS1028a pblimage support Sascha Hauer
2023-12-19 13:00 ` [PATCH 1/4] pblimage: drop PowerPC support Sascha Hauer
2023-12-19 13:00 ` [PATCH 2/4] pblimage: simplify a bit Sascha Hauer
2023-12-19 13:00 ` [PATCH 3/4] pblimage: use roundup() from kernel.h Sascha Hauer
2023-12-19 13:00 ` [PATCH 4/4] pblimage: Add LS1028a support Sascha Hauer
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox