Skip to contentSkip to conversation

Question about bootp structure pack

U-Boot rickou at rickou.net 2 participants 5 messages Feb 21, 2017 – Mar 7, 2017

lore
Share & tools
lore
#0 lore raw

Hi everyone,

I?m using u-boot-2015.07 in one of my project based on vpac270 soc module. u-boot is well configured and build is fine without error.
Gcc is v3.4.5 and glibc v2.3.6 built by crosstool 0.43 for arm-softfloat-linux-gnu

My problem is when i use DHCP command to retrieve a file from my TFTP server, i can?t get any IP from the DHCP server.
After analysing ethernet frames on server side i found that frame do not arrive at all on server.
After checking debug d?tails on U-boot, it seem bootp frame is not good because of some 0x00 paddings Inside the frame. (at end of header for example)

If i add the attribute packed to the bootp header struct and ethernet header, now all is working fine?!

In net/bootp.h?:

struct bootp_hdr {
	u8		bp_op;		/* Operation			*/
# define OP_BOOTREQUEST	1
# define OP_BOOTREPLY	2
	u8		bp_htype;	/* Hardware type		*/
# define HWT_ETHER	1
	u8		bp_hlen;	/* Hardware address length	*/
# define HWL_ETHER	6
	u8		bp_hops;	/* Hop count (gateway thing)	*/
	u32		bp_id;		/* Transaction ID		*/
	u16		bp_secs;	/* Seconds since boot		*/
	u16		bp_spare1;	/* Alignment			*/
	struct in_addr	bp_ciaddr;	/* Client IP address		*/
	struct in_addr	bp_yiaddr;	/* Your (client) IP address	*/
	struct in_addr	bp_siaddr;	/* Server IP address		*/
	struct in_addr	bp_giaddr;	/* Gateway IP address		*/
	u8		bp_chaddr[16];	/* Client hardware address	*/
	char		bp_sname[64];	/* Server host name		*/
	char		bp_file[128];	/* Boot file name		*/
	char		bp_vend[OPT_FIELD_SIZE]; /* Vendor information	*/
} __attribute__((packed));

#define BOOTP_HDR_SIZE sizeof(struct bootp_hdr)

And in include/net.h

struct ethernet_hdr {
	u8		et_dest[6];	/* Destination node		*/
	u8		et_src[6];	/* Source node			*/
	u16		et_protlen;	/* Protocol or length		*/
} __attribute__((packed));

I think the uboot src should work as is, because I have checked uboot source modification since 2015.07, but no changes on the struct definition and header_size still made with sizeof(struct). So i think, the problem come from my side and perhaps from gcc itself.

But?i don?t understand why gcc should pack these structs.. i think normal use is to not pack.. except if makefile include some build option to do that, my gcc toolchain do not understand..

Someone can help me to understand what i made wrong?? and help me to resolve this problem without patching ??

Provenance?: Courrier pour Windows 10

#1 lore raw

Hi everyone,

I?m using u-boot-2015.07 in one of my project based on vpac270 soc module.

u-boot is well configured and build is fine without error.

Gcc is v3.4.5 and glibc v2.3.6 built by crosstool 0.43 for arm-softfloat-linux-gnu

My problem is when i use DHCP command to retrieve a file from my TFTP server, i can?t get any IP from the DHCP server.

After analysing ethernet frames on server side i found that frame do not arrive at all on server.

After checking debug d?tails on U-boot, it seem bootp frame is not good because of some 0x00 paddings Inside the frame. (at end of header for example)

If i add the attribute packed to the bootp header struct and ethernet header, now all is working fine !

In net/bootp.h :

struct bootp_hdr {

u8 bp_op; /*
Operation */

# define OP_BOOTREQUEST       1
# define OP_BOOTREPLY             2

u8 bp_htype; /* Hardware
type */

# define HWT_ETHER     1

u8 bp_hlen; /*
Hardware address length */

# define HWL_ETHER     6

u8 bp_hops; /* Hop
count (gateway thing) */

u32 bp_id; /*
Transaction ID */

u16 bp_secs; /* Seconds
since boot */

u16 bp_spare1; /*
Alignment */

struct in_addr bp_ciaddr; /* Client IP
address */

struct in_addr bp_yiaddr; /* Your (client) IP
address */

struct in_addr bp_siaddr; /* Server IP
address */

struct in_addr bp_giaddr; /* Gateway IP
address */

u8 bp_chaddr[16]; /* Client
hardware address */

char bp_sname[64]; /* Server host
name */

char bp_file[128]; /* Boot file
name */

char bp_vend[OPT_FIELD_SIZE]; /*
Vendor information */

} __attribute__((packed));

#define BOOTP_HDR_SIZE sizeof(struct bootp_hdr)

And in include/net.h

struct ethernet_hdr {

u8 et_dest[6]; /*
Destination node */

u8 et_src[6]; /*
Source node */

u16 et_protlen; /* Protocol
or length */

} __attribute__((packed));

I think the uboot src should work as is, because I have checked uboot source modification since 2015.07, but no changes on the struct definition and header_size still made with sizeof(struct).

So i think, the problem come from my side and perhaps from gcc itself.

But i don?t understand why gcc should pack these structs.. i think normal use is to not pack.. except if makefile include some build option to do that, my gcc toolchain do not understand..

Someone can help me to understand what i made wrong ? and help me to resolve this problem without patching ?

#2 lore raw
Quoted 7 lines · On Sun, 26 Feb 2017 07:27:42 +0100 Eric BOUXIROT <[email protected]> wrote:

I?m using u-boot-2015.07 in one of my project based on vpac270 soc module.

u-boot is well configured and build is fine without error.

Gcc is v3.4.5 and glibc v2.3.6 built by crosstool 0.43 for arm-softfloat-linux-gnu

Could you try to use newer gcc and see if bootp is working as expected?

Best regards,

Lukasz Majewski

--

DENX Software Engineering GmbH, Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de

#3 lore raw

Hi Lukasz,

Quoted 11 lines
Quoted 7 lines

I’m using u-boot-2015.07 in one of my project based on vpac270 soc module.

u-boot is well configured and build is fine without error.

Gcc is v3.4.5 and glibc v2.3.6 built by crosstool 0.43 for arm-softfloat-linux-gnu

Could you try to use newer gcc and see if bootp is working as expected?

ok, i will test this, but i think the "normal" build is to NOT pack theses structs..
and it would be "normal" to get theses alignment gaps inside frame ...

i haven't found in Makefile any options to pack the structs.

have you an explanation about this?? may i miss something in the build process of uboot...

will let you know soon about testing with another compiler. (have gcc4.9-linaro toolchain too)

thank !
Eric BOUXIROT

#4 lore raw
In reply to Lukasz Majewski

2017-02-27 10:07 GMT+01:00 Lukasz Majewski <[email protected]>:

Quoted 11 lines
Quoted 7 lines · On Sun, 26 Feb 2017 07:27:42 +0100 Eric BOUXIROT <[email protected]> wrote:

I’m using u-boot-2015.07 in one of my project based on vpac270 soc module.

u-boot is well configured and build is fine without error.

Gcc is v3.4.5 and glibc v2.3.6 built by crosstool 0.43 for arm-softfloat-linux-gnu

Quoted 7 lines

Could you try to use newer gcc and see if bootp is working as expected?

Best regards,

Lukasz Majewski

hi Lukasz,

i have made tests with a newer GCC version (4.9 linaro) and it is working fine without patching the struct definition.

but i don't understand why now it work??

can you help me to understand ??

best regards.
Eric BOUXIROT