From dd1cb1e35bbf5b053e73c0c9489288e534ff9a56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D0=BE=D0=BD=D1=8C=D0=BA=D0=B8=D0=BD=20=D0=90=D0=BB?= =?UTF-8?q?=D0=B5=D0=BA=D1=81=D0=B5=D0=B9?= Date: Mon, 19 Sep 2022 23:04:43 +0300 Subject: [PATCH] Embed romfs support to all tools --- .../Elements/Fs/FilesystemDetector.cs | 3 ++- NyaFs/ImageFormat/Elements/Fs/Writer/Writer.cs | 4 ++++ NyaFs/ImageFormat/Helper/FitHelper.cs | 2 ++ NyaFs/Processor/Scripting/Commands/Set.cs | 10 ++++++++++ readme.md | 16 +++++++++++++--- 5 files changed, 31 insertions(+), 4 deletions(-) diff --git a/NyaFs/ImageFormat/Elements/Fs/FilesystemDetector.cs b/NyaFs/ImageFormat/Elements/Fs/FilesystemDetector.cs index 10b98d6..49a5b68 100644 --- a/NyaFs/ImageFormat/Elements/Fs/FilesystemDetector.cs +++ b/NyaFs/ImageFormat/Elements/Fs/FilesystemDetector.cs @@ -37,7 +37,6 @@ public static Types.FsType DetectFs(byte[] Raw) if (Magic == 0x2d726f6du) // romfs magic return Types.FsType.RomFs; - if (IsExt4(Raw)) return Types.FsType.Ext2; @@ -51,6 +50,8 @@ public static string GetFilesystemType(Types.FsType Type) case Types.FsType.Cpio: return "CPIO (ASCII)"; case Types.FsType.Ext2: return "Ext2"; case Types.FsType.SquashFs: return "SquashFs"; + case Types.FsType.CramFs: return "CramFs"; + case Types.FsType.RomFs: return "RomFs"; default: return "Unknown"; } } diff --git a/NyaFs/ImageFormat/Elements/Fs/Writer/Writer.cs b/NyaFs/ImageFormat/Elements/Fs/Writer/Writer.cs index f8e8f25..35165ce 100644 --- a/NyaFs/ImageFormat/Elements/Fs/Writer/Writer.cs +++ b/NyaFs/ImageFormat/Elements/Fs/Writer/Writer.cs @@ -29,6 +29,9 @@ internal static bool IsFilesystemSupported(Types.FsType Type) { case Types.FsType.Cpio: case Types.FsType.Ext2: + case Types.FsType.SquashFs: + case Types.FsType.CramFs: + case Types.FsType.RomFs: return true; default: return false; @@ -45,6 +48,7 @@ internal static Writer GetRawFilesystemWriter(LinuxFilesystem Fs) case Types.FsType.Ext2: return new Ext2FsWriter(DetectFixDiskSize(Fs, 0x800000)); case Types.FsType.SquashFs: return new SquashFsWriter(Fs.SquashFsCompression); case Types.FsType.CramFs: return new CramFsWriter(); + case Types.FsType.RomFs: return new RomFsWriter(); default: throw new InvalidOperationException($"Unsupported filesystem: {Fs.FilesystemType}"); } diff --git a/NyaFs/ImageFormat/Helper/FitHelper.cs b/NyaFs/ImageFormat/Helper/FitHelper.cs index 64eaf76..fa62ec4 100644 --- a/NyaFs/ImageFormat/Helper/FitHelper.cs +++ b/NyaFs/ImageFormat/Helper/FitHelper.cs @@ -16,6 +16,7 @@ public static string GetFilesystemType(Types.FsType Fs) case Types.FsType.Ext2: return "ext2"; case Types.FsType.SquashFs: return "squashfs"; case Types.FsType.CramFs: return "cramfs"; + case Types.FsType.RomFs: return "romfs"; case Types.FsType.Unknown: default: return "unknown"; @@ -30,6 +31,7 @@ public static Types.FsType GetFilesystemType(string Fs) case "ext2": return Types.FsType.Ext2; case "squashfs": return Types.FsType.SquashFs; case "cramfs": return Types.FsType.CramFs; + case "romfs": return Types.FsType.RomFs; default: return Types.FsType.Unknown; } } diff --git a/NyaFs/Processor/Scripting/Commands/Set.cs b/NyaFs/Processor/Scripting/Commands/Set.cs index 0e573b8..21e5d33 100644 --- a/NyaFs/Processor/Scripting/Commands/Set.cs +++ b/NyaFs/Processor/Scripting/Commands/Set.cs @@ -152,6 +152,16 @@ public override ScriptStepResult Exec(ImageProcessor Processor) Fs.FilesystemType = ImageFormat.Types.FsType.SquashFs; return new ScriptStepResult(ScriptStepStatus.Ok, $"Set filesystem type ok: squashfs!"); } + else if (Value == "cramfs") + { + Fs.FilesystemType = ImageFormat.Types.FsType.CramFs; + return new ScriptStepResult(ScriptStepStatus.Ok, $"Set filesystem type ok: cramfs!"); + } + else if (Value == "romfs") + { + Fs.FilesystemType = ImageFormat.Types.FsType.RomFs; + return new ScriptStepResult(ScriptStepStatus.Ok, $"Set filesystem type ok: romfs!"); + } else return new ScriptStepResult(ScriptStepStatus.Error, $"Unsupported filesystem type: {Value}"); } diff --git a/readme.md b/readme.md index 29fa061..1d685c6 100644 --- a/readme.md +++ b/readme.md @@ -5,7 +5,7 @@ There is possible to add or update files in ramfs image. ## Supported image formats 1. Kernel: compressed raw, fit, android, raw, legacy -2. Ramfs: cpio, ext2, squashfs, cramfs, compressed cpio or ext2, legacy, fit, android image +2. Ramfs: cpio, ext2, squashfs, cramfs, romfs, compressed cpio or ext2, legacy, fit, android image 3. Device tree: dtb, fit ## Supported filesystems @@ -14,6 +14,7 @@ Supported at now: 2. EXT2 (RW) 3. SquashFs (RW) 4. CramFs (RW) +5. RomFs (RW) ## Supported compression types Supported at now: @@ -111,7 +112,11 @@ load ramfs squashfs ``` Load fs from cramfs image: ``` -load ramfs cramfs +load ramfs cramfs +``` +Load fs from romfs image: +``` +load ramfs romfs ``` ### Kernel image @@ -161,6 +166,11 @@ store ramfs ``` (compression) is "gzip", "lz4", "lzma", "bzip2" +Store fs as romfs image: +``` +store ramfs romfs +``` + Store fs as cramfs image: ``` store ramfs cramfs @@ -214,7 +224,7 @@ Update filesystem type: ``` set ramfs filesystem ``` -(fs) is one of 'ext2', 'squashfs', 'cramfs' or 'cpio'. +(fs) is one of 'ext2', 'squashfs', 'cramfs', 'romfs' or 'cpio'. Change squash compression type: ```