busybox-dd

目前使用dd更新spi flash無法得知進度,找一下網路有說明如何得到進度,整理了解一下


更新記錄

item note
20160613 第一版

目錄


busybox dd

  • dd只有在完成之後才會顯示結果如下(dd測試)
  • 使用kill傳送USR1方式,送訊息給dd,此時dd將會打印訊息

dd測試

1
2
3
61100544 bytes (58.3MB) copied, 119.983701 seconds, 497.3KB/s
120292+0 records in
120291+0 records out

dd指令說明

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
cx004 :[/test]# dd -help
BusyBox v1.16.1 (2016-03-10 09:04:31 UTC) multi-call binary.

Usage: dd [if=FILE] [of=FILE] [ibs=N] [obs=N] [bs=N] [count=N] [skip=N]
[seek=N] [conv=notrunc|noerror|sync|fsync]

Copy a file with converting and formatting

Options:
if=FILE Read from FILE instead of stdin
of=FILE Write to FILE instead of stdout
bs=N Read and write N bytes at a time
ibs=N Read N bytes at a time
obs=N Write N bytes at a time
count=N Copy only N input blocks
skip=N Skip N input blocks
seek=N Skip N output blocks
conv=notrunc Don't truncate output file
conv=noerror Continue after read errors
conv=sync Pad blocks with zeros
conv=fsync Physically write data out before finishing

Numbers may be suffixed by c (x1), w (x2), b (x512), kD (x1000), k (x1024),
MD (x1000000), M (x1048576), GD (x1000000000) or G (x1073741824)

kill 說明

  • pgrep, pkill - look up or signal processes based on name and other attributes
  • kill: Sends a signal to a specified process, to all members of a specified process group, or to all processes on the system.
    • USR1 and USR2 are the two signals that have no attached specific meaning - intended for whatever arbitrary use the developer wants.
  • kill
    • ex. kill [-l] [-SIG] PID
  • killall
    • ex. killall [-l] [-q] [-SIG] PROCESS_NAME

pkill 測試

pkill parameter description
-n, –newest Select only the newest (most recently started) of matching process
-x, –exact Only match processes whose names ( or command line if -0f is specified ) exactly match the pattern
1
2
pkill -USR1 -n -x dd
pkill -USR1 -n -x dd
1
2
3
4
5
6
60407808 bytes (57.6MB) copied, 118.623063 seconds, 497.3KB/s
119338+0 records in
119337+0 records out
61100544 bytes (58.3MB) copied, 119.983701 seconds, 497.3KB/s
120292+0 records in
120291+0 records out

busybox dd 說明

  • 要打開(ENABLE_FEATURE_DD_SIGNAL_HANDLING),預設都是有開的
    • ENABLE_FEATURE_DD_SIGNAL_HANDLING: Enable DD Signal handling for status reporting
  • dd定義SIGUSR1為dd_output_status
  • busybox-1.16.1/coreutils/dd.c
1
2
3
4
5
6
7
8
9
int dd_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int dd_main(int argc UNUSED_PARAM, char **argv)
{

...
#if ENABLE_FEATURE_DD_SIGNAL_HANDLING
signal_SA_RESTART_empty_mask(SIGUSR1, dd_output_status);
#endif
...
}
  • signal_SA_RESTART_empty_mask
1
2
3
4
5
6
7
8
9
void FAST_FUNC signal_SA_RESTART_empty_mask(int sig, void (*handler)(int))
{

struct sigaction sa;
memset(&sa, 0, sizeof(sa));
/*sigemptyset(&sa.sa_mask);*/
sa.sa_flags = SA_RESTART;
sa.sa_handler = handler;
sigaction_set(sig, &sa);
}

參考來源