summaryrefslogtreecommitdiffstats
path: root/scripts/pblimage.c
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2023-12-19 14:00:40 +0100
committerSascha Hauer <s.hauer@pengutronix.de>2024-01-10 15:32:33 +0100
commitd5e5a65c2b64c01a8ea353b50542509ce72a4674 (patch)
treead7503592a52bc5faac4a07aec619f3e3985e36b /scripts/pblimage.c
parentd7e10f8d0e51e7f00cf2ed0de7cafef62732aa94 (diff)
downloadbarebox-d5e5a65c2b64c01a8ea353b50542509ce72a4674.tar.gz
barebox-d5e5a65c2b64c01a8ea353b50542509ce72a4674.tar.xz
pblimage: Add LS1028a support
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. Link: https://lore.barebox.org/20231219130040.4115-5-s.hauer@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'scripts/pblimage.c')
-rw-r--r--scripts/pblimage.c120
1 files changed, 106 insertions, 14 deletions
diff --git a/scripts/pblimage.c b/scripts/pblimage.c
index e8108bbb17..ef09b0f960 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,30 @@ static int spiimage;
static uint32_t pbi_crc_cmd1;
static uint32_t pbi_crc_cmd2;
+enum soc_type {
+ SOC_TYPE_INVALID = -1,
+ SOC_TYPE_LS1046A,
+ SOC_TYPE_LS1028A,
+};
+
+struct soc_type_entry {
+ const char *name;
+ bool big_endian;
+};
+
+static struct soc_type_entry socs[] = {
+ [SOC_TYPE_LS1046A] = {
+ .name = "ls1046a",
+ .big_endian = true,
+ },
+ [SOC_TYPE_LS1028A] = {
+ .name = "ls1028a",
+ .big_endian = false,
+ },
+};
+
+static enum soc_type soc_type = SOC_TYPE_INVALID;
+
static char *rcwfile;
static char *pbifile;
static char *outfile;
@@ -113,9 +138,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 +213,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 +299,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 +357,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 +381,9 @@ int main(int argc, char *argv[])
case 's':
spiimage = 1;
break;
+ case 'c':
+ cputypestr = optarg;
+ break;
default:
exit(EXIT_FAILURE);
}
@@ -332,6 +404,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 = i;
+ 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);