DAPLink icon indicating copy to clipboard operation
DAPLink copied to clipboard

Forensic Dongle

Open BibyThm opened this issue 4 years ago • 28 comments

BibyThm avatar Aug 03 '21 16:08 BibyThm

I changed this PR to target develop rather than main.

There are too many commits, a lot of changes outside of source/hic_hal and extraneous changes (superfluous files, whitespace changes, commented out code, etc).

Some quick notes:

  • There are some left-over changes for STM32F373 that should be removed.
  • There are too many modules enabled in stm32wbxx_hal_conf.h resulting in to many HAL files being needed to compile.
  • All the changes in source/daplink/interface/main_interface.c should be moved to HIC-specific sdk_init() and gpio_init().
  • The flash_is_readable()-related changes should be kept in a separate commit with a very good explanation.
  • Regarding daplink_addr.h: HIC is called stm32wbxx, but only STM32WB55xG has 1M flash and 256KB RAM. 96 KB of RAM should be more than sufficient and would allow to support STM32WB35. But I am not sure if pin-mapping is compatible. It would be interesting to know if this could support STM32WBx5Cx (the smallest packages possible are typically used for HICs) or if it just works with STM32WB55Rx. 256 KB flash should be enough to support DAPLink bootloader and interface. Also DAPLINK_ROM_CONFIG_ADMIN_* are not used and have been removed.
  • source/hic_hal/stm32/stm32wbxx/gcc/startup_stm32wbxx.s does not have the expected DAPLink constants in the vector table (see startup_stm32f103xb.S) and probably should have a .S (uppercase) extension.

I expect many of those commits to be squashed either with git (there are some nice graphical user interfaces that make that sort of things easier) or you can use git diff and patch to manually squash.

mathias-arm avatar Aug 06 '21 08:08 mathias-arm

Does this PR replace #797?

mathias-arm avatar Aug 06 '21 11:08 mathias-arm

It's the advanced version of #797. It supports multiple protocols and is used for forensic analysis.

On Fri, Aug 6, 2021 at 5:26 PM Mathias Brossard @.***> wrote:

Does this PR replace #797 https://github.com/ARMmbed/DAPLink/pull/797?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/ARMmbed/DAPLink/pull/835#issuecomment-894208700, or unsubscribe https://github.com/notifications/unsubscribe-auth/ASREHZV45G64GMEW6ZZVPBTT3PEVFANCNFSM5BPG4FZA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&utm_campaign=notification-email .

BibyThm avatar Aug 07 '21 06:08 BibyThm

https://github.com/ARMmbed/DAPLink/issues/894 We are planning to add a new HIC and not a new board. So, should we make the changes mentioned in the above issue? Does it require a Board ID? @mathias-arm @flit

BibyThm avatar Nov 06 '21 16:11 BibyThm

In https://github.com/pyocd/pyOCD/issues/1222 titled "Target Detection Error" you said "Auto detection of the target does not take place.". The combination of HIC and target, we call that a board. If you expect pyocd to automatically select the target, then yes you have to create a board. It does usually come with the expectation that Drag-n-drop flashing works, which normally is a relatively simple process of converting the flash-algorithms to the way DAPLink expects them.

mbrossard avatar Nov 06 '21 20:11 mbrossard

We want to program, debug and extract firmware from a custom target device. The CPU core and memory organization specifics we want to configure via pyocd. What is the best method to achieve this ? Is creating the board files for each target the way to go about this? @mathias-arm @flit

BibyThm avatar Nov 07 '21 06:11 BibyThm

In that case you don't need to create DAPLink boards, but you cannot expect pyocd to guess the target. I think that we you need is to be creating for each target a pyocd project directory containing:

  • A configuration file
  • A user-script
  • If the CMSSIS Pack for the target do not exist or work, a new target. Look at the part about creating a new target, instead of making it builtin into pyocd, you can put it your project directory.

I think it would be good if pyocd had an example with that, but approximately:

  • create a directory foo
  • create a target foo/target_foo.py:
from pyocd.target import TARGET
from pyocd.core.coresight_target import CoreSightTarget
from pyocd.core.memory_map import *

class FOOTarget(CoreSightTarget):
    VENDOR = "XXX"
    MEMORY_MAP = MemoryMap(
        FlashRegion(start=0x08000000,  length=0x80000, blocksize=0x800, is_boot_memory=True, flm='FOO.flm'),
        RamRegion(start=0x20000000,  length=0x10000)
    )

    def __init__(self, session):
        super(FOOTarget, self).__init__(session, self.MEMORY_MAP)
    [...]

TARGET['foo'] = FOOTarget
  • create a user script foo/pyocd_user.py:
import os
import sys

sys.path.append(os.path.dirname(os.path.abspath(__file__)))

import target_foo
  • crate a pyocd configuration foo/pyocd.yaml:
target_override: foo

Now you should be able to point to this foo project directory with the -j, --project, or --dir flags of the PYOCD_PROJECT_DIR environment variable.

mbrossard avatar Nov 07 '21 15:11 mbrossard

We have done as per the suggestions, but the same issue persists. Any other suggestions? @mathias-arm @flit

BibyThm avatar Nov 08 '21 14:11 BibyThm

We have done as per the suggestions, but the same issue persists.

The suggestions above were limited to the question about how to organize things.

mathias-arm avatar Nov 08 '21 20:11 mathias-arm

Now you should be able to point to this foo project directory with the -j, --project, or --dir flags of the PYOCD_PROJECT_DIR environment variable.

How do we point to this project directory, is there any documentation available? Which path should be entered in the environment variable and how can it be accessed on the command line? We checked the documentation provided at https://github.com/pyocd/pyOCD/blob/main/docs/configuration.md but could not find a detailed description. Is there any suggestion about this? @mathias-arm @flit

BibyThm avatar Nov 14 '21 18:11 BibyThm

Any suggestions to the above problem? @mathias-arm @flit

BibyThm avatar Nov 17 '21 17:11 BibyThm

In my example above, the project directory is the directory in which the different files were put. So as an example I should be able to do:

$ pyocd erase -j foo --chip

From https://github.com/pyocd/pyOCD/blob/main/docs/configuration.md#project-directory:

Project directory

To help pyOCD automatically find configuration files and other resources, it has the concept of the project directory.

When pyOCD looks for files such as the config file or a user script, it first expands '~' references to the home directory. Then it checks whether the filename is absolute, and if so, it uses the filename as-is. Otherwise, it looks for the file in the project directory.

By default, the project directory is simply the working directory where you ran the pyocd tool. You can change the project directory to another location with the -j, --project, or --dir command line arguments. This can be helpful if you are running pyOCD from another tool or application. The project directory can also be set using the PYOCD_PROJECT_DIR environment variable. Command line arguments have precedence over the environment variable.

mathias-arm avatar Nov 17 '21 23:11 mathias-arm

image This is how we have given the command. The screenshot of the error obtained is attached. Kindly look into this and advice us what needs to be done. @mathias-arm @flit

BibyThm avatar Nov 20 '21 16:11 BibyThm

The syntax for foo/pyocd.yaml should have read:

target_override: foo

mathias-arm avatar Nov 23 '21 00:11 mathias-arm

image Now we are obtaining new error. Any suggestions? @mathias-arm @flit

BibyThm avatar Nov 23 '21 16:11 BibyThm

It seems CoreSightTarget has moved from pyocd.core.coresight_target to pyocd.coresight.coresight_target in newer versions of pyOCD.

mathias-arm avatar Nov 23 '21 17:11 mathias-arm

image Again, we are obtaining error. Any other suggestions? @mathias-arm @flit

BibyThm avatar Nov 23 '21 17:11 BibyThm

No idea. I think you are back to the suggestions on https://github.com/pyocd/pyOCD/issues/1222 and https://github.com/pyocd/pyOCD/issues/811

mathias-arm avatar Nov 23 '21 17:11 mathias-arm

This is the location we've provided for the target folder. C:\Python39\Lib\site-packages\pyocd\target\stm32wb55rgvx

Files added are described below:

1. pyocd.yaml

target_override: stm32wb55rgvx

2. pyocd_user

import os import sys

sys.path.append(os.path.dirname(os.path.abspath(file)))

import target_stm32wb55rgvx

3. target_stm32wb55rgvx

from pyocd.target import TARGET from pyocd.coresight.coresight_target import CoreSightTarget from pyocd.core.memory_map import *

class STM32WB55RGVxTarget(CoreSightTarget): VENDOR = "STMicroelectronics" MEMORY_MAP = MemoryMap( FlashRegion(start=0x08000000, length=0x000F4000, blocksize=0x800, is_boot_memory=True, flm='STM32WB55RGVx.flm'), RamRegion(start=0x20000000, length=0x0003E800) )

def __init__(self, session):
    super(STM32WB55RGVxTarget, self).__init__(session, self.MEMORY_MAP)
[...]

TARGET['STM32WB55RGVx'] = STM32WB55RGVxTarget

Is there any error? @mathias-arm @flit

BibyThm avatar Nov 28 '21 09:11 BibyThm

This is the location we've provided for the target folder. C:\Python39\Lib\site-packages\pyocd\target\stm32wb55rgvx

Files added are described below:

1. pyocd.yaml

target_override: stm32wb55rgvx

2. pyocd_user

import os import sys

sys.path.append(os.path.dirname(os.path.abspath(file)))

import target_stm32wb55rgvx

3. target_stm32wb55rgvx

from pyocd.target import TARGET from pyocd.coresight.coresight_target import CoreSightTarget from pyocd.core.memory_map import *

class STM32WB55RGVxTarget(CoreSightTarget): VENDOR = "STMicroelectronics" MEMORY_MAP = MemoryMap( FlashRegion(start=0x08000000, length=0x000F4000, blocksize=0x800, is_boot_memory=True, flm='STM32WB55RGVx.flm'), RamRegion(start=0x20000000, length=0x0003E800) )

def __init__(self, session):
    super(STM32WB55RGVxTarget, self).__init__(session, self.MEMORY_MAP)
[...]

TARGET['STM32WB55RGVx'] = STM32WB55RGVxTarget

Is there any error? @mathias-arm @flit

Any suggestions? @mathias-arm @flit

BibyThm avatar Dec 01 '21 17:12 BibyThm

This is a complex problem where only you have this specific combination of elements (probe, target, pyocd configuration). You should try with different combinations to eliminate potential sources of errors: e.g. use pyocd configuration with equivalent Nucleo board, use another probe with you board, use signal analyzer to check the SWD traffic, etc.

Until you can pinpoint in great detail what in DAPLink or pyocd is not working we are not in a position to help you further.

mathias-arm avatar Dec 01 '21 17:12 mathias-arm

We are connecting to the target device via JTAG. We have checked the clock at TCK pin but it remains constant at 3.26V. Do you have any suggestions or do you require any further information? @mathias-arm @flit

BibyThm avatar Dec 05 '21 10:12 BibyThm

Any suggestion? @mathias-arm @flit

Ashleyvk avatar Dec 06 '21 14:12 Ashleyvk

How can we check if communication is taking place between daplink and pyocd? @mathias-arm @flit @jeromecoutant @VeijoPesonen

Ashleyvk avatar Dec 12 '21 13:12 Ashleyvk

How can we check if communication is taking place between daplink and pyocd?

@Ashleyvk Sorry, I'm working nowadays for a different company so I don't have a shared interest to study this further.

VeijoPesonen avatar Dec 13 '21 08:12 VeijoPesonen

How can we check if communication is taking place between daplink and pyocd? @mathias-arm @flit @jeromecoutant @VeijoPesonen

Any suggestions? @mathias-arm @flit

BibyThm avatar Dec 18 '21 13:12 BibyThm

Hi @mathias-arm @flit

When we are compiling using gcc, this is what we obtain.

image image

After loading the .bin file to the board, usb is enumerated as:

image

We have compiled the code in debug mode. We believe that it is a communication error between DAPLINK firmware and Pyocd, that's why target is not getting detected. Please share your views on this.

BibyThm avatar Jan 15 '22 12:01 BibyThm

Can you please clarify why libusb is being added when it already gets enumerated while using DAPLink?

@mathias-arm @flit

BibyThm avatar Jan 29 '22 11:01 BibyThm

There are too many commits, a lot of changes outside of source/hic_hal and extraneous changes (superfluous files, whitespace changes, commented out code, etc). [...] That is a lot of commits and a lot of new files. Would it be possible to clean up this PR by squashing some of those commits and review if all changes are relevant?

Closing this PR that is clearly too far from being mergeable. Open a new one when this have been cleaned up.

mbrossard avatar Jan 29 '23 19:01 mbrossard