├── .editorconfig ├── .gitignore ├── .gitmodules ├── 3rd_party └── build_qemu.sh ├── Developing.md ├── LICENSE ├── README.md ├── build_keystone.sh ├── dependencies.md ├── doc ├── setup.md └── tutorial │ ├── 0_Preqs.md │ ├── 1_HALucinator_overview.md │ ├── 2_run_uart_example.md │ ├── 3_uart_deep_dive.md │ ├── 4_extending_halucinator.md │ └── imgs │ ├── HALucinator_Components.png │ ├── decompiler_view.png │ ├── example_before_entering_characters.png │ ├── ghidra_goto_main.png │ ├── ghidra_new.png │ ├── ghidra_project_name.png │ ├── importing_file.png │ ├── led_type_def.png │ └── uart_example_after_entering_characters.png ├── halucinator ├── install_deps.sh ├── manual_avatar_install.sh ├── mapping_gui ├── src ├── SymbolBrowser.py ├── halucinator │ ├── __init__.py │ ├── bp_handlers │ │ ├── __init__.py │ │ ├── atmel_asf_v3 │ │ │ ├── __init__.py │ │ │ ├── contiki.py │ │ │ ├── edbg_stub.py │ │ │ ├── ethernet_ksz8851.py │ │ │ ├── ethernet_smart_connect.py │ │ │ ├── ext_interrupt.py │ │ │ ├── hle_ethernet.py │ │ │ ├── radio.py │ │ │ ├── rf233.py │ │ │ ├── sd_mmc.py │ │ │ ├── timers.py │ │ │ └── usart.py │ │ ├── bp_handler.py │ │ ├── generic │ │ │ ├── __init__.py │ │ │ ├── argument_loggers.py │ │ │ ├── common.py │ │ │ ├── counter.py │ │ │ ├── debug.py │ │ │ ├── function_callers.py │ │ │ └── timer.py │ │ ├── intercepts.py │ │ ├── mbed │ │ │ ├── __init__.py │ │ │ ├── boot.py │ │ │ ├── serial.py │ │ │ └── timer.py │ │ └── stm32f4 │ │ │ ├── __init__.py │ │ │ ├── stm32f4_base.py │ │ │ ├── stm32f4_eth.py │ │ │ ├── stm32f4_gpio.py │ │ │ ├── stm32f4_sd.py │ │ │ ├── stm32f4_spi.py │ │ │ ├── stm32f4_tim.py │ │ │ ├── stm32f4_uart.py │ │ │ └── stm32f4_wifi.py │ ├── external_devices │ │ ├── IEEE802_15_4.py │ │ ├── __init__.py │ │ ├── ethernet_virt_hub.py │ │ ├── ethernet_wireless.py │ │ ├── gpio.py │ │ ├── host_ethernet.py │ │ ├── host_ethernet_server.py │ │ ├── ioserver.py │ │ ├── trigger_interrupt.py │ │ ├── uart.py │ │ └── vn8200xp.py │ ├── gui.py │ ├── hal_config.py │ ├── hal_log.py │ ├── hal_stats.py │ ├── logging.cfg │ ├── main.py │ ├── peripheral_models │ │ ├── __init__.py │ │ ├── ethernet.py │ │ ├── generic.py │ │ ├── gpio.py │ │ ├── ieee802_15_4.py │ │ ├── interrupts.py │ │ ├── peripheral.py │ │ ├── peripheral_server.py │ │ ├── sd_card.py │ │ ├── spi.py │ │ ├── tcp_stack.py │ │ ├── timer_model.py │ │ └── uart.py │ ├── qemu_targets │ │ ├── __init__.py │ │ ├── arm_qemu.py │ │ └── armv7m_qemu.py │ ├── symbol_browser.py │ └── util │ │ ├── __init__.py │ │ ├── cortex_m_helpers.py │ │ ├── elf_sym_hal_getter.py │ │ ├── get_funct_name_MMIO.py │ │ ├── hexyaml.py │ │ ├── parse_symbol_tables.py │ │ └── profile_hals.py ├── requirements.txt ├── setup.py └── tools │ ├── __init__.py │ ├── create_emulation_config.py │ ├── gen_blinky_config.py │ ├── graph_qemu_trace.py │ ├── json2yaml.py │ ├── make_bin.sh │ ├── map_hal2intercepts.py │ ├── qemu_to_trace.py │ ├── result_collection │ └── py_code_stats.py │ └── stm_tools │ ├── build_scripts │ ├── CubeMX2Makefile.py │ └── CubeMX2Makefile.tpl │ └── preprocess_hal.py ├── symbol_browser ├── test ├── SAMR21 │ ├── HTTP │ │ ├── BB_SAMR21_config_LWIP.yaml │ │ ├── BB_SAMR21_config_ksz.yaml │ │ ├── BB_run_release_LWIP.sh │ │ ├── BB_run_release_ksz.sh │ │ ├── Full_SAMR21_config_LWIP.yaml │ │ ├── Full_SAMR21_config_ksz.yaml │ │ ├── Full_run_release_LWIP.sh │ │ ├── Full_run_release_ksz.sh │ │ ├── Halt_Memories_Release_USART.yaml │ │ ├── Halt_SAMR21_config.yaml │ │ ├── Halt_run_release.sh │ │ ├── Memories_Debug_USART.yaml │ │ ├── Memories_Release_USART.yaml │ │ ├── run_debug.sh │ │ ├── run_debug_ksz.sh │ │ ├── run_release_no_intercepts.sh │ │ └── test_cmds.sh │ ├── SD_MMC │ │ ├── BB_SAMR21_config.yaml │ │ ├── BB_run_release.sh │ │ ├── Full_SAMR21_config.yaml │ │ ├── Full_run_release.sh │ │ ├── Halt_Memories_Release_SD.yaml │ │ ├── Halt_SAMR21_config.yaml │ │ ├── Halt_run_release.sh │ │ ├── Memories_Debug_SD.yaml │ │ ├── Memories_Release_SD.yaml │ │ ├── run_debug.sh │ │ └── run_release_no_intercepts.sh │ ├── UART-Echo │ │ ├── BB_SAMR21_config.yaml │ │ ├── BB_run_release.sh │ │ ├── Full_SAMR21_config.yaml │ │ ├── Full_run_release.sh │ │ ├── Halt_Memories_Release_USART.yaml │ │ ├── Halt_SAMR21_config.yaml │ │ ├── Halt_run_release.sh │ │ ├── Memories_Debug_USART.yaml │ │ ├── Memories_Release_USART.yaml │ │ ├── Running.md │ │ └── run_debug.sh │ └── Wireless │ │ ├── BB_SAMR21_config.yaml │ │ ├── BB_SAMR21_config_RF233.yaml │ │ ├── BB_run_receive_release_rf233.sh │ │ ├── BB_run_send_release_rf233.sh │ │ ├── Full_SAMR21_config_RF233.yaml │ │ ├── Full_run_receive_release_rf233.sh │ │ ├── Full_run_send_release_rf233.sh │ │ ├── Halt_Memories_Release_Receive.yaml │ │ ├── Halt_Memories_Release_Send_RF233.yaml │ │ ├── Halt_SAMR21_config.yaml │ │ ├── Halt_run_receive_release_rf233.sh │ │ ├── Halt_run_send_release_rf233.sh │ │ ├── Memories_Debug_Receive.yaml │ │ ├── Memories_Debug_Send.yaml │ │ ├── Memories_Debug_Send_RF233.yaml │ │ ├── Memories_Release_Receive.yaml │ │ ├── Memories_Release_Send_RF233.yaml │ │ ├── run_broadcaster.sh │ │ ├── run_receive_debug.sh │ │ ├── run_receive_debug_rf233.sh │ │ ├── run_send_debug.sh │ │ └── run_send_debug_rf233.sh └── STM32 │ ├── STM32469_EVAL │ ├── BB_peripheral_config.yaml │ ├── Ethernet │ │ ├── BB_run_tcp_client.sh │ │ ├── BB_run_tcp_server.sh │ │ ├── BB_run_tcp_server_to_host.sh │ │ ├── BB_run_udp_client.sh │ │ ├── BB_run_udp_server.sh │ │ ├── Full_run_tcp_client.sh │ │ ├── Full_run_tcp_server.sh │ │ ├── Full_run_tcp_server_to_host.sh │ │ ├── Full_run_udp_client.sh │ │ ├── Full_run_udp_server.sh │ │ ├── Halt_TCP_Echo_Server_Client_Os_memory.yaml │ │ ├── Halt_TCP_Echo_Server_Os_memory.yaml │ │ ├── Halt_UDP-echo-client_Os_memory.yaml │ │ ├── Halt_UDP_echo_server_Os_memory.yaml │ │ ├── Halt_run_tcp_client.sh │ │ ├── Halt_run_tcp_server.sh │ │ ├── Halt_run_udp_client.sh │ │ ├── Halt_run_udp_server.sh │ │ ├── TCP_Echo_Server_Client_O0_memory.yaml │ │ ├── TCP_Echo_Server_Client_Os_memory.yaml │ │ ├── TCP_Echo_Server_O0_memory.yaml │ │ ├── TCP_Echo_Server_Os_memory.yaml │ │ ├── UDP-echo-client_O0_memory.yaml │ │ ├── UDP-echo-client_Os_memory.yaml │ │ ├── UDP_echo_server_O0_memory.yaml │ │ └── UDP_echo_server_Os_memory.yaml │ ├── Fatfs_uSD │ │ ├── BB_run_release.sh │ │ ├── FatFS_uSD_O0_memory.yaml │ │ ├── FatFS_uSD_Os_memory.yaml │ │ ├── Full_run_release.sh │ │ ├── Halt_memory_FatFS_uSD_Os.yaml │ │ └── Halt_run_release.sh │ ├── Full_peripheral_config.yaml │ ├── Halt_config.yaml │ └── UART │ │ ├── BB_run_release_DMA.sh │ │ ├── BB_run_release_IT.sh │ │ ├── Full_run_release_IT.sh │ │ ├── Halt_memory_Uart_Hyperterminal_DMA_Os.yaml │ │ ├── Halt_memory_Uart_Hyperterminal_IT_Os_Halt.yaml │ │ ├── Halt_run_release_DMA.sh │ │ ├── Halt_run_release_IT.sh │ │ ├── Running.md │ │ ├── Uart_Hyperterminal_DMA_O0_memory.yaml │ │ ├── Uart_Hyperterminal_DMA_Os_memory.yaml │ │ ├── Uart_Hyperterminal_IT_O0_memory.yaml │ │ └── Uart_Hyperterminal_IT_Os_memory.yaml │ ├── example │ ├── STM_UART_readme-license.txt │ ├── Uart_Hyperterminal_IT_O0.elf │ ├── Uart_Hyperterminal_IT_O0.elf.bin │ ├── Uart_Hyperterminal_IT_O0_addrs.yaml │ ├── Uart_Hyperterminal_IT_O0_config.yaml │ ├── Uart_Hyperterminal_IT_O0_memory.yaml │ ├── logging.cfg │ └── run.sh │ └── st-plc │ ├── peripheral_config.yaml │ ├── peripheral_config_bb.yaml │ ├── peripheral_config_halt.yaml │ ├── st-plc-bb.sh │ ├── st-plc-halt.sh │ ├── st-plc.sh │ └── st-plc_memory.yaml └── tutorial ├── hal_tutorial ├── bp_handlers │ └── led_bp_handler.py ├── external_devices │ └── led_external_device.py └── peripheral_models │ └── led_peripheral.py ├── logging.cfg ├── my_config.yaml ├── setup.py └── solutions ├── led_bp_handler.py ├── led_external_device.py ├── led_peripheral.py ├── logging.cfg └── my_config.yaml /.editorconfig: -------------------------------------------------------------------------------- 1 | # DO NOT USE: root = true 2 | 3 | [*] 4 | charset = utf-8 5 | end_of_line = lf 6 | insert_final_newline = true 7 | indent_size = 4 8 | indent_style = space 9 | 10 | [{Makefile, *,mk}] 11 | insend_style = tab 12 | 13 | [*.py] 14 | indent_style = space 15 | indent_size = 4 16 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | *~ 3 | .*.sw* 4 | *.bak 5 | 6 | __pycache__ 7 | *.egg-info 8 | 9 | src/build/ 10 | *.pyc 11 | deps/** 12 | test/**/tmp 13 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/embedded-sec/halucinator/fa85a1dcbaaa72bd425094fc3917abdd7d9b9a8a/.gitmodules -------------------------------------------------------------------------------- /3rd_party/build_qemu.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | source /etc/os-release 3 | set -e 4 | 5 | # if [[ "$ID" == "ubuntu" ]] 6 | # then 7 | # sudo bash -c 'echo "deb-src http://archive.ubuntu.com/ubuntu/ '$UBUNTU_CODENAME'-security main restricted" >> /etc/apt/sources.list' 8 | # sudo apt-get update 9 | # sudo apt-get build-dep -y qemu 10 | # fi 11 | 12 | # May need to update to different repo 13 | if [[! -d "/path/to/dir"]] 14 | then 15 | git clone https://github.com/avatartwo/avatar-qemu.git avatar-qemu 16 | fi 17 | cd avatar-qemu 18 | git submodule update --init --recursive 19 | 20 | ./configure --disable-sdl --target-list=arm-softmmu 21 | make -j4 22 | 23 | -------------------------------------------------------------------------------- /build_keystone.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | set -e 3 | set -x 4 | 5 | #Make sure in virtual environment 6 | : ${VIRTUAL_ENV:?Should be run from your halucinator virtual environment} 7 | 8 | sudo apt install -y cmake 9 | if pushd deps/keystone; then 10 | git pull 11 | popd 12 | else 13 | git clone https://github.com/keystone-engine/keystone deps/keystone 14 | fi 15 | 16 | mkdir -p deps/keystone/build 17 | pushd deps/keystone/build 18 | cmake -DBUILD_SHARED_LIBS=ON -G "Unix Makefiles" ../ 19 | make -j8 20 | 21 | pip install keystone-engine 22 | 23 | SITEPKG=$(python -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())") 24 | cp -v ./llvm/lib/libkeystone.so "${SITEPKG}"/keystone/ 25 | 26 | popd 27 | 28 | 29 | -------------------------------------------------------------------------------- /dependencies.md: -------------------------------------------------------------------------------- 1 | Program, Version, License, License Link 2 | pycparser, v2.18, BSD, https://github.com/eliben/pycparser 3 | avatar2, ? , Apache 2.0, http://www.apache.org/licenses/LICENSE-2.0 4 | angr 5 | 0MQ (pip install pyzmq) 6 | python-tk 7 | ethtool (sudo apt install ethtool) -------------------------------------------------------------------------------- /doc/tutorial/0_Preqs.md: -------------------------------------------------------------------------------- 1 | # Preqs 2 | 3 | This tutorial assumes you have HALucinator installed on Ubuntu 18.04 and in a 4 | virtual environment named `halucinator`, and that the source is located in your 5 | home directory (e.g. ~/). See main repo README for instructions on setting up. 6 | 7 | It also uses Ghidra 9.1.2 which we have located in ~/ghidra_9.1.2. It 8 | can be located anywhere but you'll have to adjust paths. It can be obtained 9 | from https://ghidra-sre.org/. 10 | 11 | We also use visual studio code through the tutorial. You can use this or your 12 | preferred editor. 13 | -------------------------------------------------------------------------------- /doc/tutorial/imgs/HALucinator_Components.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/embedded-sec/halucinator/fa85a1dcbaaa72bd425094fc3917abdd7d9b9a8a/doc/tutorial/imgs/HALucinator_Components.png -------------------------------------------------------------------------------- /doc/tutorial/imgs/decompiler_view.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/embedded-sec/halucinator/fa85a1dcbaaa72bd425094fc3917abdd7d9b9a8a/doc/tutorial/imgs/decompiler_view.png -------------------------------------------------------------------------------- /doc/tutorial/imgs/example_before_entering_characters.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/embedded-sec/halucinator/fa85a1dcbaaa72bd425094fc3917abdd7d9b9a8a/doc/tutorial/imgs/example_before_entering_characters.png -------------------------------------------------------------------------------- /doc/tutorial/imgs/ghidra_goto_main.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/embedded-sec/halucinator/fa85a1dcbaaa72bd425094fc3917abdd7d9b9a8a/doc/tutorial/imgs/ghidra_goto_main.png -------------------------------------------------------------------------------- /doc/tutorial/imgs/ghidra_new.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/embedded-sec/halucinator/fa85a1dcbaaa72bd425094fc3917abdd7d9b9a8a/doc/tutorial/imgs/ghidra_new.png -------------------------------------------------------------------------------- /doc/tutorial/imgs/ghidra_project_name.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/embedded-sec/halucinator/fa85a1dcbaaa72bd425094fc3917abdd7d9b9a8a/doc/tutorial/imgs/ghidra_project_name.png -------------------------------------------------------------------------------- /doc/tutorial/imgs/importing_file.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/embedded-sec/halucinator/fa85a1dcbaaa72bd425094fc3917abdd7d9b9a8a/doc/tutorial/imgs/importing_file.png -------------------------------------------------------------------------------- /doc/tutorial/imgs/led_type_def.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/embedded-sec/halucinator/fa85a1dcbaaa72bd425094fc3917abdd7d9b9a8a/doc/tutorial/imgs/led_type_def.png -------------------------------------------------------------------------------- /doc/tutorial/imgs/uart_example_after_entering_characters.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/embedded-sec/halucinator/fa85a1dcbaaa72bd425094fc3917abdd7d9b9a8a/doc/tutorial/imgs/uart_example_after_entering_characters.png -------------------------------------------------------------------------------- /halucinator: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | python -m halucinator.main $@ 4 | -------------------------------------------------------------------------------- /install_deps.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # . /etc/bash_completion 3 | set -e 4 | #set -x 5 | sudo apt-get install -y ethtool python-tk gdb-multiarch tcpdump python3-pip \ 6 | python3-venv cmake g++ build-essential libpixman-1-dev 7 | 8 | sudo pip3 install virtualenv virtualenvwrapper 9 | 10 | 11 | # VIRT_ENV="halucinator" 12 | # python3 -m venv ~/.virtualenvs/"$VIRT_ENV" 13 | 14 | # # Activate the virtual environment (workon doesn't work in the script) 15 | # echo "================================================" 16 | # echo "$VIRT_ENV virt environment created now run:" 17 | # echo "" 18 | # echo "source ~/.virtualenvs/$VIRT_ENV/bin/activate" 19 | # echo "./setup.sh" 20 | -------------------------------------------------------------------------------- /manual_avatar_install.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | . /etc/bash_completion 3 | set -e 4 | set -x 5 | 6 | AVATAR_REPO=https://github.com/avatartwo/avatar2.git 7 | 8 | # If avatar already cloned just pull 9 | if pushd deps/avatar2; then 10 | git pull 11 | popd 12 | else 13 | git clone "$AVATAR_REPO" deps/avatar2 14 | fi 15 | 16 | # Setup avatar2 17 | pushd deps/avatar2 18 | git submodule update --init --recursive 19 | pip install -e . 20 | 21 | pushd targets 22 | ./build_qemu.sh 23 | #./build_panda.sh 24 | popd 25 | popd 26 | 27 | -------------------------------------------------------------------------------- /mapping_gui: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | python -m halucinator.gui $@ 4 | -------------------------------------------------------------------------------- /src/halucinator/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/embedded-sec/halucinator/fa85a1dcbaaa72bd425094fc3917abdd7d9b9a8a/src/halucinator/__init__.py -------------------------------------------------------------------------------- /src/halucinator/bp_handlers/__init__.py: -------------------------------------------------------------------------------- 1 | from .generic import * 2 | from . import atmel_asf_v3, mbed, stm32f4, generic -------------------------------------------------------------------------------- /src/halucinator/bp_handlers/atmel_asf_v3/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/embedded-sec/halucinator/fa85a1dcbaaa72bd425094fc3917abdd7d9b9a8a/src/halucinator/bp_handlers/atmel_asf_v3/__init__.py -------------------------------------------------------------------------------- /src/halucinator/bp_handlers/atmel_asf_v3/contiki.py: -------------------------------------------------------------------------------- 1 | # Copyright 2019 National Technology & Engineering Solutions of Sandia, LLC (NTESS). 2 | # Under the terms of Contract DE-NA0003525 with NTESS, the U.S. Government retains 3 | # certain rights in this software. 4 | 5 | from ..bp_handler import BPHandler, bp_handler 6 | import logging 7 | import time 8 | log = logging.getLogger(__name__) 9 | 10 | 11 | class Contiki(BPHandler): 12 | 13 | def __init__(self, model=None): 14 | BPHandler.__init__(self) 15 | self.model = model 16 | self.start_time = time.time() 17 | self.ticks_per_second = 128 18 | 19 | def register_handler(self, qemu, addr, func_name, ticks_per_second=None): 20 | if ticks_per_second is not None: 21 | self.ticks_per_second = ticks_per_second 22 | return BPHandler.register_handler(self, qemu, addr, func_name) 23 | 24 | @bp_handler(['clock_time']) 25 | def clock_time(self, qemu, bp_addr): 26 | ticks = time.time() - self.start_time 27 | ticks = int(ticks * self.ticks_per_second) 28 | log.debug("#Ticks: %i" % ticks) 29 | return True, ticks 30 | 31 | @bp_handler(['clock_seconds']) 32 | def clock_seconds(self, qemu, bp_addr): 33 | secs = int(time.time() - self.start_time) 34 | log.debug("#Seconds: %i" % secs) 35 | return True, secs 36 | -------------------------------------------------------------------------------- /src/halucinator/bp_handlers/atmel_asf_v3/edbg_stub.py: -------------------------------------------------------------------------------- 1 | # Copyright 2019 National Technology & Engineering Solutions of Sandia, LLC (NTESS). 2 | # Under the terms of Contract DE-NA0003525 with NTESS, the U.S. Government retains 3 | # certain rights in this software. 4 | 5 | from ..intercepts import tx_map, rx_map 6 | from ..bp_handler import BPHandler, bp_handler 7 | from collections import defaultdict, deque 8 | import struct 9 | import binascii 10 | import os 11 | import logging 12 | import time 13 | log = logging.getLogger(__name__) 14 | 15 | 16 | # This is just a stub to enable getting edbg_eui for use as MAC 17 | # on 6LoWPAN example apps 18 | 19 | 20 | class EDBG_Stub(BPHandler): 21 | 22 | def __init__(self, model=None): 23 | BPHandler.__init__(self) 24 | self.model = model 25 | self.eui64 = '' 26 | 27 | def register_handler(self, qemu, addr, func_name, eui64=None): 28 | if eui64 is not None: 29 | self.eui64 = eui64 30 | return BPHandler.register_handler(self, qemu, addr, func_name) 31 | 32 | @bp_handler(['i2c_master_init', 'i2c_master_enable']) 33 | def return_void(self, qemu, bp_addr): 34 | return True, None 35 | 36 | @bp_handler(['i2c_master_write_packet_wait_no_stop']) 37 | def return_ok(self, qemu, bp_addr): 38 | return True, 0 39 | 40 | @bp_handler(['i2c_master_read_packet_wait']) 41 | def get_edbg_eui64(self, qemu, bp_addr): 42 | packet = qemu.regs.r1 43 | packet_struct = qemu.read_memory(packet+2, 1, 6, raw=True) 44 | (length, data_ptr) = struct.unpack(" len(self.eui64): 46 | eui64 = self.eui64 + "\55"*(length - len(self.eui64)) 47 | qemu.write_memory(data_ptr, 1, eui64, len(eui64), raw=True) 48 | else: 49 | qemu.write_memory(data_ptr, 1, self.eui64, length, raw=True) 50 | return True, 0 51 | -------------------------------------------------------------------------------- /src/halucinator/bp_handlers/atmel_asf_v3/ethernet_smart_connect.py: -------------------------------------------------------------------------------- 1 | # Copyright 2019 National Technology & Engineering Solutions of Sandia, LLC (NTESS). 2 | # Under the terms of Contract DE-NA0003525 with NTESS, the U.S. Government retains 3 | # certain rights in this software. 4 | 5 | 6 | import IPython 7 | from ...peripheral_models.ethernet import EthernetModel 8 | from ..intercepts import tx_map, rx_map 9 | from ..bp_handler import BPHandler, bp_handler 10 | from collections import defaultdict, deque 11 | import struct 12 | import binascii 13 | import os 14 | import logging 15 | import time 16 | log = logging.getLogger(__name__) 17 | 18 | 19 | 20 | class EthernetSmartConnect(BPHandler): 21 | 22 | def __init__(self, model=EthernetModel): 23 | BPHandler.__init__(self) 24 | log.debug("Ethernet Smart Connect Init") 25 | self.model = model 26 | self.last_rx_time = time.time() 27 | self.last_exec_time = time.time() 28 | self.dev_ptr = None 29 | self.netif_ptr = None 30 | 31 | def get_id(self, qemu): 32 | return 'ksz8851' 33 | 34 | # This is custom written from binary as ksz8851snl_read got inlined 35 | @bp_handler(['addr_15882']) 36 | def eth_process(self, qemu, bp_addr): 37 | now = time.time() 38 | log.info("In addr_15882: %f" % (now - self.last_exec_time)) 39 | self.last_exec_time = time.time() 40 | 41 | start_time = time.time() 42 | (num_frames, size_1st_frame) = self.model.get_frame_info(self.get_id(qemu)) 43 | if num_frames > 0: 44 | # If frame, get global buffer, write frame to it can call function to process 45 | # the frame 46 | log.info("Reading in frame") 47 | buf_ptr = qemu.read_memory(0x200000e8, 1, 4) # ip_packet_bufer 48 | frame = self.model.get_rx_frame(self.get_id(qemu)) 49 | frame_len = len(frame) 50 | qemu.write_memory(buf_ptr, 1, frame, frame_len) 51 | qemu.regs.r0 = buf_ptr 52 | qemu.regs.r1 = frame_len 53 | qemu.regs.lr = qemu.regs.pc | 1 # set thumb bit, lr already save to stack 54 | qemu.regs.pc = qemu.avatar.callables['ip64_eth_interface_input'] | 1 55 | return True, None 56 | 57 | return False, None 58 | 59 | @bp_handler(['ksz8851snl_read', 'input']) 60 | def read(self, qemu, bp_addr): 61 | # 1. See if there are frames 62 | now = time.time() 63 | log.info("In ETHERNET_INPUT: %f" % (now - self.last_exec_time)) 64 | self.last_exec_time = time.time() 65 | 66 | start_time = time.time() 67 | (num_frames, size_1st_frame) = self.model.get_frame_info(self.get_id(qemu)) 68 | if num_frames > 0: 69 | data_ptr = qemu.regs.r0 70 | max_len = qemu.regs.r1 71 | frame, rx_time = self.model.get_rx_frame(self.get_id(qemu), True) 72 | frame_length = len(frame) 73 | if max_len >= frame_length: 74 | log.info("Frame Read w len %i", frame_length) 75 | qemu.write_memory(data_ptr, 1, frame, len(frame)) 76 | return True, frame_length 77 | 78 | return True, 0 79 | 80 | @bp_handler(['ksz8851snl_send', 'output']) 81 | def send(self, qemu, bp_addr): 82 | data_ptr = qemu.regs.r0 83 | length = qemu.regs.r1 84 | frame = qemu.read_memory(data_ptr, 1, length, raw=True) 85 | log.info("Send Called w frame length: %i", length) 86 | self.model.tx_frame(self.get_id(qemu), frame) 87 | return True, length 88 | 89 | @bp_handler(['ksz8851snl_init']) 90 | def return_ok(self, qemu, bp_addr): 91 | log.info("Init Called") 92 | return True, 0 93 | -------------------------------------------------------------------------------- /src/halucinator/bp_handlers/atmel_asf_v3/ext_interrupt.py: -------------------------------------------------------------------------------- 1 | # Copyright 2019 National Technology & Engineering Solutions of Sandia, LLC (NTESS). 2 | # Under the terms of Contract DE-NA0003525 with NTESS, the U.S. Government retains 3 | # certain rights in this software. 4 | 5 | from ...peripheral_models.interrupts import Interrupts 6 | from avatar2.peripherals.avatar_peripheral import AvatarPeripheral 7 | from ..intercepts import tx_map, rx_map 8 | from ..bp_handler import BPHandler, bp_handler 9 | import logging 10 | log = logging.getLogger(__name__) 11 | 12 | 13 | 14 | class EXT_Int(BPHandler, AvatarPeripheral): 15 | 16 | def __init__(self, impl=Interrupts): 17 | self.callbacks = {} 18 | self.model = impl 19 | self.org_lr = None 20 | self.current_channel = 0 21 | self.name = 'Atmel_EIC' 22 | self.address = 0x40001800 23 | self.size = 2048 24 | 25 | log.info("Setting Handlers") 26 | AvatarPeripheral.__init__(self, self.name, self.address, self.size) 27 | 28 | self.read_handler[0:self.size] = self.hw_read 29 | self.write_handler[0:self.size] = self.hw_write 30 | 31 | def get_mmio_info(self): 32 | return self.name, self.address, self.size, 'rw-' 33 | 34 | def hw_read(self, offset, size, pc): 35 | value = 0 36 | if offset == 0x10: # Set interrupt 37 | for channel, isr_name in list(self.channel_map.items()): 38 | 39 | if self.model.is_active(isr_name): 40 | value |= (1 << channel) 41 | log.info("Read from addr, 0x%08x size: %i value: 0x%0x, pc:%s" % 42 | (self.address + offset, size, value, hex(pc))) 43 | return value 44 | 45 | def hw_write(self, offset, size, value, pc): 46 | log.info("Write to addr, 0x%08x size: %i value: 0x%0x pc:%s" % 47 | (self.address + offset, size, value, hex(pc))) 48 | if offset == 8: # Clear interrupt 49 | for channel, isr_name in list(self.channel_map.items()): 50 | if self.model.is_active(isr_name): 51 | log.info("Clearing %i:%s" % (channel, isr_name)) 52 | self.model.clear_active(isr_name) 53 | return True 54 | 55 | def register_handler(self, qemu, addr, func_name, channel_map=None): 56 | # Can be called for each function registered with the class 57 | if channel_map is not None: 58 | log.info("Setting Channel map: %s" % str(channel_map)) 59 | self.channel_map = channel_map 60 | return BPHandler.register_handler(self, qemu, addr, func_name) 61 | 62 | # @bp_handler(['EIC_Handler']) 63 | # def EIC_Handler(self, qemu, bp_addr): 64 | # log.info("In EIC_Handler: %s" % hex(bp_addr)) 65 | # return False, None 66 | 67 | @bp_handler(['extint_register_callback']) 68 | def register_callback(self, qemu, bp_addr): 69 | log.info("Callback Set %s" % hex(qemu.regs.r0)) 70 | return False, None # Just let it run, 71 | 72 | # @bp_handler("dummy") 73 | # def dummy(self, qemu, bp_addr): 74 | 75 | # return True, None 76 | -------------------------------------------------------------------------------- /src/halucinator/bp_handlers/atmel_asf_v3/timers.py: -------------------------------------------------------------------------------- 1 | # Copyright 2019 National Technology & Engineering Solutions of Sandia, LLC (NTESS). 2 | # Under the terms of Contract DE-NA0003525 with NTESS, the U.S. Government retains 3 | # certain rights in this software. 4 | from ...peripheral_models.interrupts import Interrupts 5 | from ...peripheral_models.timer_model import TimerModel 6 | from avatar2.peripherals.avatar_peripheral import AvatarPeripheral 7 | from ..intercepts import tx_map, rx_map 8 | from ..bp_handler import BPHandler, bp_handler 9 | import time 10 | from collections import defaultdict 11 | 12 | import logging 13 | log = logging.getLogger(__name__) 14 | 15 | 16 | 17 | class Timers(BPHandler, AvatarPeripheral): 18 | 19 | def __init__(self, model=TimerModel): 20 | self.model = model 21 | self.org_lr = None 22 | self.current_channel = 0 23 | self.name2isr_lut = {'Timer0': 0x20, 'Timer1': 0x21, 24 | 'Timer3': 0x22, 'Timer4': 0x23, 'Timer5': 0x24} 25 | self.irq_rates = {} 26 | self.name = 'Timer' 27 | self._init_mmio() 28 | 29 | def _init_mmio(self): 30 | # TODO should really have 5 instances of the AvatarPeripherals one for 31 | # each timer 32 | self.address = 0x42002000 33 | self.size = 0x2000 34 | 35 | log.info("Setting Handlers") 36 | AvatarPeripheral.__init__(self, self.name, self.address, self.size) 37 | self.read_handler[0:self.size] = self.hw_read 38 | self.write_handler[0:self.size] = self.hw_write 39 | 40 | def get_mmio_info(self): 41 | return self.name, self.address, self.size, 'rw-' 42 | 43 | def hw_read(self, offset, size, pc): 44 | value = 0 45 | 46 | if offset == 0x0c0e: # TC3 INT Reg 47 | value = 0xff 48 | 49 | log.info("Read from addr: 0x%08x, offset:0x%04x size: %i value: 0x%0x, pc: %s" % ( 50 | self.address + offset, offset, size, value, hex(pc))) 51 | return value 52 | 53 | def hw_write(self, offset, size, value, pc): 54 | log.info("Write to addr, 0x%08x size: %i value: 0x%0x, pc: %s" % 55 | (self.address + offset, size, value, hex(pc))) 56 | return True 57 | 58 | def register_handler(self, qemu, addr, func_name, irq_rates=None): 59 | ''' 60 | irq_rate(dict): {Name: rate (in seconds)} 61 | ''' 62 | if irq_rates is not None: 63 | self.irq_rates = irq_rates 64 | return BPHandler.register_handler(self, qemu, addr, func_name) 65 | 66 | @bp_handler(['tc_init']) 67 | def enable(self, qemu, bp_addr): 68 | log.info("Initializing %s, %s" % 69 | (hex(qemu.regs.r0), hex(qemu.regs.r1))) 70 | for irq_name, irq_rate in list(self.irq_rates.items()): 71 | self.model.start_timer( 72 | irq_name, self.name2isr_lut[irq_name], irq_rate) 73 | return False, None # Just let it run 74 | 75 | @bp_handler(['_tc_interrupt_handler']) 76 | def isr_handler(self, qemu, bp_addr): 77 | idx = qemu.regs.r0 78 | tc_instances_ptr = 0x000024E0 79 | tc_instances = 0x200021AC 80 | tc_instance = qemu.read_memory(tc_instances + (idx * 4), 4) 81 | hw_addr = qemu.read_memory(tc_instance, 4, 1) 82 | 83 | log.info("_TC_Handler: pc: 0x%08x, idx: 0x%08x, tc_instances_ptr: 0x%08x, TC_instance: 0x%08x" % 84 | (qemu.regs.pc, idx, qemu.read_memory(tc_instances_ptr, 4, 1), tc_instance)) 85 | log.info("HW_Addr: 0x%08x r4 0x%08x" % (hw_addr, qemu.regs.r4)) 86 | import os 87 | os.system("stty sane") 88 | import IPython 89 | IPython.embed() 90 | return False, None # Just let it run 91 | 92 | def disable(self, irq_name): 93 | self.model.stop_timer(irq_name) 94 | -------------------------------------------------------------------------------- /src/halucinator/bp_handlers/atmel_asf_v3/usart.py: -------------------------------------------------------------------------------- 1 | # Copyright 2019 National Technology & Engineering Solutions of Sandia, LLC (NTESS). 2 | # Under the terms of Contract DE-NA0003525 with NTESS, the U.S. Government retains 3 | # certain rights in this software. 4 | from ...peripheral_models.uart import UARTPublisher 5 | from ..intercepts import tx_map, rx_map 6 | from ..bp_handler import BPHandler, bp_handler 7 | import struct 8 | import logging 9 | import binascii 10 | 11 | log = logging.getLogger(__name__) 12 | 13 | 14 | class USART(BPHandler): 15 | 16 | def __init__(self, impl=UARTPublisher): 17 | self.model = impl 18 | 19 | @bp_handler(['usart_init', 'usart_enable']) 20 | def return_ok(self, qemu, bp_addr): 21 | return True, 0 22 | 23 | @bp_handler(['usart_write_buffer_wait']) 24 | def write_buffer(self, qemu, bp_addr): 25 | # enum status_code usart_write_buffer_wait( 26 | # struct usart_module *const module, 27 | # const uint8_t *tx_data, 28 | # uint16_t length); 29 | usart_ptr = qemu.regs.r0 30 | hw_addr = qemu.read_memory(usart_ptr, 4, 1) 31 | buf_addr = qemu.regs.r1 32 | buf_len = qemu.regs.r2 33 | data = qemu.read_memory(buf_addr, 1, buf_len, raw=True) 34 | log.info("Data %s" % data) 35 | self.model.write(hw_addr, data) 36 | return True, 0 37 | 38 | @bp_handler(['usart_write_wait']) 39 | def write_single(self, qemu, bp_addr): 40 | # enum status_code usart_write_buffer_wait( 41 | # struct usart_module *const module, 42 | # const uint16_t *tx_data); 43 | usart_ptr = qemu.regs.r0 44 | hw_addr = qemu.read_memory(usart_ptr, 4, 1) 45 | data = qemu.regs.r1 46 | log.debug("Tx_data: %s" % chr(data)) 47 | self.model.write(hw_addr, chr(data)) 48 | return True, 0 49 | 50 | @bp_handler(['usart_read_wait']) 51 | def read_single(self, qemu, bp_addr): 52 | usart_ptr = qemu.regs.r0 53 | hw_addr = qemu.read_memory(usart_ptr, 4, 1) 54 | ret = self.model.read(hw_addr, 1, block=True)[0] 55 | log.debug("Got Char: %s" % ret) 56 | qemu.write_memory(qemu.regs.r1, 2, ord(ret), 1) 57 | return True, 0 58 | -------------------------------------------------------------------------------- /src/halucinator/bp_handlers/bp_handler.py: -------------------------------------------------------------------------------- 1 | # Copyright 2019 National Technology & Engineering Solutions of Sandia, LLC (NTESS). 2 | # Under the terms of Contract DE-NA0003525 with NTESS, the U.S. Government retains 3 | # certain rights in this software. 4 | 5 | 6 | from functools import wraps 7 | 8 | 9 | def bp_handler(arg): 10 | ''' 11 | @bp_handler decorator 12 | 13 | arg: either the function if used as @bp_handler 14 | or a list of intercepting functions e.g., @bp_handler(['F1','F2']) 15 | 16 | ''' 17 | if callable(arg): 18 | # Handles @bp_handler with out args allows any function 19 | arg.is_bp_handler = True 20 | return arg 21 | else: 22 | # Handles @bp_handler(['F1','F2']) 23 | def bp_decorator(func): 24 | func.bp_func_list = arg 25 | return func 26 | return bp_decorator 27 | 28 | 29 | class BPHandler(object): 30 | 31 | def register_handler(self, qemu, addr, func_name): 32 | canidate_methods = [getattr(self.__class__, x) for x in dir( 33 | self.__class__) if hasattr(getattr(self.__class__, x), 'bp_func_list')] 34 | for canidate in canidate_methods: 35 | if func_name in canidate.bp_func_list: 36 | return canidate 37 | 38 | error_str = "%s does not have bp_handler for %s" % \ 39 | (self.__class__.__name__, func_name) 40 | raise ValueError(error_str) 41 | -------------------------------------------------------------------------------- /src/halucinator/bp_handlers/generic/__init__.py: -------------------------------------------------------------------------------- 1 | from .common import * 2 | from .counter import * 3 | from .argument_loggers import * 4 | from .debug import * 5 | from .function_callers import * 6 | from .timer import * -------------------------------------------------------------------------------- /src/halucinator/bp_handlers/generic/argument_loggers.py: -------------------------------------------------------------------------------- 1 | # Copyright 2019 National Technology & Engineering Solutions of Sandia, LLC (NTESS). 2 | # Under the terms of Contract DE-NA0003525 with NTESS, the U.S. Government retains 3 | # certain rights in this software. 4 | 5 | from ..bp_handler import BPHandler, bp_handler 6 | import re 7 | from binascii import hexlify 8 | from os import path 9 | import sys 10 | 11 | import logging 12 | from ... import hal_log 13 | 14 | log = logging.getLogger(__name__) 15 | hal_log = hal_log.getHalLogger() 16 | 17 | class ArgumentLogger(BPHandler): 18 | ''' 19 | Logs function arguments to standard out or input file 20 | 21 | Halucinator configuration usage: 22 | - class: halucinator.bp_handlers.ArgumentLogger 23 | function: 24 | addr: 25 | registration_args:{num_args: , log_ret_addr:true, 26 | intercept:false, ret_value:null} 27 | ''' 28 | def __init__(self, filename=None): 29 | self.fd = None 30 | if filename != None: 31 | self.fd = open(filename, 'wt') 32 | self.loggers = {} 33 | 34 | def register_handler(self, target, addr, func_name, num_args=0, 35 | log_ret_addr=True, intercept=False, ret_value=None, 36 | silent=False): 37 | ''' 38 | :param target The QemuTarget 39 | :param addr Address of the break point 40 | :param func_name Function name being logged 41 | :param num_args Number of arguments to log 42 | :param log_ret_addr Log the address this function will return to 43 | :param intercept Intercept execution and return without executing function 44 | :param ret_value Return value ignored if intercept != True 45 | ''' 46 | ret_value_str = "%#x " % ret_value if ret_value is not None else "None" 47 | log.debug("Registration Args: Fun: %s, num_args %i, log_ret_addr %s intercept %s, ret_value %s, silent %s " % \ 48 | (func_name, num_args, log_ret_addr, intercept, ret_value_str, silent)) 49 | self.loggers[addr] = ArgumentLogger.Logger(target,func_name, num_args, 50 | log_ret_addr, intercept, ret_value, silent) 51 | return ArgumentLogger.log_handler 52 | 53 | class Logger(): 54 | def __init__(self, target, func_name, num_args, 55 | log_caller, intercept,ret_value, silent): 56 | self.func_name = func_name 57 | self.num_args = num_args 58 | self.target = target 59 | self.log_caller= log_caller 60 | self.silent = silent 61 | self.ret_value = ret_value 62 | self.intercept = intercept 63 | 64 | 65 | def log(self): 66 | hal_log.info("###### Arg Logger ######") 67 | hal_log.info("Func: %s" % self.func_name) 68 | if self.num_args > 0: 69 | args = [hex(self.target.get_arg(i)) for i in range(self.num_args)] 70 | hal_log.info("Args: %s,".join(args)) 71 | if self.log_caller: 72 | hal_log.info("Return addr: %#x" % self.target.get_ret_addr()) 73 | 74 | @bp_handler # bp_handler no args, can intercept any function 75 | def log_handler(self, target, addr): 76 | logger = self.loggers[addr] 77 | if not logger.silent: 78 | logger.log() 79 | if logger.intercept: 80 | return True, logger.ret_value 81 | return False, None 82 | 83 | 84 | 85 | -------------------------------------------------------------------------------- /src/halucinator/bp_handlers/generic/common.py: -------------------------------------------------------------------------------- 1 | from ..bp_handler import BPHandler, bp_handler 2 | import logging 3 | from ... import hal_log 4 | 5 | log = logging.getLogger(__name__) 6 | hal_log = hal_log.getHalLogger() 7 | 8 | class ReturnZero(BPHandler): 9 | ''' 10 | Break point handler that just returns zero 11 | 12 | Halucinator configuration usage: 13 | - class: halucinator.bp_handlers.ReturnZero 14 | function: (Can be anything) 15 | registration_args: {silent:false} 16 | addr: 17 | ''' 18 | def __init__(self, filename=None): 19 | self.silent = {} 20 | self.func_names = {} 21 | 22 | def register_handler(self, qemu, addr, func_name, silent=False): 23 | self.silent[addr] = silent 24 | self.func_names[addr] = func_name 25 | return ReturnZero.return_zero 26 | 27 | @bp_handler 28 | def return_zero(self, qemu, addr): 29 | ''' 30 | Intercept Execution and return 0 31 | ''' 32 | if not self.silent[addr]: 33 | hal_log.info("ReturnZero: %s " %(self.func_names[addr])) 34 | return True, 0 35 | 36 | 37 | class ReturnConstant(BPHandler): 38 | ''' 39 | Break point handler that returns a constant 40 | 41 | Halucinator configuration usage: 42 | - class: halucinator.bp_handlers.ReturnConstant 43 | function: (Can be anything) 44 | registration_args: { ret_value:(value), silent:false} 45 | addr: 46 | ''' 47 | def __init__(self, filename=None): 48 | self.ret_values = {} 49 | self.silent = {} 50 | self.func_names = {} 51 | 52 | def register_handler(self, qemu, addr, func_name, ret_value=None, silent=False): 53 | self.ret_values[addr] = ret_value 54 | self.silent[addr] = ret_value 55 | self.func_names[addr] = func_name 56 | return ReturnConstant.return_constant 57 | 58 | @bp_handler 59 | def return_constant(self, qemu, addr): 60 | ''' 61 | Intercept Execution and return constant 62 | ''' 63 | if not self.silent[addr]: 64 | hal_log.info("ReturnConstant: %s : %#x" %(self.func_names[addr], self.ret_values[addr])) 65 | return True, self.ret_values[addr] 66 | 67 | 68 | class SkipFunc(BPHandler): 69 | ''' 70 | Break point handler that immediately returns from the function 71 | 72 | Halucinator configuration usage: 73 | - class: halucinator.bp_handlers.SkipFunc 74 | function: (Can be anything) 75 | registration_args: {silent:false} 76 | addr: 77 | ''' 78 | def __init__(self, filename=None): 79 | self.silent = {} 80 | self.func_names = {} 81 | 82 | def register_handler(self, qemu, addr, func_name, silent=False): 83 | self.silent[addr] = silent 84 | self.func_names[addr] = func_name 85 | return SkipFunc.skip 86 | 87 | @bp_handler 88 | def skip(self, qemu, addr): 89 | ''' 90 | Just return 91 | ''' 92 | if not self.silent[addr]: 93 | hal_log.info("SkipFunc: %s " %(self.func_names[addr])) 94 | return True, None -------------------------------------------------------------------------------- /src/halucinator/bp_handlers/generic/counter.py: -------------------------------------------------------------------------------- 1 | # Copyright 2019 National Technology & Engineering Solutions of Sandia, LLC (NTESS). 2 | # Under the terms of Contract DE-NA0003525 with NTESS, the U.S. Government retains 3 | # certain rights in this software. 4 | 5 | import re 6 | from binascii import hexlify 7 | from os import path 8 | import sys 9 | from ..bp_handler import BPHandler, bp_handler 10 | 11 | # sys.path.insert(0,path.dirname(path.dirname(path.abspath(__file__)))) 12 | 13 | 14 | class Counter(BPHandler): 15 | ''' 16 | Returns an increasing value for each addresss accessed 17 | 18 | Halucinator configuration usage: 19 | - class: halucinator.bp_handlers.Counter 20 | function: (Can be anything) 21 | addr: 22 | registration_args:{increment:1} (Optional) 23 | ''' 24 | 25 | def __init__(self): 26 | self.increment = {} 27 | self.counts = {} 28 | 29 | def register_handler(self, qemu, addr, func_name, increment=1): 30 | ''' 31 | 32 | ''' 33 | self.increment[addr] = increment 34 | self.counts[addr] = 0 35 | 36 | return Counter.get_value 37 | 38 | @bp_handler 39 | def get_value(self, qemu, addr): 40 | ''' 41 | Gets the counter value 42 | ''' 43 | self.counts[addr] += self.increment[addr] 44 | return True, self.counts[addr] 45 | -------------------------------------------------------------------------------- /src/halucinator/bp_handlers/generic/timer.py: -------------------------------------------------------------------------------- 1 | # Copyright 2019 National Technology & Engineering Solutions of Sandia, LLC (NTESS). 2 | # Under the terms of Contract DE-NA0003525 with NTESS, the U.S. Government retains 3 | # certain rights in this software. 4 | 5 | import re 6 | from binascii import hexlify 7 | from os import path 8 | import sys 9 | from ..bp_handler import BPHandler, bp_handler 10 | import time 11 | import logging 12 | log = logging.getLogger(__name__) 13 | # log.setLevel(logging.DEBUG) 14 | # sys.path.insert(0,path.dirname(path.dirname(path.abspath(__file__)))) 15 | 16 | 17 | class Timer(BPHandler): 18 | ''' 19 | Returns an increasing value based of host system time 20 | 21 | - class: halucinator.bp_handlers.Timer 22 | function: (Can be anything) 23 | registration_args: { scale:(value)} (Optional) 24 | addr: 25 | ''' 26 | 27 | def __init__(self): 28 | self.start_time = {} 29 | self.scale = {} 30 | 31 | def register_handler(self, qemu, addr, func_name, scale=1): 32 | ''' 33 | 34 | ''' 35 | self.start_time[addr] = time.time() 36 | self.scale[addr] = scale 37 | 38 | return Timer.get_value 39 | 40 | @bp_handler 41 | def get_value(self, qemu, addr): 42 | ''' 43 | Gets the current timer value 44 | ''' 45 | time_ms = int( 46 | (time.time() - self.start_time[addr]) * 1000 / float(self.scale[addr])) 47 | log.info("Time: %i" % time_ms) 48 | 49 | return True, time_ms 50 | -------------------------------------------------------------------------------- /src/halucinator/bp_handlers/mbed/__init__.py: -------------------------------------------------------------------------------- 1 | from .boot import MbedBoot 2 | from .serial import MbedUART 3 | from .timer import MbedTimer 4 | -------------------------------------------------------------------------------- /src/halucinator/bp_handlers/mbed/boot.py: -------------------------------------------------------------------------------- 1 | # Copyright 2019 National Technology & Engineering Solutions of Sandia, LLC (NTESS). 2 | # Under the terms of Contract DE-NA0003525 with NTESS, the U.S. Government retains 3 | # certain rights in this software. 4 | 5 | from ..bp_handler import BPHandler, bp_handler 6 | import logging 7 | log = logging.getLogger(__name__) 8 | 9 | 10 | class MbedBoot(BPHandler): 11 | 12 | def __init__(self, impl=None): 13 | BPHandler.__init__(self) 14 | 15 | @bp_handler(['SystemInit']) 16 | def SystemInit(self, qemu, bp_addr): 17 | log.info("MBED System") 18 | log.info("LR: %s" % hex(qemu.regs.lr)) 19 | # Do nothing, at all 20 | return True, None 21 | 22 | @bp_handler(['mbed_sdk_init']) 23 | def mbed_sdk_init(self, qemu, bp_addr): 24 | log.info("mbed_sdk_init") 25 | # ...you don't need to do that 26 | return True, None 27 | 28 | @bp_handler(['software_init_hook']) 29 | def software_init_hook(self, qemu, bp_addr): 30 | log.info("software_init_hook") 31 | # Nope. 32 | return True, 0 33 | 34 | @bp_handler(['software_init_hook_rtos']) 35 | def software_init_hook_rtos(self, qemu, bp_addr): 36 | log.info("software_init_hook_rtos") 37 | # Not even once 38 | return True, 0 39 | -------------------------------------------------------------------------------- /src/halucinator/bp_handlers/mbed/serial.py: -------------------------------------------------------------------------------- 1 | # Copyright 2019 National Technology & Engineering Solutions of Sandia, LLC (NTESS). 2 | # Under the terms of Contract DE-NA0003525 with NTESS, the U.S. Government retains 3 | # certain rights in this software. 4 | 5 | from ...peripheral_models.uart import UARTPublisher 6 | from ..bp_handler import BPHandler, bp_handler 7 | import logging 8 | log = logging.getLogger(__name__) 9 | 10 | 11 | class MbedUART(BPHandler): 12 | 13 | def __init__(self, impl=UARTPublisher): 14 | self.model = impl 15 | 16 | @bp_handler(['_ZN4mbed6Stream4getcEv']) 17 | def getc(self, qemu, bp_addr): 18 | param0 = qemu.regs.r0 19 | param1 = qemu.regs.r1 20 | # TODO: param0 is the 'this'pointer, use it get hw address of UART 21 | # just using the this pointer will make this change per firmware 22 | ret = self.model.read(param0, 1, block=True)[0] 23 | intercept = True 24 | return intercept, ord(ret) 25 | 26 | @bp_handler(['_ZN4mbed6Stream4putcEv', '_ZN4mbed6Serial5_putcEi']) 27 | def putc(self, qemu, bp_addr): 28 | param0 = qemu.regs.r0 29 | param1 = qemu.regs.r1 30 | log.info("Mbed Putc") 31 | # TODO: param0 is the 'this'pointer, use it to index the UARTs 32 | chars = chr(param1) 33 | 34 | ret = self.model.write(param0, chars) 35 | intercept = True 36 | return intercept, 1 37 | 38 | @bp_handler(['_ZN4mbed6Stream4putsEPKc']) 39 | def puts(self, qemu, bp_addr): 40 | log.info("Mbed Puts") 41 | param0 = qemu.regs.r0 42 | param1 = qemu.regs.r1 43 | # TODO: param0 is the 'this'pointer, use it to index the UARTs 44 | chars = [] # write is expecting an iterable 45 | chars.append(qemu.read_memory(param1, 1, 1)) 46 | while chars[-1] != '\x00': 47 | chars.append(qemu.read_memory(param1, 1, 1)) 48 | self.model.write(param0, chars) 49 | intercept = True 50 | return intercept, len(chars) 51 | -------------------------------------------------------------------------------- /src/halucinator/bp_handlers/mbed/timer.py: -------------------------------------------------------------------------------- 1 | # Copyright 2019 National Technology & Engineering Solutions of Sandia, LLC (NTESS). 2 | # Under the terms of Contract DE-NA0003525 with NTESS, the U.S. Government retains 3 | # certain rights in this software. 4 | 5 | from time import sleep 6 | from ..bp_handler import BPHandler, bp_handler 7 | import struct 8 | import logging 9 | log = logging.getLogger(__name__) 10 | 11 | 12 | class MbedTimer(BPHandler): 13 | 14 | def __init__(self, impl=None): 15 | pass 16 | 17 | @bp_handler(['wait']) 18 | def wait(self, qemu, bp_addr): 19 | log.info("MBed Wait") 20 | param0 = qemu.regs.r0 # a floating point value 21 | value = struct.pack(" 0: 71 | log.info("Returning frame") 72 | frame = cls.frame_queue.popleft() 73 | rx_time = cls.frame_time.popleft() 74 | 75 | if get_time: 76 | return frame, rx_time 77 | else: 78 | return frame 79 | 80 | @classmethod 81 | def has_frame(cls): 82 | return len(cls.frame_queue) > 0 83 | 84 | @classmethod 85 | def get_frame_info(cls): 86 | ''' 87 | return number of frames and length of first frame 88 | ''' 89 | queue = cls.frame_queue 90 | if queue: 91 | return len(queue), len(queue[0]) 92 | return 0, 0 93 | -------------------------------------------------------------------------------- /src/halucinator/peripheral_models/interrupts.py: -------------------------------------------------------------------------------- 1 | # Copyright 2019 National Technology & Engineering Solutions of Sandia, LLC (NTESS). 2 | # Under the terms of Contract DE-NA0003525 with NTESS, the U.S. Government retains 3 | # certain rights in this software. 4 | 5 | from . import peripheral_server 6 | from collections import deque, defaultdict 7 | import logging 8 | log = logging.getLogger(__name__) 9 | # log.setLevel(logging.DEBUG) 10 | 11 | 12 | # Register the pub/sub calls and methods that need mapped 13 | @peripheral_server.peripheral_model 14 | class Interrupts(object): 15 | ''' 16 | Models and external interrupt controller 17 | Use when need to trigger and interrupt and need additional state 18 | about it 19 | ''' 20 | Active_Interrupts = defaultdict(bool) 21 | 22 | @classmethod 23 | @peripheral_server.reg_rx_handler 24 | def interrupt_request(cls, msg): 25 | log.info("Int Request: %s" % str(msg)) 26 | isr_num = msg['num'] 27 | source = msg['source'] if 'source' in msg else None 28 | cls.trigger_interrupt(isr_num, source) 29 | 30 | @classmethod 31 | def trigger_interrupt(cls, isr_num, source=None): 32 | if source is not None: 33 | cls.set_active(source) 34 | log.info("Triggering Interrupt: %i" % isr_num) 35 | peripheral_server.trigger_interrupt(isr_num) 36 | 37 | @classmethod 38 | def set_active(cls, key): 39 | log.debug("Set Active: %s" % str(key)) 40 | cls.Active_Interrupts[key] = True 41 | 42 | @classmethod 43 | def clear_active(cls, key): 44 | log.debug("Clear Active: %s" % str(key)) 45 | cls.Active_Interrupts[key] = False 46 | 47 | @classmethod 48 | def is_active(cls, key): 49 | log.debug("Is Active: %s" % str(key)) 50 | return cls.Active_Interrupts[key] 51 | -------------------------------------------------------------------------------- /src/halucinator/peripheral_models/peripheral.py: -------------------------------------------------------------------------------- 1 | # Copyright 2019 National Technology & Engineering Solutions of Sandia, LLC (NTESS). 2 | # Under the terms of Contract DE-NA0003525 with NTESS, the U.S. Government retains 3 | # certain rights in this software. 4 | 5 | import struct 6 | from functools import wraps 7 | import re 8 | from binascii import hexlify 9 | 10 | 11 | def requires_tx_map(method): 12 | ''' 13 | Decorator which register class methods as requiring a tx map 14 | ''' 15 | method.req_tx_map = True 16 | return method 17 | 18 | 19 | def requires_rx_map(method): 20 | ''' 21 | Decorator which register class methods as requiring a rx map 22 | ''' 23 | method.req_rx_map = True 24 | return method 25 | 26 | 27 | def requires_interrupt_map(method): 28 | ''' 29 | Decorator which register class methods as requiring a interrupt map 30 | ''' 31 | method.req_interrupt_map = True 32 | return method 33 | -------------------------------------------------------------------------------- /src/halucinator/peripheral_models/sd_card.py: -------------------------------------------------------------------------------- 1 | # Copyright 2019 National Technology & Engineering Solutions of Sandia, LLC (NTESS). 2 | # Under the terms of Contract DE-NA0003525 with NTESS, the U.S. Government retains 3 | # certain rights in this software. 4 | 5 | from .peripheral import requires_tx_map, requires_rx_map, requires_interrupt_map 6 | from . import peripheral_server 7 | from collections import defaultdict 8 | import os 9 | import logging 10 | log = logging.getLogger(__name__) 11 | 12 | 13 | # Register the pub/sub calls and methods that need mapped 14 | # TODO Convert to class that can be instantiated with its parameters 15 | # without requiring every function to be a classmethod 16 | @peripheral_server.peripheral_model 17 | class SDCardModel(object): 18 | STATES = {'READY': 1} 19 | BLOCK_SIZE = {} 20 | filename = {} 21 | 22 | @classmethod 23 | def set_config(cls, sd_id, filename, block_size): 24 | cls.BLOCK_SIZE[sd_id] = 0x200 25 | if filename is not None: 26 | if peripheral_server.base_dir is not None: 27 | log.info("Setting File name using output dir") 28 | cls.filename[sd_id] = os.path.join( 29 | peripheral_server.base_dir, filename) 30 | else: 31 | log.info("No output found dir") 32 | cls.filename[sd_id] = filename 33 | 34 | @classmethod 35 | def get_filename(cls, sd_id): 36 | if sd_id not in cls.filename: 37 | if peripheral_server.base_dir is not None: 38 | cls.filename[sd_id] = os.path.join( 39 | peripheral_server.base_dir, "sd_card_%s.bin" % str(sd_id)) 40 | else: 41 | cls.filename[sd_id] = "sd_card_%s.bin" % str(sd_id) 42 | 43 | return cls.filename[sd_id] 44 | 45 | @classmethod 46 | def read_block(cls, sd_id, block_num): 47 | ''' 48 | Reads data from the file, and returns the data if possible 49 | return None 50 | ''' 51 | data = None 52 | with open(cls.get_filename(sd_id), 'rb') as f: 53 | addr = block_num * SDCardModel.BLOCK_SIZE[sd_id] 54 | log.info("SDCardModle Reading: %s" % hex(addr)) 55 | f.seek(addr) 56 | data = f.read(SDCardModel.BLOCK_SIZE[sd_id]) 57 | return data 58 | 59 | @classmethod 60 | @requires_tx_map 61 | def write_block(cls, sd_id, block_num, data): 62 | ''' 63 | Writes the data to a file, and returns True if no errors else 64 | return False 65 | ''' 66 | filename = cls.get_filename(sd_id) 67 | if not os.path.exists(filename): 68 | with open(filename, 'wb') as f: 69 | pass # Create the file 70 | with open(filename, 'rb+') as f: 71 | addr = block_num * SDCardModel.BLOCK_SIZE[sd_id] 72 | log.info("SDCardModle Writeing: %s" % hex(addr)) 73 | f.seek(addr) 74 | f.write(data) 75 | return True 76 | return False 77 | 78 | @classmethod 79 | def get_block_size(cls, sd_id): 80 | return SDCardModel.BLOCK_SIZE[sd_id] 81 | 82 | @classmethod 83 | @requires_rx_map 84 | def get_state(cls, sd_id): 85 | return SDCardModel.STATES['Ready'] 86 | -------------------------------------------------------------------------------- /src/halucinator/peripheral_models/spi.py: -------------------------------------------------------------------------------- 1 | # Copyright 2018 National Technology & Engineering Solutions of Sandia, LLC 2 | # (NTESS). Under the terms of Contract DE-NA0003525 with NTESS, the U.S. 3 | # Government retains certain rights in this software. 4 | 5 | 6 | from . import peripheral_server 7 | # from queue import Queue 8 | from threading import Event, Thread 9 | from collections import deque, defaultdict 10 | import sys 11 | import logging 12 | from itertools import repeat 13 | import time 14 | 15 | log = logging.getLogger(__name__) 16 | 17 | class UARTModel(object): 18 | 19 | def __init__(self): 20 | self.tx_buffer = deque() 21 | self.rx_buffer = deque() 22 | 23 | def read(self, count, blocking=True): 24 | log.info("Reading %d bytes" % count) 25 | out = b"" 26 | if self.rx_buffer: 27 | while True: 28 | data_pkt = self.rx_buffer.pop() 29 | l += min(len(data_pkt), count - bytes_read) 30 | out += data_pkt[:l] 31 | if l < len(data_pkt): 32 | leftover = data_pkt[l:] 33 | self.rx_buffer.appendleft(leftover) 34 | if bytes_read == count: 35 | break 36 | return out 37 | 38 | def write(self, data): 39 | log.info("Writing %d bytes" % len(data)) 40 | self.tx_buffer.append(data) 41 | 42 | def tx_empty(self): 43 | return self.tx_buffer.empty() 44 | 45 | def rx_empty(self): 46 | return self.rx_buffer.empty() 47 | 48 | 49 | # Register the pub/sub calls and methods that need mapped 50 | @peripheral_server.peripheral_model 51 | class SPIPublisher(object): 52 | rx_buffers = defaultdict(deque) 53 | 54 | @classmethod 55 | @peripheral_server.tx_msg 56 | def write(cls, spi_id, chars): 57 | ''' 58 | Publishes the data to sub/pub server 59 | ''' 60 | log.debug("In: SPIPublisher.write") 61 | msg = {'id': uart_id, 'chars': chars} 62 | return msg 63 | 64 | @classmethod 65 | def read(cls, spi_id, count=1, block=False): 66 | ''' 67 | Gets data previously received from the sub/pub server 68 | Args: 69 | spi_id: A unique id for the spi 70 | count: Max number of chars to read 71 | block(bool): Block if data is not available 72 | ''' 73 | log.debug("In: SPIPublisher.read id:%s count:%i, block:%s" % 74 | (hex(spi_id), count, str(block))) 75 | while block and (len(cls.rx_buffers[spi_id]) < count): 76 | pass 77 | log.debug("Done Blocking: SPIPublisher.read") 78 | buffer = cls.rx_buffers[spi_id] 79 | chars_available = len(buffer) 80 | if chars_available >= count: 81 | chars = list(map(apply, repeat(buffer.popleft, count))) 82 | chars = ''.join(chars) 83 | else: 84 | chars = list(map(apply, repeat(buffer.popleft, chars_available))) 85 | chars = ''.join(chars) 86 | 87 | return chars 88 | 89 | @classmethod 90 | @peripheral_server.reg_rx_handler 91 | def rx_data(cls, msg): 92 | ''' 93 | Handles reception of these messages from the PeripheralServer 94 | ''' 95 | log.debug("SPI rx_data got message: %s" % str(msg)) 96 | spi_id = msg['id'] 97 | data = msg['chars'] 98 | cls.rx_buffers[spi_id].extend(data) -------------------------------------------------------------------------------- /src/halucinator/peripheral_models/tcp_stack.py: -------------------------------------------------------------------------------- 1 | # Copyright 2019 National Technology & Engineering Solutions of Sandia, LLC (NTESS). 2 | # Under the terms of Contract DE-NA0003525 with NTESS, the U.S. Government retains 3 | # certain rights in this software. 4 | 5 | from . import peripheral_server 6 | # from peripheral_server import PeripheralServer, peripheral_model 7 | from collections import deque, defaultdict 8 | from .interrupts import Interrupts 9 | import binascii 10 | import struct 11 | import logging 12 | import time 13 | from threading import Thread, Event 14 | import socket 15 | log = logging.getLogger(__name__) 16 | 17 | # @peripheral_server.peripheral_model # Register the pub/sub calls and methods that need mapped 18 | 19 | 20 | class TCPModel(Thread): 21 | sock = None 22 | conn = None 23 | 24 | def __init__(self, *args, **kwargs): 25 | self.packet_queue = deque() 26 | self.packet_times = deque() # Used to record reception time 27 | self.port = None 28 | self.sock = None 29 | self._shutdown = Event() 30 | Thread.__init__(self, *args, **kwargs) 31 | 32 | def listen(self, port): 33 | self.port = port 34 | self.start() 35 | 36 | def run(self): 37 | # Receive thread 38 | log.warn("TCP Listen thread started, port %d" % self.port) 39 | self.sock = socket.socket() 40 | self.sock.bind(('0.0.0.0', self.port)) 41 | self.sock.listen(5) 42 | while not self._shutdown.is_set(): 43 | conn, addr = self.sock.accept() 44 | self.conn = conn 45 | log.info("Received connection from %s on port %d" % 46 | (repr(addr), self.port)) 47 | try: 48 | data = conn.recv(1500) 49 | while data: 50 | self.packet_queue.append(data) 51 | data = conn.recv(1500) 52 | except: 53 | log.exception("Error reading data from client") 54 | finally: 55 | if conn: 56 | conn.close() 57 | self.conn = None 58 | log.info("Listen thread shutting down") 59 | 60 | def tx_packet(self, payload): 61 | ''' 62 | Creates the message that Peripheral.tx_msgs will send on this 63 | event 64 | ''' 65 | log.info("TCP: Sending %s" % payload) 66 | 67 | if self.conn is None: 68 | l.critical("Trying to send data when there's no connected client!") 69 | else: 70 | self.conn.send(payload) 71 | #msg = {'port': port, 'payload': payload} 72 | # return msg 73 | 74 | def get_rx_packet(self): 75 | if self.packet_queue: 76 | log.info("TCP: Returning frame") 77 | pkt = self.packet_queue.popleft() 78 | return pkt 79 | else: 80 | log.info("TCP: No data to return") 81 | return None 82 | -------------------------------------------------------------------------------- /src/halucinator/peripheral_models/timer_model.py: -------------------------------------------------------------------------------- 1 | # Copyright 2019 National Technology & Engineering Solutions of Sandia, LLC (NTESS). 2 | # Under the terms of Contract DE-NA0003525 with NTESS, the U.S. Government retains 3 | # certain rights in this software. 4 | 5 | from . import peripheral_server 6 | from collections import deque, defaultdict 7 | from .interrupts import Interrupts 8 | from threading import Thread, Event 9 | import logging 10 | import time 11 | log = logging.getLogger(__name__) 12 | 13 | 14 | 15 | # Register the pub/sub calls and methods that need mapped 16 | @peripheral_server.peripheral_model 17 | class TimerModel(object): 18 | 19 | active_timers = {} 20 | @classmethod 21 | def start_timer(cls, name, isr_num, rate): 22 | log.info("Starting timer: %s" % name) 23 | if name not in cls.active_timers: 24 | stop_event = Event() 25 | t = TimerIRQ(stop_event, name, isr_num, rate) 26 | cls.active_timers[name] = (stop_event, t) 27 | t.start() 28 | 29 | @classmethod 30 | def stop_timer(cls, name): 31 | if name in cls.active_timers: 32 | (stop_event, t) = cls.active_timers[name] 33 | stop_event.set() 34 | 35 | @classmethod 36 | def clear_timer(cls, irq_name): 37 | # cls.stop_timer(name) 38 | Interrupts.clear_active(irq_name) 39 | 40 | @classmethod 41 | def shutdown(cls): 42 | for key, (stop_event, t) in list(cls.active_timers.items()): 43 | stop_event.set() 44 | 45 | 46 | class TimerIRQ(Thread): 47 | def __init__(self, event, irq_name, irq_num, rate): 48 | Thread.__init__(self) 49 | self.stopped = event 50 | self.name = irq_name 51 | self.irq_num = irq_num 52 | self.rate = rate 53 | 54 | def run(self): 55 | while not self.stopped.wait(self.rate): 56 | log.info("Sending IRQ: %s" % self.irq_num) 57 | Interrupts.set_active(self.name) 58 | Interrupts.trigger_interrupt(self.irq_num) 59 | # call a function 60 | -------------------------------------------------------------------------------- /src/halucinator/qemu_targets/__init__.py: -------------------------------------------------------------------------------- 1 | from .arm_qemu import ARMQemuTarget 2 | from .armv7m_qemu import ARMv7mQemuTarget 3 | -------------------------------------------------------------------------------- /src/halucinator/qemu_targets/arm_qemu.py: -------------------------------------------------------------------------------- 1 | # Copyright 2020 National Technology & Engineering Solutions of Sandia, LLC (NTESS). 2 | # Under the terms of Contract DE-NA0003525 with NTESS, the U.S. Government retains 3 | # certain rights in this software. 4 | 5 | 6 | from avatar2 import Avatar, QemuTarget 7 | 8 | class ARMQemuTarget(QemuTarget): 9 | ''' 10 | Implements a QEMU target that has function args for use with 11 | halucinator. Enables read/writing and returning from 12 | functions in a calling convention aware manner 13 | ''' 14 | def __init__(self, *args, **kwargs): 15 | super().__init__(*args, **kwargs) 16 | 17 | def get_arg(self, idx): 18 | ''' 19 | Gets the value for a function argument (zero indexed) 20 | 21 | :param idx The argument index to return 22 | :returns Argument value 23 | ''' 24 | if idx >= 0 and idx < 4: 25 | return self.read_register("r%i" % idx) 26 | elif idx >= 4: 27 | sp = self.read_register("sp") 28 | stack_addr = sp + (idx-4) * 4 29 | return self.read_memory(stack_addr, 4, 1) 30 | else: 31 | raise ValueError("Invalid arg index") 32 | 33 | def set_arg(self, idx, value): 34 | ''' 35 | Sets the value for a function argument (zero indexed) 36 | 37 | 38 | :param idx The argument index to return 39 | :param value Value to set index to 40 | ''' 41 | if idx >= 0 and idx < 4: 42 | self.write_register("r%i" % idx, value) 43 | elif idx >= 4: 44 | sp = self.read_register("sp") 45 | stack_addr = sp + (idx-4) * 4 46 | self.write_memory(stack_addr, 4, value) 47 | else: 48 | raise ValueError(idx) 49 | 50 | def get_ret_addr(self): 51 | ''' 52 | Gets the return address for the function call 53 | 54 | :returns Return address of the function call 55 | ''' 56 | return self.regs.lr 57 | 58 | def set_ret_addr(self, ret_addr): 59 | ''' 60 | Sets the return address for the function call 61 | :param ret_addr Value for return address 62 | ''' 63 | self.regs.lr = ret_addr 64 | 65 | def execute_return(self, ret_value): 66 | if ret_value != None: 67 | # Puts ret value in r0 68 | self.regs.r0 = ret_value 69 | self.regs.pc = self.regs.lr 70 | 71 | 72 | 73 | 74 | def irq_set(self, irq_num=1, cpu=0): 75 | self.protocols.monitor.execute_command("avatar-set-irq", 76 | args={"cpu_num":cpu, "irq_num": irq_num, "value":1}) 77 | 78 | def irq_clear(self, irq_num=1, cpu=0): 79 | self.protocols.monitor.execute_command("avatar-set-irq", 80 | args={"cpu_num":cpu, "irq_num": irq_num, "value":0}) 81 | 82 | def irq_pulse(self, irq_num=1, cpu=0): 83 | self.protocols.monitor.execute_command("avatar-set-irq", 84 | args={"cpu_num":cpu, "irq_num": irq_num, "value":3}) 85 | 86 | 87 | def get_symbol_name(self, addr): 88 | """ 89 | Get the symbol for an address 90 | 91 | :param addr: The name of a symbol whose address is wanted 92 | :returns: (Symbol name on success else None 93 | """ 94 | 95 | return self.avatar.config.get_symbol_name(addr) -------------------------------------------------------------------------------- /src/halucinator/qemu_targets/armv7m_qemu.py: -------------------------------------------------------------------------------- 1 | from .arm_qemu import ARMQemuTarget 2 | 3 | class ARMv7mQemuTarget(ARMQemuTarget): 4 | 5 | def trigger_interrupt(self, interrupt_number, cpu_number=0): 6 | self.protocols.monitor.execute_command( 7 | 'avatar-armv7m-inject-irq', 8 | {'num_irq': interrupt_number, 'num_cpu': cpu_number}) 9 | 10 | def set_vector_table_base(self, base, cpu_number=0): 11 | self.protocols.monitor.execute_command( 12 | 'avatar-armv7m-set-vector-table-base', 13 | {'base': base, 'num_cpu': cpu_number}) 14 | 15 | def enable_interrupt(self, interrupt_number, cpu_number=0): 16 | self.protocols.monitor.execute_command( 17 | 'avatar-armv7m-enable-irq', 18 | {'num_irq': interrupt_number, 'num_cpu': cpu_number}) 19 | 20 | -------------------------------------------------------------------------------- /src/halucinator/util/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/embedded-sec/halucinator/fa85a1dcbaaa72bd425094fc3917abdd7d9b9a8a/src/halucinator/util/__init__.py -------------------------------------------------------------------------------- /src/halucinator/util/cortex_m_helpers.py: -------------------------------------------------------------------------------- 1 | # Copyright 2019 National Technology & Engineering Solutions of Sandia, LLC (NTESS). 2 | # Under the terms of Contract DE-NA0003525 with NTESS, the U.S. Government retains 3 | # certain rights in this software. 4 | 5 | 6 | from struct import unpack 7 | 8 | 9 | def get_sp_and_entry(binary_filename): 10 | ''' 11 | Gets the initial stack pointer and entry point from the filename 12 | It assumes the passed file is loaded/aliased to address 0x00000000 13 | Args: 14 | binary_filename(string): path to file to open, assumes binary format 15 | 16 | Returns: 17 | sp(int), entry(int): Stack pointer and entry point of board 18 | ''' 19 | with open(binary_filename, 'rb') as bin_file: 20 | sp, entry = unpack('', 48 | os.path.split(firmware)[-1] + '.bin') 49 | mapped_intercepts = get_addr_for_intercepts(intercepts, firmware) 50 | config['intercepts'] = mapped_intercepts 51 | return config 52 | 53 | 54 | if __name__ == '__main__': 55 | from argparse import ArgumentParser 56 | p = ArgumentParser() 57 | p.add_argument('-f', '--firmware', required=True, 58 | help='firmware') 59 | p.add_argument('-m', '--memories', required=True, 60 | help='Memory description for device') 61 | p.add_argument('-i', '--intercepts', required=True, 62 | help='Mapping of intercepts functions to intercept classes') 63 | p.add_argument('-c', '--config', 64 | help='Output config file (.yaml) if not provided firmware' + 65 | 'name append with _config.yaml') 66 | p.add_argument('--ivt', type=int, default=0, 67 | help='Interrupt vector table offset (used to get entry, and sp') 68 | 69 | args = p.parse_args() 70 | 71 | with open(args.memories, 'rb') as mem_file: 72 | memories = yaml.load(mem_file) 73 | 74 | with open(args.intercepts, 'rb') as int_file: 75 | intercepts = yaml.load(int_file) 76 | 77 | config = get_emulator_config(memories, intercepts, args.firmware) 78 | 79 | if args.config == None: 80 | config_file = os.path.splitext(args.firmware)[0] + "_config.yaml" 81 | else: 82 | config_file = args.config 83 | with open(config_file, 'wb') as outfile: 84 | yaml.safe_dump(config, outfile) 85 | -------------------------------------------------------------------------------- /src/tools/gen_blinky_config.py: -------------------------------------------------------------------------------- 1 | # Copyright 2019 National Technology & Engineering Solutions of Sandia, LLC (NTESS). 2 | # Under the terms of Contract DE-NA0003525 with NTESS, the U.S. Government retains 3 | # certain rights in this software. 4 | 5 | 6 | ''' 7 | This file is primarily illustrate how to generate the config file 8 | that should be run with emulate_binary.py 9 | 10 | It generates a config for Nucleo15_Blinky 11 | ''' 12 | import hexyaml 13 | import yaml 14 | 15 | 16 | def get_memories(): 17 | ''' 18 | Memories have the following form 19 | 'name': { 20 | 'base_addr': required 21 | 'size': required 22 | 'permissions': optional if provided must one of [r--, rw-, rwx], 23 | 'emulate': optional must be class in src/peripheral_emulators 24 | 'file': optional abs path, or relative to this config file 25 | } 26 | ''' 27 | memories = {} 28 | memories['flash'] = {'file': 'STM32CubeL1_Blinky.bin', 29 | 'permissions': 'r-x', 30 | 'base_addr': 0x08000000, 31 | 'size': 0x1000000, 32 | 'name': 'flash'} 33 | 34 | memories['alias'] = {'file': 'STM32CubeL1_Blinky.bin', 35 | 'permissions': 'r-x', 36 | 'base_addr': 0x00000000, 37 | 'size': 0x1000000, 38 | 'name': 'alias'} 39 | 40 | memories['ram'] = {'base_addr': 0x20000000, 41 | 'size': 0x14000, 42 | 'name': 'ram'} 43 | 44 | return memories 45 | 46 | 47 | def get_peripherals(): 48 | peripherals = { 49 | 'logger': { 50 | 'permissions': 'rw-', 51 | 'emulate': 'GenericPeripheral', 52 | 'base_addr': 0x40000000, 53 | 'size': 0x20000000, 54 | 'name': 'peripherals' 55 | } 56 | } 57 | 58 | return peripherals 59 | 60 | 61 | def get_intercepts(): 62 | ''' 63 | Intercepts have the following form 64 | { 65 | 'class': required 66 | 'addr': required (address to intercept), 67 | 'function': required, 68 | 'class_args': {} 69 | } 70 | ''' 71 | SysInit = {'class': 'VoidIntercept', 72 | 'addr': 0x80001a8, 73 | 'function': 'SystemInit', 74 | 'class_args': None 75 | } 76 | 77 | SystemClock_Config = {'class': 'VoidIntercept', 78 | 'addr': 0x80002dc, 79 | 'function': 'SystemClock_Config', 80 | 'class_args': None 81 | } 82 | 83 | DelayIntercept = {'class': 'DelayIntercept', 84 | 'addr': 0x800020c, 85 | 'function': 'LL_mDelay', 86 | 'class_args': None 87 | } 88 | 89 | return [SysInit, SystemClock_Config, DelayIntercept] 90 | 91 | 92 | def main(config_file): 93 | 94 | config = {'init_memory': 'flash', 95 | 'memories': get_memories(), 96 | 'peripherals': get_peripherals(), 97 | 'intercepts': get_intercepts()} 98 | 99 | with open(config_file, 'wb') as outfile: 100 | yaml.dump(config, outfile, indent=4) 101 | 102 | 103 | if __name__ == '__main__': 104 | from argparse import ArgumentParser 105 | p = ArgumentParser() 106 | p.add_argument("-c", '--config', type=str, 107 | help="Output name for config file (.yaml)") 108 | args = p.parse_args() 109 | main(args.config) 110 | -------------------------------------------------------------------------------- /src/tools/json2yaml.py: -------------------------------------------------------------------------------- 1 | # Copyright 2019 National Technology & Engineering Solutions of Sandia, LLC (NTESS). 2 | # Under the terms of Contract DE-NA0003525 with NTESS, the U.S. Government retains 3 | # certain rights in this software. 4 | 5 | import json 6 | import yaml 7 | import hexyaml 8 | import os 9 | 10 | 11 | def json2yaml(json_file): 12 | yaml_file = os.path.splitext(json_file)[0] + '.yaml' 13 | with open(json_file, 'rb') as jfile: 14 | with open(yaml_file, 'wb') as yfile: 15 | yaml.safe_dump(json.load(jfile), yfile, allow_unicode=True) 16 | 17 | 18 | if __name__ == '__main__': 19 | from argparse import ArgumentParser 20 | p = ArgumentParser() 21 | p.add_argument('-i', dest='in_file', required=True, 22 | help='Json file to convert') 23 | args = p.parse_args() 24 | json2yaml(args.in_file) 25 | -------------------------------------------------------------------------------- /src/tools/make_bin.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Copyright 2018 National Technology & Engineering Solutions of Sandia, LLC 3 | # (NTESS). Under the terms of Contract DE-NA0003525 with NTESS, the U.S. 4 | # Government retains certain rights in this software. 5 | 6 | 7 | 8 | arm-none-eabi-objcopy -O binary ${1} ${1}.bin -------------------------------------------------------------------------------- /src/tools/qemu_to_trace.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | 3 | import argparse 4 | import os 5 | 6 | def main(): 7 | parser = argparse.ArgumentParser() 8 | parser.add_argument("logfile", help="qemu log file containing block trace") 9 | parser.add_argument("-o", dest='file', default=None, 10 | help="FILE: File to write trace to should have .addrlist extension") 11 | args = parser.parse_args() 12 | 13 | with open(args.logfile, 'r') as fin: 14 | addrs = list() 15 | while True: 16 | line = fin.readline() 17 | if not line: 18 | break 19 | if line == 'IN: \n': 20 | line = fin.readline() 21 | if line.startswith('0x'): 22 | pair = [int(line.split()[0][2:-1], 16), int(line.split()[0][2:-1], 16)] 23 | while True: 24 | line = fin.readline() 25 | if line == '\n': 26 | break 27 | if line.startswith('0x'): 28 | pair[1] = int(line.split()[0][2:-1], 16) 29 | addrs.append(pair) 30 | if args.file == None: 31 | args.file = os.path.splitext(args.logfile)[0] +'.addrlist' 32 | with open(args.file, 'w') as fout: 33 | fout.write('{}'.format('\n'.join('[{}]'.format(', '.join(format(x, '08x') for x in pair)) for pair in addrs))) 34 | 35 | 36 | if __name__ == "__main__": 37 | main() 38 | -------------------------------------------------------------------------------- /src/tools/result_collection/py_code_stats.py: -------------------------------------------------------------------------------- 1 | # Copyright 2019 National Technology & Engineering Solutions of Sandia, LLC (NTESS). 2 | # Under the terms of Contract DE-NA0003525 with NTESS, the U.S. Government retains 3 | # certain rights in this software. 4 | 5 | import radon 6 | from radon.cli import Config 7 | import radon.complexity as cc_mod 8 | from radon.cli.harvest import CCHarvester, RawHarvester 9 | import math 10 | import numpy as np 11 | from tabulate import tabulate 12 | import csv 13 | 14 | cc_config = Config( 15 | order=getattr(cc_mod, 'SCORE'), 16 | no_assert=False, 17 | min='A', 18 | max='F', 19 | show_complexity=True, 20 | show_closures=False, 21 | average=True, 22 | total_average=False, 23 | exclude=['*.pyc'], 24 | ignore=[""] 25 | ) 26 | 27 | 28 | def get_stats(paths): 29 | cc = CCHarvester(paths, cc_config) 30 | raw = RawHarvester(paths, cc_config) 31 | cc.run() 32 | raw.run() 33 | 34 | header = ['Filename', "SLOC", '#Functions', '#Intercepts', 'Max CC', 35 | 'Ave CC', 'Median CC', 'Min CC'] 36 | data = {} 37 | for file_data in cc.results: 38 | filename, cc_results = file_data 39 | complexity = [x.complexity for x in cc_results if hasattr( 40 | x, 'is_method') and x.is_method] 41 | if len(complexity) > 0: 42 | print("Getting Complexity for:", filename) 43 | data[filename] = {} 44 | data[filename]['Filename'] = filename 45 | data[filename]['Max CC'] = max(complexity) 46 | data[filename]['Min CC'] = min(complexity) 47 | data[filename]['Med CC'] = np.median(complexity) 48 | data[filename]['Ave CC'] = np.mean(complexity) 49 | data[filename]['#Functions'] = len(complexity) 50 | else: 51 | print("Skipping ", filename) 52 | 53 | for file_data in raw.results: 54 | filename, results = file_data 55 | if filename in data: 56 | data[filename]['SLOC'] = results['sloc'] 57 | else: 58 | print("Skipping ", filename) 59 | 60 | return data 61 | 62 | 63 | def write_csv(data, header, outfile): 64 | with open(outfile, 'wb') as csv_out: 65 | writer = csv.writer(csv_out) 66 | writer.writerow(header) 67 | for row in data: 68 | writer.writerow(row) 69 | 70 | 71 | if __name__ == "__main__": 72 | from argparse import ArgumentParser 73 | p = ArgumentParser() 74 | p.add_argument("-p", "--paths", required=True, 75 | help="Paths to parse") 76 | p.add_argument("-o", "--outfile", default='static_stats.csv', 77 | help="File to save results to") 78 | 79 | args = p.parse_args() 80 | stats = get_stats(args.paths) 81 | 82 | headers = ['Filename', "SLOC", '#Functions', 'Max CC', 83 | 'Ave CC', 'Med CC', 'Min CC'] 84 | data = [] 85 | for filename, d in list(stats.items()): 86 | data.append([d[h] for h in headers]) # flip the code and name and sort 87 | print((tabulate(data, headers=headers))) 88 | write_csv(data, headers, args.outfile) 89 | -------------------------------------------------------------------------------- /symbol_browser: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | python -m halucinator.symbol_browser $@ 4 | -------------------------------------------------------------------------------- /test/SAMR21/HTTP/BB_SAMR21_config_ksz.yaml: -------------------------------------------------------------------------------- 1 | 2 | intercepts: 3 | 4 | # --------------------------Debug -------------------------------------------- 5 | - class: halucinator.bp_handlers.generic.debug.IPythonShell 6 | function: HardFault_Handler 7 | - class: halucinator.bp_handlers.generic.debug.IPythonShell 8 | function: Dummy_Handler 9 | - class: halucinator.bp_handlers.generic.debug.IPythonShell 10 | function: SYSCTRL_Handler 11 | # - class: halucinator.bp_handlers.generic.debug.IPythonShell 12 | # function: EIC_Handler 13 | 14 | # ----------------------- Startup ------------------------------------------ 15 | 16 | - class: halucinator.bp_handlers.generic.armv7m_param_log.ARMv7MEABILogger 17 | registration_args: {ret_val: null} 18 | function: system_clock_init 19 | 20 | - class: halucinator.bp_handlers.generic.timer.Timer 21 | registration_args: { scale: 1 } 22 | function: sys_get_ms 23 | # ----------------------------------------------------------------------------- 24 | # ----------------------- EXT Interrupt---------------------------------------- 25 | # - class: halucinator.bp_handlers.atmel_asf_v3.ext_interrupt.EXT_Int 26 | # registration_args: { channel_map: {6: Ethernet_RX_Frame }} 27 | # function: EIC_Handler 28 | - class: halucinator.bp_handlers.atmel_asf_v3.ext_interrupt.EXT_Int 29 | registration_args: { channel_map: {6: Ethernet_RX_Frame }} 30 | function: extint_register_callback 31 | # ----------------------------------------------------------------------------- 32 | # ----------------------- USART ----------------------------------------------- 33 | - class: halucinator.bp_handlers.atmel_asf_v3.usart.USART 34 | function: usart_init 35 | - class: halucinator.bp_handlers.atmel_asf_v3.usart.USART 36 | function: usart_enable 37 | - class: halucinator.bp_handlers.atmel_asf_v3.usart.USART 38 | function: usart_write_buffer_wait 39 | - class: halucinator.bp_handlers.atmel_asf_v3.usart.USART 40 | function: usart_read_wait 41 | - class: halucinator.bp_handlers.atmel_asf_v3.usart.USART 42 | function: usart_write_wait 43 | # ---------------------------------------------------------------------------- 44 | # --------------------------ETHERNET ----------------------------------------- 45 | - class: halucinator.bp_handlers.atmel_asf_v3.ethernet_ksz8851.Ksz8851Eth 46 | function: ksz8851_reg_read 47 | - class: halucinator.bp_handlers.atmel_asf_v3.ethernet_ksz8851.Ksz8851Eth 48 | function: ksz8851_reg_write 49 | # - class: halucinator.bp_handlers.atmel_asf_v3.ethernet_ksz8851.Ksz8851Eth 50 | # function: ksz8851_fifo_clrbits 51 | # - class: halucinator.bp_handlers.atmel_asf_v3.ethernet_ksz8851.Ksz8851Eth 52 | # function: ksz8851_fifo_setbit 53 | - class: halucinator.bp_handlers.atmel_asf_v3.ethernet_ksz8851.Ksz8851Eth 54 | function: ksz8851_fifo_write_begin 55 | - class: halucinator.bp_handlers.atmel_asf_v3.ethernet_ksz8851.Ksz8851Eth 56 | function: ksz8851_fifo_write 57 | - class: halucinator.bp_handlers.atmel_asf_v3.ethernet_ksz8851.Ksz8851Eth 58 | function: ksz8851_fifo_write_end 59 | - class: halucinator.bp_handlers.atmel_asf_v3.ethernet_ksz8851.Ksz8851Eth 60 | function: ksz8851_fifo_read 61 | # - class: halucinator.bp_handlers.atmel_asf_v3.ethernet_ksz8851.Ksz8851Eth 62 | # function: ksz8851snl_init 63 | - class: halucinator.bp_handlers.atmel_asf_v3.ethernet_ksz8851.Ksz8851Eth 64 | function: ksz8851snl_hard_reset 65 | - class: halucinator.bp_handlers.atmel_asf_v3.ethernet_ksz8851.Ksz8851Eth 66 | function: ksz8851snl_interface_init 67 | # ---------------------------------------------------------------------------- 68 | 69 | -------------------------------------------------------------------------------- /test/SAMR21/HTTP/BB_run_release_LWIP.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | 3 | source ~/.virtualenvs/halucinator/bin/activate 4 | ./halucinator -c=test/SAMR21/HTTP/BB_SAMR21_config_LWIP.yaml \ 5 | -a=test/SAMR21/HTTP/RELEASE_THIRDPARTY_LWIP_RAW_BASIC_HTTP_EXAMPLE_AJAX1_addrs.yaml \ 6 | -m=test/SAMR21/HTTP/Memories_Release_USART.yaml --log_blocks -n BB_HTTP_Release_LWIP -------------------------------------------------------------------------------- /test/SAMR21/HTTP/BB_run_release_ksz.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | 3 | source ~/.virtualenvs/halucinator/bin/activate 4 | ./halucinator -c=test/SAMR21/HTTP/BB_SAMR21_config_ksz.yaml \ 5 | -a=test/SAMR21/HTTP/RELEASE_THIRDPARTY_LWIP_RAW_BASIC_HTTP_EXAMPLE_AJAX1_addrs.yaml \ 6 | -m=test/SAMR21/HTTP/Memories_Release_USART.yaml --log_blocks -n BB_HTTP_Release_ksz -------------------------------------------------------------------------------- /test/SAMR21/HTTP/Full_SAMR21_config_ksz.yaml: -------------------------------------------------------------------------------- 1 | 2 | intercepts: 3 | 4 | # --------------------------Debug -------------------------------------------- 5 | - class: halucinator.bp_handlers.generic.debug.IPythonShell 6 | function: HardFault_Handler 7 | - class: halucinator.bp_handlers.generic.debug.IPythonShell 8 | function: Dummy_Handler 9 | - class: halucinator.bp_handlers.generic.debug.IPythonShell 10 | function: SYSCTRL_Handler 11 | # - class: halucinator.bp_handlers.generic.debug.IPythonShell 12 | # function: EIC_Handler 13 | 14 | # ----------------------- Startup ------------------------------------------ 15 | 16 | - class: halucinator.bp_handlers.generic.armv7m_param_log.ARMv7MEABILogger 17 | registration_args: {ret_val: null} 18 | function: system_clock_init 19 | 20 | - class: halucinator.bp_handlers.generic.timer.Timer 21 | registration_args: { scale: 1 } 22 | function: sys_get_ms 23 | # ----------------------------------------------------------------------------- 24 | # ----------------------- EXT Interrupt---------------------------------------- 25 | # - class: halucinator.bp_handlers.atmel_asf_v3.ext_interrupt.EXT_Int 26 | # registration_args: { channel_map: {6: Ethernet_RX_Frame }} 27 | # function: EIC_Handler 28 | - class: halucinator.bp_handlers.atmel_asf_v3.ext_interrupt.EXT_Int 29 | registration_args: { channel_map: {6: Ethernet_RX_Frame }} 30 | function: extint_register_callback 31 | # ----------------------------------------------------------------------------- 32 | # ----------------------- USART ----------------------------------------------- 33 | - class: halucinator.bp_handlers.atmel_asf_v3.usart.USART 34 | function: usart_init 35 | - class: halucinator.bp_handlers.atmel_asf_v3.usart.USART 36 | function: usart_enable 37 | - class: halucinator.bp_handlers.atmel_asf_v3.usart.USART 38 | function: usart_write_buffer_wait 39 | - class: halucinator.bp_handlers.atmel_asf_v3.usart.USART 40 | function: usart_read_wait 41 | - class: halucinator.bp_handlers.atmel_asf_v3.usart.USART 42 | function: usart_write_wait 43 | # ---------------------------------------------------------------------------- 44 | # --------------------------ETHERNET ----------------------------------------- 45 | - class: halucinator.bp_handlers.atmel_asf_v3.ethernet_ksz8851.Ksz8851Eth 46 | function: ksz8851_reg_read 47 | - class: halucinator.bp_handlers.atmel_asf_v3.ethernet_ksz8851.Ksz8851Eth 48 | function: ksz8851_reg_write 49 | # - class: halucinator.bp_handlers.atmel_asf_v3.ethernet_ksz8851.Ksz8851Eth 50 | # function: ksz8851_fifo_clrbits 51 | # - class: halucinator.bp_handlers.atmel_asf_v3.ethernet_ksz8851.Ksz8851Eth 52 | # function: ksz8851_fifo_setbit 53 | - class: halucinator.bp_handlers.atmel_asf_v3.ethernet_ksz8851.Ksz8851Eth 54 | function: ksz8851_fifo_write_begin 55 | - class: halucinator.bp_handlers.atmel_asf_v3.ethernet_ksz8851.Ksz8851Eth 56 | function: ksz8851_fifo_write 57 | - class: halucinator.bp_handlers.atmel_asf_v3.ethernet_ksz8851.Ksz8851Eth 58 | function: ksz8851_fifo_write_end 59 | - class: halucinator.bp_handlers.atmel_asf_v3.ethernet_ksz8851.Ksz8851Eth 60 | function: ksz8851_fifo_read 61 | # - class: halucinator.bp_handlers.atmel_asf_v3.ethernet_ksz8851.Ksz8851Eth 62 | # function: ksz8851snl_init 63 | - class: halucinator.bp_handlers.atmel_asf_v3.ethernet_ksz8851.Ksz8851Eth 64 | function: ksz8851snl_hard_reset 65 | - class: halucinator.bp_handlers.atmel_asf_v3.ethernet_ksz8851.Ksz8851Eth 66 | function: ksz8851snl_interface_init 67 | # ---------------------------------------------------------------------------- 68 | 69 | -------------------------------------------------------------------------------- /test/SAMR21/HTTP/Full_run_release_LWIP.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | 3 | source ~/.virtualenvs/halucinator/bin/activate 4 | ./halucinator -c=test/SAMR21/HTTP/Full_SAMR21_config_LWIP.yaml \ 5 | -a=test/SAMR21/HTTP/RELEASE_THIRDPARTY_LWIP_RAW_BASIC_HTTP_EXAMPLE_AJAX1_addrs.yaml \ 6 | -m=test/SAMR21/HTTP/Memories_Release_USART.yaml --log_blocks -n Full_HTTP_Release_LWIP -------------------------------------------------------------------------------- /test/SAMR21/HTTP/Full_run_release_ksz.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | 3 | source ~/.virtualenvs/halucinator/bin/activate 4 | ./halucinator -c=test/SAMR21/HTTP/Full_SAMR21_config_ksz.yaml \ 5 | -a=test/SAMR21/HTTP/RELEASE_THIRDPARTY_LWIP_RAW_BASIC_HTTP_EXAMPLE_AJAX1_addrs.yaml \ 6 | -m=test/SAMR21/HTTP/Memories_Release_USART.yaml --log_blocks -n Full_HTTP_Release_ksz -------------------------------------------------------------------------------- /test/SAMR21/HTTP/Halt_Memories_Release_USART.yaml: -------------------------------------------------------------------------------- 1 | options: 2 | remove_bitband: True 3 | memories: 4 | flash: {base_addr: 0x0, file: RELEASE_THIRDPARTY_LWIP_RAW_BASIC_HTTP_EXAMPLE_AJAX1.bin, permissions: r-x, size: 0x80000} #512K 5 | ram: {base_addr: 0x20000000, size: 0x10000} #64K 6 | peripherals: 7 | logger: {base_addr: 0x40000000, emulate: HaltPeripheral, permissions: rw-, size: 0x1800} 8 | logger2: {base_addr: 0x40002000, emulate: HaltPeripheral, permissions: rw-, size: 0x1FFFE000} -------------------------------------------------------------------------------- /test/SAMR21/HTTP/Halt_SAMR21_config.yaml: -------------------------------------------------------------------------------- 1 | 2 | intercepts: {} 3 | 4 | -------------------------------------------------------------------------------- /test/SAMR21/HTTP/Halt_run_release.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | 3 | source ~/.virtualenvs/halucinator/bin/activate 4 | ./halucinator -c=test/SAMR21/HTTP/Halt_SAMR21_config.yaml \ 5 | -a=test/SAMR21/HTTP/RELEASE_THIRDPARTY_LWIP_RAW_BASIC_HTTP_EXAMPLE_AJAX1_addrs.yaml \ 6 | -m=test/SAMR21/HTTP/Halt_Memories_Release_USART.yaml --log_blocks -n Halt_HTTP_Release_LWIP -------------------------------------------------------------------------------- /test/SAMR21/HTTP/Memories_Debug_USART.yaml: -------------------------------------------------------------------------------- 1 | options: 2 | remove_bitband: True 3 | memories: 4 | flash: {base_addr: 0x0, file: DEBUG_THIRDPARTY_LWIP_RAW_BASIC_HTTP_EXAMPLE_AJAX1.bin, permissions: r-x, size: 0x80000} #512K 5 | ram: {base_addr: 0x20000000, size: 0x10000} #64K 6 | peripherals: 7 | logger: {base_addr: 0x40000000, emulate: GenericPeripheral, permissions: rw-, size: 0x1800} 8 | logger2: {base_addr: 0x40002000, emulate: GenericPeripheral, permissions: rw-, size: 0x1FFFE000} -------------------------------------------------------------------------------- /test/SAMR21/HTTP/Memories_Release_USART.yaml: -------------------------------------------------------------------------------- 1 | options: 2 | remove_bitband: True 3 | memories: 4 | flash: {base_addr: 0x0, file: RELEASE_THIRDPARTY_LWIP_RAW_BASIC_HTTP_EXAMPLE_AJAX1.bin, permissions: r-x, size: 0x80000} #512K 5 | ram: {base_addr: 0x20000000, size: 0x10000} #64K 6 | peripherals: 7 | logger: {base_addr: 0x40000000, emulate: GenericPeripheral, permissions: rw-, size: 0x1800} 8 | logger2: {base_addr: 0x40002000, emulate: GenericPeripheral, permissions: rw-, size: 0x1FFFE000} -------------------------------------------------------------------------------- /test/SAMR21/HTTP/run_debug.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | 3 | source ~/.virtualenvs/halucinator/bin/activate 4 | ./halucinator -c=test/SAMR21/HTTP/SAMR21_config_HLE.yaml \ 5 | -a=test/SAMR21/HTTP/DEBUG_THIRDPARTY_LWIP_RAW_BASIC_HTTP_EXAMPLE_AJAX1_addrs.yaml \ 6 | -m=test/SAMR21/HTTP/Memories_Debug_USART.yaml --log_blocks -n HTTP_Debug -------------------------------------------------------------------------------- /test/SAMR21/HTTP/run_debug_ksz.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | 3 | source ~/.virtualenvs/halucinator/bin/activate 4 | ./halucinator -c=test/SAMR21/HTTP/SAMR21_config.yaml \ 5 | -a=test/SAMR21/HTTP/DEBUG_THIRDPARTY_LWIP_RAW_BASIC_HTTP_EXAMPLE_AJAX1_addrs.yaml \ 6 | -m=test/SAMR21/HTTP/Memories_Debug_USART.yaml --log_blocks -n HTTP_Debug -------------------------------------------------------------------------------- /test/SAMR21/HTTP/run_release_no_intercepts.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | 3 | source ~/.virtualenvs/halucinator/bin/activate 4 | ./halucinator -c=test/SAMR21/HTTP/SAMR21_config_no_intercepts.yaml \ 5 | -a=test/SAMR21/HTTP/RELEASE_THIRDPARTY_LWIP_RAW_BASIC_HTTP_EXAMPLE_AJAX1_addrs.yaml \ 6 | -m=test/SAMR21/HTTP/Memories_Release_USART.yaml --log_blocks -n HTTP_Release_no_intercepts -------------------------------------------------------------------------------- /test/SAMR21/HTTP/test_cmds.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | 3 | ## Need to run below command from repo root in seperate terminal, updating -i to network interface 4 | # sudo ~/.virtualenvs/halucinator/bin/python -m halucinator.external_devices.host_ethernet -i=enx000acd302efe --id=ksz8851 5 | ## 6 | 7 | wget 192.168.0.100 8 | wget 192.168.0.100/index.html 9 | wget 192.168.0.100/index.htm 10 | wget 192.168.0.100/jquery.js 11 | wget 192.168.0.100/style.css 12 | wget http://192.168.0.100/favicon.ico 13 | wget http://192.168.0.100/status?_=1547486274423 14 | wget http://192.168.0.100/set_led?n=0\&set=0\&_=1547486272679 15 | wget http://192.168.0.100/set_led?n=0\&set=1\&_=1547486273588 16 | 17 | ping -c10 192.168.0.100 18 | -------------------------------------------------------------------------------- /test/SAMR21/SD_MMC/BB_run_release.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | 3 | source ~/.virtualenvs/halucinator/bin/activate 4 | ./halucinator -c=test/SAMR21/SD_MMC/BB_SAMR21_config.yaml \ 5 | -a=test/SAMR21/SD_MMC/RELEASE_SD_MMC_EXAMPLE21_addrs.yaml \ 6 | -m=test/SAMR21/SD_MMC/Memories_Release_SD.yaml --log_blocks -n BB_SD_MMC -------------------------------------------------------------------------------- /test/SAMR21/SD_MMC/Full_run_release.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | 3 | source ~/.virtualenvs/halucinator/bin/activate 4 | ./halucinator -c=test/SAMR21/SD_MMC/Full_SAMR21_config.yaml \ 5 | -a=test/SAMR21/SD_MMC/RELEASE_SD_MMC_EXAMPLE21_addrs.yaml \ 6 | -m=test/SAMR21/SD_MMC/Memories_Release_SD.yaml --log_blocks -n Full_SD_MMC -------------------------------------------------------------------------------- /test/SAMR21/SD_MMC/Halt_Memories_Release_SD.yaml: -------------------------------------------------------------------------------- 1 | options: 2 | remove_bitband: True 3 | memories: 4 | flash: {base_addr: 0x0, file: RELEASE_SD_MMC_EXAMPLE21.bin, permissions: r-x, size: 0x80000} #512K 5 | ram: {base_addr: 0x20000000, size: 0x10000} #64K 6 | peripherals: 7 | logger: {base_addr: 0x40000000, emulate: HaltPeripheral, permissions: rw-, size: 0x20000000} -------------------------------------------------------------------------------- /test/SAMR21/SD_MMC/Halt_SAMR21_config.yaml: -------------------------------------------------------------------------------- 1 | 2 | intercepts: {} 3 | 4 | -------------------------------------------------------------------------------- /test/SAMR21/SD_MMC/Halt_run_release.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | 3 | source ~/.virtualenvs/halucinator/bin/activate 4 | ./halucinator -c=test/SAMR21/UART-Echo/Halt_SAMR21_config.yaml \ 5 | -a=test/SAMR21/SD_MMC/RELEASE_SD_MMC_EXAMPLE21_addrs.yaml \ 6 | -m=test/SAMR21/SD_MMC/Halt_Memories_Release_SD.yaml \ 7 | --log_blocks -n Halt_SD_MMC -------------------------------------------------------------------------------- /test/SAMR21/SD_MMC/Memories_Debug_SD.yaml: -------------------------------------------------------------------------------- 1 | options: 2 | remove_bitband: True 3 | memories: 4 | flash: {base_addr: 0x0, file: DEBUG_SD_MMC_EXAMPLE21.bin, permissions: r-x, size: 0x80000} #512K 5 | ram: {base_addr: 0x20000000, size: 0x10000} #64K 6 | peripherals: 7 | # logger: {base_addr: 0x40000000, emulate: GenericPeripheral, permissions: rw-, size: 0x1800} #Need gap for EIC 8 | # logger2: {base_addr: 0x40002000, emulate: GenericPeripheral, permissions: rw-, size: 0x02000000} # Need gap for Timers as 0x42002000 9 | # logger3: {base_addr: 0x42003000, emulate: GenericPeripheral, permissions: rw-, size: 0x2800} #Should cover end of peripherals 10 | PAC0: {base_addr: 0x40000000, emulate: GenericPeripheral, permissions: rw-, size: 0x400} 11 | PM: {base_addr: 0x40000400, emulate: GenericPeripheral, permissions: rw-, size: 0x400} 12 | SYSCTRL: {base_addr: 0x40000800, emulate: GenericPeripheral, permissions: rw-, size: 0x400} 13 | GCLK: {base_addr: 0x40000C00, emulate: GenericPeripheral, permissions: rw-, size: 0x400} 14 | WDT: {base_addr: 0x40001000, emulate: GenericPeripheral, permissions: rw-, size: 0x400} 15 | RTC: {base_addr: 0x40001400, emulate: GenericPeripheral, permissions: rw-, size: 0x400} 16 | #EIC: {base_addr: 0x40001800, emulate: GenericPeripheral, permissions: rw-, size: 0x400} 17 | PAC1: {base_addr: 0x41000000, emulate: GenericPeripheral, permissions: rw-, size: 0x2000} 18 | DSU: {base_addr: 0x41002000, emulate: GenericPeripheral, permissions: rw-, size: 0x2000} 19 | NVMCTRL: {base_addr: 0x41004000, emulate: GenericPeripheral, permissions: rw-, size: 0x400} 20 | PORT: {base_addr: 0x41004400, emulate: GenericPeripheral, permissions: rw-, size: 0x400} 21 | DMAC: {base_addr: 0x41004800, emulate: GenericPeripheral, permissions: rw-, size: 0x800} 22 | USB: {base_addr: 0x41005000, emulate: GenericPeripheral, permissions: rw-, size: 0x1000} 23 | MTB: {base_addr: 0x41006000, emulate: GenericPeripheral, permissions: rw-, size: 0x1000} 24 | PAC2: {base_addr: 0x42000000, emulate: GenericPeripheral, permissions: rw-, size: 0x400} 25 | EVSYS: {base_addr: 0x42000400, emulate: GenericPeripheral, permissions: rw-, size: 0x400} 26 | SERCOM0: {base_addr: 0x42000800, emulate: GenericPeripheral, permissions: rw-, size: 0x400} 27 | SERCOM1: {base_addr: 0x42000C00, emulate: GenericPeripheral, permissions: rw-, size: 0x400} 28 | SERCOM2: {base_addr: 0x42001000, emulate: GenericPeripheral, permissions: rw-, size: 0x400} 29 | SERCOM3: {base_addr: 0x42001400, emulate: GenericPeripheral, permissions: rw-, size: 0x400} 30 | SERCOM4: {base_addr: 0x42001800, emulate: GenericPeripheral, permissions: rw-, size: 0x400} 31 | SERCOM5: {base_addr: 0x42001C00, emulate: GenericPeripheral, permissions: rw-, size: 0x400} 32 | # TCC0: {base_addr: 0x42002000, emulate: GenericPeripheral, permissions: rw-, size: 0x400} 33 | # TCC1: {base_addr: 0x42002400, emulate: GenericPeripheral, permissions: rw-, size: 0x400} 34 | # TCC2: {base_addr: 0x42002800, emulate: GenericPeripheral, permissions: rw-, size: 0x400} 35 | # TC3: {base_addr: 0x42002C00, emulate: GenericPeripheral, permissions: rw-, size: 0x400} 36 | # TC4: {base_addr: 0x42003000, emulate: GenericPeripheral, permissions: rw-, size: 0x400} 37 | # TC5: {base_addr: 0x42003400, emulate: GenericPeripheral, permissions: rw-, size: 0xC00} 38 | ADC: {base_addr: 0x42004000, emulate: GenericPeripheral, permissions: rw-, size: 0x400} 39 | AC: {base_addr: 0x42004400, emulate: GenericPeripheral, permissions: rw-, size: 0x800} 40 | PTC: {base_addr: 0x42004C00, emulate: GenericPeripheral, permissions: rw-, size: 0x400} 41 | RFCTRL: {base_addr: 0x42005400, emulate: GenericPeripheral, permissions: rw-, size: 0x800} -------------------------------------------------------------------------------- /test/SAMR21/SD_MMC/run_debug.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | 3 | source ~/.virtualenvs/halucinator/bin/activate 4 | ./halucinator -c=test/SAMR21/SD_MMC/SAMR21_config.yaml \ 5 | -a=test/SAMR21/SD_MMC/DEBUG_SD_MMC_EXAMPLE21_addrs.yaml \ 6 | -m=test/SAMR21/SD_MMC/Memories_Debug_SD.yaml --log_blocks -n SD_MMC -------------------------------------------------------------------------------- /test/SAMR21/SD_MMC/run_release_no_intercepts.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | 3 | source ~/.virtualenvs/halucinator/bin/activate 4 | ./halucinator -c=test/SAMR21/SD_MMC/SAMR21_config_no_intercepts.yaml \ 5 | -a=test/SAMR21/SD_MMC/RELEASE_SD_MMC_EXAMPLE21_addrs.yaml \ 6 | -m=test/SAMR21/SD_MMC/Memories_Release_SD.yaml --log_blocks -n SD_MMC_release_no_intercepts -------------------------------------------------------------------------------- /test/SAMR21/UART-Echo/BB_SAMR21_config.yaml: -------------------------------------------------------------------------------- 1 | 2 | intercepts: 3 | 4 | # ----------------------- Startup ------------------------------------------ 5 | 6 | - addr: 0x800208c 7 | class: halucinator.bp_handlers.generic.armv7m_param_log.ARMv7MEABILogger 8 | registration_args: {ret_val: null} 9 | function: system_init 10 | # ----------------------------------------------------------------------------- 11 | 12 | # ----------------------- USART ----------------------------------------------- 13 | - class: halucinator.bp_handlers.atmel_asf_v3.usart.USART 14 | function: usart_init 15 | - class: halucinator.bp_handlers.atmel_asf_v3.usart.USART 16 | function: usart_enable 17 | - class: halucinator.bp_handlers.atmel_asf_v3.usart.USART 18 | function: usart_write_buffer_wait 19 | - class: halucinator.bp_handlers.atmel_asf_v3.usart.USART 20 | function: usart_read_wait 21 | - class: halucinator.bp_handlers.atmel_asf_v3.usart.USART 22 | function: usart_write_wait 23 | # ---------------------------------------------------------------------------- 24 | 25 | 26 | memories: 27 | alias: {base_addr: 0x0, file: TCP_Echo_Server_Client--board=STM32469I_EVAL--opt=O0--comp=arm-none-eabi-gcc--comp_version=4.9.3.elf.bin, 28 | permissions: r-x, size: 0x800000} 29 | flash: {base_addr: 0x8000000, file: TCP_Echo_Server_Client--board=STM32469I_EVAL--opt=O0--comp=arm-none-eabi-gcc--comp_version=4.9.3.elf.bin, 30 | permissions: r-x, size: 0x200000} 31 | ram: {base_addr: 0x20000000, size: 0x51000} 32 | peripherals: 33 | logger: {base_addr: 0x40000000, emulate: GenericPeripheral, permissions: rw-, size: 0x20000000} 34 | -------------------------------------------------------------------------------- /test/SAMR21/UART-Echo/BB_run_release.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | 3 | source ~/.virtualenvs/halucinator/bin/activate 4 | ./halucinator -c=test/SAMR21/UART-Echo/BB_SAMR21_config.yaml \ 5 | -m=test/SAMR21/UART-Echo/Memories_Release_USART.yaml \ 6 | -a=test/SAMR21/UART-Echo/Release_USART_QUICK_START1_addrs.yaml \ 7 | --log_blocks -n BB_UART-Echo -------------------------------------------------------------------------------- /test/SAMR21/UART-Echo/Full_SAMR21_config.yaml: -------------------------------------------------------------------------------- 1 | 2 | intercepts: 3 | 4 | # ----------------------- Startup ------------------------------------------ 5 | 6 | - addr: 0x800208c 7 | class: halucinator.bp_handlers.generic.armv7m_param_log.ARMv7MEABILogger 8 | registration_args: {ret_val: null} 9 | function: system_init 10 | # ----------------------------------------------------------------------------- 11 | 12 | # ----------------------- USART ----------------------------------------------- 13 | - class: halucinator.bp_handlers.atmel_asf_v3.usart.USART 14 | function: usart_init 15 | - class: halucinator.bp_handlers.atmel_asf_v3.usart.USART 16 | function: usart_enable 17 | - class: halucinator.bp_handlers.atmel_asf_v3.usart.USART 18 | function: usart_write_buffer_wait 19 | - class: halucinator.bp_handlers.atmel_asf_v3.usart.USART 20 | function: usart_read_wait 21 | # ---------------------------------------------------------------------------- 22 | 23 | 24 | memories: 25 | alias: {base_addr: 0x0, file: TCP_Echo_Server_Client--board=STM32469I_EVAL--opt=O0--comp=arm-none-eabi-gcc--comp_version=4.9.3.elf.bin, 26 | permissions: r-x, size: 0x800000} 27 | flash: {base_addr: 0x8000000, file: TCP_Echo_Server_Client--board=STM32469I_EVAL--opt=O0--comp=arm-none-eabi-gcc--comp_version=4.9.3.elf.bin, 28 | permissions: r-x, size: 0x200000} 29 | ram: {base_addr: 0x20000000, size: 0x51000} 30 | peripherals: 31 | logger: {base_addr: 0x40000000, emulate: GenericPeripheral, permissions: rw-, size: 0x20000000} 32 | -------------------------------------------------------------------------------- /test/SAMR21/UART-Echo/Full_run_release.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | 3 | source ~/.virtualenvs/halucinator/bin/activate 4 | ./halucinator -c=test/SAMR21/UART-Echo/Full_SAMR21_config.yaml \ 5 | -m=test/SAMR21/UART-Echo/Memories_Release_USART.yaml \ 6 | -a=test/SAMR21/UART-Echo/Release_USART_QUICK_START1_addrs.yaml \ 7 | --log_blocks -n Full_UART-Echo -------------------------------------------------------------------------------- /test/SAMR21/UART-Echo/Halt_Memories_Release_USART.yaml: -------------------------------------------------------------------------------- 1 | options: 2 | remove_bitband: True 3 | memories: 4 | flash: {base_addr: 0x0, file: Release_USART_QUICK_START1.bin, permissions: r-x, size: 0x80000} #512K 5 | ram: {base_addr: 0x20000000, size: 0x10000} #64K 6 | peripherals: 7 | logger: {base_addr: 0x40000000, emulate: HaltPeripheral, permissions: rw-, size: 0x20000000} -------------------------------------------------------------------------------- /test/SAMR21/UART-Echo/Halt_SAMR21_config.yaml: -------------------------------------------------------------------------------- 1 | 2 | intercepts: {} 3 | 4 | -------------------------------------------------------------------------------- /test/SAMR21/UART-Echo/Halt_run_release.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | 3 | source ~/.virtualenvs/halucinator/bin/activate 4 | ./halucinator -c=test/SAMR21/UART-Echo/Halt_SAMR21_config.yaml \ 5 | -m=test/SAMR21/UART-Echo/Halt_Memories_Release_USART.yaml \ 6 | -a=test/SAMR21/UART-Echo/Release_USART_QUICK_START1_addrs.yaml \ 7 | --log_blocks -n Halt_UART-Echo -------------------------------------------------------------------------------- /test/SAMR21/UART-Echo/Memories_Debug_USART.yaml: -------------------------------------------------------------------------------- 1 | options: 2 | remove_bitband: True 3 | memories: 4 | flash: {base_addr: 0x0, file: Debug_USART_QUICK_START1.bin, permissions: r-x, size: 0x80000} #512K 5 | ram: {base_addr: 0x20000000, size: 0x10000} #64K 6 | peripherals: 7 | logger: {base_addr: 0x40000000, emulate: GenericPeripheral, permissions: rw-, size: 0x20000000} -------------------------------------------------------------------------------- /test/SAMR21/UART-Echo/Memories_Release_USART.yaml: -------------------------------------------------------------------------------- 1 | options: 2 | remove_bitband: True 3 | memories: 4 | flash: {base_addr: 0x0, file: Release_USART_QUICK_START1.bin, permissions: r-x, size: 0x80000} #512K 5 | ram: {base_addr: 0x20000000, size: 0x10000} #64K 6 | peripherals: 7 | logger: {base_addr: 0x40000000, emulate: GenericPeripheral, permissions: rw-, size: 0x20000000} -------------------------------------------------------------------------------- /test/SAMR21/UART-Echo/Running.md: -------------------------------------------------------------------------------- 1 | # Running 2 | 3 | ##Start Serial Device 4 | 5 | ```bash 6 | workon halucinator 7 | python -m halucinator.external_devices.uart 8 | ``` 9 | 10 | Then start the debug or release binary in a different terminal window 11 | 12 | ### Start Debug 13 | ```bash 14 | workon halucinator 15 | ./halucinator -c=test/SAMR21/UART-Echo/SAMR21_config.yaml \ 16 | -m=test/SAMR21/UART-Echo/Memories_Debug_USART.yaml \ 17 | -a=test/SAMR21/UART-Echo/Debug_USART_QUICK_START1_addrs.yaml 18 | ``` 19 | 20 | ### Start Release 21 | ```bash 22 | workon halucinator 23 | ./halucinator -c=test/SAMR21/UART-Echo/SAMR21_config.yaml \ 24 | -m=test/SAMR21/UART-Echo/Memories_Release_USART.yaml \ 25 | -a=test/SAMR21/UART-Echo/Release_USART_QUICK_START1_addrs.yaml 26 | ``` 27 | 28 | ### Output -------------------------------------------------------------------------------- /test/SAMR21/UART-Echo/run_debug.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | 3 | source ~/.virtualenvs/halucinator/bin/activate 4 | ./halucinator -c=test/SAMR21/UART-Echo/SAMR21_config.yaml \ 5 | -m=test/SAMR21/UART-Echo/Memories_Debug_USART.yaml \ 6 | -a=test/SAMR21/UART-Echo/Debug_USART_QUICK_START1_addrs.yaml \ 7 | --log_blocks -n UART-Echo_debug -------------------------------------------------------------------------------- /test/SAMR21/Wireless/BB_run_receive_release_rf233.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | 3 | source ~/.virtualenvs/halucinator/bin/activate 4 | ./halucinator -c=test/SAMR21/Wireless/BB_SAMR21_config_RF233.yaml \ 5 | -a=test/SAMR21/Wireless/Release_EXAMPLES_UDP-UNICAST-RECEIVER_addrs.yaml \ 6 | -m=test/SAMR21/Wireless/Memories_Release_Receive.yaml --log_blocks=in_asm -n BB_UDP_Received_Release_rf233 \ 7 | -t=5558 -r=5557 -p=2222 -------------------------------------------------------------------------------- /test/SAMR21/Wireless/BB_run_send_release_rf233.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | 3 | source ~/.virtualenvs/halucinator/bin/activate 4 | ./halucinator -c=test/SAMR21/Wireless/BB_SAMR21_config_RF233.yaml \ 5 | -a=test/SAMR21/Wireless/Release_EXAMPLES_UDP-UNICAST-SENDER_addrs.yaml \ 6 | -m=test/SAMR21/Wireless/Memories_Release_Send_RF233.yaml --log_blocks=in_asm -n BB_UDP_Send_Release_RF233 -------------------------------------------------------------------------------- /test/SAMR21/Wireless/Full_run_receive_release_rf233.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | 3 | source ~/.virtualenvs/halucinator/bin/activate 4 | ./halucinator -c=test/SAMR21/Wireless/Full_SAMR21_config_RF233.yaml \ 5 | -a=test/SAMR21/Wireless/Release_EXAMPLES_UDP-UNICAST-RECEIVER_addrs.yaml \ 6 | -m=test/SAMR21/Wireless/Memories_Release_Receive.yaml --log_blocks=in_asm -n Full_UDP_Received_Release_rf233 \ 7 | -t=5558 -r=5557 -p=2222 -------------------------------------------------------------------------------- /test/SAMR21/Wireless/Full_run_send_release_rf233.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | 3 | source ~/.virtualenvs/halucinator/bin/activate 4 | ./halucinator -c=test/SAMR21/Wireless/Full_SAMR21_config_RF233.yaml \ 5 | -a=test/SAMR21/Wireless/Release_EXAMPLES_UDP-UNICAST-SENDER_addrs.yaml \ 6 | -m=test/SAMR21/Wireless/Memories_Release_Send_RF233.yaml --log_blocks=in_asm -n Full_UDP_Send_Release_RF233 -------------------------------------------------------------------------------- /test/SAMR21/Wireless/Halt_SAMR21_config.yaml: -------------------------------------------------------------------------------- 1 | 2 | intercepts: {} 3 | 4 | -------------------------------------------------------------------------------- /test/SAMR21/Wireless/Halt_run_receive_release_rf233.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | 3 | source ~/.virtualenvs/halucinator/bin/activate 4 | ./halucinator -c=test/SAMR21/Wireless/Halt_SAMR21_config.yaml \ 5 | -a=test/SAMR21/Wireless/Release_EXAMPLES_UDP-UNICAST-RECEIVER_addrs.yaml \ 6 | -m=test/SAMR21/Wireless/Halt_Memories_Release_Receive.yaml --log_blocks=in_asm -n Halt_UDP_Received_Release_rf233 \ 7 | -t=5558 -r=5557 -p=2222 -------------------------------------------------------------------------------- /test/SAMR21/Wireless/Halt_run_send_release_rf233.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | 3 | source ~/.virtualenvs/halucinator/bin/activate 4 | ./halucinator -c=test/SAMR21/Wireless/Halt_SAMR21_config.yaml \ 5 | -a=test/SAMR21/Wireless/Release_EXAMPLES_UDP-UNICAST-SENDER_addrs.yaml \ 6 | -m=test/SAMR21/Wireless/Halt_Memories_Release_Send_RF233.yaml --log_blocks=in_asm -n Halt_UDP_Send_Release_RF233 -------------------------------------------------------------------------------- /test/SAMR21/Wireless/run_broadcaster.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | 3 | source ~/.virtualenvs/halucinator/bin/activate 4 | python -m halucinator.external_devices.IEEE802_15_4 -------------------------------------------------------------------------------- /test/SAMR21/Wireless/run_receive_debug.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | 3 | source ~/.virtualenvs/halucinator/bin/activate 4 | ./halucinator -c=test/SAMR21/Wireless/SAMR21_config.yaml \ 5 | -a=test/SAMR21/Wireless/DEBUG_UART_EXAMPLES_UDP-UNICAST-RECEIVER2_addrs.yaml \ 6 | -m=test/SAMR21/Wireless/Memories_Debug_Receive.yaml --log_blocks -n UDP_Receive -------------------------------------------------------------------------------- /test/SAMR21/Wireless/run_receive_debug_rf233.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | 3 | source ~/.virtualenvs/halucinator/bin/activate 4 | ./halucinator -c=test/SAMR21/Wireless/SAMR21_config_RF233.yaml \ 5 | -a=test/SAMR21/Wireless/DEBUG_UART_EXAMPLES_UDP-UNICAST-RECEIVER2_addrs.yaml \ 6 | -m=test/SAMR21/Wireless/Memories_Debug_Receive.yaml --log_blocks=in_asm -n UDP_Received_rf233 \ 7 | -t=5558 -r=5557 -p=2222 -------------------------------------------------------------------------------- /test/SAMR21/Wireless/run_send_debug.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | 3 | source ~/.virtualenvs/halucinator/bin/activate 4 | ./halucinator -c=test/SAMR21/Wireless/SAMR21_config.yaml \ 5 | -a=test/SAMR21/Wireless/DEBUG_UART_EXAMPLES_UDP-UNICAST-SENDER1_addrs.yaml \ 6 | -m=test/SAMR21/Wireless/Memories_Debug_Send.yaml --log_blocks -n UDP_Send -------------------------------------------------------------------------------- /test/SAMR21/Wireless/run_send_debug_rf233.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | 3 | source ~/.virtualenvs/halucinator/bin/activate 4 | ./halucinator -c=test/SAMR21/Wireless/SAMR21_config_RF233.yaml \ 5 | -a=test/SAMR21/Wireless/DEBUG_UART_EXAMPLES_UDP-UNICAST-SENDER1_addrs.yaml \ 6 | -m=test/SAMR21/Wireless/Memories_Debug_Send_RF233.yaml --log_blocks=in_asm -n UDP_Send -------------------------------------------------------------------------------- /test/STM32/STM32469_EVAL/Ethernet/BB_run_tcp_client.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | 3 | source ~/.virtualenvs/halucinator/bin/activate 4 | ./halucinator -c=test/STM32/STM32469_EVAL/BB_peripheral_config.yaml \ 5 | -a=test/STM32/STM32469_EVAL/Ethernet/TCP_Echo_Server_Client--board=STM32469I_EVAL--opt=Os--comp=arm-none-eabi-gcc--comp_version=4.9.3_addrs.yaml \ 6 | -m=test/STM32/STM32469_EVAL/Ethernet/TCP_Echo_Server_Client_Os_memory.yaml --log_blocks -n BB_TCP_Echo_Client -------------------------------------------------------------------------------- /test/STM32/STM32469_EVAL/Ethernet/BB_run_tcp_server.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | 3 | source ~/.virtualenvs/halucinator/bin/activate 4 | ./halucinator -c=test/STM32/STM32469_EVAL/BB_peripheral_config.yaml \ 5 | -a=test/STM32/STM32469_EVAL/Ethernet/TCP_Echo_Server--board=STM32469I_Eval--opt=Os--comp=arm-none-eabi-gcc--comp_version=4.9.3_addrs.yaml \ 6 | -m=test/STM32/STM32469_EVAL/Ethernet/TCP_Echo_Server_Os_memory.yaml --log_blocks -n BB_TCP_Echo_Server -t=5558 -r=5557 -p=2222 -------------------------------------------------------------------------------- /test/STM32/STM32469_EVAL/Ethernet/BB_run_tcp_server_to_host.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | 3 | source ~/.virtualenvs/halucinator/bin/activate 4 | ./halucinator -c=test/STM32/STM32469_EVAL/BB_peripheral_config.yaml \ 5 | -a=test/STM32/STM32469_EVAL/Ethernet/TCP_Echo_Server--board=STM32469I_Eval--opt=Os--comp=arm-none-eabi-gcc--comp_version=4.9.3_addrs.yaml \ 6 | -m=test/STM32/STM32469_EVAL/Ethernet/TCP_Echo_Server_Os_memory.yaml --log_blocks -n BB_TCP_Echo_Server_host -------------------------------------------------------------------------------- /test/STM32/STM32469_EVAL/Ethernet/BB_run_udp_client.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | 3 | source ~/.virtualenvs/halucinator/bin/activate 4 | ./halucinator -c=test/STM32/STM32469_EVAL/BB_peripheral_config.yaml \ 5 | -a=test/STM32/STM32469_EVAL/Ethernet/UDP-echo-client--board=STM32469I_Eval--opt=Os--comp=arm-none-eabi-gcc--comp_version=4.9.3_addrs.yaml \ 6 | -m=test/STM32/STM32469_EVAL/Ethernet/UDP-echo-client_Os_memory.yaml --log_blocks -n BB_UDP_Echo_Client -------------------------------------------------------------------------------- /test/STM32/STM32469_EVAL/Ethernet/BB_run_udp_server.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | 3 | source ~/.virtualenvs/halucinator/bin/activate 4 | ./halucinator -c=test/STM32/STM32469_EVAL/BB_peripheral_config.yaml \ 5 | -a=test/STM32/STM32469_EVAL/Ethernet/UDP_echo_server--board=STM32469I_Eval--opt=Os--comp=arm-none-eabi-gcc--comp_version=4.9.3_addrs.yaml \ 6 | -m=test/STM32/STM32469_EVAL/Ethernet/UDP_echo_server_Os_memory.yaml --log_blocks -n BB_UDP_Echo_Server -t=5558 -r=5557 -p=2222 -------------------------------------------------------------------------------- /test/STM32/STM32469_EVAL/Ethernet/Full_run_tcp_client.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | 3 | source ~/.virtualenvs/halucinator/bin/activate 4 | ./halucinator -c=test/STM32/STM32469_EVAL/Full_peripheral_config.yaml \ 5 | -a=test/STM32/STM32469_EVAL/Ethernet/TCP_Echo_Server_Client--board=STM32469I_EVAL--opt=Os--comp=arm-none-eabi-gcc--comp_version=4.9.3_addrs.yaml \ 6 | -m=test/STM32/STM32469_EVAL/Ethernet/TCP_Echo_Server_Client_Os_memory.yaml --log_blocks -n Full_TCP_Echo_Client -------------------------------------------------------------------------------- /test/STM32/STM32469_EVAL/Ethernet/Full_run_tcp_server.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | 3 | source ~/.virtualenvs/halucinator/bin/activate 4 | ./halucinator -c=test/STM32/STM32469_EVAL/Full_peripheral_config.yaml \ 5 | -a=test/STM32/STM32469_EVAL/Ethernet/TCP_Echo_Server--board=STM32469I_Eval--opt=Os--comp=arm-none-eabi-gcc--comp_version=4.9.3_addrs.yaml \ 6 | -m=test/STM32/STM32469_EVAL/Ethernet/TCP_Echo_Server_Os_memory.yaml --log_blocks -n Full_TCP_Echo_Server -t=5558 -r=5557 -p=2222 -------------------------------------------------------------------------------- /test/STM32/STM32469_EVAL/Ethernet/Full_run_tcp_server_to_host.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | 3 | source ~/.virtualenvs/halucinator/bin/activate 4 | ./halucinator -c=test/STM32/STM32469_EVAL/Full_peripheral_config.yaml \ 5 | -a=test/STM32/STM32469_EVAL/Ethernet/TCP_Echo_Server--board=STM32469I_Eval--opt=Os--comp=arm-none-eabi-gcc--comp_version=4.9.3_addrs.yaml \ 6 | -m=test/STM32/STM32469_EVAL/Ethernet/TCP_Echo_Server_Os_memory.yaml --log_blocks -n Full_TCP_Echo_Server_host -------------------------------------------------------------------------------- /test/STM32/STM32469_EVAL/Ethernet/Full_run_udp_client.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | 3 | source ~/.virtualenvs/halucinator/bin/activate 4 | ./halucinator -c=test/STM32/STM32469_EVAL/Full_peripheral_config.yaml \ 5 | -a=test/STM32/STM32469_EVAL/Ethernet/UDP-echo-client--board=STM32469I_Eval--opt=Os--comp=arm-none-eabi-gcc--comp_version=4.9.3_addrs.yaml \ 6 | -m=test/STM32/STM32469_EVAL/Ethernet/UDP-echo-client_Os_memory.yaml --log_blocks -n Full_UDP_Echo_Client -------------------------------------------------------------------------------- /test/STM32/STM32469_EVAL/Ethernet/Full_run_udp_server.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | 3 | source ~/.virtualenvs/halucinator/bin/activate 4 | ./halucinator -c=test/STM32/STM32469_EVAL/Full_peripheral_config.yaml \ 5 | -a=test/STM32/STM32469_EVAL/Ethernet/UDP_echo_server--board=STM32469I_Eval--opt=Os--comp=arm-none-eabi-gcc--comp_version=4.9.3_addrs.yaml \ 6 | -m=test/STM32/STM32469_EVAL/Ethernet/UDP_echo_server_Os_memory.yaml --log_blocks -n Full_UDP_Echo_Server -t=5558 -r=5557 -p=2222 -------------------------------------------------------------------------------- /test/STM32/STM32469_EVAL/Ethernet/Halt_TCP_Echo_Server_Client_Os_memory.yaml: -------------------------------------------------------------------------------- 1 | memories: 2 | alias: {base_addr: 0x0, file: TCP_Echo_Server_Client--board=STM32469I_EVAL--opt=Os--comp=arm-none-eabi-gcc--comp_version=4.9.3.elf.bin, 3 | permissions: r-x, size: 0x800000} 4 | flash: {base_addr: 0x8000000, file: TCP_Echo_Server_Client--board=STM32469I_EVAL--opt=Os--comp=arm-none-eabi-gcc--comp_version=4.9.3.elf.bin, 5 | permissions: r-x, size: 0x200000} 6 | ram: {base_addr: 0x20000000, size: 0x51000} 7 | peripherals: 8 | logger: {base_addr: 0x40000000, emulate: HaltPeripheral, permissions: rw-, size: 0x20000000} -------------------------------------------------------------------------------- /test/STM32/STM32469_EVAL/Ethernet/Halt_TCP_Echo_Server_Os_memory.yaml: -------------------------------------------------------------------------------- 1 | memories: 2 | alias: {base_addr: 0x0, file: TCP_Echo_Server--board=STM32469I_Eval--opt=Os--comp=arm-none-eabi-gcc--comp_version=4.9.3.elf.bin, 3 | permissions: r-x, size: 0x800000} 4 | flash: {base_addr: 0x8000000, file: TCP_Echo_Server--board=STM32469I_Eval--opt=Os--comp=arm-none-eabi-gcc--comp_version=4.9.3.elf.bin, 5 | permissions: r-x, size: 0x200000} 6 | ram: {base_addr: 0x20000000, size: 0x51000} 7 | peripherals: 8 | logger: {base_addr: 0x40000000, emulate: HaltPeripheral, permissions: rw-, size: 0x20000000} -------------------------------------------------------------------------------- /test/STM32/STM32469_EVAL/Ethernet/Halt_UDP-echo-client_Os_memory.yaml: -------------------------------------------------------------------------------- 1 | memories: 2 | alias: {base_addr: 0x0, file: UDP-echo-client--board=STM32469I_Eval--opt=Os--comp=arm-none-eabi-gcc--comp_version=4.9.3.elf.bin, 3 | permissions: r-x, size: 0x800000} 4 | flash: {base_addr: 0x8000000, file: UDP-echo-client--board=STM32469I_Eval--opt=Os--comp=arm-none-eabi-gcc--comp_version=4.9.3.elf.bin, 5 | permissions: r-x, size: 0x200000} 6 | ram: {base_addr: 0x20000000, size: 0x51000} 7 | peripherals: 8 | logger: {base_addr: 0x40000000, emulate: HaltPeripheral, permissions: rw-, size: 0x20000000} -------------------------------------------------------------------------------- /test/STM32/STM32469_EVAL/Ethernet/Halt_UDP_echo_server_Os_memory.yaml: -------------------------------------------------------------------------------- 1 | memories: 2 | alias: {base_addr: 0x0, file: UDP_echo_server--board=STM32469I_Eval--opt=Os--comp=arm-none-eabi-gcc--comp_version=4.9.3.elf.bin, 3 | permissions: r-x, size: 0x800000} 4 | flash: {base_addr: 0x8000000, file: UDP_echo_server--board=STM32469I_Eval--opt=Os--comp=arm-none-eabi-gcc--comp_version=4.9.3.elf.bin, 5 | permissions: r-x, size: 0x200000} 6 | ram: {base_addr: 0x20000000, size: 0x51000} 7 | peripherals: 8 | logger: {base_addr: 0x40000000, emulate: HaltPeripheral, permissions: rw-, size: 0x20000000} -------------------------------------------------------------------------------- /test/STM32/STM32469_EVAL/Ethernet/Halt_run_tcp_client.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | 3 | source ~/.virtualenvs/halucinator/bin/activate 4 | ./halucinator -c=test/STM32/STM32469_EVAL/Halt_config.yaml \ 5 | -a=test/STM32/STM32469_EVAL/Ethernet/TCP_Echo_Server_Client--board=STM32469I_EVAL--opt=Os--comp=arm-none-eabi-gcc--comp_version=4.9.3_addrs.yaml \ 6 | -m=test/STM32/STM32469_EVAL/Ethernet/Halt_TCP_Echo_Server_Client_Os_memory.yaml --log_blocks -n Halt_TCP_Echo_Client -------------------------------------------------------------------------------- /test/STM32/STM32469_EVAL/Ethernet/Halt_run_tcp_server.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | 3 | source ~/.virtualenvs/halucinator/bin/activate 4 | ./halucinator -c=test/STM32/STM32469_EVAL/Halt_config.yaml \ 5 | -a=test/STM32/STM32469_EVAL/Ethernet/TCP_Echo_Server--board=STM32469I_Eval--opt=Os--comp=arm-none-eabi-gcc--comp_version=4.9.3_addrs.yaml \ 6 | -m=test/STM32/STM32469_EVAL/Ethernet/Halt_TCP_Echo_Server_Os_memory.yaml --log_blocks -n Halt_TCP_Echo_Server -t=5558 -r=5557 -p=2222 -------------------------------------------------------------------------------- /test/STM32/STM32469_EVAL/Ethernet/Halt_run_udp_client.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | 3 | source ~/.virtualenvs/halucinator/bin/activate 4 | ./halucinator -c=test/STM32/STM32469_EVAL/Halt_config.yaml \ 5 | -a=test/STM32/STM32469_EVAL/Ethernet/UDP-echo-client--board=STM32469I_Eval--opt=Os--comp=arm-none-eabi-gcc--comp_version=4.9.3_addrs.yaml \ 6 | -m=test/STM32/STM32469_EVAL/Ethernet/Halt_UDP-echo-client_Os_memory.yaml --log_blocks -n Halt_UDP_Echo_Client_no_intercepts -------------------------------------------------------------------------------- /test/STM32/STM32469_EVAL/Ethernet/Halt_run_udp_server.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | 3 | source ~/.virtualenvs/halucinator/bin/activate 4 | ./halucinator -c=test/STM32/STM32469_EVAL/Halt_config.yaml \ 5 | -a=test/STM32/STM32469_EVAL/Ethernet/UDP_echo_server--board=STM32469I_Eval--opt=Os--comp=arm-none-eabi-gcc--comp_version=4.9.3_addrs.yaml \ 6 | -m=test/STM32/STM32469_EVAL/Ethernet/Halt_UDP_echo_server_Os_memory.yaml --log_blocks -n Halt_UDP_Echo_Server -t=5558 -r=5557 -p=2222 -------------------------------------------------------------------------------- /test/STM32/STM32469_EVAL/Ethernet/TCP_Echo_Server_Client_O0_memory.yaml: -------------------------------------------------------------------------------- 1 | memories: 2 | alias: {base_addr: 0x0, file: TCP_Echo_Server_Client--board=STM32469I_EVAL--opt=O0--comp=arm-none-eabi-gcc--comp_version=4.9.3.elf.bin, 3 | permissions: r-x, size: 0x800000} 4 | flash: {base_addr: 0x8000000, file: TCP_Echo_Server_Client--board=STM32469I_EVAL--opt=O0--comp=arm-none-eabi-gcc--comp_version=4.9.3.elf.bin, 5 | permissions: r-x, size: 0x200000} 6 | ram: {base_addr: 0x20000000, size: 0x51000} 7 | peripherals: 8 | logger: {base_addr: 0x40000000, emulate: GenericPeripheral, permissions: rw-, size: 0x20000000} -------------------------------------------------------------------------------- /test/STM32/STM32469_EVAL/Ethernet/TCP_Echo_Server_Client_Os_memory.yaml: -------------------------------------------------------------------------------- 1 | memories: 2 | alias: {base_addr: 0x0, file: TCP_Echo_Server_Client--board=STM32469I_EVAL--opt=Os--comp=arm-none-eabi-gcc--comp_version=4.9.3.elf.bin, 3 | permissions: r-x, size: 0x800000} 4 | flash: {base_addr: 0x8000000, file: TCP_Echo_Server_Client--board=STM32469I_EVAL--opt=Os--comp=arm-none-eabi-gcc--comp_version=4.9.3.elf.bin, 5 | permissions: r-x, size: 0x200000} 6 | ram: {base_addr: 0x20000000, size: 0x51000} 7 | peripherals: 8 | logger: {base_addr: 0x40000000, emulate: GenericPeripheral, permissions: rw-, size: 0x20000000} -------------------------------------------------------------------------------- /test/STM32/STM32469_EVAL/Ethernet/TCP_Echo_Server_O0_memory.yaml: -------------------------------------------------------------------------------- 1 | memories: 2 | alias: {base_addr: 0x0, file: TCP_Echo_Server--board=STM32469I_Eval--opt=O0--comp=arm-none-eabi-gcc--comp_version=4.9.3.elf.bin, 3 | permissions: r-x, size: 0x800000} 4 | flash: {base_addr: 0x8000000, file: TCP_Echo_Server--board=STM32469I_Eval--opt=O0--comp=arm-none-eabi-gcc--comp_version=4.9.3.elf.bin, 5 | permissions: r-x, size: 0x200000} 6 | ram: {base_addr: 0x20000000, size: 0x51000} 7 | peripherals: 8 | logger: {base_addr: 0x40000000, emulate: GenericPeripheral, permissions: rw-, size: 0x20000000} -------------------------------------------------------------------------------- /test/STM32/STM32469_EVAL/Ethernet/TCP_Echo_Server_Os_memory.yaml: -------------------------------------------------------------------------------- 1 | memories: 2 | alias: {base_addr: 0x0, file: TCP_Echo_Server--board=STM32469I_Eval--opt=Os--comp=arm-none-eabi-gcc--comp_version=4.9.3.elf.bin, 3 | permissions: r-x, size: 0x800000} 4 | flash: {base_addr: 0x8000000, file: TCP_Echo_Server--board=STM32469I_Eval--opt=Os--comp=arm-none-eabi-gcc--comp_version=4.9.3.elf.bin, 5 | permissions: r-x, size: 0x200000} 6 | ram: {base_addr: 0x20000000, size: 0x51000} 7 | peripherals: 8 | logger: {base_addr: 0x40000000, emulate: GenericPeripheral, permissions: rw-, size: 0x20000000} -------------------------------------------------------------------------------- /test/STM32/STM32469_EVAL/Ethernet/UDP-echo-client_O0_memory.yaml: -------------------------------------------------------------------------------- 1 | memories: 2 | alias: {base_addr: 0x0, file: UDP-echo-client--board=STM32469I_Eval--opt=O0--comp=arm-none-eabi-gcc--comp_version=4.9.3.elf.bin, 3 | permissions: r-x, size: 0x800000} 4 | flash: {base_addr: 0x8000000, file: UDP-echo-client--board=STM32469I_Eval--opt=O0--comp=arm-none-eabi-gcc--comp_version=4.9.3.elf.bin, 5 | permissions: r-x, size: 0x200000} 6 | ram: {base_addr: 0x20000000, size: 0x51000} 7 | peripherals: 8 | logger: {base_addr: 0x40000000, emulate: GenericPeripheral, permissions: rw-, size: 0x20000000} -------------------------------------------------------------------------------- /test/STM32/STM32469_EVAL/Ethernet/UDP-echo-client_Os_memory.yaml: -------------------------------------------------------------------------------- 1 | memories: 2 | alias: {base_addr: 0x0, file: UDP-echo-client--board=STM32469I_Eval--opt=Os--comp=arm-none-eabi-gcc--comp_version=4.9.3.elf.bin, 3 | permissions: r-x, size: 0x800000} 4 | flash: {base_addr: 0x8000000, file: UDP-echo-client--board=STM32469I_Eval--opt=Os--comp=arm-none-eabi-gcc--comp_version=4.9.3.elf.bin, 5 | permissions: r-x, size: 0x200000} 6 | ram: {base_addr: 0x20000000, size: 0x51000} 7 | peripherals: 8 | logger: {base_addr: 0x40000000, emulate: GenericPeripheral, permissions: rw-, size: 0x20000000} -------------------------------------------------------------------------------- /test/STM32/STM32469_EVAL/Ethernet/UDP_echo_server_O0_memory.yaml: -------------------------------------------------------------------------------- 1 | memories: 2 | alias: {base_addr: 0x0, file: UDP_echo_server--board=STM32469I_Eval--opt=O0--comp=arm-none-eabi-gcc--comp_version=4.9.3.elf.bin, 3 | permissions: r-x, size: 0x800000} 4 | flash: {base_addr: 0x8000000, file: UDP_echo_server--board=STM32469I_Eval--opt=O0--comp=arm-none-eabi-gcc--comp_version=4.9.3.elf.bin, 5 | permissions: r-x, size: 0x200000} 6 | ram: {base_addr: 0x20000000, size: 0x51000} 7 | peripherals: 8 | logger: {base_addr: 0x40000000, emulate: GenericPeripheral, permissions: rw-, size: 0x20000000} -------------------------------------------------------------------------------- /test/STM32/STM32469_EVAL/Ethernet/UDP_echo_server_Os_memory.yaml: -------------------------------------------------------------------------------- 1 | memories: 2 | alias: {base_addr: 0x0, file: UDP_echo_server--board=STM32469I_Eval--opt=Os--comp=arm-none-eabi-gcc--comp_version=4.9.3.elf.bin, 3 | permissions: r-x, size: 0x800000} 4 | flash: {base_addr: 0x8000000, file: UDP_echo_server--board=STM32469I_Eval--opt=Os--comp=arm-none-eabi-gcc--comp_version=4.9.3.elf.bin, 5 | permissions: r-x, size: 0x200000} 6 | ram: {base_addr: 0x20000000, size: 0x51000} 7 | peripherals: 8 | logger: {base_addr: 0x40000000, emulate: GenericPeripheral, permissions: rw-, size: 0x20000000} -------------------------------------------------------------------------------- /test/STM32/STM32469_EVAL/Fatfs_uSD/BB_run_release.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | 3 | source ~/.virtualenvs/halucinator/bin/activate 4 | 5 | ./halucinator -c=test/results/STM32469_EVAL/BB_peripheral_config.yaml \ 6 | -a=test/results/STM32469_EVAL/Fatfs_uSD/FatFS_uSD--board=STM32469_EVAL--opt=Os--comp=arm-none-eabi-gcc--comp_version=4.9.3_addrs.yaml \ 7 | -m=test/results/STM32469_EVAL/Fatfs_uSD/FatFS_uSD_Os_memory.yaml --log_blocks -n BB_FatFS_uSD -------------------------------------------------------------------------------- /test/STM32/STM32469_EVAL/Fatfs_uSD/FatFS_uSD_O0_memory.yaml: -------------------------------------------------------------------------------- 1 | memories: 2 | alias: {base_addr: 0x0, file: FatFS_uSD--board=STM32469_EVAL--opt=O0--comp=arm-none-eabi-gcc--comp_version=4.9.3.elf.bin, 3 | permissions: r-x, size: 0x800000} 4 | flash: {base_addr: 0x8000000, file: FatFS_uSD--board=STM32469_EVAL--opt=O0--comp=arm-none-eabi-gcc--comp_version=4.9.3.elf.bin, 5 | permissions: r-x, size: 0x200000} 6 | ram: {base_addr: 0x20000000, size: 0x51000} 7 | peripherals: 8 | logger: {base_addr: 0x40000000, emulate: GenericPeripheral, permissions: rw-, size: 0x20000000} -------------------------------------------------------------------------------- /test/STM32/STM32469_EVAL/Fatfs_uSD/FatFS_uSD_Os_memory.yaml: -------------------------------------------------------------------------------- 1 | memories: 2 | alias: {base_addr: 0x0, file: FatFS_uSD--board=STM32469_EVAL--opt=Os--comp=arm-none-eabi-gcc--comp_version=4.9.3.elf.bin, 3 | permissions: r-x, size: 0x800000} 4 | flash: {base_addr: 0x8000000, file: FatFS_uSD--board=STM32469_EVAL--opt=Os--comp=arm-none-eabi-gcc--comp_version=4.9.3.elf.bin, 5 | permissions: r-x, size: 0x200000} 6 | ram: {base_addr: 0x20000000, size: 0x51000} 7 | peripherals: 8 | logger: {base_addr: 0x40000000, emulate: GenericPeripheral, permissions: rw-, size: 0x20000000} -------------------------------------------------------------------------------- /test/STM32/STM32469_EVAL/Fatfs_uSD/Full_run_release.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | 3 | source ~/.virtualenvs/halucinator/bin/activate 4 | 5 | ./halucinator -c=test/results/STM32469_EVAL/Full_peripheral_config.yaml \ 6 | -a=test/results/STM32469_EVAL/Fatfs_uSD/FatFS_uSD--board=STM32469_EVAL--opt=Os--comp=arm-none-eabi-gcc--comp_version=4.9.3_addrs.yaml \ 7 | -m=test/results/STM32469_EVAL/Fatfs_uSD/FatFS_uSD_Os_memory.yaml --log_blocks -n Full_FatFS_uSD -------------------------------------------------------------------------------- /test/STM32/STM32469_EVAL/Fatfs_uSD/Halt_memory_FatFS_uSD_Os.yaml: -------------------------------------------------------------------------------- 1 | memories: 2 | alias: {base_addr: 0x0, file: FatFS_uSD--board=STM32469_EVAL--opt=Os--comp=arm-none-eabi-gcc--comp_version=4.9.3.elf.bin, 3 | permissions: r-x, size: 0x800000} 4 | flash: {base_addr: 0x8000000, file: FatFS_uSD--board=STM32469_EVAL--opt=Os--comp=arm-none-eabi-gcc--comp_version=4.9.3.elf.bin, 5 | permissions: r-x, size: 0x200000} 6 | ram: {base_addr: 0x20000000, size: 0x51000} 7 | peripherals: 8 | logger: {base_addr: 0x40000000, emulate: HaltPeripheral, permissions: rw-, size: 0x20000000} -------------------------------------------------------------------------------- /test/STM32/STM32469_EVAL/Fatfs_uSD/Halt_run_release.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | 3 | source ~/.virtualenvs/halucinator/bin/activate 4 | 5 | ./halucinator -c=test/results/STM32469_EVAL/Halt_config.yaml \ 6 | -a=test/results/STM32469_EVAL/Fatfs_uSD/FatFS_uSD--board=STM32469_EVAL--opt=Os--comp=arm-none-eabi-gcc--comp_version=4.9.3_addrs.yaml \ 7 | -m=test/results/STM32469_EVAL/Fatfs_uSD/Halt_memory_FatFS_uSD_Os.yaml --log_blocks -n Halt_FatFS -------------------------------------------------------------------------------- /test/STM32/STM32469_EVAL/Halt_config.yaml: -------------------------------------------------------------------------------- 1 | intercepts: {} 2 | -------------------------------------------------------------------------------- /test/STM32/STM32469_EVAL/UART/BB_run_release_DMA.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | 3 | source ~/.virtualenvs/halucinator/bin/activate 4 | 5 | ./halucinator -c=test/results/STM32469_EVAL/BB_peripheral_config.yaml \ 6 | -a=test/results/STM32469_EVAL/UART/Uart_Hyperterminal_DMA--board=STM32469I_EVAL--opt=O0--comp=arm-none-eabi-gcc--comp_version=4.9.3_addrs.yaml \ 7 | -m=test/results/STM32469_EVAL/UART/Uart_Hyperterminal_DMA_Os_memory.yaml --log_blocks -n BB_UART_DMA -------------------------------------------------------------------------------- /test/STM32/STM32469_EVAL/UART/BB_run_release_IT.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | 3 | # source ~/.virtualenvs/halucinator/bin/activate 4 | 5 | ./halucinator -c=test/results/STM32469_EVAL/BB_peripheral_config.yaml \ 6 | -a=test/results/STM32469_EVAL/UART/Uart_Hyperterminal_IT--board\=STM32469_EVAL--opt\=Os--comp\=arm-none-eabi-gcc--comp_version\=4.9.3_addrs.yaml \ 7 | -m=test/results/STM32469_EVAL/UART/Uart_Hyperterminal_IT_Os_memory.yaml --log_blocks -n BB_UART_IT -------------------------------------------------------------------------------- /test/STM32/STM32469_EVAL/UART/Full_run_release_IT.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | 3 | source ~/.virtualenvs/halucinator/bin/activate 4 | 5 | ./halucinator -c=test/results/STM32469_EVAL/Full_peripheral_config.yaml \ 6 | -a=test/results/STM32469_EVAL/UART/Uart_Hyperterminal_IT--board\=STM32469_EVAL--opt\=Os--comp\=arm-none-eabi-gcc--comp_version\=4.9.3_addrs.yaml \ 7 | -m=test/results/STM32469_EVAL/UART/Uart_Hyperterminal_IT_Os_memory.yaml --log_blocks -n Full_UART_IT -------------------------------------------------------------------------------- /test/STM32/STM32469_EVAL/UART/Halt_memory_Uart_Hyperterminal_DMA_Os.yaml: -------------------------------------------------------------------------------- 1 | memories: 2 | alias: {base_addr: 0x0, file: Uart_Hyperterminal_DMA--board=STM32469I_EVAL--opt=Os--comp=arm-none-eabi-gcc--comp_version=4.9.3.elf.bin, 3 | permissions: r-x, size: 0x800000} 4 | flash: {base_addr: 0x8000000, file: Uart_Hyperterminal_DMA--board=STM32469I_EVAL--opt=Os--comp=arm-none-eabi-gcc--comp_version=4.9.3.elf.bin, 5 | permissions: r-x, size: 0x200000} 6 | ram: {base_addr: 0x20000000, size: 0x51000} 7 | peripherals: 8 | logger: {base_addr: 0x40000000, emulate: HaltPeripheral, permissions: rw-, size: 0x20000000} -------------------------------------------------------------------------------- /test/STM32/STM32469_EVAL/UART/Halt_memory_Uart_Hyperterminal_IT_Os_Halt.yaml: -------------------------------------------------------------------------------- 1 | memories: 2 | alias: {base_addr: 0x0, file: Uart_Hyperterminal_IT--board=STM32469_EVAL--opt=Os--comp=arm-none-eabi-gcc--comp_version=4.9.3.elf.bin, 3 | permissions: r-x, size: 0x800000} 4 | flash: {base_addr: 0x8000000, file: Uart_Hyperterminal_IT--board=STM32469_EVAL--opt=Os--comp=arm-none-eabi-gcc--comp_version=4.9.3.elf.bin, 5 | permissions: r-x, size: 0x200000} 6 | ram: {base_addr: 0x20000000, size: 0x51000} 7 | peripherals: 8 | logger: {base_addr: 0x40000000, emulate: HaltPeripheral, permissions: rw-, size: 0x20000000} -------------------------------------------------------------------------------- /test/STM32/STM32469_EVAL/UART/Halt_run_release_DMA.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | 3 | source ~/.virtualenvs/halucinator/bin/activate 4 | 5 | ./halucinator -c=test/results/STM32469_EVAL/Halt_config.yaml \ 6 | -a=test/results/STM32469_EVAL/UART/Uart_Hyperterminal_DMA--board=STM32469_EVAL--opt=Os--comp=arm-none-eabi-gcc--comp_version=4.9.3_addrs.yaml \ 7 | -m=test/results/STM32469_EVAL/UART/Halt_memory_Uart_Hyperterminal_DMA_Os.yaml --log_blocks -n Halt_UART_DMA -------------------------------------------------------------------------------- /test/STM32/STM32469_EVAL/UART/Halt_run_release_IT.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | 3 | source ~/.virtualenvs/halucinator/bin/activate 4 | 5 | ./halucinator -c=test/results/STM32469_EVAL/Halt_config.yaml \ 6 | -a=test/results/STM32469_EVAL/UART/Uart_Hyperterminal_IT--board\=STM32469_EVAL--opt\=Os--comp\=arm-none-eabi-gcc--comp_version\=4.9.3_addrs.yaml \ 7 | -m=test/results/STM32469_EVAL/UART/Halt_memory_Uart_Hyperterminal_IT_Os_Halt.yaml --log_blocks -n Halt_UART_IT -------------------------------------------------------------------------------- /test/STM32/STM32469_EVAL/UART/Running.md: -------------------------------------------------------------------------------- 1 | # Running Uart Examples 2 | 3 | For all two terminals are needed in one run. All commands should be run 4 | from the repo root 5 | 6 | ```sh 7 | workon halucinator 8 | python -m halucinator.external_devices.uart -i=1073811456 9 | ``` 10 | 11 | Then run either the IT or DMA example, each has 3 options. Halt on first MMIO, 12 | Black box emulation, and No MMIO. 13 | 14 | ## UART_Hyperterminal_IT 15 | 16 | Halt 17 | 18 | ```sh 19 | ./test/results/STM32469_EVAL/UART/Halt_run_release_IT.sh 20 | ``` 21 | 22 | Black Box 23 | 24 | ```sh 25 | ./test/results/STM32469_EVAL/UART/BB_run_release_IT.sh 26 | ``` 27 | 28 | Terminal 2 29 | 30 | ```sh 31 | python -m halucinator.external_devices.uart -i=1073811456 32 | ``` 33 | 34 | ## UART_Hypertermincal_DMA 35 | 36 | Currently broken 37 | 38 | -------------------------------------------------------------------------------- /test/STM32/STM32469_EVAL/UART/Uart_Hyperterminal_DMA_O0_memory.yaml: -------------------------------------------------------------------------------- 1 | memories: 2 | alias: {base_addr: 0x0, file: Uart_Hyperterminal_DMA--board=STM32469I_EVAL--opt=O0--comp=arm-none-eabi-gcc--comp_version=4.9.3.elf.bin, 3 | permissions: r-x, size: 0x800000} 4 | flash: {base_addr: 0x8000000, file: Uart_Hyperterminal_DMA--board=STM32469I_EVAL--opt=O0--comp=arm-none-eabi-gcc--comp_version=4.9.3.elf.bin, 5 | permissions: r-x, size: 0x200000} 6 | ram: {base_addr: 0x20000000, size: 0x51000} 7 | peripherals: 8 | logger: {base_addr: 0x40000000, emulate: GenericPeripheral, permissions: rw-, size: 0x20000000} -------------------------------------------------------------------------------- /test/STM32/STM32469_EVAL/UART/Uart_Hyperterminal_DMA_Os_memory.yaml: -------------------------------------------------------------------------------- 1 | memories: 2 | alias: {base_addr: 0x0, file: Uart_Hyperterminal_DMA--board=STM32469I_EVAL--opt=Os--comp=arm-none-eabi-gcc--comp_version=4.9.3.elf.bin, 3 | permissions: r-x, size: 0x800000} 4 | flash: {base_addr: 0x8000000, file: Uart_Hyperterminal_DMA--board=STM32469I_EVAL--opt=Os--comp=arm-none-eabi-gcc--comp_version=4.9.3.elf.bin, 5 | permissions: r-x, size: 0x200000} 6 | ram: {base_addr: 0x20000000, size: 0x51000} 7 | peripherals: 8 | logger: {base_addr: 0x40000000, emulate: GenericPeripheral, permissions: rw-, size: 0x20000000} -------------------------------------------------------------------------------- /test/STM32/STM32469_EVAL/UART/Uart_Hyperterminal_IT_O0_memory.yaml: -------------------------------------------------------------------------------- 1 | memories: 2 | alias: {base_addr: 0x0, file: Uart_Hyperterminal_IT--board=STM32469_EVAL--opt=O0--comp=arm-none-eabi-gcc--comp_version=4.9.3.elf.bin, 3 | permissions: r-x, size: 0x800000} 4 | flash: {base_addr: 0x8000000, file: Uart_Hyperterminal_IT--board=STM32469_EVAL--opt=O0--comp=arm-none-eabi-gcc--comp_version=4.9.3.elf.bin, 5 | permissions: r-x, size: 0x200000} 6 | ram: {base_addr: 0x20000000, size: 0x51000} 7 | peripherals: 8 | logger: {base_addr: 0x40000000, emulate: GenericPeripheral, permissions: rw-, size: 0x20000000} -------------------------------------------------------------------------------- /test/STM32/STM32469_EVAL/UART/Uart_Hyperterminal_IT_Os_memory.yaml: -------------------------------------------------------------------------------- 1 | memories: 2 | alias: {base_addr: 0x0, file: Uart_Hyperterminal_IT--board=STM32469_EVAL--opt=Os--comp=arm-none-eabi-gcc--comp_version=4.9.3.elf.bin, 3 | permissions: r-x, size: 0x800000} 4 | flash: {base_addr: 0x8000000, file: Uart_Hyperterminal_IT--board=STM32469_EVAL--opt=Os--comp=arm-none-eabi-gcc--comp_version=4.9.3.elf.bin, 5 | permissions: r-x, size: 0x200000} 6 | ram: {base_addr: 0x20000000, size: 0x51000} 7 | peripherals: 8 | logger: {base_addr: 0x40000000, emulate: GenericPeripheral, permissions: rw-, size: 0x20000000} -------------------------------------------------------------------------------- /test/STM32/example/Uart_Hyperterminal_IT_O0.elf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/embedded-sec/halucinator/fa85a1dcbaaa72bd425094fc3917abdd7d9b9a8a/test/STM32/example/Uart_Hyperterminal_IT_O0.elf -------------------------------------------------------------------------------- /test/STM32/example/Uart_Hyperterminal_IT_O0.elf.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/embedded-sec/halucinator/fa85a1dcbaaa72bd425094fc3917abdd7d9b9a8a/test/STM32/example/Uart_Hyperterminal_IT_O0.elf.bin -------------------------------------------------------------------------------- /test/STM32/example/Uart_Hyperterminal_IT_O0_addrs.yaml: -------------------------------------------------------------------------------- 1 | architecture: ARMEL 2 | base_address: 0 3 | entry_point: 0 4 | symbols: 5 | 134218164: deregister_tm_clones 6 | 134218196: register_tm_clones 7 | 134218232: __do_global_dtors_aux 8 | 134218272: frame_dummy 9 | 134218328: __aeabi_uldivmod 10 | 134218376: __gnu_ldivmod_helper 11 | 134218424: __gnu_uldivmod_helper 12 | 134218472: __aeabi_idiv0 13 | 134218476: __divdi3 14 | 134219160: __udivdi3 15 | 134219784: Reset_Handler 16 | 134219864: DMA1_Stream3_IRQHandler 17 | 134219868: HAL_RCC_ClockConfig 18 | 134220320: HAL_RCC_GetSysClockFreq 19 | 134220652: HAL_RCC_GetHCLKFreq 20 | 134220676: HAL_RCC_GetPCLK1Freq 21 | 134220716: HAL_RCC_GetPCLK2Freq 22 | 134220756: HAL_GPIO_Init 23 | 134221600: HAL_GPIO_WritePin 24 | 134221648: HAL_Init 25 | 134221716: HAL_MspInit 26 | 134221728: HAL_InitTick 27 | 134221824: HAL_IncTick 28 | 134221860: HAL_GetTick 29 | 134221884: main 30 | 134222132: SystemClock_Config 31 | 134222356: Error_Handler 32 | 134222368: HAL_UART_TxCpltCallback 33 | 134222388: HAL_UART_RxCpltCallback 34 | 134222408: HAL_UART_ErrorCallback 35 | 134222428: HAL_UART_Init 36 | 134222584: HAL_UART_Transmit_IT 37 | 134222724: HAL_UART_Receive_IT 38 | 134222880: HAL_UART_IRQHandler 39 | 134223380: HAL_UART_GetState 40 | 134223440: UART_EndRxTransfer 41 | 134223500: UART_DMAAbortOnError 42 | 134223540: UART_Transmit_IT 43 | 134223712: UART_EndTransmit_IT 44 | 134223760: UART_Receive_IT 45 | 134224004: UART_SetConfig 46 | 134225080: HAL_UART_MspInit 47 | 134225260: HAL_DMA_Abort_IT 48 | 134225328: HAL_RCC_OscConfig 49 | 134226480: HAL_PWREx_EnableOverDrive 50 | 134226636: BSP_LED_Init 51 | 134226752: BSP_LED_On 52 | 134226804: NMI_Handler 53 | 134226816: HardFault_Handler 54 | 134226824: MemManage_Handler 55 | 134226832: BusFault_Handler 56 | 134226840: UsageFault_Handler 57 | 134226848: SVC_Handler 58 | 134226860: DebugMon_Handler 59 | 134226872: PendSV_Handler 60 | 134226884: SysTick_Handler 61 | 134226896: USART1_IRQHandler 62 | 134226912: SystemInit 63 | 134227004: NVIC_SetPriorityGrouping 64 | 134227076: NVIC_GetPriorityGrouping 65 | 134227104: NVIC_EnableIRQ 66 | 134227152: NVIC_SetPriority 67 | 134227236: NVIC_EncodePriority 68 | 134227336: SysTick_Config 69 | 134227404: HAL_NVIC_SetPriorityGrouping 70 | 134227424: HAL_NVIC_SetPriority 71 | 134227480: HAL_NVIC_EnableIRQ 72 | 134227508: HAL_SYSTICK_Config 73 | 134227532: atexit 74 | 134227544: __libc_fini_array 75 | 134227588: __libc_init_array 76 | 134227668: __register_exitproc 77 | 134227832: register_fini 78 | 134227852: _init 79 | 134227864: _fini 80 | -------------------------------------------------------------------------------- /test/STM32/example/Uart_Hyperterminal_IT_O0_config.yaml: -------------------------------------------------------------------------------- 1 | intercepts: 2 | 3 | - class: halucinator.bp_handlers.IPythonShell 4 | function: HardFault_Handler 5 | symbol: HardFault_Handler 6 | 7 | # - class: halucinator.bp_handlers.IPythonShell 8 | # addr: 0x0800_2384 9 | # function: Infinite_fault 10 | 11 | 12 | # -------------------------------UART ---------------------------------------- 13 | - class: halucinator.bp_handlers.stm32f4.stm32f4_uart.STM32F4UART 14 | function: HAL_UART_Init 15 | symbol: HAL_UART_Init 16 | - class: halucinator.bp_handlers.stm32f4.stm32f4_uart.STM32F4UART 17 | function: HAL_UART_GetState 18 | symbol: HAL_UART_GetState 19 | - class: halucinator.bp_handlers.stm32f4.stm32f4_uart.STM32F4UART 20 | function: HAL_UART_Transmit 21 | symbol: HAL_UART_Transmit 22 | - class: halucinator.bp_handlers.stm32f4.stm32f4_uart.STM32F4UART 23 | function: HAL_UART_Transmit_IT 24 | symbol: HAL_UART_Transmit_IT 25 | - class: halucinator.bp_handlers.stm32f4.stm32f4_uart.STM32F4UART 26 | function: HAL_UART_Transmit_DMA 27 | symbol: HAL_UART_Transmit_DMA 28 | - class: halucinator.bp_handlers.stm32f4.stm32f4_uart.STM32F4UART 29 | function: HAL_UART_Receive 30 | symbol: HAL_UART_Receive 31 | - class: halucinator.bp_handlers.stm32f4.stm32f4_uart.STM32F4UART 32 | function: HAL_UART_Receive_IT 33 | symbol: HAL_UART_Receive_IT 34 | - class: halucinator.bp_handlers.stm32f4.stm32f4_uart.STM32F4UART 35 | function: HAL_UART_Receive_DMA 36 | symbol: HAL_UART_Receive_DMA 37 | # ---------------------------------------------------------------------------- 38 | 39 | # -------------------------------Generic ------------------------------------ 40 | 41 | - class: halucinator.bp_handlers.SkipFunc 42 | function: HAL_Delay 43 | symbol: HAL_Delay 44 | - class: halucinator.bp_handlers.generic.timer.Timer 45 | function: HAL_GetTick 46 | symbol: HAL_GetTick 47 | - class: halucinator.bp_handlers.ReturnZero 48 | function: HAL_Init 49 | symbol: HAL_Init 50 | - class: halucinator.bp_handlers.ReturnZero 51 | function: HAL_InitTick 52 | symbol: HAL_InitTick 53 | - class: halucinator.bp_handlers.Counter 54 | function: HAL_IncTick 55 | symbol: HAL_IncTick 56 | - class: halucinator.bp_handlers.ReturnZero 57 | function: HAL_MspInit 58 | symbol: HAL_MspInit 59 | 60 | - class: halucinator.bp_handlers.ReturnZero 61 | function: HAL_RCC_ClockConfig 62 | symbol: HAL_RCC_ClockConfig 63 | # - class: halucinator.bp_handlers.ReturnZero 64 | # function: HAL_RCC_GetHCLKFreq 65 | # - class: halucinator.bp_handlers.ReturnZero 66 | # function: HAL_RCC_GetPCLK1Freq 67 | # - class: halucinator.bp_handlers.ReturnZero 68 | # function: HAL_RCC_GetSysClockFreq 69 | - class: halucinator.bp_handlers.ReturnZero 70 | function: HAL_RCC_OscConfig 71 | symbol: HAL_RCC_OscConfig 72 | # - class: halucinator.bp_handlers.ReturnZero 73 | # function: HAL_SYSTICK_Config 74 | - class: halucinator.bp_handlers.ReturnZero 75 | function: HAL_PWREx_EnableOverDrive 76 | symbol: HAL_PWREx_EnableOverDrive 77 | # - class: halucinator.bp_handlers.ReturnZero 78 | # function: BSP_IO_Init 79 | # - class: halucinator.bp_handlers.ReturnZero 80 | # function: BSP_IO_ConfigPin 81 | -------------------------------------------------------------------------------- /test/STM32/example/Uart_Hyperterminal_IT_O0_memory.yaml: -------------------------------------------------------------------------------- 1 | memories: 2 | alias: {base_addr: 0x0, file: Uart_Hyperterminal_IT_O0.elf.bin, 3 | permissions: r-x, size: 0x800000} 4 | flash: {base_addr: 0x8000000, file: Uart_Hyperterminal_IT_O0.elf.bin, 5 | permissions: r-x, size: 0x200000} 6 | ram: {base_addr: 0x20000000, size: 0x51000} 7 | peripherals: 8 | logger: {base_addr: 0x40000000, emulate: GenericPeripheral, permissions: rw-, size: 0x20000000} -------------------------------------------------------------------------------- /test/STM32/example/logging.cfg: -------------------------------------------------------------------------------- 1 | # For file format and explaination see 2 | # https://docs.python.org/3/library/logging.config.html#logging-config-fileformat 3 | [loggers] 4 | keys=root,halucinator.main,HAL_LOG 5 | 6 | [handlers] 7 | keys=consoleHandler 8 | 9 | [formatters] 10 | keys=sampleFormatter 11 | 12 | [logger_root] 13 | level=ERROR 14 | handlers=consoleHandler 15 | 16 | [logger_halucinator.main] 17 | level=INFO 18 | handlers=consoleHandler 19 | propagate=0 20 | qualname=halucinator.main 21 | 22 | [logger_HAL_LOG] 23 | level=INFO 24 | handlers=consoleHandler 25 | propagate=0 26 | qualname=HAL_LOG 27 | 28 | [logger_halucinator] 29 | level=DEBUG 30 | handlers=consoleHandler 31 | propagate=0 32 | qualname=halucinator 33 | 34 | [handler_consoleHandler] 35 | class=StreamHandler 36 | level=DEBUG 37 | formatter=sampleFormatter 38 | args=(sys.stdout,) 39 | 40 | [formatter_sampleFormatter] 41 | format=%(name)s|%(levelname)s| %(message)s 42 | -------------------------------------------------------------------------------- /test/STM32/example/run.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | 3 | #source ~/.virtualenvs/halucinator/bin/activate 4 | 5 | halucinator -c=test/STM32/example/Uart_Hyperterminal_IT_O0_config.yaml \ 6 | -c test/STM32/example/Uart_Hyperterminal_IT_O0_addrs.yaml \ 7 | -c test/STM32/example/Uart_Hyperterminal_IT_O0_memory.yaml --log_blocks=trace-nochain -n Uart_Example 8 | -------------------------------------------------------------------------------- /test/STM32/st-plc/peripheral_config_halt.yaml: -------------------------------------------------------------------------------- 1 | intercepts: {} 2 | -------------------------------------------------------------------------------- /test/STM32/st-plc/st-plc-bb.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | 3 | source ~/.virtualenvs/halucinator/bin/activate 4 | ./halucinator -c=test/STM32/st-plc/peripheral_config_bb.yaml \ 5 | -a=test/STM32/st-plc/st-plc_addrs.yaml \ 6 | -m=test/STM32/st-plc/st-plc_memory.yaml --log_blocks -n BB-ST-PLC -t=5558 -r=5557 -p=2222 7 | -------------------------------------------------------------------------------- /test/STM32/st-plc/st-plc-halt.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | 3 | source ~/.virtualenvs/halucinator/bin/activate 4 | ./halucinator -c=test/STM32/st-plc/peripheral_config_halt.yaml \ 5 | -a=test/STM32/st-plc/st-plc_addrs.yaml \ 6 | -m=test/STM32/st-plc/st-plc_memory.yaml --log_blocks -n Halt-ST-PLC -t=5558 -r=5557 -p=2222 7 | -------------------------------------------------------------------------------- /test/STM32/st-plc/st-plc.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | 3 | source ~/.virtualenvs/halucinator/bin/activate 4 | ./halucinator -c=test/STM32/st-plc/peripheral_config.yaml \ 5 | -a=test/STM32/st-plc/st-plc_addrs.yaml \ 6 | -m=test/STM32/st-plc/st-plc_memory.yaml --log_blocks -n ST-PLC -t=5558 -r=5557 -p=2222 -------------------------------------------------------------------------------- /test/STM32/st-plc/st-plc_memory.yaml: -------------------------------------------------------------------------------- 1 | memories: 2 | alias: {base_addr: 0x0, file: st-plc.bin, 3 | permissions: r-x, size: 0x800000} 4 | flash: {base_addr: 0x8000000, file: st-plc.bin, 5 | permissions: r-x, size: 0x200000} 6 | ram: {base_addr: 0x20000000, size: 0x100000} 7 | peripherals: 8 | logger: {base_addr: 0x40000000, emulate: GenericPeripheral, permissions: rw-, size: 0x20000000} -------------------------------------------------------------------------------- /tutorial/hal_tutorial/bp_handlers/led_bp_handler.py: -------------------------------------------------------------------------------- 1 | # Copyright 2019 National Technology & Engineering Solutions of Sandia, LLC (NTESS). 2 | # Under the terms of Contract DE-NA0003525 with NTESS, the U.S. Government retains 3 | # certain rights in this software. 4 | 5 | from os import sys, path 6 | # NOTE: 7 | # We import LED Model here 8 | from ..peripheral_models.led_peripheral import LEDModel 9 | from halucinator.bp_handlers import BPHandler, bp_handler 10 | import logging 11 | log = logging.getLogger(__name__) 12 | 13 | from halucinator import hal_log 14 | hal_log = hal_log.getHalLogger() 15 | 16 | 17 | class LEDHandler(BPHandler): 18 | 19 | def __init__(self, map_dict=None): 20 | self.model = LEDModel 21 | if map_dict == None: 22 | self.led_map = {} 23 | else: 24 | self.led_map = map_dict 25 | 26 | def get_id(self, led_id): 27 | try: 28 | led_id = self.led_map[led_id] 29 | except (KeyError): 30 | led_id = led_id 31 | return led_id 32 | 33 | @bp_handler(['My_BSP_LED_Init']) 34 | def led_init(self, target, bp_addr): 35 | log.debug("Init Called") 36 | # STEP 1. 37 | # Use target's get_arg method to get the LED arg 0 the function. 38 | # Then use self.get_id to convert it an id and 39 | # call self.model.off(led_id) to set the LED to off 40 | 41 | return True, None # Intercept and Return type is void 42 | 43 | @bp_handler(['My_BSP_LED_On']) 44 | def on(self, target, bp_addr): 45 | log.debug("LED On Called") 46 | # STEP 2. 47 | # Use target's get_arg method to get the LED arg 0 the function. 48 | # Then use self.get_id to convert it an id and 49 | # call self.model.on(led_id) to set the LED to on in the peripheral model 50 | 51 | return True, None # Return type is void 52 | 53 | @bp_handler(['My_BSP_LED_Off']) 54 | def off(self, target, bp_addr): 55 | log.debug("LED Off Called") 56 | # STEP 3. 57 | # Use target's get_arg method to get the LED arg 0 the function. 58 | # Then use self.get_id to convert it an id and 59 | # call self.model.off(led_id) to set the LED to off in the peripheral model 60 | 61 | return True, None # Return type is void 62 | 63 | -------------------------------------------------------------------------------- /tutorial/hal_tutorial/external_devices/led_external_device.py: -------------------------------------------------------------------------------- 1 | # Copyright 2020 National Technology & Engineering Solutions of Sandia, LLC (NTESS). 2 | # Under the terms of Contract DE-NA0003525 with NTESS, the U.S. Government retains 3 | # certain rights in this software. 4 | 5 | 6 | from halucinator.external_devices.ioserver import IOServer 7 | from halucinator.external_devices.uart import UARTPrintServer 8 | import logging 9 | log = logging.getLogger(__name__) 10 | 11 | # This is our extenal device calass that is going 12 | # to handle LEDs 13 | class LEDDevice(object): 14 | 15 | def __init__(self, ioserver): 16 | self.ioserver = ioserver 17 | # STEP 1 18 | # Notice saving the ioserver (above) and registing for the topic 19 | # There is a typo in topic class name that makes it so this 20 | # won't receive messages from your peripheral model. 21 | # It needs to match your peripheral_model class name 22 | topic = 'Peripheral.XXX_Model.led_status' 23 | 24 | log.debug("Registering for topic %s" % topic) 25 | ioserver.register_topic(topic, self.write_handler) 26 | 27 | def write_handler(self, ioserver, msg): 28 | log.debug("Got status %s" % str(msg)) 29 | # STEP 2 30 | # You will msg will be a dict like {'id': LED_ID, 'status':} 31 | # Use print so message always shows up with format like 32 | # "LED: %s is %s" % (led_id, state) where state is 'On' or 'Off' 33 | 34 | 35 | 36 | def main(): 37 | from argparse import ArgumentParser 38 | p = ArgumentParser() 39 | p.add_argument('-r', '--rx_port', default=5556, 40 | help='Port number to receive zmq messages for IO on') 41 | p.add_argument('-t', '--tx_port', default=5555, 42 | help='Port number to send IO messages via zmq') 43 | p.add_argument('-i', '--id', default=0x20000ab0, type=int, 44 | help="Id to use when sending data") 45 | p.add_argument('-n', '--newline', default=False, action='store_true', 46 | help="Append Newline") 47 | args = p.parse_args() 48 | 49 | import halucinator.hal_log as hal_log 50 | hal_log.setLogConfig() 51 | 52 | io_server = IOServer(args.rx_port, args.tx_port) 53 | uart = UARTPrintServer(io_server) 54 | 55 | # STEP 3 56 | # Instantiate your LEDDevice class and as led and pass io_server to its initializer 57 | led = LEDDevice(io_server) 58 | io_server.start() 59 | 60 | try: 61 | while(1): 62 | data = input() 63 | log.debug("Got %s" % str(data)) 64 | if args.newline: 65 | data +="\n" 66 | if data == '\\n': 67 | data = '\r\n' 68 | elif data == '': 69 | break 70 | #d = {'id':args.id, 'data': data} 71 | uart.send_data(args.id, data) 72 | except KeyboardInterrupt: 73 | pass 74 | log.info("Shutting Down") 75 | io_server.shutdown() 76 | 77 | 78 | if __name__ == '__main__': 79 | main() -------------------------------------------------------------------------------- /tutorial/hal_tutorial/peripheral_models/led_peripheral.py: -------------------------------------------------------------------------------- 1 | # Copyright 2020 National Technology & Engineering Solutions of Sandia, LLC (NTESS). 2 | # Under the terms of Contract DE-NA0003525 with NTESS, the U.S. Government retains 3 | # certain rights in this software. 4 | 5 | from halucinator.peripheral_models import peripheral_server 6 | import logging 7 | from itertools import repeat 8 | 9 | log = logging.getLogger(__name__) 10 | 11 | #STEP 1. Register the class with the peripheral server 12 | # using the @peripheral_server.peripheral_model decorator 13 | 14 | class LEDModel(object): 15 | 16 | 17 | @classmethod 18 | #STEP 2. Add the @peripheral_server.tx_msg decorater to transmit the return 19 | # value of this method out the peripheral server with topic 20 | # 'Peripheral.LEDModel.led_status' 21 | 22 | def led_status(cls, led_id, status): 23 | log.debug("LED Status %s: %s" %(led_id, status)) 24 | #STEP 3. Compose a dictionary with the keys 'id' and 'status' and return it 25 | 26 | 27 | @classmethod 28 | def led_off(cls, led_id): 29 | log.debug("LED Off %s" % (led_id)) 30 | #STEP 4. Call the led_status method providing False for off 31 | 32 | 33 | 34 | @classmethod 35 | def led_on(cls, led_id): 36 | log.debug("LED On %s" % (led_id)) 37 | #STEP 5. Call the led_status method providing True for On 38 | -------------------------------------------------------------------------------- /tutorial/logging.cfg: -------------------------------------------------------------------------------- 1 | # For file format and explaination see 2 | # https://docs.python.org/3/library/logging.config.html#logging-config-fileformat 3 | [loggers] 4 | keys=root,halucinator.main,HAL_LOG,hal_tutorial 5 | 6 | [handlers] 7 | keys=consoleHandler 8 | 9 | [formatters] 10 | keys=sampleFormatter 11 | 12 | [logger_root] 13 | level=ERROR 14 | handlers=consoleHandler 15 | 16 | [logger_hal_tutorial] 17 | # STEP 1 Change from DEBUG to INFO 18 | level=DEBUG 19 | handlers=consoleHandler 20 | propagate=0 21 | qualname=hal_tutorial 22 | 23 | [logger_halucinator.main] 24 | level=INFO 25 | handlers=consoleHandler 26 | propagate=0 27 | qualname=halucinator.main 28 | 29 | [logger_HAL_LOG] 30 | level=INFO 31 | handlers=consoleHandler 32 | propagate=0 33 | qualname=HAL_LOG 34 | 35 | [logger_halucinator] 36 | level=DEBUG 37 | handlers=consoleHandler 38 | propagate=0 39 | qualname=halucinator 40 | 41 | [handler_consoleHandler] 42 | class=StreamHandler 43 | level=DEBUG 44 | formatter=sampleFormatter 45 | args=(sys.stdout,) 46 | 47 | [formatter_sampleFormatter] 48 | format=%(name)s|%(levelname)s| %(message)s 49 | -------------------------------------------------------------------------------- /tutorial/my_config.yaml: -------------------------------------------------------------------------------- 1 | intercepts: 2 | 3 | - class: hal_tutorial.bp_handlers.led_bp_handler.LEDHandler 4 | # STEP 1a 5 | # Uncomment the class_args, this will pass map_dict to the constructor 6 | # for this class and use nice strings for our LED names instead of numbers 7 | # class_args: {map_dict: {0: GREEN, 1: ORANGE, 2: RED, 3: BLUE}} 8 | function: My_BSP_LED_Init 9 | symbol: BSP_LED_Init 10 | 11 | - class: hal_tutorial.bp_handlers.led_bp_handler.LEDHandler 12 | # STEP 1b 13 | # Uncomment the class_args, this will pass map_dict to the constructor 14 | # for this class and use nice strings for our LED names instead of numbers 15 | # class_args: {map_dict: {0: GREEN, 1: ORANGE, 2: RED, 3: BLUE}} 16 | function: My_BSP_LED_Off 17 | symbol: BSP_LED_Off 18 | 19 | # Step 2 20 | # Using BSP_LED_Off as a template, add the intercept for BSP_LED_On 21 | # The name to map this to the bp_handler method is My_BSP_LED_On 22 | 23 | 24 | # NOTE: 25 | # We are going to make HAL_UART_Receive_IT appear to fail by returning -1 26 | # Comment out below to restore normal receive functionality 27 | - class: halucinator.bp_handlers.ReturnConstant 28 | registration_args: {ret_value: -1} 29 | function: HAL_UART_Receive_IT 30 | symbol: HAL_UART_Receive_IT 31 | 32 | 33 | -------------------------------------------------------------------------------- /tutorial/setup.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | # Copyright 2020 National Technology & Engineering Solutions of Sandia, LLC (NTESS). 4 | # Under the terms of Contract DE-NA0003525 with NTESS, the U.S. Government retains 5 | # certain rights in this software. 6 | 7 | 8 | import os 9 | from distutils.core import setup 10 | 11 | 12 | def get_packages(rel_dir): 13 | packages = [rel_dir] 14 | for x in os.walk(rel_dir): 15 | # break into parts 16 | base = list(os.path.split(x[0])) 17 | if base[0] == "": 18 | del base[0] 19 | 20 | for mod_name in x[1]: 21 | packages.append(".".join(base + [mod_name])) 22 | 23 | return packages 24 | 25 | 26 | setup(name='hal_tutorial', 27 | version='0.0.1', 28 | description='Halucinator Tutorial', 29 | author='', 30 | packages=get_packages('hal_tutorial'), 31 | entry_points ={'console_scripts': [ 32 | 'my_led_device = hal_tutorial.external_devices.led_external_device:main' 33 | ]}, 34 | requires=['halucinator']) 35 | -------------------------------------------------------------------------------- /tutorial/solutions/led_bp_handler.py: -------------------------------------------------------------------------------- 1 | # Copyright 2019 National Technology & Engineering Solutions of Sandia, LLC (NTESS). 2 | # Under the terms of Contract DE-NA0003525 with NTESS, the U.S. Government retains 3 | # certain rights in this software. 4 | 5 | from os import sys, path 6 | # NOTE: 7 | # We import LED Model here 8 | from ..peripheral_models.led_peripheral import LEDModel 9 | from halucinator.bp_handlers import BPHandler, bp_handler 10 | import logging 11 | log = logging.getLogger(__name__) 12 | 13 | from halucinator import hal_log 14 | hal_log = hal_log.getHalLogger() 15 | 16 | 17 | class LEDHandler(BPHandler): 18 | 19 | def __init__(self, map_dict=None): 20 | self.model = LEDModel 21 | if map_dict == None: 22 | self.led_map = {} 23 | else: 24 | self.led_map = map_dict 25 | 26 | def get_id(self, led_id): 27 | try: 28 | led_id = self.led_map[led_id] 29 | except (KeyError): 30 | led_id = led_id 31 | return led_id 32 | 33 | @bp_handler(['My_BSP_LED_Init']) 34 | def led_init(self, target, bp_addr): 35 | log.debug("Init Called") 36 | # STEP 1. 37 | # Use target's get_arg method to get the LED arg 0 the function. 38 | # Then use self.get_id to convert it an id and 39 | # call self.model.off(led_id) to set the LED to off 40 | led_id = self.get_id(target.get_arg(0)) 41 | self.model.led_off(led_id) 42 | return True, None # Intercept and Return type is void 43 | 44 | @bp_handler(['My_BSP_LED_On']) 45 | def on(self, target, bp_addr): 46 | log.debug("LED On Called") 47 | # STEP 2. 48 | # Use target's get_arg method to get the LED arg 0 the function. 49 | # Then use self.get_id to convert it an id and 50 | # call self.model.on(led_id) to set the LED to on in the peripheral model 51 | led_id = self.get_id(target.get_arg(0)) 52 | self.model.led_on(led_id) 53 | return True, None # Return type is void 54 | 55 | @bp_handler(['My_BSP_LED_Off']) 56 | def off(self, target, bp_addr): 57 | log.debug("LED Off Called") 58 | # STEP 3. 59 | # Use target's get_arg method to get the LED arg 0 the function. 60 | # Then use self.get_id to convert it an id and 61 | # call self.model.on(led_id) to set the LED to on in the peripheral model 62 | led_id = self.get_id(target.get_arg(0)) 63 | self.model.led_off(led_id) 64 | return True, None # Return type is void 65 | 66 | -------------------------------------------------------------------------------- /tutorial/solutions/led_external_device.py: -------------------------------------------------------------------------------- 1 | # Copyright 2020 National Technology & Engineering Solutions of Sandia, LLC (NTESS). 2 | # Under the terms of Contract DE-NA0003525 with NTESS, the U.S. Government retains 3 | # certain rights in this software. 4 | 5 | 6 | from halucinator.external_devices.ioserver import IOServer 7 | from halucinator.external_devices.uart import UARTPrintServer 8 | import logging 9 | log = logging.getLogger(__name__) 10 | 11 | # This is our extenal device calass that is going 12 | # to handle LEDs 13 | class LEDDevice(object): 14 | 15 | def __init__(self, ioserver): 16 | self.ioserver = ioserver 17 | # STEP 1 18 | # Notice saving the ioserver (above) and registing for the topic 19 | # There is a typo in topic class name that makes it so this 20 | # won't receive messages from your peripheral model. 21 | # It needs to match your peripheral_model class name 22 | topic = 'Peripheral.LEDModel.led_status' 23 | 24 | log.debug("Registering for topic %s" % topic) 25 | ioserver.register_topic(topic, self.write_handler) 26 | 27 | def write_handler(self, ioserver, msg): 28 | log.debug("Got status %s" % str(msg)) 29 | # STEP 2 30 | # You will msg will be a dict like {'id': LED_ID, 'status':} 31 | # Use print so message always shows up with format like 32 | # "LED: %s is %s" % (led_id, state) where state is 'On' or 'Off' 33 | state = 'On' if msg['status'] else 'Off' 34 | print("LED: %s is %s" % (msg['id'], state)) 35 | 36 | 37 | def main(): 38 | from argparse import ArgumentParser 39 | p = ArgumentParser() 40 | p.add_argument('-r', '--rx_port', default=5556, 41 | help='Port number to receive zmq messages for IO on') 42 | p.add_argument('-t', '--tx_port', default=5555, 43 | help='Port number to send IO messages via zmq') 44 | p.add_argument('-i', '--id', default=0x20000ab0, type=int, 45 | help="Id to use when sending data") 46 | p.add_argument('-n', '--newline', default=False, action='store_true', 47 | help="Append Newline") 48 | args = p.parse_args() 49 | 50 | import halucinator.hal_log as hal_log 51 | hal_log.setLogConfig() 52 | 53 | io_server = IOServer(args.rx_port, args.tx_port) 54 | uart = UARTPrintServer(io_server) 55 | 56 | # STEP 3 57 | # Instantiate your LEDDevice class and as led and pass io_server to its initializer 58 | led = LEDDevice(io_server) 59 | io_server.start() 60 | 61 | try: 62 | while(1): 63 | data = input() 64 | log.debug("Got %s" % str(data)) 65 | if args.newline: 66 | data +="\n" 67 | if data == '\\n': 68 | data = '\r\n' 69 | elif data == '': 70 | break 71 | #d = {'id':args.id, 'data': data} 72 | uart.send_data(args.id, data) 73 | except KeyboardInterrupt: 74 | pass 75 | log.info("Shutting Down") 76 | io_server.shutdown() 77 | 78 | 79 | if __name__ == '__main__': 80 | main() -------------------------------------------------------------------------------- /tutorial/solutions/led_peripheral.py: -------------------------------------------------------------------------------- 1 | # Copyright 2020 National Technology & Engineering Solutions of Sandia, LLC (NTESS). 2 | # Under the terms of Contract DE-NA0003525 with NTESS, the U.S. Government retains 3 | # certain rights in this software. 4 | 5 | from halucinator.peripheral_models import peripheral_server 6 | import logging 7 | from itertools import repeat 8 | 9 | log = logging.getLogger(__name__) 10 | 11 | #STEP 1. Register the class with the peripheral server 12 | # using the @peripheral_server.peripheral_model decorator 13 | @peripheral_server.peripheral_model 14 | class LEDModel(object): 15 | 16 | 17 | @classmethod 18 | #STEP 2. Add the @peripheral_server.tx_msg decorater to transmit the return 19 | # value of this method out the peripheral server with topic 20 | # 'Peripheral.LEDModel.led_status' 21 | @peripheral_server.tx_msg 22 | def led_status(cls, led_id, status): 23 | log.debug("LED Status %s: %s" %(led_id, status)) 24 | #STEP 3. Compose a dictionary with the keys 'id' and 'status' and return it 25 | return {'id':led_id, 'status':status} 26 | 27 | @classmethod 28 | def led_off(cls, led_id): 29 | log.debug("LED Off %s" % (led_id)) 30 | #STEP 4. Call the led_status method providing False for off 31 | cls.led_status(led_id, False) 32 | 33 | 34 | @classmethod 35 | def led_on(cls, led_id): 36 | log.debug("LED On %s" % (led_id)) 37 | #STEP 5. Call the led_status method providing True for On 38 | cls.led_status(led_id, True) -------------------------------------------------------------------------------- /tutorial/solutions/logging.cfg: -------------------------------------------------------------------------------- 1 | # For file format and explaination see 2 | # https://docs.python.org/3/library/logging.config.html#logging-config-fileformat 3 | [loggers] 4 | keys=root,halucinator.main,HAL_LOG,hal_tutorial 5 | 6 | [handlers] 7 | keys=consoleHandler 8 | 9 | [formatters] 10 | keys=sampleFormatter 11 | 12 | [logger_root] 13 | level=ERROR 14 | handlers=consoleHandler 15 | 16 | [logger_hal_tutorial] 17 | # STEP 1 Change from DEBUG to INFO 18 | level=INFO 19 | handlers=consoleHandler 20 | propagate=0 21 | qualname=hal_tutorial 22 | 23 | [logger_halucinator.main] 24 | level=INFO 25 | handlers=consoleHandler 26 | propagate=0 27 | qualname=halucinator.main 28 | 29 | [logger_HAL_LOG] 30 | level=INFO 31 | handlers=consoleHandler 32 | propagate=0 33 | qualname=HAL_LOG 34 | 35 | [logger_halucinator] 36 | level=DEBUG 37 | handlers=consoleHandler 38 | propagate=0 39 | qualname=halucinator 40 | 41 | [handler_consoleHandler] 42 | class=StreamHandler 43 | level=DEBUG 44 | formatter=sampleFormatter 45 | args=(sys.stdout,) 46 | 47 | [formatter_sampleFormatter] 48 | format=%(name)s|%(levelname)s| %(message)s 49 | -------------------------------------------------------------------------------- /tutorial/solutions/my_config.yaml: -------------------------------------------------------------------------------- 1 | intercepts: 2 | 3 | - class: hal_tutorial.bp_handlers.led_bp_handler.LEDHandler 4 | # STEP 1a 5 | # Uncomment the class_args, this will pass map_dict to the constructor 6 | # for this class and use nice strings for our LED names instead of numbers 7 | class_args: {map_dict: {0: GREEN, 1: ORANGE, 2: RED, 3: BLUE}} 8 | function: My_BSP_LED_Init 9 | symbol: BSP_LED_Init 10 | 11 | - class: hal_tutorial.bp_handlers.led_bp_handler.LEDHandler 12 | # STEP 1b 13 | # Uncomment the class_args, this will pass map_dict to the constructor 14 | # for this class and use nice strings for our LED names instead of numbers 15 | class_args: {map_dict: {0: GREEN, 1: ORANGE, 2: RED, 3: BLUE}} 16 | function: My_BSP_LED_Off 17 | symbol: BSP_LED_Off 18 | 19 | # Step 2 20 | # Using BSP_LED_Off as a template, add the intercept for BSP_LED_On 21 | # The name to map this to the bp_handler method is My_BSP_LED_On 22 | - class: hal_tutorial.bp_handlers.led_bp_handler.LEDHandler 23 | # STEP 1b 24 | # Uncomment the class_args, this will pass map_dict to the constructor 25 | # for this class and use nice strings for our LED names instead of numbers 26 | class_args: {map_dict: {0: GREEN, 1: ORANGE, 2: RED, 3: BLUE}} 27 | function: My_BSP_LED_On 28 | symbol: BSP_LED_On 29 | 30 | # NOTE: 31 | # We are going to make HAL_UART_Receive_IT appear to fail by returning -1 32 | # Comment out below to restore normal receive functionality 33 | - class: halucinator.bp_handlers.ReturnConstant 34 | registration_args: {ret_value: -1} 35 | function: HAL_UART_Receive_IT 36 | symbol: HAL_UART_Receive_IT 37 | 38 | 39 | --------------------------------------------------------------------------------