2019年11月29日 星期五

Cut-through Switching

傳統 Ethernet Switch 轉送封包的方式是 Store and forward,整個封包收到檢查 CRC 後再轉送,延遲計算是收到最後一個 bit 到送出第一個 bit 的時間。

而 Cut through 收到封包的 Destination MAC 就馬上開始進行轉送,減少接收剩下資料的延遲,但沒檢查 CRC 錯誤的封包沒丟棄。延遲計算是收到第一個 bit 到送出第一的 bit 的時間。

Fragment free

應用:需要很低延遲的應用。

Adaptive switching 是動態切換 cut-throught 或 store-and-forward。

Wormhole switching:封包切成 flits (flow control units)。通常第一個 flit (header flit) 有位址資訊建立到輸出口的連線,剩下 flits 沿用直到最後 flit (tail flits) 關閉連線。出口 buffer 滿了,後送 "back-pressure" 告知來源暫停傳送。

參考
  1. https://hlchang.com/2010/08/cut-through-捲土重來/
  2. https://en.wikipedia.org/wiki/Cut-through_switching
  3. https://en.wikipedia.org/wiki/Wormhole_switching

2019年11月23日 星期六

OpenWrt REVISION

由 scripts/getver.sh 產生


用途
  • base-files VERSION 一部分
  • VERSION_SED 取代 %R:用在 /etc/banner, /etc/openwrt_version, /etc/openwrt_release, /etc/device_info, /etc/opkg/distfeeds.conf
  • repositories.conf
  • mac80211 編譯 compat_version
  • netgear-dni、tplink-safeloader

ssh client

ssh client 的系統設定在 /etc/ssh/ssh_config,如果要個人設定,是寫在 ~/.ssh/config。

有個方便的用處是,當 ssh 伺服器不是使用預設通訊埠時,可以寫在設定檔裡,這樣 ssh 連線時就不用再額外指定通訊埠。此外也可以設定別名。

連線到伺服器有些情況會有 locale 問題,可以關掉 SendEnv。但由於 SendEnv 是累加的,不是不設 SendEnv 或將 SendEnv 設為空白就可以,如果 /etc/ssh/ssh_config 有設 SendEnv,也需要移除。

問題:no matching key exchange method found. Their offer: diffie-hellman-group1-sha1
  • 加參數 -oKexAlgorithms=+diffie-hellman-group1-sha1
  • 設定加入連線加密方法
  • 參考
ssh 是一個透過 SSH 加密連線登入遠端機器執行指令的程式,同時這個連線也可以用來轉送 X11 連線、任意 TCP port、和 UNIX-domain socket。

指令參數

  • -N:不執行遠端指令
  • -nNT:不開 tty
  • -f:背景執行 
  • -L:local port forwarding
  • -D:dynamic port forwarding
  • -R:remote port forwarding
  • -X:X11 Forwarding

SSH tunnel

local port forwarding

ssh client 近端一個 port 透過 SSH 通到 ssh server,然後存取遠端 remotehost:remoteport:

ssh -L localport:remotehost:remoteport user@example.com

連 ssh client 的 localport,相當於連到遠端的 remotehost:remoteport,SSH server 會去解析 remotehost。遠端位置可能是 Web Server、RDP Server、VNC Server 等。

dynamic port forwording

同 local port forwarding,但最終位置不指定,改依 L5 SOCKS 協定的 handshake 得知。可用於任何 TCP/UDP socket 連線。provide a local SOCKS 4/4A/5 proxy on a local port

ssh -D localport user@example.com

所有連 ssh client 的 localport,都會連到 SSH server 再去進行連線到最終位置。例如 Firefox 等瀏覽器可設定 SOCKS proxy 為 SSH client 的 localport,網頁就會透過 SSH server 去連線。參考:https://linuxize.com/post/how-to-setup-ssh-socks-tunnel-for-private-browsing/

remote port forwarding

遠端 ssh server 的一個 port 透過 SSH 通到 ssh client,然後存取近端的 localhost:port:

ssh -R 9000:localhost:3000 user@example.com

SSH server 預設不允許 remote port forwarding,啟用需要在 /etc/ssh/sshd_config

GatewayPorts yes

然後重啟

sudo service ssh restart

連遠端 ssh server 的 port,相當於連到近端的 localhost:port。

ssh client


PuTTY pieTTY Xshell FireSSH zterm
安裝 可免安裝 可免安裝 需要安裝,個人用免費 JavaScript 版,給 Firefox 使用 Java 版,用於各式瀏覽器,需要 Java 執行環境
拖曳傳擋
有 (sftp,需要輸入密碼、選目錄) 有 (sftp)

Tab



中文



判斷字元自動輸入



其它說明
基於 PuTTY,但沒隨時跟上更新

選項設定

ssh 依照下列優先來源取得設定:

  1. command-line options
  2. 個人設定檔:~/.ssh/config
  3. 系統設定檔:/etc/ssh/ssh_config

設定檔包含 host 規範的 section,只要符合指令行的主機名稱就有效 (見 CanonicalizeHostname)。由於每個參數使用第一個取得的值,越 host 特殊的宣告應該要放在前面,越通用的放後面。

設定檔包含 keyword-argument 對,每對一行。# 開始的行和空白行是註解。argument 可用双引號包起來,為了包含空白。Configuration options may be separated by whitespace or optional whitespace and exactly one ‘=’; the latter format is useful to avoid the need to quote whitespace when specifying configuration options using the ssh, scp, and sftp -o option.

keyword argument

keyword=argument

keyword =arguemnt

keyword 不分大小寫,argument 分大小寫。

Host

接下來設定區塊 (到下個的 Host 或 Match 為止) 適用的 host,多個用 whitespace 分隔。「*」表示所有 host。The host is usually the hostname argument given on the command line (見 CanonicalizeHostname).

A pattern entry may be negated by prefixing it with an exclamation mark (‘!’).  If a negated entry is matched, then the Host entry is ignored, regardless of whether any other patterns on the line match.  Negated matches are therefore useful to provide exceptions for wildcard matches.

See PATTERNS for more information on patterns.

Match

接下來設定區塊 (到下個的 Host 或 Match 為止) 適用的條件,可多個,前置驚嘆號否定。

all: 都符合。必須單獨使用或緊接著 canonicalfinal 之後。

canonical:遠端 hostname 有 canonicalization 時額外套用。

final:最後額外套用。

exec 指令:在 shell 在執行指令回 0 時。指令有 whitespace characters 要quoted,接受 token %%、%h、%i、%L、%l、%n、%p、%r、和 %u。

The other keywords' criteria must be single entries or comma-separated lists and may use the wildcard and negation operators described in the PATTERNS section.

host hostname:比對 HostnameCanonicalizeHostname 轉換過後 hostname 符合。

originalhost hostname:比對指令行原始 hostname 符合。

user user:比對遠端帳號符合。

localuser user:比對本地帳號符合。在系統設定檔較有用。

BatchMode
如果設為 yes,user interaction such as password prompts and host key confirmation requests will be disabled. In addition, the ServerAliveInterval option will be set to 300 seconds by default (Debian-specific). This option is useful in scripts and other batch jobs where no user is present to interact with ssh(1), and where it is desirable to detect a broken network swiftly. The argument must be yes or no (the default).
CanonicalizeHostname
控制是否進行 hostname canonicalization。參考:https://sleeplessbeastie.eu/2020/08/24/how-to-perform-hostname-canonicalization/

預設 no:使用系統 resolver 處理 hostname lookups。

設為 yes:不用 ProxyCommand 或 ProxyJump 的連線,嘗試使用 CanonicalDomains 後綴和 CanonicalizePermittedCNAMEs 規則來canonicalize 指令行的 hostname。

設為 always:也用在 proxied 的連線。

設為 enabled:the configuration files are processed again using the new target name to pick up any new configuration in matching Host and Match stanzas.

CheckHostIP

預設是 yes,額外檢查 known_hosts 檔的 host IP 位址,無論 StrictHostKeyChecking 的設定都會加 host 位址到 ~/.ssh/known_hosts,用來偵測 host key 是否因為 DNS spoofing 而改變。

If the option is set to no, the check will not be executed.

Hostname
實際要登入的 host name,可以是 nicknames or abbreviations,接受 token %% and %h,可以是數字 IP (both on the command line and in Hostname specifications). The default is the name given on the command line.
KexAlgorithms
指定可用的 KEX (Key Exchange) 演算法. Multiple algorithms must be comma-separated. If the specified list begins with a ‘+’ character, then the specified methods will be appended to the default set instead of replacing them. If the specified list begins with a ‘-’ character, then the specified methods (in‐ cluding wildcards) will be removed from the default set instead of replacing them. If the specified list begins with a ‘^’ char‐ acter, then the specified methods will be placed at the head of the default set. The default is: curve25519-sha256,curve25519-sha256@libssh.org, ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521, diffie-hellman-group-exchange-sha256, diffie-hellman-group16-sha512, diffie-hellman-group18-sha512, diffie-hellman-group14-sha256 The list of available key exchange algorithms may also be ob‐ tained using "ssh -Q kex".
NumberOfPasswordPrompts
密碼嘗試次數,預設是 3。
PasswordAuthentication
是否使用密碼認證,yes (預設) 或 no。
Port
遠端 port,方便不是預設的 22。
PreferredAuthentications
嘗試認證方式的順序,預設是 gssapi-with-mic,hostbased,publickey,keyboard-interactive,password。
ServerAliveInterval
Sets a timeout interval 秒數 after which if no data has been received from the server, ssh 會送 message to request a response from the server. The default is 0, indicating that these messages will not be sent to the server, or 300 if the BatchMode option is set (Debian-spe‐ cific). ProtocolKeepAlives and SetupTimeOut are Debian-specific compatibility aliases for this option.
StrictHostKeyChecking

預設是 ask,新 host 的 key 在使用者同意後加入 ~/.ssh/known_hosts。host key 改變會拒絕連線。

設為 accept-new,自動加新 host 的 key。host key 改變會拒絕連線。

設為 yes,使用者必須手動加入新 host 的 key。host key 改變會拒絕連線。提供 man-in-the-middle (MITM) 攻擊最大的保護, though it can be annoying when the /etc/ssh/ssh_known_hosts file is poorly maintained or when connections to new hosts are frequently made.

設為 no 或 off,自動加新 host 的 key。host key 改變會檢查,除了一些限制外,仍允許連線。

User
指定登入帳號。
UserKnownHostsFile

Specifies one or more files to use for the user host key database, separated by whitespace. 預設是「~/.ssh/known_hosts ~/.ssh/known_hosts2」。

設為 UserKnownHostsFile=/dev/null

VerifyHostKeyDNS

Specifies whether to verify the remote key using DNS and SSHFP resource records.

設為 yes, the client will implicitly trust keys that match a secure fingerprint from DNS. Insecure fingerprints will be handled as if this option was set to ask.

設為 ask, information on fingerprint match will be displayed, but the user will still need to confirm new host keys according to the StrictHostKeyChecking option.

預設是 no。

See also VERIFYING HOST KEYS in ssh(1).

PATTERNS

pattern 是 0 或更多 non-whitespace characters

*:代表 0 或更多 characters

?:代表 1 個 character

pattern-list 是逗號分隔的 pattern 列表。裡面的 pattern 可以前置驚嘆號來否定。要注意的是否定符合本身不會變成正面的符合結果,例如下列結果 host3 並不符合:

from="!host1,!host2"

一種解決方式是包含一項達到正面符合,如 wildcard:

from="!host1,!host2,*"

TOKENS

有些 keyword 的 argument 可用 token,意思如下:

%%%
%CHash of %l%h%p%r。
%d自己的家目錄。
%h遠端 hostname。
%i自己 user ID。
%L自己 hostname。
%l自己 hostname, including the domain name。
%n原始指令行的遠端 hostname。
%p遠端 port。
%r遠端 username。
%T請求 tunnel forwarding 指定的 tun 或 tap 網路界面,無則 "NONE"。
%u自己 username。

      CertificateFile accepts the tokens %%, %d, %h, %i, %l, %r, and %u.

      ControlPath accepts the tokens %%, %C, %h, %i, %L, %l, %n, %p, %r, and
     %u.

    

     IdentityAgent and IdentityFile accept the tokens %%, %d, %h, %i, %l, %r,
     and %u.

     LocalCommand accepts the tokens %%, %C, %d, %h, %i, %l, %n, %p, %r, %T,
     and %u.

     ProxyCommand accepts the tokens %%, %h, %n, %p, and %r.

     RemoteCommand accepts the tokens %%, %C, %d, %h, %i, %l, %n, %p, %r, and
     %u.

問題

參考

  1. http://stackoverflow.com/questions/7332124/gitolite-with-non-default-port
  2. man ssh
  3. 基於 sftp 的 sshfs
  4. http://blog.trackets.com/2014/05/17/ssh-tunnel-local-and-remote-port-forwarding-explained-with-examples.html
  5. Bash ssh 由歷史資料來自動補齊主機名稱
  6. man ssh_config

SEE ALSO

     scp(1), ssh-add(1), ssh-agent(1), ssh-argv0(1), ssh-keygen(1),
     ssh-keyscan(1), tun(4), ssh-keysign(8), sshd(8)
待讀
https://www.bitvise.com/remote-desktop
http://www.howtogeek.com/114812/5-cool-things-you-can-do-with-an-ssh-server/
http://www.linuxjournal.com/content/more-secure-ssh-connections?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed%3A+linuxjournalcom+%28Linux+Journal+-+The+Original+Magazine+of+the+Linux+Community%29
http://www.cyberciti.biz/faq/install-ssh-identity-key-remote-host/
[Linux 透過 SSH SOCKS 連線 來 使用 Firefox / Pidgin(MSN, GTalk..)](https://blog.longwin.com.tw/2010/01/linux-ssh-socks-firefox-pidgin-2010/)

2019年11月16日 星期六

sftp

sftp 是一個類似 ftp 的互動式檔案傳送程式,但使用加密的 ssh 傳輸,可使用許多 ssh 功能,例如公鑰認證和壓縮。和 ftp 一樣。sftp 也可以直接取得特定檔案。

指令格式
sftp [-46aCfpqrv] [-B buffer_size] [-b batchfile] [-c cipher]
     [-D sftp_server_path] [-F ssh_config] [-i identity_file] [-l limit]
     [-o ssh_option] [-P port] [-R num_requests] [-S program]
     [-s subsystem | sftp_server] host

sftp [user@]host[:file ...] #取得特定檔案
sftp [user@]host[:dir[/]] #指定遠端起始目錄
sftp -b batchfile [user@]host #自動 session

因為有些用法使用分號區隔主機名稱和檔名路徑,IPv6 位址需要用方括號來區別。

參數:見 man sftp。

指令:類似 ftp 用的指令,不分大小寫,有 space 的檔名路徑需要加 quotes,pathname 的特殊字元 (見 glob() 函數) 需要 backslashes (‘\’) 跳脫。見 man sftp。

參考:

繼電器

http://www.makezine.com.tw/make2599131456/34

KYOTO KD20C25AX 固態繼電器 (SSR):「若輸入4到32伏特電壓大小的DC直流電流,即可讓接上24-280伏特AC交流電流之電器產生通路並啟動」

Fotek SSR-25 DA

latching relay 鎖定型繼電器

或稱 "impulse", "keep", "stay" relays。
磁保持繼電器

即使沒電時仍維持接點位置,只有在切換時需要電。

用latch繼電器切換訊號
可降低線圈對訊號的影響

松川 902U-2C-S 單線圈 latching
松川 902K-2C-S 雙線圈 latching

NAIS DS2Y-SL2

TAKAMISAWA AL5WN-K (ruten $25)

TQ2-5v-L2 TQ2-12V-L2

滑鼠微動開關

Flash Memory

MOSFET (metal–oxide–semiconductor field-effect transistor,金屬氧化物半導體場效電晶體),或稱為 MOS (metal–oxide–silicon) 電晶體,由閘極 (Gate) 電壓控制源極 (Source) 和汲極 (Drain) 是否導通。

在 MOS 閘極多做一層跟週邊絕緣的浮柵 (floating-gate, FG),像個電容,並可以透過 Fowler-Nordheim tunneling (排掉電荷) 和 hot-carrier injection (注入電荷) 機制改變儲存的電荷,可作為記憶單元 (Memory Cell),分別是抹除 (erase) 和寫入 (programming)。FG 的電荷加上閘極適當的電壓,可以共同控制源極和汲極是否導通來讀取。

EEPROM (electrically erasable programmable read-only memory) 是記憶單元排成陣列,每個記憶單元一端接 source line 接地,另一端接 bit line,位址解碼成 word line 接閘極,選到的記憶單元依記憶內容決定是否導通而 pull 輸出 bit line 為 low。這個架構像 NOR gate。EEPROM 後來為了加速而允許 multi-byte 的 page 操作。EEPROM 抹除次數有限制,現在可達 1,000,000 次。使用在常需要寫入新資料的情況時,需要考量 EEPROM 的壽命。

Flash memory 是 EEPROM 為高速和高容量設計而使用較大的 erase block (典型是512-byte 或更大)。NOR flash 延續 EEPROM NOR 架構,提供完整的位址和資料線,可對任何位置隨機存取,但抹除和寫入時間較長。適合取代傳統 ROM,很少需要更新。

NAND flash 架構是數個記憶單元為一組串接後,才一端接 source line 接地,另一端接 bit line,word line 一樣接閘極,選到的那個記憶單元依記憶內容決定是否導通,而沒選到的其它記憶單元則提供更高電壓強制導通,類似 NAND Gate,全部導通時為 low。


NAND flash 記憶單元串接的架構需要較少晶片空間,也減少抹除和寫入的時間,因此允許較高的儲存密度和每位元較低的價格。然而,NAND flash 的 I/O 界面不是隨機存取的,而必須以 page 為單位讀取。由此觀點,NAND flash 較像硬碟而較適合大量儲存裝置。


參考:
https://en.wikipedia.org/wiki/MOSFET
https://en.wikipedia.org/wiki/Floating-gate_MOSFET
https://en.wikipedia.org/wiki/Flash_memory
https://www.embedded.com/flash-101-nand-flash-vs-nor-flash/
http://wiki.csie.ncku.edu.tw/embedded/Flash
http://cushychicken.github.io/posts/nand-pt2-floating/

2019年11月9日 星期六

UBIFS

UBIFS 可視為下一代的 JFFS2 檔案系統。JFFS2 直接運用 MTD,UBIFS 則是透過 UBI volume 運用 MTD,UBI 處理 wear-leveling、bad block 及 volume management  (logical eraseblock 到 physical eraseblock 對應) 等問題。

使用
  • 在 Kernel 先開啟 UBI,再開啟 UBIFS
  • 掛載
    • mount -t ubifs /dev/ubi0_0 /mnt (掛載 UBI device 0 volume 0)
    • mount -t ubifs ubi1_0 /mnt (掛載 UBI device 1 volume 0)
    • mount -r ubifs ubi0:rootfs /mnt (掛載 UBI device 0 volume rootfs)
  • 掛載為根目錄
    • 必須內建於 kernel
    • 開機參數指定 ubi.mtd= root= rootfstype=ubifs
  • 建立 UBIFS 影像檔
    • 用 mkfs.ubifs 產生,用於 running system,用 ubiupdatevol 寫入
    • 如果要直接寫入 flash,需再用 ubinize 產生 UBI 影像檔
    • 需要先了解下列資訊
      • MTD partition size
      • physical eraseblock size:cat /proc/mtd 可看到
      • min. flash I/O unit
      • NAND's sub-page size:一些 SLC NAND 有 sub-page
      • logical eraseblock size
壓縮
 
partition scalability:JFFS2YAFFS2 有 partition scalability 的問題,時間、RAM consumption、及 CPU usage 跟 partition 大小成正比,當 partition 大於 100 MiB 時效能就不太好了。
 
write-back caching

2019年11月8日 星期五

YAFFS

YAFFS (Yet Another Flash File System) 是特別依 NAND Flash 特性設計的檔案系統,針對 NAND 可能壞掉的情況使用日誌、錯誤更正和 verification 技術來強化穩定性。

YAFFS1 設計時是舊的 NAND Flash,其 eraseblock 是 512-byte 外加 16-byte OOB,利用通常每個 page 允許 2 或 3 次寫入 cycles, i.e. 透過寫一個在 specific spare 區域的 byte 來標記 dirty pages

新的 NAND Flash 的 eraseblock 較大,是 2048-byte 外加 64-byte OOB。並且限制在同一個 block 裡的 page 只能依序寫入,且只能寫一次。所以演進為 YAFFS2,主要差別是內部架構不固定為 512-byte,且在每個 page 放一個 block 序號。如此一來,舊的 page 可邏輯上覆蓋而不違反 "write once" 規則。

 YAFFS 是一個強健的 log-structured file system,視 data integrity 為高優先權。另一個 YAFFS 目標是高效能。

JFFS2 比較
適用於 NOR Flash 的檔案系統使用了 NAND Flash 不需要的機制,而 NAND 需要一些 NOR Flash 不需要的機制。例如 garbage collection 的效能取決於 erase time,因為 NOR 的 erase 很慢,需要較複雜的 garbage collection 的策略,而 NAND 則不必。另外,NAND 有 bad block 的問題,NOR 則無。

參考文獻
  1. http://esslab.tw/wiki/index.php/YAFFS (相當詳細)
  2. YAFFS [Wikipedia]
延伸閱讀
  1. YAFFS talk — Slides for "YAFFS - A NAND-flash filesystem" presented at FOSDEM 2004 (February 23rd).
  2. YAFFS2 跟 YAFFS1 比較、跟 JFFS2 效能比較

2019年11月2日 星期六

Compact Flash

CF 卡通常是指 CF 記憶卡,但也可以是其它週邊。繼承自 PCMCIA,有兩種厚度:

  • Type I — 厚度 3.3mm。
  • Type II — 厚度 5mm,大多只有 Microdrives 使用。Type II 插槽可插 Type I 的卡。
其介面電子訊號跟 ATA 硬碟一樣,但進一步將電源整合進來,並使用較小的硬體介面,比起許多後進的新介面如 SD/MMC 等大。早期 CF 記憶卡使用 NOR Flash,現在用 NAND Flash,通常 CF 內的控制器會分散使用 sector 來避免特定的 sector 寫壞掉。

速度通常以 150 kB/s 的倍數 8x、20x、133x、.. 表示 (如同 CD-ROM)。有四種:
  • CF
  • CF High Speed (CF+/CF2.0) — max. 16 MB/s
  • CF 3.0 — 支援 UDMA mode 4, max. 66 MB/s
  • CF 4.0 — 支援 UDMA mode 5, max. 100 MB/s
  • CF 4.1 — 支援 UDMA mode 6, max. 133 MB/s
操作在 3.3 V 或 5 V。

自製手工牌SSD
http://en.wikipedia.org/wiki/CompactFlash

Memory Technology Device

MTD (Memory Technology Device) 是指各種 raw flash,如 NAND, NOR 等。

Linux MTD (Memory Technology Device) 子系統設計用來直接使用記憶體晶片,特別是有 erase-block 的 NAND flash 晶片 (raw flash),寫入之前需要先抹除。erase-block 大小 64 KiB、128 KiB、或更大,有抹除次數限制,一般 NOR Flash 或 SLC NAND Flash 約 100K-1G 次,MLC NAND Flash 約 1K-10K 次,需要 wear-leveling 打散到不同的 erase-block 來延長壽命,適用的檔案系統有 JFFS2YAFFSUBIFS 等。MTD 軟體也可以通用在 block 裝置或 RAM,只是不做抹除動作。

比較:block 裝置是傳統硬碟的存取方式,以 512-byte 或 4096-byte 的 block (或稱 sector) 為單位,直接寫入不需要先抹除。block 裝置和 MTD 裝置的分割方式和適用的檔案系統不同。block 裝置分割資訊存在 MBRGPT。Linux 將 數個 sector 合為 page,一般為 4096 bytes,跟 file system 及 buffer cache 的設計有關。適用的檔案系統有 ext2、ext3、等。

Flash 晶片可透過 FTL (Flash Translation Layer) 管理晶片變成 block 裝置,稱為 managed flash,包括 USB flash、SD/MMC card、SSD 等,但裡面的 flash 晶片仍有壞 erase-block 問題,雖然管理晶片會替換壞 erase-block,不適合非常頻繁的寫入。

MTD 附有 FTL 功能轉換成 block 裝置 -- mtdblock,使用傳統 block 檔案系統 ext2, ext3 等,但效能會變差,突然斷電也會有問題。使用 mtdblock_ro 倒是合理的。block 裝置可透過 block2mtd 轉成 MTD 裝置,一樣可能有效能問題。

raw flash 有 NOR 和 NAND 兩種。NOR flash 容量較小,直接定址每個 word 可以隨機存取,約 100K-1G 抹除次數。NAND flash 容量大,儲存空間是切成 erase-block,為減少所需要的位址線再切成更小的 page (大多 512-byte) 作為存取單位,需要處理壞 erase-block。SPI Flash 通常也是 raw flash,只是做成序列界面。


抹除存取單位
硬碟不需要block
managed flash管理晶片自動處理block
NOR flashMTD 軟體word
NAND flashMTD 軟體page
RAM不需要word


隨時都有可能沒經過 shutdown 程序而直接斷電,仍需要維持資料一致。一般檔案系統都設計用於有 buffer cache 的環境。

MTD 裝置的分割以 erase block 為集合,不用 MBR/GPT,使用 MTD 特定的方法決定位置和大小,開機時可 discovering。

MTD 裝置不能 loop

  • erase NAND flash 的 MTD 分割。使用 flash_erase (erase one eraseblock) 或 flash_eraseall。如果分割用 JFFS2 檔案系統,建議用選項 -j 或 --jffs2,會將「clean-marker」寫到 out of band area,掛載時不需要 further 格式化。This is also necessary before you copy a filesystem image to the chip.

參考
  1. https://openwrt.org/docs/techref/flash.layout
  2. http://events17.linuxfoundation.org/sites/events/files/slides/An%20Introduction%20to%20SPI-NOR%20Subsystem%20-%20v3_0.pdf
  3. cat /proc/mtd
  4. ls -l /dev
  • 目前企業型的 SSD 都是 TLC 了,基本上也可以有 MLC 的耐用度,甚至更好,QLC 跟 PLC 比較慘一點,PLC 的寫入速度還可以比硬碟慢了。高速大容量的話至少需要 TLC,如果需要高耐用度的話還是 MLC,長期資料保存的話就是 SLC,QLC 跟 PLC 基本上寫速入速度跟硬碟不相上下甚至更慢。

•Provides char(/dev/mtdX) and block(/dev/mtdblockX) device support

•Abstracts flash specific properties like sector, page and ECC handling

•Wear and bad block handling using UBI

•Handles partitioning of flash storage space

•/proc/mtdlists all devices

SIP header Via

所有 SIP 訊息 都要有 Via,縮寫 v。一開始的 UAC 和後續途經的每個 proxy 都會疊加一個 Via 放傳送的位址,依序作為回應的路徑。 格式 sent-protocol sent-by [ ;branch= branch ][ ; 參數 ...] s...