FreeRTOSを動かしてみる(8)

[前回](https://qiita.com/t-yano-tryhard/items/f6992531359a914c13d9)の続き

一旦FreeRTOSとqemuだけでarp replyが受け取れるか試してみる

# FreeRTOSのドライバ改造

の前に日立がnewlib弄ってきて鬱陶しいことこの上ない

<details>
<summary> グローバル変数書き換え </summary>

```
(gdb) c
Continuing.

Hardware watchpoint 3: et_status

Old value = 1
New value = 0
0x0000dbcc in _malloc_r (reent_ptr=0x20000130 <_impure_data>, s=s@entry=82) at ../../../../../../newlib/libc/stdlib/nano-mallocr.c:281
281	../../../../../../newlib/libc/stdlib/nano-mallocr.c: No such file or directory.
(gdb) bt
#0  0x0000dbcc in _malloc_r (reent_ptr=0x20000130 <_impure_data>, s=s@entry=82) at ../../../../../../newlib/libc/stdlib/nano-mallocr.c:281
#1  0x0000dade in malloc (nbytes=nbytes@entry=82) at ../../../../../../newlib/libc/stdlib/malloc.c:164
#2  0x000038ce in pvPortMalloc (xWantedSize=xWantedSize@entry=82) at /home/voyager/workspace/freertos/freertos_cm3/FreeRTOS/Source/portable/MemMang/heap_3.c:65
#3  0x0000d176 in pxGetNetworkBufferWithDescriptor (xRequestedSizeBytes=xRequestedSizeBytes@entry=42, xBlockTimeTicks=xBlockTimeTicks@entry=0) at /home/voyager/workspace/freertos/FreeRTOS-Plus-TCP/source/portable/BufferManagement/BufferAllocation_2.c:282
#4  0x00003d50 in FreeRTOS_OutputARPRequest (ulIPAddress=3372878346) at /home/voyager/workspace/freertos/FreeRTOS-Plus-TCP/source/FreeRTOS_ARP.c:1284
#5  0x0000bd14 in prvTCPPrepareConnect_IPV4 (pxSocket=0x20012f98) at /home/voyager/workspace/freertos/FreeRTOS-Plus-TCP/source/FreeRTOS_TCP_Transmission_IPv4.c:367
#6  0x0000b4da in prvTCPPrepareConnect (pxSocket=<optimized out>) at /home/voyager/workspace/freertos/FreeRTOS-Plus-TCP/source/FreeRTOS_TCP_Transmission.c:496
#7  0x0000b4f6 in prvTCPMakeSurePrepared (pxSocket=<optimized out>) at /home/voyager/workspace/freertos/FreeRTOS-Plus-TCP/source/FreeRTOS_TCP_Transmission.c:87
#8  0x0000b956 in prvTCPSendPacket (pxSocket=pxSocket@entry=0x20012f98) at /home/voyager/workspace/freertos/FreeRTOS-Plus-TCP/source/FreeRTOS_TCP_Transmission.c:139
#9  0x0000a392 in xTCPSocketCheck (pxSocket=pxSocket@entry=0x20012f98) at /home/voyager/workspace/freertos/FreeRTOS-Plus-TCP/source/FreeRTOS_TCP_IP.c:226
#10 0x00009194 in xTCPTimerCheck (xWillSleep=xWillSleep@entry=1) at /home/voyager/workspace/freertos/FreeRTOS-Plus-TCP/source/FreeRTOS_Sockets.c:4824
#11 0x00005edc in vCheckNetworkTimers () at /home/voyager/workspace/freertos/FreeRTOS-Plus-TCP/source/FreeRTOS_IP_Timers.c:302
#12 0x00005b84 in prvProcessIPEventsAndTimers () at /home/voyager/workspace/freertos/FreeRTOS-Plus-TCP/source/FreeRTOS_IP.c:268
#13 0x00005cae in prvIPTask (pvParameters=<optimized out>) at /home/voyager/workspace/freertos/FreeRTOS-Plus-TCP/source/FreeRTOS_IP.c:249
#14 0x00000280 in prvPortStartFirstTask () at /home/voyager/workspace/freertos/freertos_cm3/FreeRTOS/Source/portable/GCC/ARM_CM3/port.c:247
(gdb) disas $pc-0x10,+0x20
Dump of assembler code from 0xdbbc to 0xdbdc:
   0x0000dbbc <_malloc_r+132>:	ldr	r2, [r4, #0]
   0x0000dbbe <_malloc_r+134>:	subs	r2, r2, r5
   0x0000dbc0 <_malloc_r+136>:	bmi.n	0xdbfe <_malloc_r+198>
   0x0000dbc2 <_malloc_r+138>:	cmp	r2, #11
   0x0000dbc4 <_malloc_r+140>:	bls.n	0xdbf4 <_malloc_r+188>
   0x0000dbc6 <_malloc_r+142>:	adds	r1, r4, r5
   0x0000dbc8 <_malloc_r+144>:	cmp	r3, r4
   0x0000dbca <_malloc_r+146>:	str	r5, [r4, #0]
=> 0x0000dbcc <_malloc_r+148>:	it	ne
   0x0000dbce <_malloc_r+150>:	strne	r1, [r3, #4]
   0x0000dbd0 <_malloc_r+152>:	ldr	r3, [r4, #4]
   0x0000dbd2 <_malloc_r+154>:	it	eq
   0x0000dbd4 <_malloc_r+156>:	streq	r1, [r7, #0]
   0x0000dbd6 <_malloc_r+158>:	str	r2, [r4, r5]
   0x0000dbd8 <_malloc_r+160>:	str	r3, [r1, #4]
   0x0000dbda <_malloc_r+162>:	mov	r0, r6
End of assembler dump.
(gdb) p/x $r4
$4 = 0x200113ce

```

</details>

ていうか日立はnewlibの改ざん好きだな

直しても直しても違うところを書き換えてきてきりがない
とりあえずnewlibの影響受けない場所に変更したら通った。
けど結局connectはできず。ARP リプライだけだとだめなのか？

<details>
<summary>MMIOに吐き出したら諦めやがったログ</summary>

日立の技術者(笑)ってツール使ってファイル改ざんするしか脳がない

```
mps2.c(625) add_extra_mmio_an385 added to 28000000
mps2.c(715) udp_recvfromdummy 
[0000] main_tcp.c(22) main_tcp 13:24:51, Dec 18 2023(51a0cff96d5468ad2355cf219d72f0f524ecdb2b-dirty) fr:0x1c7 
[0000] NetworkInterface.c(140) pxFillInterfaceDescriptor mac:0 fr:0x552b 
mps2.c(663) an385_ex_mmio_write 100:0 -> 1
[1ce0] NetworkInterface.c(224) ether_task sleep fr:0x281 
[1ce0] tasks.c(1683) vTaskSuspend suspend:0 0x20011ce0 fr:0xd5c3 
[1ce0] tasks.c(1708) vTaskSuspend suspend:1 0x20011ce0 fr:0xd5c3 
[1ce0] tasks.c(1743) vTaskSuspend suspend:1 0x20011ce0 fr:0xd5c3 
[67ac] FreeRTOS_IP.c(1398) xSendEventStructToIPTask et:0 fr:0x58a1 
[67ac] FreeRTOS_IP.c(1418) xSendEventStructToIPTask  fr:0x58a1 
[67ac] FreeRTOS_IP.c(1428) xSendEventStructToIPTask xReturn:1 fr:0x58a1 
[2518] app_server.c(14) server_task  fr:0x281 
[2518] app_server.c(31) vCreateTCPServerSocket sock:536948144 fr:0xdbf1 
[2518] FreeRTOS_IP.c(1398) xSendEventStructToIPTask et:9 fr:0x9ac1 
[2518] FreeRTOS_IP.c(1418) xSendEventStructToIPTask  fr:0x9ac1 
[2d50] app_client.c(28) client_task  fr:0x281 
[2d50] app_client.c(44) vTCPSend IN fr:0xdad5 
[2d50] app_client.c(54) vTCPSend socket fr:0xdad5 
[2d50] FreeRTOS_Sockets.c(3783) FreeRTOS_connect  fr:0xd9d9 
[2d50] FreeRTOS_IP.c(1398) xSendEventStructToIPTask et:9 fr:0x9ac1 
[2d50] FreeRTOS_IP.c(1418) xSendEventStructToIPTask  fr:0x9ac1 
[67ac] NetworkInterface.c(114) xApplicationGetRandomNumber  fr:0x8a79 
[2518] FreeRTOS_IP.c(1428) xSendEventStructToIPTask xReturn:1 fr:0x9ac1 
[2518] app_server.c(45) vCreateTCPServerSocket bind fr:0xdbf1 
[2518] app_server.c(48) vCreateTCPServerSocket listen fr:0xdbf1 
[2d50] FreeRTOS_IP.c(1428) xSendEventStructToIPTask xReturn:1 fr:0x9ac1 
[2d50] FreeRTOS_Sockets.c(3694) prvTCPConnectStart  fr:0x9df5 
[2d50] FreeRTOS_Sockets.c(3701) prvTCPConnectStart fam:2 fr:0x9df5 
[2d50] FreeRTOS_Sockets.c(3717) prvTCPConnectStart FreeRTOS_connect: lp:1024 -> a0a0ac9:10000 fr:0x9df5 
[2d50] FreeRTOS_IP.c(1398) xSendEventStructToIPTask et:6 fr:0x5917 
[2d50] FreeRTOS_IP.c(1418) xSendEventStructToIPTask  fr:0x5917 
mps2.c(663) an385_ex_mmio_write 200:0 -> 20011ce0
mps2.c(653) an385_ex_mmio_read 200:20011ce0
mps2.c(653) an385_ex_mmio_read 100:1
[67ac] NetworkInterface.c(180) pfOutput arp request et:1 h:0x20011ce0 fr:0x3eb1 
mps2.c(663) an385_ex_mmio_write 0:0 -> 1
mps2.c(663) an385_ex_mmio_write 10:0 -> 8
mps2.c(663) an385_ex_mmio_write 11:0 -> 14
mps2.c(663) an385_ex_mmio_write 12:0 -> 1
mps2.c(663) an385_ex_mmio_write 13:0 -> 20
mps2.c(663) an385_ex_mmio_write 14:0 -> 0
mps2.c(663) an385_ex_mmio_write 15:0 -> 0
mps2.c(663) an385_ex_mmio_write 16:0 -> 0
mps2.c(663) an385_ex_mmio_write 17:0 -> 0
mps2.c(663) an385_ex_mmio_write 18:0 -> 81
mps2.c(663) an385_ex_mmio_write 19:0 -> d3
mps2.c(663) an385_ex_mmio_write 1a:0 -> 0
mps2.c(663) an385_ex_mmio_write 1b:0 -> 0
mps2.c(663) an385_ex_mmio_write 1c:0 -> e7
mps2.c(663) an385_ex_mmio_write 1d:0 -> d3
mps2.c(663) an385_ex_mmio_write 1e:0 -> 0
mps2.c(663) an385_ex_mmio_write 1f:0 -> 0
mps2.c(663) an385_ex_mmio_write 20:0 -> a9
mps2.c(663) an385_ex_mmio_write 21:0 -> d3
mps2.c(663) an385_ex_mmio_write 22:0 -> 0
mps2.c(663) an385_ex_mmio_write 23:0 -> 0
mps2.c(663) an385_ex_mmio_write 24:0 -> 1
mps2.c(663) an385_ex_mmio_write 25:0 -> 0
mps2.c(663) an385_ex_mmio_write 26:0 -> 0
mps2.c(663) an385_ex_mmio_write 27:0 -> 0
mps2.c(663) an385_ex_mmio_write 28:0 -> 24
mps2.c(663) an385_ex_mmio_write 29:0 -> 68
mps2.c(663) an385_ex_mmio_write 2a:0 -> 0
mps2.c(663) an385_ex_mmio_write 2b:0 -> 20
mps2.c(663) an385_ex_mmio_write 2c:0 -> 0
mps2.c(663) an385_ex_mmio_write 2d:0 -> 0
mps2.c(663) an385_ex_mmio_write 2e:0 -> 0
mps2.c(663) an385_ex_mmio_write 2f:0 -> 0
mps2.c(663) an385_ex_mmio_write 30:0 -> a
mps2.c(663) an385_ex_mmio_write 31:0 -> a
mps2.c(663) an385_ex_mmio_write 32:0 -> a
mps2.c(663) an385_ex_mmio_write 33:0 -> c8
mps2.c(663) an385_ex_mmio_write 34:0 -> ff
mps2.c(663) an385_ex_mmio_write 35:0 -> 0
mps2.c(663) an385_ex_mmio_write 36:0 -> 0
mps2.c(663) an385_ex_mmio_write 37:0 -> 0
mps2.c(663) an385_ex_mmio_write 38:0 -> a
mps2.c(663) an385_ex_mmio_write 39:0 -> a
mps2.c(663) an385_ex_mmio_write 3a:0 -> a
mps2.c(663) an385_ex_mmio_write 3b:0 -> 1
mps2.c(663) an385_ex_mmio_write 3c:0 -> d0
mps2.c(663) an385_ex_mmio_write 3d:0 -> 43
mps2.c(663) an385_ex_mmio_write 3e:0 -> de
mps2.c(663) an385_ex_mmio_write 3f:0 -> de
mps2.c(663) an385_ex_mmio_write 40:0 -> 0
mps2.c(663) an385_ex_mmio_write 41:0 -> 0
mps2.c(663) an385_ex_mmio_write 42:0 -> 0
mps2.c(663) an385_ex_mmio_write 43:0 -> 0
mps2.c(663) an385_ex_mmio_write 44:0 -> a
mps2.c(663) an385_ex_mmio_write 45:0 -> ff
mps2.c(663) an385_ex_mmio_write 46:0 -> ff
mps2.c(663) an385_ex_mmio_write 47:0 -> ff
mps2.c(663) an385_ex_mmio_write 48:0 -> ff
mps2.c(663) an385_ex_mmio_write 49:0 -> ff
mps2.c(663) an385_ex_mmio_write 4a:0 -> ff
mps2.c(663) an385_ex_mmio_write 4b:0 -> ff
mps2.c(663) an385_ex_mmio_write 4c:0 -> ff
mps2.c(663) an385_ex_mmio_write 4d:0 -> ff
mps2.c(663) an385_ex_mmio_write 4e:0 -> 0
mps2.c(663) an385_ex_mmio_write 4f:0 -> 11
mps2.c(663) an385_ex_mmio_write 50:0 -> 22
mps2.c(663) an385_ex_mmio_write 51:0 -> 33
mps2.c(663) an385_ex_mmio_write 52:0 -> 44
mps2.c(663) an385_ex_mmio_write 53:0 -> 55
mps2.c(663) an385_ex_mmio_write 54:0 -> 8
mps2.c(663) an385_ex_mmio_write 55:0 -> 6
mps2.c(663) an385_ex_mmio_write 56:0 -> 0
mps2.c(663) an385_ex_mmio_write 57:0 -> 1
mps2.c(663) an385_ex_mmio_write 58:0 -> 8
mps2.c(663) an385_ex_mmio_write 59:0 -> 0
mps2.c(663) an385_ex_mmio_write 5a:0 -> 6
mps2.c(663) an385_ex_mmio_write 5b:0 -> 4
mps2.c(663) an385_ex_mmio_write 5c:0 -> 0
mps2.c(663) an385_ex_mmio_write 5d:0 -> 1
mps2.c(663) an385_ex_mmio_write 5e:0 -> 0
mps2.c(663) an385_ex_mmio_write 5f:0 -> 11
mps2.c(663) an385_ex_mmio_write 60:0 -> 22
mps2.c(663) an385_ex_mmio_write 61:0 -> 33
mps2.c(663) an385_ex_mmio_write 62:0 -> 44
mps2.c(663) an385_ex_mmio_write 63:0 -> 55
mps2.c(663) an385_ex_mmio_write 64:0 -> a
mps2.c(663) an385_ex_mmio_write 65:0 -> a
mps2.c(663) an385_ex_mmio_write 66:0 -> a
mps2.c(663) an385_ex_mmio_write 67:0 -> c8
mps2.c(663) an385_ex_mmio_write 68:0 -> 0
mps2.c(663) an385_ex_mmio_write 69:0 -> 0
mps2.c(663) an385_ex_mmio_write 6a:0 -> 0
mps2.c(663) an385_ex_mmio_write 6b:0 -> 0
mps2.c(663) an385_ex_mmio_write 6c:0 -> 0
mps2.c(663) an385_ex_mmio_write 6d:0 -> 0
mps2.c(663) an385_ex_mmio_write 6e:0 -> a
mps2.c(663) an385_ex_mmio_write 6f:0 -> a
mps2.c(663) an385_ex_mmio_write 70:0 -> a
mps2.c(663) an385_ex_mmio_write 71:0 -> c9
mps2.c(663) an385_ex_mmio_write 0:1 -> 0
mps2.c(701) udp_send2dummy 
mps2.c(653) an385_ex_mmio_read 100:1
[67ac] tasks.c(1839) vTaskResume suspend:1 0x20011ce0 fr:0xd4cb 
[67ac] tasks.c(1853) vTaskResume tpri:9 cpri:8 fr:0xd4cb 
[1ce0] tasks.c(1770) vTaskSuspend suspend:0 0x20011ce0 fr:0xd5c3 
[1ce0] NetworkInterface.c(226) ether_task wakeup fr:0x281 
mps2.c(663) an385_ex_mmio_write 100:1 -> 0
[2d50] FreeRTOS_IP.c(1428) xSendEventStructToIPTask xReturn:1 fr:0x5917 
[67ac] NetworkInterface.c(192) pfOutput ip:c90a0a0a po:0 bp:0 len:42 r:1 wk:1 data:
ff ff ff ff ff ff 00 11 22 33 44 55 08 06 00 01
08 00 06 04 00 01 00 11 22 33 44 55 0a 0a 0a c8
00 00 00 00 00 00 0a 0a 0a c9 
 fr:0x3eb1 
[1ce0] NetworkInterface.c(256) ether_task send 
00 11 22 33 44 55 01 12 23 34 45 56 08 06 00 01
08 00 06 04 00 02 01 12 23 34 45 56 0a 0a 0a c9
00 11 22 33 44 55 0a 0a 0a c8 
 fr:0x281 
[1ce0] FreeRTOS_IP.c(1398) xSendEventStructToIPTask et:1 fr:0xd57b 
[1ce0] FreeRTOS_IP.c(1418) xSendEventStructToIPTask  fr:0xd57b 
[1ce0] FreeRTOS_IP.c(1428) xSendEventStructToIPTask xReturn:1 fr:0xd57b 
[1ce0] NetworkInterface.c(258) ether_task st:1 fr:0x281 
mps2.c(663) an385_ex_mmio_write 100:0 -> 1
[1ce0] NetworkInterface.c(224) ether_task sleep fr:0x281 
[1ce0] tasks.c(1683) vTaskSuspend suspend:0 0x20011ce0 fr:0xd5c3 
[1ce0] tasks.c(1708) vTaskSuspend suspend:1 0x20011ce0 fr:0xd5c3 
[1ce0] tasks.c(1743) vTaskSuspend suspend:1 0x20011ce0 fr:0xd5c3 
[2d50] FreeRTOS_Sockets.c(3797) FreeRTOS_connect prvTCPConnectStart:0 fr:0xd9d9 
[2d50] FreeRTOS_Sockets.c(3826) FreeRTOS_connect xResult:0 fr:0xd9d9 
mps2.c(663) an385_ex_mmio_write 200:20011ce0 -> fffffffa
mps2.c(653) an385_ex_mmio_read 200:20011ce0
mps2.c(653) an385_ex_mmio_read 100:1
[67ac] NetworkInterface.c(180) pfOutput arp request et:1 h:0x20011ce0 fr:0x3eb1 
mps2.c(663) an385_ex_mmio_write 0:0 -> 1
mps2.c(663) an385_ex_mmio_write 10:20011408 -> 8
mps2.c(663) an385_ex_mmio_write 11:200114 -> 14
mps2.c(663) an385_ex_mmio_write 12:2001 -> 1
mps2.c(663) an385_ex_mmio_write 13:20 -> 20
mps2.c(663) an385_ex_mmio_write 14:0 -> 0
mps2.c(663) an385_ex_mmio_write 15:81000000 -> 0
mps2.c(663) an385_ex_mmio_write 16:d3810000 -> 0
mps2.c(663) an385_ex_mmio_write 17:d38100 -> 0
mps2.c(663) an385_ex_mmio_write 18:d381 -> 81
mps2.c(663) an385_ex_mmio_write 19:e70000d3 -> d3
mps2.c(663) an385_ex_mmio_write 1a:d3e70000 -> 0
mps2.c(663) an385_ex_mmio_write 1b:d3e700 -> 0
mps2.c(663) an385_ex_mmio_write 1c:d3e7 -> e7
mps2.c(663) an385_ex_mmio_write 1d:a90000d3 -> d3
mps2.c(663) an385_ex_mmio_write 1e:d3a90000 -> 0
mps2.c(663) an385_ex_mmio_write 1f:d3a900 -> 0
mps2.c(663) an385_ex_mmio_write 20:d3a9 -> a9
mps2.c(663) an385_ex_mmio_write 21:10000d3 -> d3
mps2.c(663) an385_ex_mmio_write 22:10000 -> 0
mps2.c(663) an385_ex_mmio_write 23:100 -> 0
mps2.c(663) an385_ex_mmio_write 24:1 -> 1
mps2.c(663) an385_ex_mmio_write 25:24000000 -> 0
mps2.c(663) an385_ex_mmio_write 26:68240000 -> 0
mps2.c(663) an385_ex_mmio_write 27:682400 -> 0
mps2.c(663) an385_ex_mmio_write 28:20006824 -> 24
mps2.c(663) an385_ex_mmio_write 29:200068 -> 68
mps2.c(663) an385_ex_mmio_write 2a:2000 -> 0
mps2.c(663) an385_ex_mmio_write 2b:20 -> 20
mps2.c(663) an385_ex_mmio_write 2c:0 -> 0
mps2.c(663) an385_ex_mmio_write 2d:a000000 -> 0
mps2.c(663) an385_ex_mmio_write 2e:a0a0000 -> 0
mps2.c(663) an385_ex_mmio_write 2f:a0a0a00 -> 0
mps2.c(663) an385_ex_mmio_write 30:c80a0a0a -> a
mps2.c(663) an385_ex_mmio_write 31:ffc80a0a -> a
mps2.c(663) an385_ex_mmio_write 32:ffc80a -> a
mps2.c(663) an385_ex_mmio_write 33:ffc8 -> c8
mps2.c(663) an385_ex_mmio_write 34:ff -> ff
mps2.c(663) an385_ex_mmio_write 35:a000000 -> 0
mps2.c(663) an385_ex_mmio_write 36:a0a0000 -> 0
mps2.c(663) an385_ex_mmio_write 37:a0a0a00 -> 0
mps2.c(663) an385_ex_mmio_write 38:10a0a0a -> a
mps2.c(663) an385_ex_mmio_write 39:d0010a0a -> a
mps2.c(663) an385_ex_mmio_write 3a:43d0010a -> a
mps2.c(663) an385_ex_mmio_write 3b:de43d001 -> 1
mps2.c(663) an385_ex_mmio_write 3c:dede43d0 -> d0
mps2.c(663) an385_ex_mmio_write 3d:dede43 -> 43
mps2.c(663) an385_ex_mmio_write 3e:dede -> de
mps2.c(663) an385_ex_mmio_write 3f:de -> de
mps2.c(663) an385_ex_mmio_write 40:0 -> 0
mps2.c(663) an385_ex_mmio_write 41:a000000 -> 0
mps2.c(663) an385_ex_mmio_write 42:ff0a0000 -> 0
mps2.c(663) an385_ex_mmio_write 43:ffff0a00 -> 0
mps2.c(663) an385_ex_mmio_write 44:ffffff0a -> a
mps2.c(663) an385_ex_mmio_write 45:ffffffff -> ff
mps2.c(663) an385_ex_mmio_write 46:ffffffff -> ff
mps2.c(663) an385_ex_mmio_write 47:ffffffff -> ff
mps2.c(663) an385_ex_mmio_write 48:ffffffff -> ff
mps2.c(663) an385_ex_mmio_write 49:ffffffff -> ff
mps2.c(663) an385_ex_mmio_write 4a:ffffffff -> ff
mps2.c(663) an385_ex_mmio_write 4b:ffffff -> ff
mps2.c(663) an385_ex_mmio_write 4c:1100ffff -> ff
mps2.c(663) an385_ex_mmio_write 4d:221100ff -> ff
mps2.c(663) an385_ex_mmio_write 4e:33221100 -> 0
mps2.c(663) an385_ex_mmio_write 4f:44332211 -> 11
mps2.c(663) an385_ex_mmio_write 50:55443322 -> 22
mps2.c(663) an385_ex_mmio_write 51:8554433 -> 33
mps2.c(663) an385_ex_mmio_write 52:6085544 -> 44
mps2.c(663) an385_ex_mmio_write 53:60855 -> 55
mps2.c(663) an385_ex_mmio_write 54:1000608 -> 8
mps2.c(663) an385_ex_mmio_write 55:8010006 -> 6
mps2.c(663) an385_ex_mmio_write 56:80100 -> 0
mps2.c(663) an385_ex_mmio_write 57:6000801 -> 1
mps2.c(663) an385_ex_mmio_write 58:4060008 -> 8
mps2.c(663) an385_ex_mmio_write 59:40600 -> 0
mps2.c(663) an385_ex_mmio_write 5a:1000406 -> 6
mps2.c(663) an385_ex_mmio_write 5b:10004 -> 4
mps2.c(663) an385_ex_mmio_write 5c:11000100 -> 0
mps2.c(663) an385_ex_mmio_write 5d:22110001 -> 1
mps2.c(663) an385_ex_mmio_write 5e:33221100 -> 0
mps2.c(663) an385_ex_mmio_write 5f:44332211 -> 11
mps2.c(663) an385_ex_mmio_write 60:55443322 -> 22
mps2.c(663) an385_ex_mmio_write 61:a554433 -> 33
mps2.c(663) an385_ex_mmio_write 62:a0a5544 -> 44
mps2.c(663) an385_ex_mmio_write 63:a0a0a55 -> 55
mps2.c(663) an385_ex_mmio_write 64:c80a0a0a -> a
mps2.c(663) an385_ex_mmio_write 65:c80a0a -> a
mps2.c(663) an385_ex_mmio_write 66:c80a -> a
mps2.c(663) an385_ex_mmio_write 67:c8 -> c8
mps2.c(663) an385_ex_mmio_write 68:0 -> 0
mps2.c(663) an385_ex_mmio_write 69:0 -> 0
mps2.c(663) an385_ex_mmio_write 6a:0 -> 0
mps2.c(663) an385_ex_mmio_write 6b:a000000 -> 0
mps2.c(663) an385_ex_mmio_write 6c:a0a0000 -> 0
mps2.c(663) an385_ex_mmio_write 6d:a0a0a00 -> 0
mps2.c(663) an385_ex_mmio_write 6e:c90a0a0a -> a
mps2.c(663) an385_ex_mmio_write 6f:c90a0a -> a
mps2.c(663) an385_ex_mmio_write 70:c90a -> a
mps2.c(663) an385_ex_mmio_write 71:c9 -> c9
mps2.c(663) an385_ex_mmio_write 0:1 -> 0
mps2.c(701) udp_send2dummy 
mps2.c(653) an385_ex_mmio_read 100:1
[67ac] tasks.c(1839) vTaskResume suspend:1 0x20011ce0 fr:0xd4cb 
[67ac] tasks.c(1853) vTaskResume tpri:9 cpri:8 fr:0xd4cb 
[1ce0] tasks.c(1770) vTaskSuspend suspend:0 0x20011ce0 fr:0xd5c3 
[1ce0] NetworkInterface.c(226) ether_task wakeup fr:0x281 
mps2.c(663) an385_ex_mmio_write 100:1 -> 0
[67ac] NetworkInterface.c(192) pfOutput ip:c90a0a0a po:0 bp:0 len:42 r:1 wk:1 data:
ff ff ff ff ff ff 00 11 22 33 44 55 08 06 00 01
08 00 06 04 00 01 00 11 22 33 44 55 0a 0a 0a c8
00 00 00 00 00 00 0a 0a 0a c9 
 fr:0x3eb1 
[1ce0] NetworkInterface.c(256) ether_task send 
00 11 22 33 44 55 01 12 23 34 45 56 08 06 00 01
08 00 06 04 00 02 01 12 23 34 45 56 0a 0a 0a c9
00 11 22 33 44 55 0a 0a 0a c8 
 fr:0x281 
[1ce0] FreeRTOS_IP.c(1398) xSendEventStructToIPTask et:1 fr:0xd57b 
[1ce0] FreeRTOS_IP.c(1418) xSendEventStructToIPTask  fr:0xd57b 
[1ce0] FreeRTOS_IP.c(1428) xSendEventStructToIPTask xReturn:1 fr:0xd57b 
[1ce0] NetworkInterface.c(258) ether_task st:1 fr:0x281 
mps2.c(663) an385_ex_mmio_write 100:0 -> 1
[1ce0] NetworkInterface.c(224) ether_task sleep fr:0x281 
[1ce0] tasks.c(1683) vTaskSuspend suspend:0 0x20011ce0 fr:0xd5c3 
[1ce0] tasks.c(1708) vTaskSuspend suspend:1 0x20011ce0 fr:0xd5c3 
[1ce0] tasks.c(1743) vTaskSuspend suspend:1 0x20011ce0 fr:0xd5c3 
mps2.c(653) an385_ex_mmio_read 200:20011ce0
mps2.c(653) an385_ex_mmio_read 100:1
[67ac] NetworkInterface.c(180) pfOutput arp request et:1 h:0x20011ce0 fr:0x3eb1 
mps2.c(663) an385_ex_mmio_write 0:0 -> 1
mps2.c(663) an385_ex_mmio_write 10:20011408 -> 8
mps2.c(663) an385_ex_mmio_write 11:200114 -> 14
mps2.c(663) an385_ex_mmio_write 12:2001 -> 1
mps2.c(663) an385_ex_mmio_write 13:20 -> 20
mps2.c(663) an385_ex_mmio_write 14:0 -> 0
mps2.c(663) an385_ex_mmio_write 15:81000000 -> 0
mps2.c(663) an385_ex_mmio_write 16:d3810000 -> 0
mps2.c(663) an385_ex_mmio_write 17:d38100 -> 0
mps2.c(663) an385_ex_mmio_write 18:d381 -> 81
mps2.c(663) an385_ex_mmio_write 19:e70000d3 -> d3
mps2.c(663) an385_ex_mmio_write 1a:d3e70000 -> 0
mps2.c(663) an385_ex_mmio_write 1b:d3e700 -> 0
mps2.c(663) an385_ex_mmio_write 1c:d3e7 -> e7
mps2.c(663) an385_ex_mmio_write 1d:a90000d3 -> d3
mps2.c(663) an385_ex_mmio_write 1e:d3a90000 -> 0
mps2.c(663) an385_ex_mmio_write 1f:d3a900 -> 0
mps2.c(663) an385_ex_mmio_write 20:d3a9 -> a9
mps2.c(663) an385_ex_mmio_write 21:10000d3 -> d3
mps2.c(663) an385_ex_mmio_write 22:10000 -> 0
mps2.c(663) an385_ex_mmio_write 23:100 -> 0
mps2.c(663) an385_ex_mmio_write 24:1 -> 1
mps2.c(663) an385_ex_mmio_write 25:24000000 -> 0
mps2.c(663) an385_ex_mmio_write 26:68240000 -> 0
mps2.c(663) an385_ex_mmio_write 27:682400 -> 0
mps2.c(663) an385_ex_mmio_write 28:20006824 -> 24
mps2.c(663) an385_ex_mmio_write 29:200068 -> 68
mps2.c(663) an385_ex_mmio_write 2a:2000 -> 0
mps2.c(663) an385_ex_mmio_write 2b:20 -> 20
mps2.c(663) an385_ex_mmio_write 2c:0 -> 0
mps2.c(663) an385_ex_mmio_write 2d:a000000 -> 0
mps2.c(663) an385_ex_mmio_write 2e:a0a0000 -> 0
mps2.c(663) an385_ex_mmio_write 2f:a0a0a00 -> 0
mps2.c(663) an385_ex_mmio_write 30:c80a0a0a -> a
mps2.c(663) an385_ex_mmio_write 31:ffc80a0a -> a
mps2.c(663) an385_ex_mmio_write 32:ffc80a -> a
mps2.c(663) an385_ex_mmio_write 33:ffc8 -> c8
mps2.c(663) an385_ex_mmio_write 34:ff -> ff
mps2.c(663) an385_ex_mmio_write 35:a000000 -> 0
mps2.c(663) an385_ex_mmio_write 36:a0a0000 -> 0
mps2.c(663) an385_ex_mmio_write 37:a0a0a00 -> 0
mps2.c(663) an385_ex_mmio_write 38:10a0a0a -> a
mps2.c(663) an385_ex_mmio_write 39:d0010a0a -> a
mps2.c(663) an385_ex_mmio_write 3a:43d0010a -> a
mps2.c(663) an385_ex_mmio_write 3b:de43d001 -> 1
mps2.c(663) an385_ex_mmio_write 3c:dede43d0 -> d0
mps2.c(663) an385_ex_mmio_write 3d:dede43 -> 43
mps2.c(663) an385_ex_mmio_write 3e:dede -> de
mps2.c(663) an385_ex_mmio_write 3f:de -> de
mps2.c(663) an385_ex_mmio_write 40:0 -> 0
mps2.c(663) an385_ex_mmio_write 41:a000000 -> 0
mps2.c(663) an385_ex_mmio_write 42:ff0a0000 -> 0
mps2.c(663) an385_ex_mmio_write 43:ffff0a00 -> 0
mps2.c(663) an385_ex_mmio_write 44:ffffff0a -> a
mps2.c(663) an385_ex_mmio_write 45:ffffffff -> ff
mps2.c(663) an385_ex_mmio_write 46:ffffffff -> ff
mps2.c(663) an385_ex_mmio_write 47:ffffffff -> ff
mps2.c(663) an385_ex_mmio_write 48:ffffffff -> ff
mps2.c(663) an385_ex_mmio_write 49:ffffffff -> ff
mps2.c(663) an385_ex_mmio_write 4a:ffffffff -> ff
mps2.c(663) an385_ex_mmio_write 4b:ffffff -> ff
mps2.c(663) an385_ex_mmio_write 4c:1100ffff -> ff
mps2.c(663) an385_ex_mmio_write 4d:221100ff -> ff
mps2.c(663) an385_ex_mmio_write 4e:33221100 -> 0
mps2.c(663) an385_ex_mmio_write 4f:44332211 -> 11
mps2.c(663) an385_ex_mmio_write 50:55443322 -> 22
mps2.c(663) an385_ex_mmio_write 51:8554433 -> 33
mps2.c(663) an385_ex_mmio_write 52:6085544 -> 44
mps2.c(663) an385_ex_mmio_write 53:60855 -> 55
mps2.c(663) an385_ex_mmio_write 54:1000608 -> 8
mps2.c(663) an385_ex_mmio_write 55:8010006 -> 6
mps2.c(663) an385_ex_mmio_write 56:80100 -> 0
mps2.c(663) an385_ex_mmio_write 57:6000801 -> 1
mps2.c(663) an385_ex_mmio_write 58:4060008 -> 8
mps2.c(663) an385_ex_mmio_write 59:40600 -> 0
mps2.c(663) an385_ex_mmio_write 5a:1000406 -> 6
mps2.c(663) an385_ex_mmio_write 5b:10004 -> 4
mps2.c(663) an385_ex_mmio_write 5c:11000100 -> 0
mps2.c(663) an385_ex_mmio_write 5d:22110001 -> 1
mps2.c(663) an385_ex_mmio_write 5e:33221100 -> 0
mps2.c(663) an385_ex_mmio_write 5f:44332211 -> 11
mps2.c(663) an385_ex_mmio_write 60:55443322 -> 22
mps2.c(663) an385_ex_mmio_write 61:a554433 -> 33
mps2.c(663) an385_ex_mmio_write 62:a0a5544 -> 44
mps2.c(663) an385_ex_mmio_write 63:a0a0a55 -> 55
mps2.c(663) an385_ex_mmio_write 64:c80a0a0a -> a
mps2.c(663) an385_ex_mmio_write 65:c80a0a -> a
mps2.c(663) an385_ex_mmio_write 66:c80a -> a
mps2.c(663) an385_ex_mmio_write 67:c8 -> c8
mps2.c(663) an385_ex_mmio_write 68:0 -> 0
mps2.c(663) an385_ex_mmio_write 69:0 -> 0
mps2.c(663) an385_ex_mmio_write 6a:0 -> 0
mps2.c(663) an385_ex_mmio_write 6b:a000000 -> 0
mps2.c(663) an385_ex_mmio_write 6c:a0a0000 -> 0
mps2.c(663) an385_ex_mmio_write 6d:a0a0a00 -> 0
mps2.c(663) an385_ex_mmio_write 6e:c90a0a0a -> a
mps2.c(663) an385_ex_mmio_write 6f:c90a0a -> a
mps2.c(663) an385_ex_mmio_write 70:c90a -> a
mps2.c(663) an385_ex_mmio_write 71:c9 -> c9
mps2.c(663) an385_ex_mmio_write 0:1 -> 0
mps2.c(701) udp_send2dummy 
mps2.c(653) an385_ex_mmio_read 100:1
[67ac] tasks.c(1839) vTaskResume suspend:1 0x20011ce0 fr:0xd4cb 
[67ac] tasks.c(1853) vTaskResume tpri:9 cpri:8 fr:0xd4cb 
[1ce0] tasks.c(1770) vTaskSuspend suspend:0 0x20011ce0 fr:0xd5c3 
[1ce0] NetworkInterface.c(226) ether_task wakeup fr:0x281 
mps2.c(663) an385_ex_mmio_write 100:1 -> 0
[67ac] NetworkInterface.c(192) pfOutput ip:c90a0a0a po:0 bp:0 len:42 r:1 wk:1 data:
ff ff ff ff ff ff 00 11 22 33 44 55 08 06 00 01
08 00 06 04 00 01 00 11 22 33 44 55 0a 0a 0a c8
00 00 00 00 00 00 0a 0a 0a c9 
 fr:0x3eb1 
[1ce0] NetworkInterface.c(256) ether_task send 
00 11 22 33 44 55 01 12 23 34 45 56 08 06 00 01
08 00 06 04 00 02 01 12 23 34 45 56 0a 0a 0a c9
00 11 22 33 44 55 0a 0a 0a c8 
 fr:0x281 
[1ce0] FreeRTOS_IP.c(1398) xSendEventStructToIPTask et:1 fr:0xd57b 
[1ce0] FreeRTOS_IP.c(1418) xSendEventStructToIPTask  fr:0xd57b 
[1ce0] FreeRTOS_IP.c(1428) xSendEventStructToIPTask xReturn:1 fr:0xd57b 
[1ce0] NetworkInterface.c(258) ether_task st:1 fr:0x281 
mps2.c(663) an385_ex_mmio_write 100:0 -> 1
[1ce0] NetworkInterface.c(224) ether_task sleep fr:0x281 
[1ce0] tasks.c(1683) vTaskSuspend suspend:0 0x20011ce0 fr:0xd5c3 
[1ce0] tasks.c(1708) vTaskSuspend suspend:1 0x20011ce0 fr:0xd5c3 
[1ce0] tasks.c(1743) vTaskSuspend suspend:1 0x20011ce0 fr:0xd5c3 
[2d50] FreeRTOS_Sockets.c(3854) FreeRTOS_connect uxEvents:20 xResut:0 fr:0xd9d9 
[2d50] app_client.c(84) vTCPSend not connected fr:0xdad5 
[2d50] FreeRTOS_IP.c(1398) xSendEventStructToIPTask et:10 fr:0x9f6b 
[2d50] FreeRTOS_IP.c(1418) xSendEventStructToIPTask  fr:0x9f6b 
[2d50] FreeRTOS_IP.c(1428) xSendEventStructToIPTask xReturn:1 fr:0x9f6b 
[2d50] app_client.c(105) vTCPSend OUT fr:0xdad5 
qemu-system-arm: terminating on signal 2

```
</details>

こんな感じのコード
```c
#define ET_STATUS *(uint32_t*)0x28000100

static BaseType_t pfOutput(struct xNetworkInterface *pxDescriptor,
                           NetworkBufferDescriptor_t *const pxNetworkBuffer,
                           BaseType_t xReleaseAfterSend)
{
    ARPPacket_t *arp;
    (void)xReleaseAfterSend;
    bool wakeup = false;
    static TaskHandle_t handle = NULL;
    if (!handle) {
        *(uint32_t*)0x28000200 = (uint32_t)ether_handle;
    }
    handle = (TaskHandle_t)*(uint32_t*)0x28000200;

    arp = (ARPPacket_t *)pxNetworkBuffer->pucEthernetBuffer;
    if (arp->xARPHeader.usOperation == ipARP_REQUEST)
    {
        d("arp request et:%d h:%p", ether_task_is_sleeping(), handle);
        mmio_write_on();
        mmio_write(0, (uint8_t *)pxDescriptor, sizeof(NetworkBufferDescriptor_t));
        mmio_write(sizeof(NetworkBufferDescriptor_t), (uint8_t *)arp, sizeof(ARPPacket_t));
        mmio_write_off();
        if (ether_task_is_sleeping())
        {
            wakeup = true;
            vTaskResume(handle);
            vTaskDelay(1);
        }
    }
    d("ip:%lx po:%x bp:%x len:%u r:%ld wk:%d data:\n%s", pxNetworkBuffer->xIPAddress.ulIP_IPv4, pxNetworkBuffer->usPort, pxNetworkBuffer->usBoundPort, pxNetworkBuffer->xDataLength, xReleaseAfterSend, wakeup, b2s(pxNetworkBuffer->pucEthernetBuffer, pxNetworkBuffer->xDataLength));
    return pdPASS;
}

static bool ether_task_is_sleeping()
{
    return ET_STATUS != 0;
}
```

## 正しい(?)ARP
つながっている実機でping打って確認してみる。
コマンドは以下
```shell
sudo tcpdump arp net 192.168.10.0 mask 255.255.255.0 -s 0 -w /tmp/pcap
```

wiresharkは入れておく
```shell
sudo yum install wireshark
```

リクエスト
![arp_req.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2383810/3c94e269-b492-5f92-dad2-7119bcfd0b61.png)


応答
![arp_rply.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2383810/9770686d-ec7f-123f-d5cd-5b6e5b3d3837.png)


qemuのログと見比べてみるが、送っている内容は間違っていない。

なので考えられることは
- FreeRTOS-Plus-TCPの使い方が間違っている
- 日立の嫌がらせでFreeRTOS-Plus-TCPがつながらないようにされている

なんとなく後者っぽいな

----
参考
https://qiita.com/RyomaTaniyama/items/6fcb7ecef701fd62cd89