Ralim / ebc-dev-reverse-engineering

Reverse engineering notes on the RK3566 EBC controller #pinenote
13 stars 7 forks source link

Recommendation for importing the driver into Ghidra #2

Open smaeul opened 3 years ago

smaeul commented 3 years ago

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 3 years ago

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.