Bladeren bron

clarify header values, cleanup

Andrey Rys 1 jaar geleden
bovenliggende
commit
50d7070092
1 gewijzigde bestanden met toevoegingen van 25 en 21 verwijderingen
  1. 25 21
      spl_tool/jh7110_uboot_spl.c

+ 25 - 21
spl_tool/jh7110_uboot_spl.c

@@ -16,29 +16,26 @@
 extern uint32_t crc32(uint32_t iv, uint32_t sv, const void *data, size_t n);
 extern uint32_t crc32_final(uint32_t iv);
 
+/* all uint32_t ends up little endian in output header */
 struct __attribute__((__packed__)) ubootsplhdr {
-	uint8_t  res1[  2];
-	uint8_t  zro1[  4];
-	uint8_t  res2[  4];
-	uint8_t  zro2[634];
-	uint32_t vers;
-	uint32_t fsiz;
-	uint8_t  res3[  4];
-	uint32_t crcs;
+	uint32_t sofs;		/* offset of "second?" header: 0x240, dunno */
+	uint32_t bofs;		/* SBL_BAK_OFFSET: Offset of backup SBL from Flash info start (from input_sbl_normal.cfg) */
+	uint8_t  zro2[636];
+	uint32_t vers;		/* version: shall be 0x01010101
+				 * (from https://doc-en.rvspace.org/VisionFive2/SWTRM/VisionFive2_SW_TRM/create_spl.html) */
+	uint32_t fsiz;		/* u-boot-spl.bin size in bytes */
+	uint32_t res1;		/* unknown, 0x400 (00 04 00 00) currently */
+	uint32_t crcs;		/* CRC32 of u-boot-spl.bin */
 	uint8_t  zro3[364];
 };
 
-static struct ubootsplhdr ubsplhdr = {
-	.res1[0] = 0x40, .res1[1] = 0x02,
-	/* res2 seems to be "# Offset of backup SBL from Flash info start"
-	 * from SBL_BAK_OFFSET @ input_files/input_sbl_normal.cfg */
-	.res2[0] = 0x20, .res2[1] = 0x00, .res2[2] = 0x00, .res2[3] = 0x00,
-	.res3[0] = 0x00, .res3[1] = 0x04, .res3[2] = 0x00, .res3[3] = 0x00,
-};
+static struct ubootsplhdr ubsplhdr;
 
 static char ubootspl[131072-0x400];
 static char outpath[PATH_MAX];
 
+#define DEFVERSID 0x01010101
+
 static void xerror(int errnoval, const char *s)
 {
 	if (errnoval) perror(s);
@@ -48,9 +45,9 @@ static void xerror(int errnoval, const char *s)
 
 static void usage(void)
 {
-	printf("usage: jh7110_uboot_spl u-boot-spl.bin version\n");
+	printf("usage: jh7110_uboot_spl u-boot-spl.bin [version]\n");
 	printf("u-boot-spl.bin is path to input U-Boot SPL file\n");
-	printf("version shall be 0x01010101\n");
+	printf("if version specified, shall be 0x01010101\n");
 	printf("output will be written to u-boot-spl.bin.out\n");
 	exit(1);
 }
@@ -61,14 +58,21 @@ int main(int argc, char **argv)
 	uint32_t v;
 	size_t sz;
 
-	if (argc < 3) usage();
+	if (argc < 2) usage();
 
 	fd = open(argv[1], O_RDONLY);
 	if (fd == -1) xerror(errno, argv[1]);
 
-	v = (uint32_t)strtoul(argv[2], NULL, 16);
-	v = htole32(v);
-	ubsplhdr.vers = v;
+	ubsplhdr.sofs = htole32(0x240U);
+	ubsplhdr.bofs = htole32(0x200000U);
+	ubsplhdr.res1 = htole32(0x400U);
+
+	if (argc >= 3) {
+		v = (uint32_t)strtoul(argv[2], NULL, 16);
+		v = htole32(v);
+		ubsplhdr.vers = v;
+	}
+	else ubsplhdr.vers = htole32(DEFVERSID);
 
 	sz = (size_t)read(fd, ubootspl, sizeof(ubootspl));
 	if (sz == NOSIZE) xerror(errno, argv[1]);