[U-Boot-Users] byteorder of image_header_t members?

Hi there,
if uint32_t members of image_header_t are stored in network byteorder, then all references of these members should use ntohl(), right?
So should we fix this for instance:
#~> grep "->ih_magic" * cmd_autoscript.c: if (ntohl(hdr->ih_magic) != IH_MAGIC) { cmd_bootm.c: if (ntohl(hdr->ih_magic) != IH_MAGIC) {
cmd_bootm.c: if (hdr->ih_magic != IH_MAGIC) { <<<
cmd_bootm.c: if (ntohl(hdr->ih_magic) != IH_MAGIC) { cmd_bootm.c: (ntohl(hdr->ih_magic) != IH_MAGIC))
cmd_doc.c: if (hdr->ih_magic == IH_MAGIC) { <<< cmd_fdc.c: if (hdr->ih_magic != IH_MAGIC) { <<<
cmd_fpga.c: if (ntohl(hdr->ih_magic) != IH_MAGIC) { cmd_ide.c: if (ntohl(hdr->ih_magic) != IH_MAGIC) { cmd_nand.c: if (ntohl(hdr->ih_magic) == IH_MAGIC) { cmd_scsi.c: if (ntohl(hdr->ih_magic) == IH_MAGIC) { cmd_usb.c: if (ntohl(hdr->ih_magic) != IH_MAGIC) {

In message 42A97ECC.5030708@imc-berlin.de you wrote:
if uint32_t members of image_header_t are stored in network byteorder, then all references of these members should use ntohl(), right?
Right.
So should we fix this for instance:
cmd_bootm.c: if (hdr->ih_magic != IH_MAGIC) { <<<
Done.
cmd_doc.c: if (hdr->ih_magic == IH_MAGIC) { <<< cmd_fdc.c: if (hdr->ih_magic != IH_MAGIC) { <<<
Looking forward to see your patch... :-)
Best regards,
Wolfgang Denk

Hi there,
I wrote:
if uint32_t members of image_header_t are stored in network byteorder, then all references of these members should use ntohl(), right?
So should we fix this for instance:
Maybe you want to consider the attached patch.
* Patch by Steven Scholz, 10 Jun 2005: Adding loads of ntohl() in image header handling (for the sake of readability)
-- Steven
Index: u-boot/common/cmd_bootm.c =================================================================== RCS file: /cvsroot/u-boot/u-boot/common/cmd_bootm.c,v retrieving revision 1.42 diff -p -u -r1.42 cmd_bootm.c --- u-boot/common/cmd_bootm.c 3 Apr 2005 21:11:18 -0000 1.42 +++ u-boot/common/cmd_bootm.c 10 Jun 2005 12:19:13 -0000 @@ -592,7 +592,7 @@ do_bootm_linux (cmd_tbl_t *cmdtp, int fl #endif /* CONFIG_MPC5xxx */ }
- kernel = (void (*)(bd_t *, ulong, ulong, ulong, ulong))hdr->ih_ep; + kernel = (void (*)(bd_t *, ulong, ulong, ulong, ulong)) ntohl(hdr->ih_ep);
/* * Check if there is an initrd image @@ -607,7 +607,7 @@ do_bootm_linux (cmd_tbl_t *cmdtp, int fl /* Copy header so we can blank CRC field for re-calculation */ memmove (&header, (char *)addr, sizeof(image_header_t));
- if (hdr->ih_magic != IH_MAGIC) { + if (ntohl(hdr->ih_magic) != IH_MAGIC) { puts ("Bad Magic Number\n"); SHOW_BOOT_PROGRESS (-10); do_reset (cmdtp, flag, argc, argv); @@ -616,7 +616,7 @@ do_bootm_linux (cmd_tbl_t *cmdtp, int fl data = (ulong)&header; len = sizeof(image_header_t);
- checksum = hdr->ih_hcrc; + checksum = ntohl(hdr->ih_hcrc); hdr->ih_hcrc = 0;
if (crc32 (0, (char *)data, len) != checksum) { @@ -630,7 +630,7 @@ do_bootm_linux (cmd_tbl_t *cmdtp, int fl print_image_hdr (hdr);
data = addr + sizeof(image_header_t); - len = hdr->ih_size; + len = ntohl(hdr->ih_size);
if (verify) { ulong csum = 0; @@ -656,7 +656,7 @@ do_bootm_linux (cmd_tbl_t *cmdtp, int fl csum = crc32 (0, (char *)data, len); #endif /* CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG */
- if (csum != hdr->ih_dcrc) { + if (csum != ntohl(hdr->ih_dcrc)) { puts ("Bad Data CRC\n"); SHOW_BOOT_PROGRESS (-12); do_reset (cmdtp, flag, argc, argv); @@ -858,7 +858,7 @@ do_bootm_netbsd (cmd_tbl_t *cmdtp, int f cmdline = ""; }
- loader = (void (*)(bd_t *, image_header_t *, char *, char *)) hdr->ih_ep; + loader = (void (*)(bd_t *, image_header_t *, char *, char *)) ntohl(hdr->ih_ep);
printf ("## Transferring control to NetBSD stage-2 loader (at address %08lx) ...\n", (ulong)loader); @@ -1320,7 +1320,7 @@ do_bootm_rtems (cmd_tbl_t *cmdtp, int fl image_header_t *hdr = &header; void (*entry_point)(bd_t *);
- entry_point = (void (*)(bd_t *)) hdr->ih_ep; + entry_point = (void (*)(bd_t *)) ntohl(hdr->ih_ep);
printf ("## Transferring control to RTEMS (at address %08lx) ...\n", (ulong)entry_point); @@ -1343,7 +1343,7 @@ do_bootm_vxworks (cmd_tbl_t *cmdtp, int image_header_t *hdr = &header; char str[80];
- sprintf(str, "%x", hdr->ih_ep); /* write entry-point into string */ + sprintf(str, "%x", ntohl(hdr->ih_ep)); /* write entry-point into string */ setenv("loadaddr", str); do_bootvx(cmdtp, 0, 0, NULL); } @@ -1356,7 +1356,7 @@ do_bootm_qnxelf (cmd_tbl_t *cmdtp, int f char *local_args[2]; char str[16];
- sprintf(str, "%x", hdr->ih_ep); /* write entry-point into string */ + sprintf(str, "%x", ntohl(hdr->ih_ep)); /* write entry-point into string */ local_args[0] = argv[0]; local_args[1] = str; /* and provide it via the arguments */ do_bootelf(cmdtp, 0, 2, local_args); Index: u-boot/common/cmd_doc.c =================================================================== RCS file: /cvsroot/u-boot/u-boot/common/cmd_doc.c,v retrieving revision 1.6 diff -p -u -r1.6 cmd_doc.c --- u-boot/common/cmd_doc.c 10 Sep 2003 22:30:54 -0000 1.6 +++ u-boot/common/cmd_doc.c 10 Jun 2005 12:19:13 -0000 @@ -249,7 +249,7 @@ int do_docboot (cmd_tbl_t *cmdtp, int fl
print_image_hdr (hdr);
- cnt = (hdr->ih_size + sizeof(image_header_t)); + cnt = (ntohl(hdr->ih_size) + sizeof(image_header_t)); cnt -= SECTORSIZE; } else { puts ("\n** Bad Magic Number **\n"); Index: u-boot/common/cmd_fdc.c =================================================================== RCS file: /cvsroot/u-boot/u-boot/common/cmd_fdc.c,v retrieving revision 1.6 diff -p -u -r1.6 cmd_fdc.c --- u-boot/common/cmd_fdc.c 1 Jul 2003 21:07:07 -0000 1.6 +++ u-boot/common/cmd_fdc.c 10 Jun 2005 12:19:14 -0000 @@ -836,13 +836,13 @@ int do_fdcboot (cmd_tbl_t *cmdtp, int fl return 1; } hdr = (image_header_t *)addr; - if (hdr->ih_magic != IH_MAGIC) { + if (ntohl(hdr->ih_magic) != IH_MAGIC) { printf ("Bad Magic Number\n"); return 1; } print_image_hdr(hdr);
- imsize= hdr->ih_size+sizeof(image_header_t); + imsize= ntohl(hdr->ih_size)+sizeof(image_header_t); nrofblk=imsize/512; if((imsize%512)>0) nrofblk++; Index: u-boot/common/cmd_nand.c =================================================================== RCS file: /cvsroot/u-boot/u-boot/common/cmd_nand.c,v retrieving revision 1.21 diff -p -u -r1.21 cmd_nand.c --- u-boot/common/cmd_nand.c 12 May 2005 22:48:11 -0000 1.21 +++ u-boot/common/cmd_nand.c 10 Jun 2005 12:19:14 -0000 @@ -355,7 +355,7 @@ int do_nandboot (cmd_tbl_t *cmdtp, int f cnt = (ntohl(hdr->ih_size) + sizeof(image_header_t)); cnt -= SECTORSIZE; } else { - printf ("\n** Bad Magic Number 0x%x **\n", hdr->ih_magic); + printf ("\n** Bad Magic Number 0x%x **\n", ntohl(hdr->ih_magic)); SHOW_BOOT_PROGRESS (-1); return 1; } Index: u-boot/common/lynxkdi.c =================================================================== RCS file: /cvsroot/u-boot/u-boot/common/lynxkdi.c,v retrieving revision 1.2 diff -p -u -r1.2 lynxkdi.c --- u-boot/common/lynxkdi.c 15 Oct 2003 23:53:50 -0000 1.2 +++ u-boot/common/lynxkdi.c 10 Jun 2005 12:19:14 -0000 @@ -23,11 +23,11 @@ #if defined(CONFIG_MPC8260) void lynxkdi_boot ( image_header_t *hdr ) { - void (*lynxkdi)(void) = (void(*)(void))hdr->ih_ep; + void (*lynxkdi)(void) = (void(*)(void)) ntohl(hdr->ih_ep); lynxos_bootparms_t *parms = (lynxos_bootparms_t *)0x0020; bd_t *kbd; DECLARE_GLOBAL_DATA_PTR; - u32 *psz = (u32 *)(hdr->ih_load + 0x0204); + u32 *psz = (u32 *)(ntohl(hdr->ih_load) + 0x0204);
memset( parms, 0, sizeof(*parms)); kbd = gd->bd; @@ -39,9 +39,9 @@ void lynxkdi_boot ( image_header_t *hdr /* Do a simple check for Bluecat so we can pass the * kernel command line parameters. */ - if( le32_to_cpu(*psz) == hdr->ih_size ){ + if( le32_to_cpu(*psz) == ntohl(hdr->ih_size) ){ /* FIXME: NOT SURE HERE ! */ char *args; - char *cmdline = (char *)(hdr->ih_load + 0x020c); + char *cmdline = (char *)(ntohl(hdr->ih_load) + 0x020c); int len;
printf("Booting Bluecat KDI ...\n");

In message 42A9AC33.5020204@imc-berlin.de you wrote:
- Patch by Steven Scholz, 10 Jun 2005: Adding loads of ntohl() in image header handling (for the sake of readability)
Applied, thanks.
Best regards,
Wolfgang Denk
participants (2)
-
Steven Scholz
-
Wolfgang Denk