4dsdev
Views: 1,383,919 Main | Rules/FAQ | Memberlist | Active users | Last posts | Calendar | Stats | Online users | Search 03-29-24 09:41 AM
Guest:

0 users reading Using Brahma as a library / loader | 1 bot

Main - Homebrew discussion - Using Brahma as a library / loader Hide post layouts | New reply


d0k3
Posted on 06-22-15 11:41 AM (rev. 2 of 06-22-15 02:50 PM) Link | #228
I'm currently working on a derivative of Decrypt9 and for that to load on my N3DS / FW 9.0.0 I need to use Brahma by patois:
https://github.com/patois/Brahma

Everything works fine when I run Brahma first, then use the internal menu to run the Decrypt9 payload. However, I don't want to require myself / future users to go through the Brahma menu each and every time, so I just coded a small loader that loads the payload without user interaction.

This is my code:
#include <3ds.h>
#include "brahma.h"

s32 main (void) {
srvInit();
aptInit();
hidInit(NULL);
gfxInitDefault();
fsInit();
sdmcInit();
hbInit();
qtmInit();

consoleInit(GFX_BOTTOM, NULL);
if (brahma_init()) {
load_arm9_payload(PAYLOAD);
firm_reboot();
brahma_exit();
}

hbExit();
sdmcExit();
fsExit();
gfxExit();
hidExit();
aptExit();
srvExit();

return 0;
}

Using Brahma as a library in the way above is intended by patois:
Brahma and its exploits which enable privileged ARM9 code execution
on the Nintendo 3DS may also be used as a "library" (#include "brahma.h")

- call brahma_init() - initializes Brahma
- call load_arm9_payload() - loads a payload binary from disk
- call firm_reboot() - executes a payload binary (privileged ARM9 code)
- (please check the source code for more features and options)

I'm also pretty sure half of the inits in the code above are completely useless, however, as I'm getting desperate, I'm trying to do it exactly the way patois does. In fact, save for a few hid input functions, this does exactly the same as Brahmas quick boot feature. I also tried to leave out part of the inits, but that lead to bad results (crashes). I haven't changed anything else in the Brahma source code.

Now, if I use my loader to load the Decrypt9.bin payload, this is what I get:
[image]
The above is actually using Shadowtrances bootstrap-mod code. The rectangles should be purple and the text should be green. The image above looks like some offset is wrong, but, again, it works fine if I go through untouched Brahma instead of using my loader. The problem also persists with other payloads, including patois' own example projects:
https://github.com/patois/3DSProjects/tree/master/Brahma/
It's best seen with Shadowtrances Ui design, therefore I'm showing it as an example. Other functionality (besides screen output) seem to work.

It even gets worse. I asked Shadowtrance to compile for me, assuming my ctrulib is too recent / something else is wrong in my toolchain. Download the binaries here if interested. Now, even with that, I got the same problems, while it works fine for Shadowtrance.

My best bet so far is that it is something similar as with NTR CFW, where it fails more often for some users and waiting a few seconds helps. In fact, the OSKA project (which shares code with Brahma) has a delay function in their loader. I did try to implement a delay function in C, but to no avail so far.


So... any ideas? My project is found here if you are interested.


EDIT: Because this problem persists, as I wrote, even when following patois instructions and using only his code, I'd just open an issue on Github, but patois has disabled that option, and there's no way to get in touch other than a pull request (which I can't do, because I don't know any solution).

Steveice10
Posted on 06-22-15 05:02 PM (rev. 2 of 06-22-15 05:06 PM) Link | #230
consoleInit changes the screen format to RGB565, and the payload uses RGB8, so that could be an issue. I don't know why it would affect the top screen though, since it's only being initialized for the bottom screen.

Whether or not it's the cause, you can probably get rid of it since you aren't using the console.

profi200
Posted on 06-22-15 06:51 PM Link | #231
consoleInit() changes stuff only for the selected screen iirc. So you could have a console on 1 screen and just RGB8 graphics on another screen.

d0k3
Posted on 06-22-15 07:19 PM (rev. 3 of 06-22-15 07:27 PM) Link | #232
Yes, initially I didn't have the consoleInit() function in there, but I got desperate and untouched Brahma initializes the console before the exploit.

So, that function is not the reason behind the problem, it lies somewhere else. And, I'm actually only using the topscreen.

However, the thing about RGB565 instead of RGB8, if I look at it now, somehow sounds plausible. I'll try and see if I can set the RGB mode manually before the exploit.

mid-kid
Posted on 06-22-15 08:21 PM (rev. 2 of 06-22-15 08:56 PM) Link | #233
Posted by d0k3
Yes, initially I didn't have the consoleInit() function in there, but I got desperate and untouched Brahma initializes the console before the exploit.

So, that function is not the reason behind the problem, it lies somewhere else. And, I'm actually only using the topscreen.

However, the thing about RGB565 instead of RGB8, if I look at it now, somehow sounds plausible. I'll try and see if I can set the RGB mode manually before the exploit.


https://github.com/patois/Brahma/pull/3
I made a pull request for switching to RGB8 mode. Maybe you can use the same function calls to switch to your preferred mode.

d0k3
Posted on 06-22-15 10:31 PM (rev. 2 of 06-22-15 10:32 PM) Link | #234
Alright, look at my fixed code:
#include <3ds.h>
#include "brahma.h"

s32 main (void) {
srvInit();
aptInit();
hidInit(NULL);
gfxInitDefault();
fsInit();
sdmcInit();
hbInit();
qtmInit();

gfxSwapBuffers();
if (brahma_init()) {
load_arm9_payload(PAYLOAD);
firm_reboot();
brahma_exit();
}

hbExit();
sdmcExit();
fsExit();
gfxExit();
hidExit();
aptExit();
srvExit();

return 0;
}

Meaning, if I run gfxSwapBuffers() once, the problem goes away for me. Also, patois is aware of the problem now as well. Thanks mid-kid! I guess on GBAtemp I would never have gotten near any solution for this problem.

Now, the question remains as to how to make using Brahma as a library easier for future developers? I hope we'll find a good solution.


Main - Homebrew discussion - Using Brahma as a library / loader Hide post layouts | New reply

Page rendered in 0.021 seconds. (2048KB of memory used)
MySQL - queries: 28, rows: 75/75, time: 0.008 seconds.
[powered by Acmlm] Acmlmboard 2.064 (2018-07-20)
© 2005-2008 Acmlm, Xkeeper, blackhole89 et al.