[PATCH 4/4] pblimage: Add LS1028a support
Sascha Hauer
s.hauer at pengutronix.de
Tue Dec 19 05:00:40 PST 2023
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 at 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
More information about the barebox
mailing list