When the fail0verflow team published their tools, it was clear that they were not all functionnal and bug-free. Waninkoko had the "honor" of realizing this on his own when releasing the first true custom firmware, which unfortunately left a couple of users with bricked PS3s since the tools were not really working correctly.
More recently, we have seen new custom firmwares being pushed that seem to be having the same problem when rebuilding the CORE OS package (it's clear, for example, that a not-fully-working version of cospkg was used for building Rogero's 4.21 CFW, inevitably bricking more consoles) and to be honest, although I'm still doing fine on 3.41 and have no intention of returning to the PS3 scene, I feel like I have some sort of "moral" obligation so I'm opening a thread regarding updates to the tools. Extracting CORE OS
After unpacking the .PUP and extracting the contents of the .tar file with unpkg, we can unpack CORE OS like this:
unpkg 341firm/CORE_OS_PACKAGE.pkg 341firm/cos
This command should generate 3 files in the "cos" folder: "info0", "info1" and "content". The "content" file can be further unpacked using cosunpkg like this:
cosunpkg 341firm/cos/content 341firm/cos/files
We now have a new folder named "files" inside the "cos" folder, where we could now proceed to patch lv1 or lv2 for example.
Once these are patched, we need to repack CORE OS, and this is when the problems arise.
When flukes1 introduced his 3.55 CFW, it came to my attention that his python program used to build his PUP behaved differently of the technique I had shown him, but he still managed to patch the original contents of the firmware with new content without using the "cospkg" utility.
So I did the same with 3.41 CFW and, as we can see, there were no bricks reported for that reason.
This technique has a drawback though: filesize for modified selfs cannot exceed the size of the original selfs, because they need to fit in the "hole" of the old one.
The advantage is that it respects the order of the files and keeps the the original lineup (something that cospkg discards). But what happens if for some reason we need to pack files with a size greater than the original?
Well, we have no choice but to fix cosunpkg and cospkg to generate the "content" exactly as it was in the original.
To achieve this, I had to try and test with multiple official firmwares because obviously, if I extract the contents of the update and repackage them exactly like they were, I should obtain the same data (both files are equal). By using a bunch of different firmwares, I was able to detect any small differences and particularities that needed to be implemented in the repackaging process. (A tool which never fails in firmwares with really sublte differences means we're on the right track).
The "cosunpkg" tool that is attached works just like the original one, exept that it generates a file named "list.txt", which contains the number of entries and a list of files in the original content's order.
"cospkg" then generates the new contents with that list and applies the corresponding alignment following my tests on the following firmware versions: 1.02, 3.15, 3.41, 3.50, 3.55, 4.21, 4.21 and 4.30 (after a small detection based on the name of a couple of important files).
To pack a firmware, proceed as follows:
cospkg 341firm/cos/content 341firm/cos/files
If we unpack the original firmware and repack it without having changed anything, there shouldn't be any differences at all between them and that is what I have seen with these firmwares. That is, since I have no hardware flash, no interest in making a CFW and no console to risk, I CANNOT GUARANTEE THAT IT WILL NEVER FAIL. In principle, it should not, but I wouldn't play with fire and I guess that someone that develops a CFW has the means and knowledge to test and reverse the possible errors that could occur with a hardware flasher.
So use it responsibly and understand that even though original files are regenerated correctly, it may not work with modified files if you change the filesize. Or there might be a problem in another tool that has to be fixed (there might be a problem somewhere else in the process, either in the making of the PKG, the tar archive or the PUP)
Attached are the sources of the modified ps3tools cosunpkg.c and cospkg.c, and the executables compiled for Cygwin. I hope that you find them useful and please refrain from using such tools if you don't know what you're doing or do not have the possibility to fix a potential problem.
Oh, and if you can't understand one iota of what I'm saying, you can keep your questions to yourself as I will not anwser them.