[U-Boot] [PATCH v2 22/25] net: Fix incorrect DHCP/BOOTP packets on 64-bit systems

2015-04-08 Thread Joe Hershberger
From: Sergey Temerkhanov s.temerkha...@gmail.com

This commit fixes incorrect DHCP/BOOTP packet layout caused by
'ulong' type size difference on 64 and 32-bit architectures.
It also renames NetReadLong()/NetCopyLong() to
net_read_u32/net_copy_u32() accordingly.


Signed-off-by: Radha Mohan Chintakuntla rchintakun...@cavium.com
Signed-off-by: Sergey Temerkhanov s.temerkha...@gmail.com
Signed-off-by: Joe Hershberger joe.hershber...@ni.com
---

Changes in v2: None

 include/net.h | 10 +-
 net/bootp.c   | 33 -
 net/bootp.h   |  4 ++--
 3 files changed, 23 insertions(+), 24 deletions(-)

diff --git a/include/net.h b/include/net.h
index e9131f7..def1fd9 100644
--- a/include/net.h
+++ b/include/net.h
@@ -410,7 +410,7 @@ struct icmp_hdr {
ushort  id;
ushort  sequence;
} echo;
-   ulong   gateway;
+   u32 gateway;
struct {
ushort  unused;
ushort  mtu;
@@ -678,9 +678,9 @@ static inline struct in_addr net_read_ip(void *from)
 }
 
 /* return ulong *in network byteorder* */
-static inline ulong net_read_long(ulong *from)
+static inline u32 net_read_u32(u32 *from)
 {
-   ulong l;
+   u32 l;
 
memcpy((void *)l, (void *)from, sizeof(l));
return l;
@@ -699,9 +699,9 @@ static inline void net_copy_ip(void *to, void *from)
 }
 
 /* copy ulong */
-static inline void net_copy_long(ulong *to, ulong *from)
+static inline void net_copy_u32(u32 *to, u32 *from)
 {
-   memcpy((void *)to, (void *)from, sizeof(ulong));
+   memcpy((void *)to, (void *)from, sizeof(u32));
 }
 
 /**
diff --git a/net/bootp.c b/net/bootp.c
index 500850c..43466af 100644
--- a/net/bootp.c
+++ b/net/bootp.c
@@ -51,7 +51,7 @@
 #define CONFIG_BOOTP_ID_CACHE_SIZE 4
 #endif
 
-ulong  bootp_ids[CONFIG_BOOTP_ID_CACHE_SIZE];
+u32bootp_ids[CONFIG_BOOTP_ID_CACHE_SIZE];
 unsigned int   bootp_num_ids;
 intbootp_try;
 ulong  bootp_start;
@@ -62,7 +62,7 @@ char net_root_path[64] = {0,}; /* Our bootpath */
 
 #if defined(CONFIG_CMD_DHCP)
 static dhcp_state_t dhcp_state = INIT;
-static unsigned long dhcp_leasetime;
+static u32 dhcp_leasetime;
 static struct in_addr dhcp_server_ip;
 static void dhcp_handler(uchar *pkt, unsigned dest, struct in_addr sip,
unsigned src, unsigned len);
@@ -128,7 +128,7 @@ static int check_packet(uchar *pkt, unsigned dest, unsigned 
src, unsigned len)
retval = -4;
else if (bp-bp_hlen != HWL_ETHER)
retval = -5;
-   else if (!bootp_match_id(net_read_long((ulong *)bp-bp_id)))
+   else if (!bootp_match_id(net_read_u32(bp-bp_id)))
retval = -6;
 
debug(Filtering pkt = %d\n, retval);
@@ -356,8 +356,7 @@ static void bootp_handler(uchar *pkt, unsigned dest, struct 
in_addr sip,
store_net_params(bp);   /* Store net parameters from reply */
 
/* Retrieve extended information (we must parse the vendor area) */
-   if (net_read_long((ulong *)bp-bp_vend[0]) ==
-   htonl(BOOTP_VENDOR_MAGIC))
+   if (net_read_u32((u32 *)bp-bp_vend[0]) == htonl(BOOTP_VENDOR_MAGIC))
bootp_process_vendor((uchar *)bp-bp_vend[4], len);
 
net_set_timeout_handler(0, (thand_f *)0);
@@ -666,7 +665,7 @@ void bootp_request(void)
 #ifdef CONFIG_BOOTP_RANDOM_DELAY
ulong rand_ms;
 #endif
-   ulong bootp_id;
+   u32 bootp_id;
struct in_addr zero_ip;
struct in_addr bcast_ip;
 
@@ -734,14 +733,14 @@ void bootp_request(void)
 *  Bootp ID is the lower 4 bytes of our ethernet address
 *  plus the current time in ms.
 */
-   bootp_id = ((ulong)net_ethaddr[2]  24)
-   | ((ulong)net_ethaddr[3]  16)
-   | ((ulong)net_ethaddr[4]  8)
-   | (ulong)net_ethaddr[5];
+   bootp_id = ((u32)net_ethaddr[2]  24)
+   | ((u32)net_ethaddr[3]  16)
+   | ((u32)net_ethaddr[4]  8)
+   | (u32)net_ethaddr[5];
bootp_id += get_timer(0);
bootp_id = htonl(bootp_id);
bootp_add_id(bootp_id);
-   net_copy_long(bp-bp_id, bootp_id);
+   net_copy_u32(bp-bp_id, bootp_id);
 
/*
 * Calculate proper packet lengths taking into account the
@@ -780,7 +779,7 @@ static void dhcp_process_options(uchar *popt, struct 
bootp_hdr *bp)
 #if defined(CONFIG_CMD_SNTP)  defined(CONFIG_BOOTP_TIMEOFFSET)
case 2: /* Time offset  */
to_ptr = net_ntp_time_offset;
-   net_copy_long((ulong *)to_ptr, (ulong *)(popt + 2));
+   net_copy_u32((u32 *)to_ptr, (u32 *)(popt + 2));
net_ntp_time_offset = ntohl(net_ntp_time_offset);
break;
 #endif
@@ -816,7 +815,7 @@ static void dhcp_process_options(uchar *popt, struct 
bootp_hdr 

Re: [U-Boot] [PATCH v2 22/25] net: Fix incorrect DHCP/BOOTP packets on 64-bit systems

2015-04-08 Thread Simon Glass
On 8 April 2015 at 06:47, Simon Glass s...@chromium.org wrote:
 On 8 April 2015 at 00:41, Joe Hershberger joe.hershber...@ni.com wrote:
 From: Sergey Temerkhanov s.temerkha...@gmail.com

 This commit fixes incorrect DHCP/BOOTP packet layout caused by
 'ulong' type size difference on 64 and 32-bit architectures.
 It also renames NetReadLong()/NetCopyLong() to
 net_read_u32/net_copy_u32() accordingly.


 Signed-off-by: Radha Mohan Chintakuntla rchintakun...@cavium.com
 Signed-off-by: Sergey Temerkhanov s.temerkha...@gmail.com
 Signed-off-by: Joe Hershberger joe.hershber...@ni.com
 ---

 Changes in v2: None

  include/net.h | 10 +-
  net/bootp.c   | 33 -
  net/bootp.h   |  4 ++--
  3 files changed, 23 insertions(+), 24 deletions(-)

 Acked-by: Simon Glass s...@chromium.org

Applied to u-boot-dm/next, thanks!
___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


Re: [U-Boot] [PATCH v2 22/25] net: Fix incorrect DHCP/BOOTP packets on 64-bit systems

2015-04-08 Thread Simon Glass
On 8 April 2015 at 00:41, Joe Hershberger joe.hershber...@ni.com wrote:
 From: Sergey Temerkhanov s.temerkha...@gmail.com

 This commit fixes incorrect DHCP/BOOTP packet layout caused by
 'ulong' type size difference on 64 and 32-bit architectures.
 It also renames NetReadLong()/NetCopyLong() to
 net_read_u32/net_copy_u32() accordingly.


 Signed-off-by: Radha Mohan Chintakuntla rchintakun...@cavium.com
 Signed-off-by: Sergey Temerkhanov s.temerkha...@gmail.com
 Signed-off-by: Joe Hershberger joe.hershber...@ni.com
 ---

 Changes in v2: None

  include/net.h | 10 +-
  net/bootp.c   | 33 -
  net/bootp.h   |  4 ++--
  3 files changed, 23 insertions(+), 24 deletions(-)

Acked-by: Simon Glass s...@chromium.org
___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot