hos: refactor fss to pkg3

To `fss0` config is now renamed to `pkg3`.
`fss0` still works but is deprecated.
Additionally `fss0experimental` key is now renamed to `pkg3ex`
This commit is contained in:
CTCaer 2025-04-30 08:27:36 +03:00
commit f110f97099
8 changed files with 88 additions and 80 deletions

View file

@ -48,7 +48,7 @@ OBJS += $(addprefix $(BUILDDIR)/$(TARGET)/, \
# Horizon.
OBJS += $(addprefix $(BUILDDIR)/$(TARGET)/, \
hos.o hos_config.o pkg1.o pkg2.o pkg2_ini_kippatch.o fss.o secmon_exo.o \
hos.o hos_config.o pkg1.o pkg2.o pkg3.o pkg2_ini_kippatch.o secmon_exo.o \
)
# Libraries.

View file

@ -98,8 +98,9 @@ There are four possible type of entries. "**[ ]**": Boot entry, "**{ }**": Capti
| kernel={FILE path} | Replaces the kernel binary |
| kip1={FILE path} | Replaces/Adds kernel initial process. Multiple can be set. |
| kip1={FOLDER path}/* | Loads every .kip/.kip1 inside a folder. Compatible with single kip1 keys. |
| fss0={FILE path} | Takes an Atmosphere `package3` binary (formerly fusee-secondary.bin) and `extracts` all needed parts from it. kips, exosphere, warmboot and mesophere if enabled. |
| fss0experimental=1 | Enables loading of experimental content from a FSS0 storage |
| pkg3={FILE path} | Takes an Atmosphere `package3` binary and `extracts` all needed parts from it. kips, exosphere, warmboot and mesophere. |
| fss0={FILE path} | Same as above. Deprecated! |
| pkg3ex=1 | Enables loading of experimental content from a PKG3/FSS0 storage |
| exofatal={FILE path} | Replaces the exosphere fatal binary for Mariko |
| ---------------------- | ---------------------------------------------------------- |
| kip1patch=patchname | Enables a kip1 patch. Specify with multiple lines and/or in one line with `,` as separator. If actual patch is not found, a warning will show up |
@ -109,7 +110,7 @@ There are four possible type of entries. "**[ ]**": Boot entry, "**{ }**": Capti
| stock=1 | OFW via hekate bootloader. Disables unneeded kernel patching and CFW kips when running stock. `If emuMMC is enabled, emummc_force_disable=1` is required. emuMMC is not supported on stock. If additional KIPs are needed other than OFW's, you can define them with `kip1` key. No kip should be used that relies on Atmosphère patching, because it will hang. If `NOGC` is needed, use `kip1patch=nogc`. |
| fullsvcperm=1 | Disables SVC verification (full services permission). Doesn't work with Mesosphere as kernel. |
| debugmode=1 | Enables Debug mode. Obsolete when used with exosphere as secmon. |
| kernelprocid=1 | Enables stock kernel process id send/recv patching. Not needed when `fss0` is used. |
| kernelprocid=1 | Enables stock kernel process id send/recv patching. Not needed when `pkg3`/`fss0` is used. |
| ---------------------- | ---------------------------------------------------------- |
| payload={FILE path} | Payload launching. Tools, Android/Linux, CFW bootloaders, etc. Any key above when used with that, doesn't get into account. |
| ---------------------- | ---------------------------------------------------------- |
@ -129,11 +130,11 @@ There are four possible type of entries. "**[ ]**": Boot entry, "**{ }**": Capti
**Note1**: When using the wildcard (`/*`) with `kip1` you can still use the normal `kip1` after that to load extra single kips.
**Note2**: When using FSS0 it parses exosphere, warmboot and all core kips. You can override the first 2 by using `secmon`/`warmboot` after defining `fss0`.
**Note2**: When using PKG3/FSS0 it parses exosphere, warmboot and all core kips. You can override the first 2 by using `secmon`/`warmboot` after defining `pkg3`/`fss0`.
You can define `kip1` to load an extra kip or many via the wildcard (`/*`) usage.
**Warning**: Careful when you define *fss0 core* kips when using `fss0` or the folder (when using `/*`) includes them.
This is in case the kips are incompatible between them. If compatible, you can override `fss0` kips with no issues (useful for testing with intermediate kip changes). In such cases, the `kip1` line must be under `fss0` line.
**Warning**: Careful when you define *pkg3/fss core* kips when using `pkg3`/`fss0` or the folder (when using `/*`) includes them.
That's in case the kips are incompatible between them. If compatible, you can override `pkg3`/`fss0` kips with no issues (useful for testing with intermediate kip changes). In such cases, the `kip1` line must be after `pkg3`/`fss0` line.
### Boot entry key/value combinations for Exosphère:
@ -155,7 +156,7 @@ This is in case the kips are incompatible between them. If compatible, you can o
### Payload storage:
hekate has a boot storage in the binary that helps it configure it outside of BPMP enviroment:
hekate has a boot storage in the binary that helps it configure it outside of BPMP environment:
| Offset / Name | Description |
| ----------------------- | ----------------------------------------------------------------- |
@ -188,9 +189,9 @@ hekate has a boot storage in the binary that helps it configure it outside of BP
```
hekate (c) 2018, naehrwert, st4rk.
(c) 2018-2024, CTCaer.
(c) 2018-2025, CTCaer.
Nyx GUI (c) 2019-2024, CTCaer.
Nyx GUI (c) 2019-2025, CTCaer.
Thanks to: derrek, nedwill, plutoo, shuffle2, smea, thexyz, yellows8.
Greetings to: fincs, hexkyz, SciresM, Shiny Quagsire, WinterMute.

View file

@ -698,7 +698,7 @@ out:
static void _free_launch_components(launch_ctxt_t *ctxt)
{
// Free the malloc'ed guaranteed addresses.
free(ctxt->fss0);
free(ctxt->pkg3);
free(ctxt->keyblob);
free(ctxt->pkg1);
free(ctxt->pkg2);

View file

@ -111,8 +111,8 @@ typedef struct _launch_ctxt_t
bool stock;
bool emummc_forced;
void *fss0;
u32 fss0_hosver;
void *pkg3;
u32 pkg3_hosver;
bool patch_krn_proc_id;
int ucid;

View file

@ -21,7 +21,7 @@
#include "hos.h"
#include "hos_config.h"
#include "fss.h"
#include "pkg3.h"
#include <libs/fatfs/ff.h>
//#define DPRINTF(...) gfx_printf(__VA_ARGS__)
@ -255,9 +255,9 @@ static int _config_exo_cal0_writes_enable(launch_ctxt_t *ctxt, const char *value
return 1;
}
static int _config_fss(launch_ctxt_t *ctxt, const char *value)
static int _config_pkg3(launch_ctxt_t *ctxt, const char *value)
{
return parse_fss(ctxt, value);
return parse_pkg3(ctxt, value);
}
static int _config_exo_fatal_payload(launch_ctxt_t *ctxt, const char *value)
@ -295,7 +295,8 @@ static const cfg_handler_t _config_handlers[] = {
{ "kernelprocid", _config_kernel_proc_id },
// To override elements from PKG3, it should be set before others.
{ "fss0", _config_fss },
{ "pkg3", _config_pkg3 },
{ "fss0", _config_pkg3 },
{ "exofatal", _config_exo_fatal_payload},
{ "emummcforce", _config_emummc_forced },

View file

@ -1,7 +1,7 @@
/*
* Atmosphère Fusée Secondary Storage (Package3) parser.
* Atmosphère Package 3 parser.
*
* Copyright (c) 2019-2024 CTCaer
* Copyright (c) 2019-2025 CTCaer
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
@ -20,7 +20,7 @@
#include <bdk.h>
#include "fss.h"
#include "pkg3.h"
#include "hos.h"
#include "../config.h"
#include <libs/fatfs/ff.h>
@ -33,12 +33,14 @@ extern hekate_config h_cfg;
extern bool is_ipl_updated(void *buf, const char *path, bool force);
// FSS0 Magic and Meta header offset.
#define FSS0_MAGIC 0x30535346
#define FSS0_META_OFFSET 0x4
#define FSS0_VERSION_0_17_0 0x110000
#define PKG3_KIP_SKIP_MAX 16
// FSS0 Content Types.
// PKG3 Magic and Meta header offset.
#define PKG3_MAGIC 0x30535346 // FSS0.
#define PKG3_META_OFFSET 0x4
#define PKG3_VERSION_0_17_0 0x110000
// PKG3 Content Types.
#define CNT_TYPE_FSP 0
#define CNT_TYPE_EXO 1 // Exosphere (Secure Monitor).
#define CNT_TYPE_WBT 2 // Warmboot (SC7Exit fw).
@ -53,11 +55,11 @@ extern bool is_ipl_updated(void *buf, const char *path, bool force);
#define CNT_TYPE_EXF 11 // Exosphere Mariko fatal payload.
#define CNT_TYPE_TKG 12 // Tsec Keygen.
// FSS0 Content Flags.
// PKG3 Content Flags.
#define CNT_FLAG0_EXPERIMENTAL BIT(0)
// FSS0 Meta Header.
typedef struct _fss_meta_t
// PKG3 Meta Header.
typedef struct _pkg3_meta_t
{
u32 magic;
u32 size;
@ -67,10 +69,10 @@ typedef struct _fss_meta_t
u32 hos_ver;
u32 version;
u32 git_rev;
} fss_meta_t;
} pkg3_meta_t;
// FSS0 Content Header.
typedef struct _fss_content_t
// PKG3 Content Header.
typedef struct _pkg3_content_t
{
u32 offset;
u32 size;
@ -80,9 +82,9 @@ typedef struct _fss_content_t
u8 flags2;
u32 rsvd1;
char name[0x10];
} fss_content_t;
} pkg3_content_t;
static void _fss_update_r2p()
static void _pkg3_update_r2p()
{
u8 *r2p_payload = sd_file_read("atmosphere/reboot_payload.bin", NULL);
@ -91,7 +93,7 @@ static void _fss_update_r2p()
free(r2p_payload);
}
int parse_fss(launch_ctxt_t *ctxt, const char *path)
int parse_pkg3(launch_ctxt_t *ctxt, const char *path)
{
FIL fp;
@ -108,7 +110,7 @@ int parse_fss(launch_ctxt_t *ctxt, const char *path)
if (kv->val[0] == '1')
stock = true;
if (!strcmp("fss0experimental", kv->key))
if (!strcmp("pkg3ex", kv->key))
if (kv->val[0] == '1')
experimental = true;
}
@ -121,48 +123,48 @@ int parse_fss(launch_ctxt_t *ctxt, const char *path)
return 1;
#endif
// Try to open FSS0.
// Try to open PKG3.
if (f_open(&fp, path, FA_READ) != FR_OK)
return 0;
void *fss = malloc(f_size(&fp));
void *pkg3 = malloc(f_size(&fp));
// Read first 1024 bytes of the FSS0 file.
f_read(&fp, fss, 1024, NULL);
// Read first 1024 bytes of the PKG3 file.
f_read(&fp, pkg3, 1024, NULL);
// Get FSS0 Meta header offset.
u32 fss_meta_addr = *(u32 *)(fss + FSS0_META_OFFSET);
fss_meta_t *fss_meta = (fss_meta_t *)(fss + fss_meta_addr);
// Get PKG3 Meta header offset.
u32 pkg3_meta_addr = *(u32 *)(pkg3 + PKG3_META_OFFSET);
pkg3_meta_t *pkg3_meta = (pkg3_meta_t *)(pkg3 + pkg3_meta_addr);
// Check if valid FSS0 and parse it.
if (fss_meta->magic == FSS0_MAGIC)
// Check if valid PKG3 and parse it.
if (pkg3_meta->magic == PKG3_MAGIC)
{
gfx_printf("Atmosphere %d.%d.%d-%08x via FSS0/PKG3\n"
gfx_printf("Atmosphere %d.%d.%d-%08x via PKG3\n"
"Max HOS: %d.%d.%d\n"
"Unpacking.. ",
fss_meta->version >> 24, (fss_meta->version >> 16) & 0xFF, (fss_meta->version >> 8) & 0xFF, fss_meta->git_rev,
fss_meta->hos_ver >> 24, (fss_meta->hos_ver >> 16) & 0xFF, (fss_meta->hos_ver >> 8) & 0xFF);
pkg3_meta->version >> 24, (pkg3_meta->version >> 16) & 0xFF, (pkg3_meta->version >> 8) & 0xFF, pkg3_meta->git_rev,
pkg3_meta->hos_ver >> 24, (pkg3_meta->hos_ver >> 16) & 0xFF, (pkg3_meta->hos_ver >> 8) & 0xFF);
ctxt->patch_krn_proc_id = true;
ctxt->fss0_hosver = fss_meta->hos_ver;
ctxt->pkg3_hosver = pkg3_meta->hos_ver;
// Parse FSS0 contents.
fss_content_t *curr_fss_cnt = (fss_content_t *)(fss + fss_meta->cnt_off);
// Parse PKG3 contents.
pkg3_content_t *curr_pkg3_cnt = (pkg3_content_t *)(pkg3 + pkg3_meta->cnt_off);
void *content;
for (u32 i = 0; i < fss_meta->cnt_count; i++)
for (u32 i = 0; i < pkg3_meta->cnt_count; i++)
{
content = (void *)(fss + curr_fss_cnt[i].offset);
content = (void *)(pkg3 + curr_pkg3_cnt[i].offset);
// Check if offset is inside limits.
if ((curr_fss_cnt[i].offset + curr_fss_cnt[i].size) > fss_meta->size)
if ((curr_pkg3_cnt[i].offset + curr_pkg3_cnt[i].size) > pkg3_meta->size)
continue;
// If content is experimental and experimental config is not enabled, skip it.
if ((curr_fss_cnt[i].flags0 & CNT_FLAG0_EXPERIMENTAL) && !experimental)
if ((curr_pkg3_cnt[i].flags0 & CNT_FLAG0_EXPERIMENTAL) && !experimental)
continue;
// Prepare content.
switch (curr_fss_cnt[i].type)
switch (curr_pkg3_cnt[i].type)
{
case CNT_TYPE_KIP:
if (stock)
@ -170,30 +172,30 @@ int parse_fss(launch_ctxt_t *ctxt, const char *path)
merge_kip_t *mkip1 = (merge_kip_t *)malloc(sizeof(merge_kip_t));
mkip1->kip1 = content;
list_append(&ctxt->kip1_list, &mkip1->link);
DPRINTF("Loaded %s.kip1 from FSS0 (size %08X)\n", curr_fss_cnt[i].name, curr_fss_cnt[i].size);
DPRINTF("Loaded %s.kip1 from PKG3 (size %08X)\n", curr_pkg3_cnt[i].name, curr_pkg3_cnt[i].size);
break;
case CNT_TYPE_KRN:
if (stock)
continue;
ctxt->kernel_size = curr_fss_cnt[i].size;
ctxt->kernel_size = curr_pkg3_cnt[i].size;
ctxt->kernel = content;
break;
case CNT_TYPE_EXO:
ctxt->secmon_size = curr_fss_cnt[i].size;
ctxt->secmon_size = curr_pkg3_cnt[i].size;
ctxt->secmon = content;
break;
case CNT_TYPE_EXF:
ctxt->exofatal_size = curr_fss_cnt[i].size;
ctxt->exofatal_size = curr_pkg3_cnt[i].size;
ctxt->exofatal = content;
break;
case CNT_TYPE_WBT:
if (h_cfg.t210b01)
continue;
ctxt->warmboot_size = curr_fss_cnt[i].size;
ctxt->warmboot_size = curr_pkg3_cnt[i].size;
ctxt->warmboot = content;
break;
@ -202,23 +204,24 @@ int parse_fss(launch_ctxt_t *ctxt, const char *path)
}
// Load content to launch context.
f_lseek(&fp, curr_fss_cnt[i].offset);
f_read(&fp, content, curr_fss_cnt[i].size, NULL);
f_lseek(&fp, curr_pkg3_cnt[i].offset);
f_read(&fp, content, curr_pkg3_cnt[i].size, NULL);
}
gfx_printf("Done!\n");
f_close(&fp);
ctxt->fss0 = fss;
ctxt->pkg3 = pkg3;
// Update r2p if needed.
_fss_update_r2p();
_pkg3_update_r2p();
return 1;
}
// Failed. Close and free all.
f_close(&fp);
free(fss);
free(pkg3);
return 0;
}

View file

@ -14,11 +14,11 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _FSS_H_
#define _FSS_H_
#ifndef _PKG3_H_
#define _PKG3_H_
#include "hos.h"
int parse_fss(launch_ctxt_t *ctxt, const char *path);
int parse_pkg3(launch_ctxt_t *ctxt, const char *path);
#endif

View file

@ -9,10 +9,13 @@ autonogc=1
updater2p=1
bootprotect=0
# Only include above what you want to change from defaults.
# config.c in bootloader and Nyx have all the defaults.
{-------- Stock -------}
[Stock]
fss0=atmosphere/package3
pkg3=atmosphere/package3
stock=1
emummc_force_disable=1
@ -26,7 +29,7 @@ emummc_force_disable=1
{-- Custom Firmwares --}
[Atmo Vanilla]
fss0=atmosphere/package3
pkg3=atmosphere/package3
kip1=atmosphere/kips/*
# Note:
@ -36,11 +39,11 @@ kip1=atmosphere/kips/*
[Atmo EMU]
fss0=atmosphere/package3
pkg3=atmosphere/package3
emummcforce=1
[Atmo SYS]
fss0=atmosphere/package3
pkg3=atmosphere/package3
emummc_force_disable=1
# Note:
@ -55,7 +58,7 @@ emummc_force_disable=1
[Atmo EMU2]
fss0=atmosphere/package3
pkg3=atmosphere/package3
emupath=emuMMC/SD02
emummcforce=1
@ -68,26 +71,26 @@ emummcforce=1
[Atmo with extra kips]
fss0=atmosphere/package3
pkg3=atmosphere/package3
kip1=cfw/mods/mods_extra/*
kip1=cfw/mods/mods_extra/single/extra.kip
# Note:
# The above can be used with any fss0 entry. Like the ones above.
# You can even override atmosphere (fss0) kips with this.
# The above can be used with any pkg3 entry. Like the ones above.
# You can even override atmosphere (pkg3) kips with this.
# The wildcard '*' like above can be used to load all kips from a selected directory.
{-- Custom Firmwares Old methods --}
[CFW FSS0 extra kips & patches]
fss0=atmosphere/package3
[CFW PKG3 extra kips & patches]
pkg3=atmosphere/package3
kip1patch=name_of_patch
kip1=cfw/mods/mods_extra/*
kip1=cfw/mods/mods_extra/single/extra.kip
# Note:
# Both options for kip1 can be used. Wildcard and single.
# You can override kips loaded from FSS0/PKG3 if you define them after the fss0 key.
# You can override kips loaded from PKG3/FSS0 if you define them after the pkg3 key.
# If kip1 patch resides in patches.ini and that file OR the patch for
# current HOS version does not exist, it will error out.
@ -106,7 +109,7 @@ atmosphere=1
# Note:
# All kips defined method. This can be changed to what is below also.
# atmosphere=1 key is IMPORTANT when no FFS0 is defined.
# atmosphere=1 key is IMPORTANT when no PKG3/FSS0 is defined.