PS2 PSBBN support for larger drives definitely possible

Ok found it. It is file opt0/bn/pfsd/pfsd (PFS Driver). There is no sources for it, you can try to patch it with ATAD Patcher 0.04

some tips and tricks for ps2linux:
you can connect to bbn via telnet
install PS2Linux ssh and samba rpm packages from usb, then
you can connect BBNav via ssh.
Code:
ssh -oKexAlgorithms=diffie-hellman-group-exchange-sha1 -oHostKeyAlgorithms=ssh-dss -c aes128-cbc [email protected]
then you can install rpm packages from usb or from SMB mounted folder on your PC:
Code:
mount -t smbfs -o rw,username=ps2,password=ps2 //ps2-PC/PS2SMB /mnt/smb3

For faster access to some game or application you can modify top.xml and add somewhere:
HTML:
<ITEM id="TEST-GAME2" label="Game2 ule" link="href" linkargs="uri=pfs:/PP.ULE" href="file:/opt0/bn/script/game/boot_game3.xml" />
this will directly boot partition you choose.

It is possible to setup apache server and launch game channel backups from there. You still need internet on launch to bypass BBNav DNAS check, luckily Sony servers still are alive and you can do it even in 2024. I wasnt able to setup apache DNAS bypass server, but it is possible via https://gitlab.com/gh0stl1ne/DNASrep/.

You can get more debug messages about bn if you connect via ssh or telnet, kill bn and restart it from terminal:
Code:
sudo killall -8 bn
/opt0/bn/bn --debug
 
PSBBN 0.20 boots with the official Linux RTE disc but not kloader so that's definitely a compatibility issue, on the other hand 0.32 won't boot with either. According to wikipedia version 0.31 fixed an exploit so I'm guessing it's related to that.
As for game launch from BBNav main executable, I suspect that it is done via some closed source driver
I was thinking that myself so I started looking into another solution. If we could trick the BBNav main executable to think there's less data on the drive then apps in the first 130GB would hopefully continue to boot. With the way OPL-Launcher works on PSBBN it would enable us to boot hundreds of games from the Game Channel.

Could we achieve this by modifying the kernel to ignore data that goes over the 28-bit LBA address limit?

Again, with the help of ChatGPT I came up with this:
Code:
/*
 *  fs/partitions/ps2.c
 */
#include <linux/genhd.h>
#include <linux/blk.h>
#include "./ps2.h"
#include <linux/slab.h>
static unsigned int get_ptable_blocksize(kdev_t dev)
{
    int ret = 1024;
    // Check for the minimum block size provided by the low-level driver
    if (!blksize_size[MAJOR(dev)])
    {
        return ret;
    }
    // Check for specific power-of-two block sizes
    switch (blksize_size[MAJOR(dev)][MINOR(dev)])
    {
    case 2048:
        ret = 2048;
        break;
    case 4096:
        ret = 4096;
        break;
    case 8192:
        ret = 8192;
        break;
    case 1024:
    case 512:
    case 256:
    case 0:
        // These block sizes are acceptable
        break;
    default:
        panic("Strange blocksize for partition table\n");
    }
    return ret;
}
static int ps2_partition_one(struct gendisk *hd, kdev_t dev,
                             struct ps2_partition *pp, int resv_m, int resv_s)
{
    int i, pno;
    long nr_sects;
    struct hd_struct *part;
    struct hd_seg_struct *seg, *sp;
    char *p, *pe;
    int resv0;
    // Initialize 'sp' to NULL
    sp = NULL;
    // Input validation and checks
    if (!pp || pp->magic != PS2_PARTITION_MAGIC || (pp->flag & PS2_PART_FLAG_SUB))
        return 0;
    pe = &pp->id[PS2_PART_NID];
    if (pp->id[0] != '\0' && pp->id[1] != '\0' &&
        strncmp((char*)(&pp->id), PS2_LINUX_ID, strlen(PS2_LINUX_ID)) == 0) {
        // PS2 Linux partition detected
        resv0 = resv_m;
        p = &pp->id[strlen(PS2_LINUX_ID)];
    } else {
        // Not a PS2 Linux partition
        return 0;
    }
    pno = 0;
    while (p < pe && *p >= '0' && *p <= '9')
        pno = pno * 10 + (*p++ - '0');
    if (pno == 0)
        pno = 1;
    if (pno < 1 || pno > hd->max_p - 1)
        return 0;
    part = &hd->part[MINOR(dev) + pno];
    // Memory allocation for 'hash' and 'seg'
    part->hash = kmalloc(sizeof(struct hd_seg_struct *) * PS2_SEGMENT_HASH_ENTRIES, GFP_KERNEL);
    if (!part->hash)
        return 0;
    seg = kmalloc(sizeof(struct hd_seg_struct) * (pp->nsub + 1), GFP_KERNEL);
    if (!seg) {
        kfree(part->hash);
        return 0;
    }
    // Initialize 'seg' and 'part' parameters
    part->nr_segs = pp->nsub + 1;
    part->seg = seg;
    seg->start_sect = part->start_sect = min((unsigned long long)pp->start + resv0, (unsigned long long)((1ULL << 28) - 1));
    seg->nr_sects = nr_sects = min((unsigned long long)pp->nsector - resv0, (unsigned long long)((1ULL << 28) - seg->start_sect));
    seg->offset = 0;
    seg++;
    for (i = 0; i < pp->nsub; i++) {
        seg->start_sect = min((unsigned long long)pp->subs.start + resv_s, (unsigned long long)((1ULL << 28) - 1));
        seg->nr_sects = min((unsigned long long)pp->subs.nsector - resv_s, (unsigned long long)((1ULL << 28) - seg->start_sect));
        seg->offset = nr_sects;
        nr_sects += seg->nr_sects;
        seg++;
    }
    // Proper loop and condition checks
    sp = part->seg;
    while (sp && nr_sects < part->nr_sects && nr_sects < (sp->offset + sp->nr_sects)) {
        // Perform operations within the loop...
        sp++;
    }
    // Calculate 'hash_unit' and populate 'hash' array
    part->hash_unit = (nr_sects + PS2_SEGMENT_HASH_ENTRIES - 1) / PS2_SEGMENT_HASH_ENTRIES;
    sp = part->seg;
    nr_sects = 0;
    for (i = 0; i < PS2_SEGMENT_HASH_ENTRIES; i++) {
        while (sp && nr_sects < part->nr_sects && nr_sects < (sp->offset + sp->nr_sects))
            sp++;
        part->hash = sp;
        nr_sects += part->hash_unit;
    }
    return 1;
}
int ps2_partition(struct gendisk *hd, struct block_device *bdev, unsigned long first_sector, int first_part_minor)
{
    struct buffer_head *bh;
    int dev_bsize, dev_ssize, stob, resv_m, resv_s;
    struct ps2_partition *pp;
    long sect;
    int i;
    char buf[8];
    kdev_t dev;
    dev = to_kdev_t(bdev->bd_dev);
    dev_bsize = get_ptable_blocksize(dev);
    dev_ssize = 512;
    if (hardsect_size[MAJOR(dev)] != 0)
        dev_ssize = hardsect_size[MAJOR(dev)][MINOR(dev)];
    stob = dev_bsize / dev_ssize;
    if (stob == 0)
        stob = 1;
    resv_m = PS2_PART_RESV_MAIN / dev_ssize;
    if (resv_m == 0)
        resv_m = 1;
    resv_s = PS2_PART_RESV_SUB / dev_ssize;
    if (resv_s == 0)
        resv_s = 1;
    sect = 0;
    do {
        if (!(bh = bread(dev, sect / stob, dev_bsize))) {
            printk("%s: unable to read sector %ld\n", kdevname(dev), sect);
            return -1;
        }
        pp = (struct ps2_partition *)bh->b_data;
        if (sect == 0) {
            if (memcmp(pp->mbr.magic, PS2_MBR_MAGIC, 32) != 0 ||
                pp->mbr.version > PS2_MBR_VERSION) {
                brelse(bh);
                return 0;
            }
        }
        if (!ps2_partition_one(hd, dev, pp, resv_m, resv_s)) {
            brelse(bh);
            break;
        }
        sect = pp->next;
        brelse(bh);
    } while (sect != 0);
    printk(" [APA]");
    for (i = 1; i < hd->max_p; i++) {
        if (hd->part[MINOR(dev) + i].nr_sects != 0) {
            printk(" %s", disk_name(hd, MINOR(dev) + i, buf));
        }
    }
    printk("\n");
    return 1;
}
Again, all I get is a kernel panic.
 
Ok found it. It is file opt0/bn/pfsd/pfsd (PFS Driver). There is no sources for it, you can try to patch it with ATAD Patcher 0.04
How would I go about going that?
You still need internet on launch to bypass BBNav DNAS check
No need for that. It's super easy to disable DNAS. Just delete __contents/bn.conf/default_isp.dat
 
How would I go about going that?
Didnt found it in psx-pace, made by @krHACKen : see attached file. It is patching any atad.irx based app or driver to support 48-bit.
No need for that. It's super easy to disable DNAS. Just delete __contents/bn.conf/default_isp.dat
As I understand you will loose ability to browse online channels after that, even if you redirect them into mirror. Correct me if I am wrong, cause if Scej CH (the only alive channel) still is accessible after that, it will be nice solution.
I was thinking that myself so I started looking into another solution. If we could trick the BBNav main executable to think there's less data on the drive then apps in the first 130GB would hopefully continue to boot.
I will not advice to do that. First it will be not that easy. You need to hack kernel to report wrong HDD size (so it will limit HDD to 137Gb), that should be done inside kernel and I dont think that it will help cause you will break APA chain. Also, when BBNav will try to make some modifications you will destroy partition table on the hdd.
Back in times there were created Toxic OS for dealing with big HDDs and keeping compatible with old 28-bit software. It is splitting HDD in 2 areas: 40Gb + the rest. And each area is formatted independently. Unfortunately modern software doesnt support that, I think that opl stripped support for Toxic OS in 2020. Without that you will not be able to add support for old software without corrupting partition table.

Again, all I get is a kernel panic.
You don't need to modify it. It is good driver with 32-bit support. Anyway, for limiting to 28-bit you should do it differently. All prev, next, nr_sect, hdd_size should be applied with 28-bit mask.
You can ask chatgpt how to hack kernel sources to always report hdd size 40 Gb (137 Gb). And also ensure that you didnt install anything on the hdd pass that mark. If you install past that mark, you will get out of bounds or apa chain aerror, I dont think that you will found solution for fixing that with 28-bit compatibility.
 

Attachments

As I understand you will loose ability to browse online channels after that, even if you redirect them into mirror
Nope, all the online stuff works fine after deleting that file. Just make sure you've set up a network connection before deleting it. That's all I did to disable DNAS for my "PSBBN Definitive English Patch". Scej channel and all the mirrors working perfectly.

Thanks for the file. I'll give the patch a go.
 
It is patching any atad.irx based app or driver to support 48-bit.
I just looked at the patcher and it modifies some hex values to allow support for non-Sony HDDs and that's all. It doesn't add 48-bit LBA support.

If the problem can't be tackled by modifying the open source kernel then maybe we have hit a brick wall...

However, HDDOSD was somehow patched for 48-bit support. I'd really like to know how that was achieved. Perhaps whatever was done to that could be applied to the the pfs driver.
 
Nope, all the online stuff works fine after deleting that file. Just make sure you've set up a network connection before deleting it. That's all I did to disable DNAS for my "PSBBN Definitive English Patch". Scej channel and all the mirrors working perfectly.
Nice, didnt know about that, this is very cool hack.

However, HDDOSD was somehow patched for 48-bit support. I'd really like to know how that was achieved.
ah, yes, sorry, 48-bit support was added in different way - by completely replacing Sony driver with ps2sdk driver. This is not applicable for BBNav unfortunately.

I've also found an open source "ps2fs driver" for PS2 Linux. Could possibly be reworked to replace Sony's driver:
https://ps2linux.no-ip.info/playstation2-linux.com/projects/apa.html
actually it doesnt differ much from the code you placed earlier, it has the same limitations for 2Tb. Actually BBNav driver for mounting linux partition is very good.
But if you want to replace closed source driver inside BBNav executable you need to reverse it in IDA, cause it is completely unknown the library structure , what it is calling and what it is checking. As BBNav for launching games doesnt use any of built-in linux drivers and use its own custom driver with unknown functionality.
 
It's looking increasingly likely that an APA Jail hybrid drive might be the only viable solution. @Berion I know OPL now supports exFAT on internal drives. Does it now work with APA Jail? Would 28-bit LBA apps still work with APA Jail as long as the PS2 partitions didn't exceed its addressable limit?
 
Yes, that's the purpose of it. But remember that once setup, none of of the partition tables (APA and GPT) can be modified on PC and PS2 because current tools on both sides will damage opposite environment.

I have in plans making script for forging and customizing APA Jail. Only for Linux.
 
It's looking increasingly likely that an APA Jail
APA jail has its limitations. GPT partition table and APA filesystem journal uses the same sectors for storing data, so its just matter of time until APA will update the journal and successfully destroy GPT partition scheme. For example it is enough to put Audio CD and BBNav will create temp partition for storing data. apa jpurnal will update, GPT checksum will be destroyed.
It is possible to use it with MBR partition scheme though. MBR uses first sector and once you fix APA checksum and dont touch MBR partitions, you can use APA side freely without breaking MBR. But of course MBR is a bit outdated and limited to 2Tb.
 
Audio CD and BBNav will create temp partition for storing data
When you rip a CD for the first time PSBBN creates a 5GB reiserfs filesystem for music. There's no creation of temp partitions. You would definitely need to rip a CD before attempting APA jail but after that it should be fine.

I have in plans making script for forging and customizing APA Jail. Only for Linux.
I'd love to give that a go. If you need people to test the script when it's done then just give me a shout.
 
Last edited by a moderator:
When you rip a CD for the first time PSBBN creates a 5GB reiserfs filesystem for music.
Sure, but journaling can also occur randomly, APA driver can rewrite journal when it notices something strange in APA scheme, and linux version of ATAD also can do that. APA driver assumes that sectors 7-10 belongs only to him. It is not writing there every second of course, but it can do that. Even if you rip Audio CD first, and then fix GPT, when you insert Audio CD next time APA driver will update date-time for partition access. Driver will count it as APA change and will write updated data into APA journal sectors.
This is not all scenarios, when APA journal may update himself. Linux has fsck modules, and when reiserfs fsck module will run it will also update partition data, that triggers APA Journal update as well. So you need to fix GPT each time fsck module is called, that is kanda difficult cause many programs and scenarios may run it.
Also possible to write daemon that will constantly check if GPT and APA is ok and doesnt destroy each other. That will require some coding and isnt that easy of course.
 
I was just thinking. The PSX must have some kind of hybrid drive. It has 40GB reserved for PS2 compatibility and the rest for DVR. I believe the PSX runs on Linux just like PSBBN
 
DESRs are really twisted. HDD is split into two areas: first one with __mbr covering standard LBA28 space and PS2 hw handle it. And __extend which covering the rest of drive which is handled by DVR hw (DVRP/SPEED etc.). Additionally, it encrypts transparently each used sector by both environments.

DESRs doesn't run on Linux AFAIK but custom dashborad (but PSBBN stuff was supported).
 
The PSX must have some kind of hybrid drive. It has 40GB reserved for PS2 compatibility and the rest for DVR. I believe the PSX runs on Linux just like PSBBN
1st gen PSX has PS2BBN but it is very limited and is coded as DESR firmware module but PSX firmware isnt driven by Linux (more like PS2 elf). BTW original PS2Linux will refuse to install onto DESR - Sony blocked Linux installation.
As about 40GB reservation, its done very similar to Toxic OS. But there is a problem that DESR store partition table inside DVRP processor firmware. I mean that 40Gb - you can change that number and it will update that minimal partition table inside DVRP firmware. So DESR does not store main partition table in first HDD sectors, but instead inside DVRP firmware.
Unfortunately, this is not the option for PS2 as APA, GPT and MBR all of them need first HDD sectors to store some data. @Berion uses that hacky solution that GPT may partially work if it stores partition table at the end of the HDD, but this is not official specs and moreover not recommended.
My recommendation to look into MBR scheme. APA cannot destroy MBR in all scenarios, MBR can affect APA only by corrupting one checksum and only when repartition occurs and anyway main checksum is very easy to fix. MBR doesnt interfere with APA journaling.
You can create 137Gb jail MBR partition for BBNav and other PS2 apps, and the rest (2Tb (or less if HDD isnt that big) - 137Gb) format as exfat.
 
As about 40GB reservation, its done very similar to Toxic OS. But there is a problem that DESR store partition table inside DVRP processor firmware. I mean that 40Gb - you can change that number and it will update that minimal partition table inside DVRP firmware. So DESR does not store main partition table in first HDD sectors, but instead inside DVRP firmware.
AFAIK partition table for second area is stored in "__extend". Which is right after first area ends. At least judging by krHACKen's decrypted dump. "__extend" covering up "__xcontents" and "__xdata".
 

Similar threads

Back
Top