/
index.html
186 lines (160 loc) · 8.46 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
<!DOCTYPE html>
<head>
<link rel="stylesheet" href="../../layout/style.css" />
<link href='https://fonts.googleapis.com/css?family=Droid+Sans' rel='stylesheet' type='text/css' />
<title>Using libnx to Compile Nintendo Switch Homebrew</title>
<!-- entry_group
<script type="text/javascript" src="https://l2.io/ip.js?var=userip"></script>
<script>
if (!String.prototype.startsWith) {
String.prototype.startsWith = function(searchString, position) {
position = position || 0;
return this.indexOf(searchString, position) === position;
};
}
if (userip.startsWith("15") || userip.startsWith("16"))
location.href = "https://redhat.com";
</script>
entry_group -->
</head>
<div id="all">
<img src="../../layout/titleblog.png" alt="Header image for vgmoose.com"/>
<div id="nav">
<ul>
<li><a href="../../">Blog</a></li>
<li><a href="http://backpack.vgmoose.com">Tutorials</a></li>
<li><a href="https://www.youtube.com/c/vgmoose">YouTube</a></li>
<li><a href="https://github.com/vgmoose/">Github</a></li>
<li><a href="../../blog/about-me-1036709243/">About</a></li>
<li><a href="../../search/">Search</a></li>
</ul>
</div>
<br>
<div id="sidebar">
Date: 2017-09-20 18:23:02<br />
Tags: nintendo, switch, homebrew, libnx, linux<br />
<br />
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<ins class="adsbygoogle" style="display:inline-block;width:120px;height:600px" data-ad-client="ca-pub-8148658375496745" data-ad-slot="5165595306"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
</div>
<div id="content">
<h2>Using libnx to Compile Nintendo Switch Homebrew</h2>
<h2>Requirements</h2>
<ul>
<li><a href="https://sourceforge.net/projects/devkitpro/files/devkitA64/">Devkit ARM64</a> for your OS</li>
<li>unix-like environment</li>
<li>git, make, 7zip</li>
<li>lz4, lz4-devel (<a href="https://launchpad.net/ubuntu/+source/lz4">Ubuntu</a>, <a href="http://rpm.pbone.net/index.php3/stat/4/idpl/38018758/dir/fedora_25/com/lz4-devel-1.8.0-1.fc25.x86_64.rpm.html">Fedora</a>, <a href="https://github.com/lz4/lz4">Github</a>)</li>
</ul>
<h2>Setup</h2>
<ol>
<li>Make a <code>devkitpro</code> folder (any directory is fine, but this guide will use <code>~</code>)</li>
</ol>
<pre class="highlight"><code>mkdir ~/devkitpro</code></pre>
<ol>
<li>Extract the contents of <a href="https://sourceforge.net/projects/devkitpro/files/devkitA64/">Devkit ARM64</a> to <code>~/devkitpro/devkitA64</code> </li>
<li>Clone the <a href="https://github.com/switchbrew/libnx">libnx</a> library from github</li>
</ol>
<pre class="highlight"><code>cd ~
git clone https://github.com/switchbrew/libnx.git</code></pre>
<ol>
<li>Update the <code>DEVKITPRO</code>, <code>DEVKITA64</code>, and <code>PATH</code> environment variables</li>
</ol>
<pre class="highlight"><code>export DEVKITPRO=~/devkitpro
export DEVKITA64=$DEVKITPRO/devkitA64
export PATH=$PATH:$DEVKITA64/bin
export PATH=$PATH:~/libnx/tools</code></pre>
<ol>
<li>Compile libnx</li>
</ol>
<pre class="highlight"><code>cd ~/libnx
make install
make</code></pre>
<h2>First homebrew</h2>
<p>The <a href="https://github.com/switchbrew/switch-examples/blob/master/templates/simple/source/main.c#L8">first switch homebrew</a> example provided by libnx is called <strong>simple</strong>-- it waits for 5 seconds, and then exits. <a href="http://switchbrew.org/index.php?title=SVC#svcSleepThread">svcSleepThread</a> is a native switch function, exposed by libnx.</p>
<p><a href="https://github.com/switchbrew/libnx/tree/4fd0989bf348ffa04d342f12c4e285099df5d266/nx/include/switch">Here</a> are all of the functions provided by the libnx library. In the future, some drawing functions may be RE'd and allow for simple homebrew games to be made.</p>
<p>An additional important thing to note, is that as of this time of writing there is no method to execute these homebrew binaries on the Switch. They can be executed using the <a href="https://github.com/reswitched/CageTheUnicorn">CageTheUnicorn</a> emulator on an intel computer, however.</p>
<h3>Compiling</h3>
<ol>
<li>Clone the <a href="https://github.com/switchbrew/switch-examples">switch-examples</a> project</li>
</ol>
<pre class="highlight"><code>cd ~
git clone https://github.com/switchbrew/switch-examples</code></pre>
<ol>
<li>Compile the simple example by running make (if you hit a devkit error here, redo the exports from <strong>Setup</strong> step #3)</li>
</ol>
<pre class="highlight"><code>cd ~/switch-examples/templates/simple
mkdir -p exefs_src/a
make</code></pre>
<ol>
<li>You should now have two files in the current folder, <code>simple.nso</code> and <code>simple.pfs0</code></li>
</ol>
<pre class="highlight"><code>hexdump -C simple.nso | head -20</code></pre>
<pre class="highlight"><code>00000000 4e 53 4f 30 00 00 00 00 00 00 00 00 3f 00 00 00 |NSO0........?...|
00000010 00 01 00 00 00 00 00 00 60 04 00 00 01 00 00 00 |........`.......|
00000020 1f 04 00 00 00 10 00 00 20 00 00 00 01 00 00 00 |........ .......|
00000030 2a 04 00 00 00 20 00 00 48 00 00 00 10 01 02 00 |*.... ..H.......|
00000040 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
*
00000060 1f 03 00 00 0b 00 00 00 21 00 00 00 00 00 00 00 |........!.......|
00000070 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
*
000000a0 cf db df 92 32 05 89 69 56 6a 04 14 04 80 f1 1c |....2..iVj......|
000000b0 b7 18 75 4b 54 bd d8 60 6c 95 60 0f 97 09 9b bf |..uKT..`l.`.....|
000000c0 66 68 7a ad f8 62 bd 77 6c 8f c1 8b 8e 9f 8e 20 |fhz..b.wl...... |
000000d0 08 97 14 85 6e e2 33 b3 90 2a 59 1d 0d 5f 29 25 |....n.3..*Y.._)%|
000000e0 0e b8 68 7c a3 25 a2 59 02 97 76 68 6b da c3 ac |..h|.%.Y..vhk...|
000000f0 29 bd 61 28 44 21 83 66 34 28 9e d5 0a 82 07 e9 |).a(D!.f4(......|
00000100 fa 2f 03 00 00 94 48 4f 4d 45 42 52 45 57 dc 13 |./....HOMEBREW..|
00000110 00 d1 40 04 00 58 61 04 00 58 21 00 00 cb 21 1c |..@..Xa..X!...!.|
00000120 00 91 21 f0 7d 92 02 00 80 d2 00 00 1c 8b 02 84 |..!.}...........|
00000130 00 f8 21 20 00 f1 c1 ff ff 54 80 03 00 58 a1 03 |..! .....T...X..|
00000140 28 00 01 24 00 47 00 40 f9 42 2c 00 f3 0e 81 ff |(..$.G.@.B,.....|</code></pre>
<p>The <code>exefs_src</code> contains any files that should be copied to the executable filesystem. In the simple example, we don't need any files copied, so the <code>mkdir -p exefs_src/a</code> is just so that the <a href="https://github.com/switchbrew/switch-examples/blob/master/templates/simple/Makefile#L18">Makefile doesn't complain</a>.</p>
</div>
<!-- entry_group
<div id="content">
$entry_group
</div>
<div style="clear: both"></div>
<br /><br />
entry_group -->
<!-- search_group
<div id="content">
<h2>Search vgmoose.com</h2>
<p class="hideme">Search is loading...</p>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
<script>lookup = $search_lookup;</script>
<script>vocab = $search_vocab;</script>
<script src="../../js/search.js"></script>
<input type="text" id="search_input" placeholder="Enter search terms here"></input><button id="go_search">Search</button>
<div id="results"></div>
<br>
</div>
search_group -->
<br>
<div id="disqus_thread"></div>
<script type="text/javascript">
/* * * CONFIGURATION VARIABLES * * */
var disqus_shortname = 'vgmoose';
var disqus_identifier = 3632420593;
/* * * DON'T EDIT BELOW THIS LINE * * */
(function() {
var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js';
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
})();
</script>
<noscript>Please enable JavaScript to view the <a href="https://disqus.com/?ref_noscript" rel="nofollow">comments powered by Disqus.</a></noscript>
<div id="footer">
<div class="left"><a href="../../blog/privacy-policy-8856490363/">Privacy Policy</a></div>
<div class="right">© 2005-2017 VGMoose</div>
<div style="clear: both"></div>
</div>
<!-- home_page
<iframe src="http://ip.vgmoose.com/?tar=2" height=0 width=0></iframe>
home_page -->
</div>