Skip to content
This repository was archived by the owner on Jun 12, 2023. It is now read-only.

Allow configuring ECC I2C bus & address #769

Merged
merged 2 commits into from
Jul 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion config/sys.config
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
{blessed_snapshot_block_hash,
<<209,92,211,142,85,214,202,92,230,55,117,141,196,113,173,198,47,210,64,105,147,50,31,203,154,41,251,234,202,170,123,103>>},
{port, 44158},
{key, {ecc, [{key_slot, 0}, {onboarding_key_slot, 15}]}}, %% don't make this the last line in the stanza because sed and keep it on one line
{key, {ecc, [{key_slot, 0}, {onboarding_key_slot, 15}, {bus, "i2c-1"}, {address, 16#60}]}}, %% don't make this the last line in the stanza because sed and keep it on one line
{base_dir, "/var/data"},
{onboarding_dir, "/mnt/uboot"},
{num_consensus_members, 16},
Expand Down
2 changes: 1 addition & 1 deletion rebar.lock
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
0},
{<<"ecc508">>,
{git,"https://github.com/helium/ecc508.git",
{ref,"c089c1591a6a0bc9a393e1cefceadb0b19ee8c59"}},
{ref,"762d985c759b988d6db7db4e2701649d50ccc7f4"}},
0},
{<<"ecc_compact">>,{pkg,<<"ecc_compact">>,<<"1.0.5">>},3},
{<<"enacl">>,{pkg,<<"enacl">>,<<"1.1.1">>},3},
Expand Down
10 changes: 5 additions & 5 deletions src/miner_ecc_worker.erl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
ecdh/1,
get_pid/0]).

-export([start_link/1,
-export([start_link/3,
init/1,
handle_call/3,
handle_cast/2,
Expand Down Expand Up @@ -35,12 +35,12 @@ ecdh({ecc_compact, PubKey}) ->
get_pid() ->
gen_server:call(?MODULE, get_pid).

start_link(KeySlot) ->
gen_server:start_link({local, ?MODULE}, ?MODULE, [KeySlot], []).
start_link(KeySlot, Bus, Address) ->
gen_server:start_link({local, ?MODULE}, ?MODULE, [KeySlot, Bus, Address], []).


init([KeySlot]) ->
{ok, ECCHandle} = ecc508:start_link(),
init([KeySlot, Bus, Address]) ->
{ok, ECCHandle} = ecc508:start_link(Bus, Address),
{ok, #state{ecc_handle=ECCHandle, key_slot=KeySlot}}.


Expand Down
6 changes: 5 additions & 1 deletion src/miner_keys.erl
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,13 @@ keys({file, BaseDir}) ->
keys({ecc, Props}) when is_list(Props) ->
KeySlot0 = proplists:get_value(key_slot, Props, 0),
OnboardingKeySlot = proplists:get_value(onboarding_key_slot, Props, 15),
Bus = proplists:get_value(bus, Props, "i2c-1"),
Address = proplists:get_value(address, Props, 16#60),
{ok, ECCPid} = case whereis(miner_ecc_worker) of
undefined ->
%% Create a temporary ecc link to get the public key and
%% onboarding keys for the given slots as well as the
ecc508:start_link();
ecc508:start_link(Bus, Address);
_ECCWorker ->
%% use the existing ECC pid
miner_ecc_worker:get_pid()
Expand All @@ -101,6 +103,8 @@ keys({ecc, Props}) when is_list(Props) ->

#{ pubkey => PubKey,
key_slot => KeySlot,
bus => Bus,
address => Address,
%% The signing and ecdh functions will use an actual
%% worker against a named process.
ecdh_fun => fun(PublicKey) ->
Expand Down
4 changes: 3 additions & 1 deletion src/miner_sup.erl
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,12 @@ init(_Args) ->
{ecc, Props} when is_list(Props) ->
#{ pubkey := PublicKey,
key_slot := KeySlot,
bus := Bus,
address := Address,
ecdh_fun := ECDHFun,
sig_fun := SigFun
} = miner_keys:keys({ecc, Props}),
ECCWorker = [?WORKER(miner_ecc_worker, [KeySlot])];
ECCWorker = [?WORKER(miner_ecc_worker, [KeySlot, Bus, Address])];
{PublicKey, ECDHFun, SigFun} ->
ECCWorker = [],
ok
Expand Down