天线|RF射频
直播中

杨桂英

8年用户 201经验值
私信 关注
[问答]

LWIP使用TFTP出现死机

PC端与开发板网络连接正常。
采用tftp32.exe软件进行tftp get 测试时,出现了hardfault,串口打印
Assertion "pbuf_free: p->ref > 0" failed at line 651 in ..LWIPlwip-1.4.1srccorepbuf.c
Assertion "pbuf_free: sane type" failed at line 636 in ..LWIPlwip-1.4.1srccorepbuf.c
搜索论坛发现之前有类似现象,原子建议关中断解决,尝试后无效。
之后采用抓包软件发现tftp请求能够正常收到,并且从sd卡已经读取文件并且发送了block1 - block3 在发送block4时,死机。
结合打印提示应该是内存相关的问题。
然后单步仿真跟踪,发现pbuf链表中,有一个链表元素的next指针指向了FFFFFFF,并且FFFFFFFF中所有成员的值均为FFFF。
因此在low_level_output中memcpy((u8_t*)&buffer[l], q->payload, q->len);调用了非法的指针导致程序死机。
目前还没找到这个FFFFFFF成员从哪里来的,继续debug。

回帖(1)

乔军

2020-3-9 09:55:31
进一步跟踪,发现
err_t tftp_send_message(struct udp_pcb *upcb, struct ip_addr *to_ip, unsigned short to_port, char *buf, unsigned short buflen)
{
  err_t err;
  struct pbuf *pkt_buf; /* Chain of pbuf's to be sent */
  /* PBUF_TRANSPORT - specifies the transport layer */
  pkt_buf = pbuf_alloc(PBUF_TRANSPORT, buflen, PBUF_POOL);
  if (!pkt_buf)      /*if the packet pbuf == NULL exit and end transmission */
    return ERR_MEM;
  /* Copy the original data buffer over to the packet buffer's payload */
  memcpy(pkt_buf->payload, buf, buflen);
  /* Sending packet by UDP protocol */
  err = udp_sendto(upcb, pkt_buf, to_ip, to_port);
  /* free the buffer pbuf */
  pbuf_free(pkt_buf);
  return err;
}
执行memcpy(pkt_buf->payload, buf, buflen);的时候pkt_buf中next中的next指向地址从000000变为FFFFFF
举报

更多回帖

发帖
×
20
完善资料,
赚取积分