mirror of
https://github.com/switchbrew/switch-tools.git
synced 2025-06-22 14:02:40 +02:00
Compare commits
5 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
22756068dd | ||
|
0098896307 | ||
|
28bd095683 | ||
|
e36a8251cd | ||
|
786ccde466 |
@ -2,7 +2,7 @@
|
|||||||
# Process this file with autoconf to produce a configure script.
|
# Process this file with autoconf to produce a configure script.
|
||||||
|
|
||||||
AC_PREREQ(2.61)
|
AC_PREREQ(2.61)
|
||||||
AC_INIT([switch-tools],[1.12.0],[https://github.com/switchbrew/switch-tools/issues])
|
AC_INIT([switch-tools],[1.13.1],[https://github.com/switchbrew/switch-tools/issues])
|
||||||
AC_CONFIG_SRCDIR([src/build_pfs0.c])
|
AC_CONFIG_SRCDIR([src/build_pfs0.c])
|
||||||
|
|
||||||
AM_INIT_AUTOMAKE([subdir-objects])
|
AM_INIT_AUTOMAKE([subdir-objects])
|
||||||
|
@ -554,6 +554,7 @@ int ParseKipConfiguration(const char *json, KipHeader *kip_hdr) {
|
|||||||
}
|
}
|
||||||
int allow_debug = 0;
|
int allow_debug = 0;
|
||||||
int force_debug = 0;
|
int force_debug = 0;
|
||||||
|
int force_debug_prod = 0;
|
||||||
if (!cJSON_GetBoolean(value, "allow_debug", &allow_debug)) {
|
if (!cJSON_GetBoolean(value, "allow_debug", &allow_debug)) {
|
||||||
status = 0;
|
status = 0;
|
||||||
goto PARSE_CAPS_END;
|
goto PARSE_CAPS_END;
|
||||||
@ -562,7 +563,11 @@ int ParseKipConfiguration(const char *json, KipHeader *kip_hdr) {
|
|||||||
status = 0;
|
status = 0;
|
||||||
goto PARSE_CAPS_END;
|
goto PARSE_CAPS_END;
|
||||||
}
|
}
|
||||||
desc = (allow_debug & 1) | ((force_debug & 1) << 1);
|
if (!cJSON_GetBoolean(value, "force_debug_prod", &force_debug_prod)) {
|
||||||
|
status = 0;
|
||||||
|
goto PARSE_CAPS_END;
|
||||||
|
}
|
||||||
|
desc = (allow_debug & 1) | ((force_debug_prod & 1) << 1) | ((force_debug & 1) << 2);
|
||||||
kip_hdr->Capabilities[cur_cap++] = (u32)((desc << 17) | (0xFFFF));
|
kip_hdr->Capabilities[cur_cap++] = (u32)((desc << 17) | (0xFFFF));
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr, "Error: unknown capability %s\n", type_str);
|
fprintf(stderr, "Error: unknown capability %s\n", type_str);
|
||||||
|
@ -21,9 +21,9 @@ typedef struct {
|
|||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
u8 Magic[4];
|
u8 Magic[4];
|
||||||
u32 Unk1;
|
u32 version;
|
||||||
u32 size;
|
u32 size;
|
||||||
u32 Unk2;
|
u32 flags;
|
||||||
NsoSegment Segments[3];
|
NsoSegment Segments[3];
|
||||||
u32 bssSize;
|
u32 bssSize;
|
||||||
u32 Unk3;
|
u32 Unk3;
|
||||||
@ -78,9 +78,10 @@ int main(int argc, char* argv[]) {
|
|||||||
fprintf(stderr, "--nacp=<control.nacp> Embeds control.nacp into the output file.\n");
|
fprintf(stderr, "--nacp=<control.nacp> Embeds control.nacp into the output file.\n");
|
||||||
fprintf(stderr, "--romfs=<image> Embeds RomFS into the output file.\n");
|
fprintf(stderr, "--romfs=<image> Embeds RomFS into the output file.\n");
|
||||||
fprintf(stderr, "--romfsdir=<directory> Builds and embeds RomFS into the output file.\n");
|
fprintf(stderr, "--romfsdir=<directory> Builds and embeds RomFS into the output file.\n");
|
||||||
|
fprintf(stderr, "--alignedheader Sets the \"AlignedHeader\" flag in the output file.\n");
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
NroStart nro_start;
|
NroStart nro_start;
|
||||||
memset(&nro_start, 0, sizeof(nro_start));
|
memset(&nro_start, 0, sizeof(nro_start));
|
||||||
|
|
||||||
@ -102,18 +103,20 @@ int main(int argc, char* argv[]) {
|
|||||||
|
|
||||||
int argi;
|
int argi;
|
||||||
char* icon_path = NULL, *nacp_path = NULL, *romfs_path = NULL, *romfs_dir_path = NULL;
|
char* icon_path = NULL, *nacp_path = NULL, *romfs_path = NULL, *romfs_dir_path = NULL;
|
||||||
|
u32 aligned_header = 0;
|
||||||
for (argi=3; argi<argc; argi++) {
|
for (argi=3; argi<argc; argi++) {
|
||||||
if (strncmp(argv[argi], "--icon=", 7)==0) icon_path = &argv[argi][7];
|
if (strncmp(argv[argi], "--icon=", 7)==0) icon_path = &argv[argi][7];
|
||||||
if (strncmp(argv[argi], "--nacp=", 7)==0) nacp_path = &argv[argi][7];
|
if (strncmp(argv[argi], "--nacp=", 7)==0) nacp_path = &argv[argi][7];
|
||||||
if (strncmp(argv[argi], "--romfs=", 8)==0) romfs_path = &argv[argi][8];
|
if (strncmp(argv[argi], "--romfs=", 8)==0) romfs_path = &argv[argi][8];
|
||||||
if (strncmp(argv[argi], "--romfsdir=", 11)==0) romfs_dir_path = &argv[argi][11];
|
if (strncmp(argv[argi], "--romfsdir=", 11)==0) romfs_dir_path = &argv[argi][11];
|
||||||
|
if (strncmp(argv[argi], "--alignedheader", 15)==0) aligned_header = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (romfs_dir_path != NULL && romfs_path != NULL) {
|
if (romfs_dir_path != NULL && romfs_path != NULL) {
|
||||||
fprintf(stderr, "Cannot have a RomFS and a RomFS Directory at the same time!\n");
|
fprintf(stderr, "Cannot have a RomFS and a RomFS Directory at the same time!\n");
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (elf_len < sizeof(Elf64_Ehdr)) {
|
if (elf_len < sizeof(Elf64_Ehdr)) {
|
||||||
fprintf(stderr, "Input file doesn't fit ELF header!\n");
|
fprintf(stderr, "Input file doesn't fit ELF header!\n");
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
@ -154,7 +157,7 @@ int main(int argc, char* argv[]) {
|
|||||||
fprintf(stderr, "Invalid ELF: expected 3 loadable phdrs and a bss!\n");
|
fprintf(stderr, "Invalid ELF: expected 3 loadable phdrs and a bss!\n");
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
// .bss is special
|
// .bss is special
|
||||||
if (i == 3) {
|
if (i == 3) {
|
||||||
tmpsize = (phdr->p_filesz + 0xFFF) & ~0xFFF;
|
tmpsize = (phdr->p_filesz + 0xFFF) & ~0xFFF;
|
||||||
@ -174,13 +177,13 @@ int main(int argc, char* argv[]) {
|
|||||||
fprintf(stderr, "Out of memory!\n");
|
fprintf(stderr, "Out of memory!\n");
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy(buf[i], &elf[phdr->p_offset], phdr->p_filesz);
|
memcpy(buf[i], &elf[phdr->p_offset], phdr->p_filesz);
|
||||||
|
|
||||||
file_off += nro_hdr.Segments[i].Size;
|
file_off += nro_hdr.Segments[i].Size;
|
||||||
file_off = (file_off + 0xFFF) & ~0xFFF;
|
file_off = (file_off + 0xFFF) & ~0xFFF;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Iterate over sections to find build id. */
|
/* Iterate over sections to find build id. */
|
||||||
size_t cur_sect_hdr_ofs = hdr->e_shoff;
|
size_t cur_sect_hdr_ofs = hdr->e_shoff;
|
||||||
for (unsigned int i = 0; i < hdr->e_shnum; i++) {
|
for (unsigned int i = 0; i < hdr->e_shnum; i++) {
|
||||||
@ -206,9 +209,12 @@ int main(int argc, char* argv[]) {
|
|||||||
fprintf(stderr, "Failed to open output file!\n");
|
fprintf(stderr, "Failed to open output file!\n");
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
nro_hdr.size = file_off;
|
nro_hdr.size = file_off;
|
||||||
|
|
||||||
|
nro_hdr.version = 0;
|
||||||
|
nro_hdr.flags = (aligned_header << 0);
|
||||||
|
|
||||||
// TODO check retvals
|
// TODO check retvals
|
||||||
|
|
||||||
for (i=0; i<3; i++)
|
for (i=0; i<3; i++)
|
||||||
@ -270,7 +276,7 @@ int main(int argc, char* argv[]) {
|
|||||||
asset_hdr.romfs.offset = tmp_off;
|
asset_hdr.romfs.offset = tmp_off;
|
||||||
asset_hdr.romfs.size = romfs_len;
|
asset_hdr.romfs.size = romfs_len;
|
||||||
tmp_off+= romfs_len;
|
tmp_off+= romfs_len;
|
||||||
|
|
||||||
} else if (romfs_dir_path) {
|
} else if (romfs_dir_path) {
|
||||||
asset_hdr.romfs.offset = tmp_off;
|
asset_hdr.romfs.offset = tmp_off;
|
||||||
asset_hdr.romfs.size = build_romfs_by_path_into_file(romfs_dir_path, out, file_off + tmp_off);
|
asset_hdr.romfs.size = build_romfs_by_path_into_file(romfs_dir_path, out, file_off + tmp_off);
|
||||||
|
@ -373,6 +373,16 @@ int CreateNpdm(const char *json, void **dst, u32 *dst_size) {
|
|||||||
header.MmuFlags |= ((disable_device_address_space_merge & 1) << 5);
|
header.MmuFlags |= ((disable_device_address_space_merge & 1) << 5);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int enable_alias_region_extra_size; // optional
|
||||||
|
if (cJSON_GetBoolean(npdm_json, "enable_alias_region_extra_size", &enable_alias_region_extra_size)) {
|
||||||
|
header.MmuFlags |= ((enable_alias_region_extra_size & 1) << 6);
|
||||||
|
}
|
||||||
|
|
||||||
|
int prevent_code_reads; // optional
|
||||||
|
if (cJSON_GetBoolean(npdm_json, "prevent_code_reads", &prevent_code_reads)) {
|
||||||
|
header.MmuFlags |= ((prevent_code_reads & 1) << 7);
|
||||||
|
}
|
||||||
|
|
||||||
u8 signature_key_generation; // optional
|
u8 signature_key_generation; // optional
|
||||||
if (cJSON_GetU8(npdm_json, "signature_key_generation", &signature_key_generation)) {
|
if (cJSON_GetU8(npdm_json, "signature_key_generation", &signature_key_generation)) {
|
||||||
header.SignatureKeyGeneration = signature_key_generation;
|
header.SignatureKeyGeneration = signature_key_generation;
|
||||||
@ -819,15 +829,16 @@ int CreateNpdm(const char *json, void **dst, u32 *dst_size) {
|
|||||||
}
|
}
|
||||||
int allow_debug = 0;
|
int allow_debug = 0;
|
||||||
int force_debug = 0;
|
int force_debug = 0;
|
||||||
if (!cJSON_GetBoolean(value, "allow_debug", &allow_debug)) {
|
int force_debug_prod = 0;
|
||||||
|
cJSON_GetBoolean(value, "allow_debug", &allow_debug);
|
||||||
|
cJSON_GetBoolean(value, "force_debug", &force_debug);
|
||||||
|
cJSON_GetBoolean(value, "force_debug_prod", &force_debug_prod);
|
||||||
|
if ( allow_debug + force_debug + force_debug_prod > 1 ) {
|
||||||
|
fprintf(stderr, "Only one of allow_debug, force_debug, or force_debug_prod can be set!\n");
|
||||||
status = 0;
|
status = 0;
|
||||||
goto NPDM_BUILD_END;
|
goto NPDM_BUILD_END;
|
||||||
}
|
}
|
||||||
if (!cJSON_GetBoolean(value, "force_debug", &force_debug)) {
|
desc = (allow_debug & 1) | ((force_debug_prod & 1) << 1) | ((force_debug & 1) << 2);
|
||||||
status = 0;
|
|
||||||
goto NPDM_BUILD_END;
|
|
||||||
}
|
|
||||||
desc = (allow_debug & 1) | ((force_debug & 1) << 1);
|
|
||||||
caps[cur_cap++] = (u32)((desc << 17) | (0xFFFF));
|
caps[cur_cap++] = (u32)((desc << 17) | (0xFFFF));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user