-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FlashIdDecoder: implement Kioxia and WD
- Loading branch information
Showing
9 changed files
with
407 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
FlashDetector/src/iTXTech/FlashDetector/FlashId/Decoder.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<?php | ||
|
||
/* | ||
* iTXTech FlashDetector | ||
* | ||
* Copyright (C) 2018-2021 iTX Technologies | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
|
||
namespace iTXTech\FlashDetector\FlashId; | ||
|
||
use iTXTech\FlashDetector\FlashIdInfo; | ||
|
||
abstract class Decoder{ | ||
public $def; | ||
public $vendorName; | ||
public $vendorId; | ||
|
||
public function __construct(string $vendorName, int $vendorId, array $def){ | ||
$this->vendorName = $vendorName; | ||
$this->vendorId = $vendorId; | ||
$this->def = $def; | ||
} | ||
|
||
public function check(int $id) : bool{ | ||
if(($id > 0x100000000000 and $id < 0x1000000000000) and $id >> 40 == $this->vendorId){ | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
public function decode(string $id) : FlashIdInfo{ | ||
return self::decodeIdDef($id, $this->def, (new FlashIdInfo($id))->setVendor($this->vendorName)); | ||
} | ||
|
||
public function decodeIdDef(int $id, array $def, FlashIdInfo $info) : FlashIdInfo{ | ||
foreach($def as $offset => $rules){ | ||
$byte = ($id >> (8 * (6 - $offset))) & 0xff; | ||
foreach($rules as $name => $rule){ | ||
$data = 0; | ||
foreach($rule["dq"] as $dq){ | ||
$data = ($data << 1) + (($byte >> $dq) & 0b1); | ||
} | ||
if(isset($rule["def"][$data])){ | ||
$info->{"set" . ucfirst($name)}($rule["def"][$data]); | ||
} | ||
} | ||
} | ||
return $info; | ||
} | ||
} |
140 changes: 140 additions & 0 deletions
140
FlashDetector/src/iTXTech/FlashDetector/FlashId/Kioxia.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
<?php | ||
|
||
/* | ||
* iTXTech FlashDetector | ||
* | ||
* Copyright (C) 2018-2021 iTX Technologies | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
|
||
namespace iTXTech\FlashDetector\FlashId; | ||
|
||
use iTXTech\FlashDetector\Constants; | ||
use iTXTech\FlashDetector\FlashIdInfo; | ||
|
||
class Kioxia extends Decoder{ | ||
public const ID_DEFINITION = [ | ||
2 => [ | ||
"density" => [ | ||
"dq" => [7, 6, 5, 4, 3, 2, 1, 0], | ||
"def" => [ | ||
0b11010011 => 8 * Constants::DENSITY_GBITS, //D3 | ||
0b11010101 => 16 * Constants::DENSITY_GBITS, //D5 | ||
0b11010111 => 32 * Constants::DENSITY_GBITS, //D7 | ||
0b11011110 => 64 * Constants::DENSITY_GBITS, //DE | ||
0b00111010 => 128 * Constants::DENSITY_GBITS, //3A | ||
0b00111100 => 256 * Constants::DENSITY_GBITS, //3C | ||
0b00111110 => 512 * Constants::DENSITY_GBITS, //3E | ||
0b01001000 => 1 * Constants::DENSITY_TBITS, //48 | ||
0x49 => 2 * Constants::DENSITY_TBITS, | ||
0x40 => 4 * Constants::DENSITY_TBITS, | ||
0x4C => 256 * Constants::DENSITY_GBITS | ||
] | ||
] | ||
], | ||
3 => [ | ||
"die" => [ | ||
"dq" => [1, 0], | ||
"def" => [ | ||
0b00 => 1, | ||
0b01 => 2, | ||
0b10 => 4, | ||
0b11 => 8 | ||
] | ||
], | ||
"cellLevel" => [ | ||
"dq" => [3, 2], | ||
"def" => [ | ||
0b00 => 1, //SLC | ||
0b01 => 2, //MLC | ||
0b10 => 3, //TLC | ||
0b11 => 4, //QLC | ||
] | ||
] | ||
], | ||
4 => [ | ||
"pageSize" => [ | ||
"dq" => [1, 0], | ||
"def" => [ | ||
0b00 => 2, //2KB | ||
0b01 => 4, //4KB | ||
0b10 => 8, //8KB | ||
0b11 => 16, //16KB | ||
] | ||
], | ||
"blockSize" => [ | ||
"dq" => [7, 5, 4], | ||
"def" => [ | ||
0b000 => 128, | ||
0b001 => 256, | ||
0b010 => 512, | ||
0b011 => 1024, | ||
0b100 => 2048, | ||
0b101 => 4096, | ||
0b110 => 6144, | ||
0b111 => 0 | ||
] | ||
] | ||
], | ||
5 => [ | ||
"plane" => [ | ||
"dq" => [3, 2], | ||
"def" => [ | ||
0b00 => 1, | ||
0b01 => 2, | ||
0b10 => 4, | ||
0b11 => 8 | ||
] | ||
] | ||
], | ||
6 => [ | ||
"toggle" => [ | ||
"dq" => [7], | ||
"def" => [ | ||
0b0 => false, | ||
0b1 => true | ||
] | ||
], | ||
"processNode" => [ | ||
"dq" => [6, 5, 2, 1, 0], | ||
"def" => [ | ||
0b10100 => "43nm", | ||
0b10101 => "32nm", | ||
0b10110 => "24nm", | ||
0b10111 => "19nm", | ||
0b10000 => "A19nm", | ||
0b10001 => "15nm", | ||
0b11001 => "BiCS2", | ||
0b11010 => "BiCS3", | ||
0b11011 => "BiCS4" | ||
] | ||
|
||
] | ||
] | ||
]; | ||
|
||
public function __construct(){ | ||
parent::__construct(Constants::VENDOR_KIOXIA, 0x98, self::ID_DEFINITION); | ||
} | ||
|
||
public function decode(string $id) : FlashIdInfo{ | ||
$info = parent::decode($id); | ||
if($info->getDie() > 0 and $info->getPlane() > 0){ | ||
return $info->setPlane($info->getPlane() / $info->getDie()); | ||
} | ||
return $info; | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
FlashDetector/src/iTXTech/FlashDetector/FlashId/WesternDigital.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
/* | ||
* iTXTech FlashDetector | ||
* | ||
* Copyright (C) 2018-2021 iTX Technologies | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
|
||
namespace iTXTech\FlashDetector\FlashId; | ||
|
||
use iTXTech\FlashDetector\Constants; | ||
|
||
class WesternDigital extends Kioxia{ | ||
public function __construct(){ | ||
Decoder::__construct(Constants::VENDOR_WESTERN_DIGITAL, 0x45, self::ID_DEFINITION); | ||
} | ||
} |
Oops, something went wrong.