Ralim/ebc-dev-reverse-engineering

Recommendation for importing the driver into Ghidra

smaeul opened this issue · 1 comments

Here's a suggestion for anyone wanting to look at the pre-compiled files in Ghidra. This is most useful if you haven't already made a bunch of annotations; I don't know how to copy those over. So it's not really aimed at this repo, per se, but here's where the action seems to be.

  1. Run make ARCH=arm64 rockchip_linux_defconfig to start with a kernel config that builds the EBC driver.
  2. Run make ARCH=arm64 nconfig and enable CONFIG_DEBUG_INFO_DWARF4 (at "Kernel hacking" -> "Compile-time checks and compiler options" -> "Generate dwarf4 debuginfo"). DWARF4 is the newest debug info format that Ghidra understands, but recent GCC will generate DWARF5 by default.
  3. Run make ARCH=arm64 to compile the kernel. If it fails, that is fine, as long as drivers/gpu/drm/rockchip/ebc-dev/built-in.a gets created.
  4. Finally, take the archive containing the EBC driver, and convert it to an object file: aarch64-linux-gnu-ld -r -o drivers/gpu/drm/rockchip/ebc-dev/built-in.o --whole-archive drivers/gpu/drm/rockchip/ebc-dev/built-in.a.

This will create a single file, built-in.o, that includes all of the C and pre-compiled source for the driver, so everything gets loaded together in one code browser, and you don't have to worry about function imports and thunks and whatnot.

Ralim commented

This would have been amazingly useful to know.. a while a go 😂 Thankfully adding thunks is not too hard at all.

That said, this is super useful to know in case I end up regenerating any of the code again. I've done that a fair few times already when trying different ideas.