Comments (20)
@rawsample When i try replacing the import, it works normally. I think your guess is correct, Thank you for your answer.
2022-07-12 03:33:09,533 | avatar.INFO | Initialized Avatar. Output directory is ./tmp1/avatar
2022-07-12 03:33:09,535 | avatar.targets.QemuTarget0.WARNING | No cpu_model specified - are you sure?
2022-07-12 03:33:09,540 | avatar.targets.QemuTarget0.INFO | QEMU process running
2022-07-12 03:33:09,753 | avatar.targets.QemuTarget0.INFO | State changed to TargetStates.STOPPED
2022-07-12 03:33:09,754 | avatar.INFO | Received state update of target QemuTarget0 to TargetStates.STOPPED
2022-07-12 03:33:09,769 | avatar.targets.QemuTarget0.QMPProtocol.INFO | b'{"return": {}, "id": 0}\r\n'
2022-07-12 03:33:09,771 | avatar.targets.QemuTarget0.INFO | Connected to remote target
2022-07-12 03:33:09,774 | avatar.targets.QemuTarget0.RemoteMemoryProtocol.INFO | Successfully connected rmp
2022-07-12 03:33:10,275 | avatar.targets.QemuTarget0.RemoteMemoryProtocol.WARNING | Tried to close/unlink non existent rx_queue
2022-07-12 03:33:10,275 | avatar.targets.QemuTarget0.RemoteMemoryProtocol.WARNING | Tried to close/unlink non existent tx_queue
from avatar2.
Hi,
that's a good point. We could make this a complete example. In the mean time, did you look at the examples repository ? Probably this can help.
https://github.com/avatartwo/avatar2-examples
from avatar2.
Besides this, you can also find examples implementation for the nucleo_usart or max32-uart in the avatar2 pyperipheral directory.
Hope this helps!
from avatar2.
Hi, that's a good point. We could make this a complete example. In the mean time, did you look at the examples repository ? Probably this can help.
Thank you for your reply. I have seen the examples repository, but I still don't understand it. I will take a closer look. Thank you again for your reply.
from avatar2.
Besides this, you can also find examples implementation for the nucleo_usart or max32-uart in the avatar2 pyperipheral directory.
Hope this helps!
Ok, I'll take a closer look, thanks for your reply and suggestion. : )
from avatar2.
Besides this, you can also find examples implementation for the nucleo_usart or max32-uart in the avatar2 pyperipheral directory.
Hope this helps!
Hi, when i run
from avatar2 import *
import struct
from avatar_peripheral import AvatarPeripheral
class HelloWorldPeripheral(AvatarPeripheral):
def hw_read(self, offset, size):
ret = self.hello_world[:size]
self.hello_world = self.hello_world[size:] + self.hello_world[:size]
# Convert the return value to an integer (py2/py3-compatible)
# Python >3.2 could just call int.from_bytes(ret, byteorder='little')
s2fmt = {1: 'B', 2: 'H', 4: 'I', 8: 'Q'}
ret = struct.unpack('<' + s2fmt[size], ret)[0]
return ret
def nop_write(self, offset, size, value):
return True
def __init__(self, name, address, size, **kwargs):
AvatarPeripheral.__init__(self, name, address, size)
self.hello_world=b'Hello World'
self.read_handler[0:size] = self.hw_read
self.write_handler[0:size] = self.nop_write
avatar = Avatar(arch=ARM,output_directory='./tmp1/avatar')
qemu = avatar.add_target(QemuTarget)
hw = avatar.add_memory_range(0x40004c00, 0x100, name='hello_world',
emulate=HelloWorldPeripheral, permissions='rw-')
avatar.init_targets()
it will have this problem
root@avatar2-exp:~# python3 hello_world.py
2022-07-05 13:44:28,842 | avatar.INFO | Initialized Avatar. Output directory is ./tmp1/avatar
2022-07-05 13:44:28,844 | avatar.targets.QemuTarget0.WARNING | No cpu_model specified - are you sure?
Traceback (most recent call last):
File "hello_world.py", line 36, in <module>
avatar.init_targets()
File "/usr/local/lib/python3.8/dist-packages/avatar2-1.4.7-py3.8.egg/avatar2/avatar2.py", line 233, in init_targets
t[1].init()
File "/usr/local/lib/python3.8/dist-packages/avatar2-1.4.7-py3.8.egg/avatar2/watchmen.py", line 78, in watchtrigger
ret = func(self, *args, **kwargs)
File "/usr/local/lib/python3.8/dist-packages/avatar2-1.4.7-py3.8.egg/avatar2/targets/qemu_target.py", line 263, in init
file_name=self.qemu_config_file, config=self.generate_qemu_config()
File "/usr/local/lib/python3.8/dist-packages/avatar2-1.4.7-py3.8.egg/avatar2/targets/qemu_target.py", line 174, in generate_qemu_config
conf_dict = self.avatar.generate_config()
File "/usr/local/lib/python3.8/dist-packages/avatar2-1.4.7-py3.8.egg/avatar2/avatar2.py", line 153, in generate_config
conf_dict["memory_mapping"].append(mr.data.dictify())
File "/usr/local/lib/python3.8/dist-packages/avatar2-1.4.7-py3.8.egg/avatar2/memory_range.py", line 65, in dictify
raise Exception(
Exception: Unsupported type <class '__main__.HelloWorldPeripheral'> for dictifying python_peripheral for mem_range at 0x40004c00
Did I write something wrong?Can you take a look at it.Thanks!
from avatar2.
from avatar2.
from avatar2.
Hello @zhao-dddw , I'm going to look at it but i need to finish other tasks before.
from avatar2.
@rawsample Ok, you go to work first.
from avatar2.
Could you try replacing the import with from avatar2.peripherals.avatar_peripheral import AvatarPeripheral
?
My guess is that HelloWorldPeripheral
doesn't inherit from the correct AvatarPeripheral
class and therefore fail the check on the expected_types
from avatar2.
Can we maybe update the handbook to reflect this pitfall?
from avatar2.
Changes added in 974c6b3
from avatar2.
@rawsample
Excuse me, do you have the source code of this binary file? I tried to compile it, but it couldn't run.
https://github.com/avatartwo/avatar2/tree/main/tests/pyperipheral
from avatar2.
I'm afraid not, maybe @mariusmue has?
Be aware in the case you recompile it, you may need to update the different addresses used in test_pyperipheral.py
.
from avatar2.
@mariusmue Hi,do you have the source code of this binary file.
from avatar2.
@rawsample Ok,thank you for your advice.
from avatar2.
Hi, sorry for the delay.
The source code should be:
#include "mbed.h"
//------------------------------------
// Hyperterminal configuration
// 9600 bauds, 8-bit data, no parity
//------------------------------------
Serial pc(SERIAL_TX, SERIAL_RX);
DigitalOut myled(LED1);
int main()
{
int i = 1;
pc.printf("Hello World !\n");
while(1) {
wait(1);
pc.printf("This program runs since %d seconds.\n", i++);
myled = !myled;
}
}
The example was build with mbed-os2, also known as libmbed. In comparison to more recent version of mbedOS, that version linked everything into a monoloithic application. If I recall correctly, I either built this example using the mbed online compiler, or using the linux mbed toolchain.
Hope that helps!
from avatar2.
@mariusmue Thank you for your answer.But I have one more question, do the other two bin files have any specific purpose?
rcc_dump.bin
sram_dump.bin
Sorry to bother you again.
from avatar2.
No worries! Yes, these are dumps of the memory regions of the device in the right state. They are defined here in the according script.
The "right state" here, means that there was a breakpoint set on the device on the entry of the main-loop (which matches the entry-address for the qemu object.
This allows to emulate the firmware without the need of having the physical device to transfer the state from at this point.
from avatar2.
Related Issues (20)
- RemoteMemoryRead failed: Failed to read memory!
- Exception: GDBProtocol was unable to connect HOT 4
- Installer has invalid references to GitHub repos HOT 2
- Is it possible to dynamically analyse the firmware of a ESP32 just with the default avatar2 tools? HOT 4
- AvatarPeripheral with x86 target HOT 5
- A naive question: what means rcc dump HOT 1
- Stuck when openocd_target try to wait HOT 2
- RecursionError: maximum recursion depth exceeded in comparison HOT 2
- geting to halt state when transfer state from QemuTarget to gdbTarget
- How to deal with interrupt (NVIC) HOT 2
- avatar.CRITICAL | No Memory range specified at 0x400008
- qemu-system-arm, configurable does not work with cpu_model=cortex-m4 HOT 7
- questions regarding gdbstub, SerialICE and avatar[one] HOT 2
- Failure to check for qemu failure at startup HOT 2
- query: per-opcode filters/logging? HOT 2
- AvatarPeripheral: pci/pcie devices
- How to implement an Android Emulator target? HOT 7
- avatar2/handbook/0x03_memory.md Qemu Properties dict possible types and values details HOT 1
- Does avatar2 support Unicorn emulator? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from avatar2.