In init.c at line 275:
random_init (rtc_get_time ());
The comments claim that "This has no effect if an "-rs" option was
specified." However, this line actually overrides the initialization at
“-rs”.
To see the effect, we can try generating some random bytes after parsing
the arguments. Apply the patch file randprint.patch, I get the following
group of output w/ and w/o "-rs", and w/ and w/o simulator RTC:
Kernel command line: -q
Unix epoch is 9
10 c4 c3 f4 1a 18 b0 cb 5f 2a 4d d5 d8 73 42 66
Kernel command line: -q -rs=1
Unix epoch is 9
10 c4 c3 f4 1a 18 b0 cb 5f 2a 4d d5 d8 73 42 66
Kernel command line: -q -rs=1
Unix epoch is
1621759823
60 4a 91 29 c3 d4 f5 16 96 7e c8 05 37 6f 79 4e
Kernel command line: -q -rs=1
Unix epoch is
1621759824
c1 ac a2 a1 3c e7 83 a3 31 a9 31 3f 2d 1c fa f9
Expected output is that the last three ones has the same output, and
they should differ from the first output.
This commit fixes the problem. We check `inited` variable at the
beginning of the random_init function.
New output:
Kernel command line: -q
Unix epoch is 9
10 c4 c3 f4 1a 18 b0 cb 5f 2a 4d d5 d8 73 42 66
Kernel command line: -q -rs=1
Unix epoch is 9
01 48 10 d0 18 1c 6a 43 a4 19 73 08 d7 cc d3 39
Kernel command line: -q -rs=1
Unix epoch is
1621760373
01 48 10 d0 18 1c 6a 43 a4 19 73 08 d7 cc d3 39
Kernel command line: -q -rs=1
Unix epoch is
1621760377
01 48 10 d0 18 1c 6a 43 a4 19 73 08 d7 cc d3 39