ååãããRenode ã¨ãã QEMU ã«ä¼¼ããªã¼ãã³ã½ã¼ã¹ã®ã¨ãã¥ã¬ã¼ã¿ã試ãã¦ã¾ãã
ååã¯ãã¤ã³ã¹ãã¼ã«ã¨STM32ã®ãµã³ãã«ã½ã¼ã¹ã®å®è¡ã¾ã§ãããã¾ããã
ä»åã¯ãGDB ã§æ¥ç¶ãã¦ããããã°ãã¦ã¿ã¾ãã
ããã§ã¯ããã£ã¦ããã¾ãã
åèæç®
ã¯ããã«
ãQEMUãåãããã®è¨äºä¸è¦§ã§ããè¯ãã£ããåèã«ãã¦ãã ããã
QEMUãåããã®è¨äºä¸è¦§
ã¾ããRenode ã®å
¬å¼ãµã¤ãã¯ä»¥ä¸ã§ãã
https://renode.io/
Renode ã®å
¬å¼ã®ããã¥ã¡ã³ãã¯ä»¥ä¸ã§ãã
https://renode.readthedocs.io/en/latest/
ã¾ããGitHub ã¯ä»¥ä¸ã§ãã
https://github.com/renode/renode
ä»åã¯ãRenode ã GDB ã使ã£ã¦åããã¦ããã¾ãã
STM32ã®ãµã³ãã«ã½ã¼ã¹ããããã°ãã
ããã§ã¯ãæ©éãåå ã®ç¶ãã§ãSTM32F4 ã® Discovery ã対象ã¨ã㦠Renode ãèµ·åãã¾ãã
åå ã¨ã¯ç°ãªããRenode ã¢ãã¿ã¼ã§ start ã¯ãã¾ãããRenode ã®ããã¥ã¡ã³ãã® GDB ã§ãããã° ãè¦ãã¨ãRenode ã¯ã3種é¡ã®ã¨ãã¥ã¬ã¼ã·ã§ã³ã®éå§æ¹æ³ãç¨æããã¦ããã¨æ¸ããã¦ãã¾ãã
1ã¤ç®ã¯ Renode ãã start ã§éå§ããæ¹æ³ã§ã2ã¤ç®ã¯ GDB ãã monitor start ã§éå§ããæ¹æ³ã§ã3ã¤ç®ã¯ GDB ããæ¥ç¶ãããã¨èªåçã«éå§ããæ¹æ³ã§ãã
ä»åã¯ã2ã¤ç®ã® GDB ãã monitor start ã¨å
¥åãã¦éå§ããæ¹æ³ã§ãã£ã¦ã¿ããã¨æãã¾ãã
$ ./renode renode-config.resc
å¥ã®ã³ã³ã½ã¼ã«ãç«ã¡ä¸ãã¦ãGDB ãèµ·åãã¦ããã¾ãã
$ arm-none-eabi-gdb renode-example.elf
(gdb) target remote :3333
reset_handler () at ../../cm3/vector.c:67
67 for (src = &_data_loadaddr, dest = &_data;
(gdb) c
GDB ã§æ¥ç¶ããã¨ãã¨ã³ããªãã¤ã³ãã§åæ¢ããç¶æ
ã«ãªãã¾ãããcï¼continueï¼ã§å®è¡ãéå§ããã¨ããhello world!ããåºåããã¾ããã
ã§ããããã®ã¨ãã¥ã¬ã¼ã·ã§ã³ã®éå§ã¯ãããã¥ã¡ã³ãã«æ¸ããã¦ããã3ã¤ç®ã®æ¹æ³ã®ãããªæåã§ãã
renode-config.resc ãã¡ã¤ã«ã«ã¯ã以ä¸ã®ããã«ãªã£ã¦ãã¾ãã
machine StartGdbServer 3333
Renode ã®ããã¥ã¡ã³ãã«ã¯ã3ã¤ç®ã®æ¹æ³ã«ããã«ã¯ã以ä¸ã®ããã«ããã¨ããã¾ãã
machine StartGdbServer 3333 true
ãããããã¨ã以åã¯ãããã©ã«ãã false ã ã£ããã©ãä»ã¯ãããã©ã«ãã true ã«ãªã£ãã¨ãããããã¾ããã
ã¨ã«ãããGDB ã§æ¥ç¶ãã§ãã¾ããã
以åä½ã£ãELFãã¡ã¤ã«ã§ãããã°ãã
以åãInterface 2022å¹´ 7æå· ã®ã«ã¼ã¬ããã²ã¼ã ã®ãµã³ãã«ã½ã¼ã¹ã使ã£ã¦ãQEMU ã§åããã¾ããã
ãã® ELFãã¡ã¤ã«ã使ã£ã¦ãRenode ã§åããã¦ããããã¨æãã¾ãã
ã¾ãã¯ãRenode ã®ãã£ã¬ã¯ããªã«ã以åã«ä½ã£ã ELFãã¡ã¤ã«ã®ã·ã³ããªãã¯ãªã³ã¯ãä½ãã¾ãã1ã¤ç®ãæ®éã® ELFãã¡ã¤ã«ã§ã2ã¤ç®ã¯ãä¸åº¦ãã¤ããªãã¡ã¤ã«ã«å¤æãã¦ãã·ã³ãã«æ
å ±ãªã©ã®ãããã°æ
å ±ãåé¤ãã¦ãELFãã¡ã¤ã«ã«åæ§ç¯ãããã¡ã¤ã«ã§ãã
$ ln -s ~/eclipse-workspace/stm32f4discovery_sample/Debug/stm32f4discovery_sample.elf
$ ln -s ~/eclipse-workspace/stm32f4discovery_sample/Debug/stm32f4discovery_sample_bin2elf_entry.elf
æ®éã®ELFãã¡ã¤ã«ãåããã¦ã¿ã
ã§ã¯ãã¾ãã¯ãæ®éã®ELFãã¡ã¤ã«ã®æ¹ããæå㧠Renode ãèµ·åãã¦ããã¾ãã
$ renode
Gtk-Message: 21:29:43.731: Failed to load module "canberra-gtk-module"
21:29:44.6876 [INFO] Loaded monitor commands from: /home/daisuke/svn_/renode/renode_1.15.0_portable/scripts/monitor.py
(monitor) mach create
21:30:27.2465 [INFO] System bus created.
(machine-0) machine LoadPlatformDescription @platforms/boards/stm32f4_discovery-kit.repl
21:30:49.7163 [INFO] Reading cache
21:30:50.1987 [INFO] sysbus: Loaded SVD: /tmp/renode-10320/b9a14342-eb23-457c-9175-699febb364f2.tmp. Name: STM32F40x. Description: STM32F40x.
(machine-0) sysbus LoadELF @stm32f4discovery_sample.elf
21:31:19.4952 [INFO] sysbus: Loading segment of 11000 bytes length at 0x8000000.
21:31:19.5196 [INFO] sysbus: Loading segment of 360 bytes length at 0x8002AF8.
21:31:19.5199 [INFO] sysbus: Loading segment of 256 bytes length at 0x2001F700.
(machine-0) machine StartGdbServer 3333
21:31:38.0812 [INFO] machine-0: GDB server with all CPUs started on port :3333
åé¡ãªãèµ·åã§ãã¦ãããã§ããç¶ãã¦ãGDB ã§æ¥ç¶ãã¾ãã
$ arm-none-eabi-gdb stm32f4discovery_sample.elf
(gdb) target remote :3333
Remote debugging using :3333
Reset_Handler () at ../startup.S:119
119 mrs r0, control
(gdb) c
Continuing.
^C
Program received signal SIGTRAP, Trace/breakpoint trap.
main () at ../main.c:107
107 break;
GDB ã§æ¥ç¶ããã¨ãã¨ã³ããªãã¤ã³ãã§åæ¢ããç¶æ
ã«ãªãã¾ããããã®å¾ãcï¼continueï¼ã§å®è¡éå§ãã¾ãããLED ãè¦ããªãã§ãããCtrl+C ã§ããã£ããåæ¢ãã㨠mainé¢æ°ã®ã©ããã§æ¢ã¾ã£ãã®ã§ãåãã¦ããã§ãã
ãããã°æ
å ±ã®ç¡ãELFãã¡ã¤ã«ãåããã¦ã¿ã
æ®éã® ELFãã¡ã¤ã«ã¨åãããã«ãæå㧠Renode ã§èµ·åãã¦ããã¾ãã
$ renode
Gtk-Message: 21:31:59.406: Failed to load module "canberra-gtk-module"
21:32:00.3045 [INFO] Loaded monitor commands from: /home/daisuke/svn_/renode/renode_1.15.0_portable/scripts/monitor.py
(monitor) mach create
21:32:20.0797 [INFO] System bus created.
(machine-0) machine LoadPlatformDescription @platforms/boards/stm32f4_discovery-kit.repl
21:32:33.8938 [INFO] Reading cache
21:32:34.3756 [INFO] sysbus: Loaded SVD: /tmp/renode-10368/5f7902f5-f5f6-40d8-bda6-cc71e8ab32c4.tmp. Name: STM32F40x. Description: STM32F40x.
(machine-0) sysbus LoadELF @stm32f4discovery_sample.elf
21:33:04.9895 [INFO] sysbus: Loading segment of 11116 bytes length at 0x8000000.
(machine-0) machine StartGdbServer 3333
21:33:18.2970 [INFO] machine-0: GDB server with all CPUs started on port :3333
ELFãã¡ã¤ã«ããã¼ãããã¨ãã®ãã°ãæ®éã® ELFãã¡ã¤ã«ã®å ´åã¨ç°ãªãã¾ããGDB ãæ¥ç¶ãã¾ãã
$ arm-none-eabi-gdb stm32f4discovery_sample.elf
(gdb) target remote :3333
Remote debugging using :3333
0x00000000 in ?? ()
ã¨ã³ããªãã¤ã³ãã¾ã§ãããã0çªå°ã§èµ·åãã¾ããã
Renode å´ã®ãã°ã¯ä»¥ä¸ã®ããã«ãªã£ã¦ãã¾ããã
21:35:26.6557 [WARNING] sysbus: [cpu: 0x0] ReadDoubleWord from non existing peripheral at 0x4.
21:35:26.6559 [WARNING] sysbus: [cpu: 0x0] ReadDoubleWord from non existing peripheral at 0x0.
21:35:26.6588 [ERROR] cpu: PC does not lay in memory or PC and SP are equal to zero. CPU was halted.
21:35:26.6656 [INFO] cpu: Setting initial values: PC = 0x0, SP = 0x0.
21:35:26.6664 [WARNING] cpu: Patching PC 0x0 for Thumb mode.
21:35:26.6678 [INFO] machine-0: Machine started.
STM32 ã®å ´åã4çªå°ã¯ãªã»ãããã³ãã©ã®ã¢ãã¬ã¹ãæ ¼ç´ããã¦ãã¦ã0çªå°ã¯ã¹ã¿ãã¯ãã¤ã³ã¿ã®åæå¤ãæ ¼ç´ããã¦ãã¾ããããããèªã¿åºããªãã£ããã¨ããè¦åãåºã¦ãã¾ãã
ãã®ãããã°æ
å ±ã®ç¡ã ELFãã¡ã¤ã«ã¯ãæä½éã®ãªã³ã«ã¹ã¯ãªãã㧠ELFãã¡ã¤ã«ãä½ã£ã¦ãã¾ãããããåå ããããã¾ããã
ãããã°æ
å ±ã®ç¡ã raw binary ã®ãã¤ããªãã¡ã¤ã«ã§åããã¦ã¿ã
Renode ã®ããã¥ã¡ã³ãã® CPUç°å¢ã®æ§ç¯ ã®ã¨ãããè¦ãã¨ãRenode ã¯ãELFãã¡ã¤ã«ã ãã§ãªãããã¤ããªãã¡ã¤ã«ã®ãã¼ãã«ã対å¿ãã¦ããããã§ãããã£ã¦ã¿ã¾ãã
ã¾ãã¯ããã¤ããªãã¡ã¤ã«ãåãããã«ãã·ã³ããªãã¯ãªã³ã¯ãä½ãã¾ãã
$ ln -s ~/eclipse-workspace/stm32f4discovery_sample/Debug/stm32f4discovery_sample_objcopy.bin
ã§ã¯ããã®ãã¤ããªãã¡ã¤ã«ã Renode ã§èµ·åãã¦ããã¾ãã
$ renode
Gtk-Message: 21:46:48.764: Failed to load module "canberra-gtk-module"
21:46:49.6671 [INFO] Loaded monitor commands from: /home/daisuke/svn_/renode/renode_1.15.0_portable/scripts/monitor.py
(monitor) mach create
21:46:59.5845 [INFO] System bus created.
(machine-0) machine LoadPlatformDescription @platforms/boards/stm32f4_discovery-kit.repl
21:48:45.2759 [INFO] Reading cache
21:48:45.7662 [INFO] sysbus: Loaded SVD: /tmp/renode-10451/b58a73de-2638-46a1-9d68-515741ec08ce.tmp. Name: STM32F40x. Description: STM32F40x.
(machine-0) sysbus LoadBinary @stm32f4discovery_sample_objcopy.bin
The following methods are available:
- Void LoadBinary (ReadFilePath fileName, UInt64 loadPoint, ICPU cpu = null)
Usage:
sysbus MethodName param1 param2 ...
There was an error executing command 'sysbus LoadBinary @/home/daisuke/svn_/renode/renode_1.15.0_portable/stm32f4discovery_sample_objcopy.bin'
Parameters did not match the signature
åç´ã«ãã¤ããªãã¡ã¤ã«ãæå®ããã ãã§ã¯ã¨ã©ã¼ã«ãªãã¾ããããã¼ãããã¢ãã¬ã¹ãæå®ããå¿
è¦ãããããã§ãããã®å¾ãã® ICPUï¼ã¯åãããªãã®ã§ãã¨ããããã¢ãã¬ã¹ã ãæå®ãã¦ã¿ã¾ãã
(machine-0) sysbus LoadBinary @stm32f4discovery_sample_objcopy.bin 0x08000000
(machine-0) machine StartGdbServer 3333
21:57:01.2632 [INFO] machine-0: GDB server with all CPUs started on port :3333
ã¨ã©ã¼ã¯åºãªããªãã¾ããããæ£å¸¸ãªå ´åã¯ããã¼ããããã¨ãããã°ãåºã¦ããã®ã§ããã¾ããã£ã¦ãªãããããã¾ãããã¨ãããã GDB ãæ¥ç¶ãã¦ã¿ã¾ãã
$ arm-none-eabi-gdb stm32f4discovery_sample_objcopy.bin
"/home/daisuke/svn_/renode/renode_1.15.0_portable/stm32f4discovery_sample_objcopy.bin": not in executable format: file format not recognized
(gdb) target remote :3333
Remote debugging using :3333
warning: No executable has been specified and target does not support
determining executable automatically. Try using the "file" command.
0x00000000 in ?? ()
Renode å´ã®ãã°ã§ãã
21:58:16.4682 [WARNING] sysbus: [cpu: 0x0] ReadDoubleWord from non existing peripheral at 0x4.
21:58:16.4686 [WARNING] sysbus: [cpu: 0x0] ReadDoubleWord from non existing peripheral at 0x0.
21:58:16.4712 [ERROR] cpu: PC does not lay in memory or PC and SP are equal to zero. CPU was halted.
21:58:16.4781 [INFO] cpu: Setting initial values: PC = 0x0, SP = 0x0.
21:58:16.4786 [WARNING] cpu: Patching PC 0x0 for Thumb mode.
21:58:16.4798 [INFO] machine-0: Machine started.
å
ã»ã©ã¨åãã§ããã
ELFãã¡ã¤ã«ã®å ´åã¯ãæ
å ±ãä¸è¶³ãã¦ããã®ã§ã失æãã¦ãä»æ¹ãªãã§ããããã¤ããªãã¡ã¤ã«ã®å ´åã¯ãæ
å ±ãç¡ããã¡ã¤ã«ãªã®ã§ããã®çµæã¯å¤ã ã¨æãã¾ãã
ãããã«
ä»åã¯ãRenode ã§ãGDB ã使ã£ã¦åããã¦ã¿ã¾ããã
GDB èªä½ã¯åé¡ãªãåãã¾ãããããã¤ããªãã¡ã¤ã«ã«ã¤ãã¦ã¯ Renode ã®åä½ãæªããæ°ããã¾ãã
次åã¯ããã¤ããªãã¡ã¤ã«ã§åä½ããªãåå ãè¦ã¦ãããã¨æãã¾ãã
ãã®è¨äºã誰ãã®å½¹ã«ç«ã¦ã°å¬ããã§ãã
æå¾ã«ãªãã¾ããããã¨ã³ã¸ãã¢ã°ã«ã¼ãã®ã©ã³ãã³ã°ã«åå ä¸ã§ãã
æ°æ¥½ã«ãããã¨ãããããé¡ããããã¾ãð
ä»åã¯ä»¥ä¸ã§ãï¼
æå¾ã¾ã§ãèªã¿ããã ãããããã¨ããããã¾ããã