Here's my 2 cents after doing a similar swap. Before reading this long diatribe, note that in the country I live in I cannot change ECU due to legal = pollution related reasons. Thus I have a 2013 D40 in a 2005 R51M.
I agree with tweak'e, just be wary of the gearbox, ask me how I know. I swapped in a 2013 (D40, NP300) manual into a 2005 R51M and had to do some major tweaks on the block to make fit. So assuming the 2012 block is ok for your 2009 gearbox, check that the glowplugs are compatible too. Besides finding them either on the intake side or exhaust side depending on the 2009 YD25 versions, the 2012 connector is plug-in and not screw-on. On the 2012 (plug-in) they are 7V and not 12V as per my 2005, the timer of the ecu will still work, however I had to make some voltage step down converters to get them to work at 7V after burning the 4 original ones shoving 12V into them, sure first start up was great, then not. I thus built 2 modules at 60A each driving 2 plugs each [overkill but for transistor heat management that's what i needed]. In theory you should be ok and already be at 7V if your plugs are plug-in type (though these glowplug types are available in 12V I believe, but do they fit the/your application/heads?). A mutlimeter will answer that question easily. Also, I'm not too familiar with the 2009 YD25 though I've seen them mounted either with the electric turbo wastegate and others with the "old" vaccum controlled one (GT2056V or similar), so going from the electric to vaccum is "sort of easy", but the exhaust manifold will kick you in the nuts ('cause exhaust inlet position), check that the bolt pattern on the heads match. I had to drill my head to fit 2 studs to allow the 2005 manifold to bolt on...scary because you do end up in the coolant passage.
In my case I had some major changes both mechanical and electrical to get it to run. To avoid a lot of swearing, again, check the the rear end of the block vs your gearbox, that would be your main concern. Looking from the rear check the dowel position (and size) and 3 screw hole provisions going clockwise (i said block not the oil pan)..and see the pics below (2005 block, 2013 block, and 2013 vs 2005 mounting plate, in red the 2005 holes, in blue the 2013 holes and in green the dowel locations (bottom is 2005 and top is 2013)). Note that all the other bolts should line up as well as the upper most dowel (not shown here), same with oil pans, 2005 or 2013 are identical on the rear.
Oh the oil pan! might be an issue too if you want to keep the 2012 AC and alternator bracket... Alternator will fit, not so sure about the 2009 AC pump though, so you'll need to keep your AC pump AND the original oil pan and bracket because the bottom screws of the AC pump bolt into it. In my case were way off.... and there's a lot of other little bits and pieces to check too.
What I'm saying is just do your due diligence before making your move. You can avoid a lot of work and swea(r)(t)ing (choose the right letter as per your preference). My guess is that you'll have a lot fewer issues than me, doable but please double check everything before spending the time and money. It ain't cheap, at least it wasn't for me in Europe, it cost me a leg... but it worked.
Sorry for being so long winded... just passing on my ruined knuckle knowledge (and I haven't detailed everything either)
Keep us posted.