xref: /aosp_15_r20/external/pigweed/pw_software_update/get_started.rst (revision 61c4878ac05f98d0ceed94b57d316916de578985)
1*61c4878aSAndroid Build Coastguard Worker.. _module-pw_software_update-get-started:
2*61c4878aSAndroid Build Coastguard Worker
3*61c4878aSAndroid Build Coastguard Worker-------------------------------
4*61c4878aSAndroid Build Coastguard Workerpw_software_update: Get started
5*61c4878aSAndroid Build Coastguard Worker-------------------------------
6*61c4878aSAndroid Build Coastguard Worker.. pigweed-module-subpage::
7*61c4878aSAndroid Build Coastguard Worker   :name: pw_software_update
8*61c4878aSAndroid Build Coastguard Worker
9*61c4878aSAndroid Build Coastguard WorkerHello Bundles!
10*61c4878aSAndroid Build Coastguard Worker--------------
11*61c4878aSAndroid Build Coastguard Worker
12*61c4878aSAndroid Build Coastguard WorkerA bundle represents a single software release instance -- including
13*61c4878aSAndroid Build Coastguard Workerall target files of the software build and metadata needed to match,
14*61c4878aSAndroid Build Coastguard Workerverify and install the build on a target device.
15*61c4878aSAndroid Build Coastguard Worker
16*61c4878aSAndroid Build Coastguard WorkerThe following illustrates how a bundle is created, signed, inspected,
17*61c4878aSAndroid Build Coastguard Workerand verified using ``pw update ...`` commands.
18*61c4878aSAndroid Build Coastguard Worker
19*61c4878aSAndroid Build Coastguard Worker1. First let's make a working directory under your Pigweed dir. The
20*61c4878aSAndroid Build Coastguard Worker   ``pw update`` command is not yet visible outside the Pigweed
21*61c4878aSAndroid Build Coastguard Worker   directory.
22*61c4878aSAndroid Build Coastguard Worker
23*61c4878aSAndroid Build Coastguard Worker.. code-block:: bash
24*61c4878aSAndroid Build Coastguard Worker
25*61c4878aSAndroid Build Coastguard Worker   $ cd ~/pigweed
26*61c4878aSAndroid Build Coastguard Worker   $ source activate.sh
27*61c4878aSAndroid Build Coastguard Worker
28*61c4878aSAndroid Build Coastguard Worker   $ mkdir hello_bundles
29*61c4878aSAndroid Build Coastguard Worker   $ cd hello_bundles
30*61c4878aSAndroid Build Coastguard Worker
31*61c4878aSAndroid Build Coastguard Worker
32*61c4878aSAndroid Build Coastguard Worker2. Create signing keys for "root" and "targets" roles.
33*61c4878aSAndroid Build Coastguard Worker
34*61c4878aSAndroid Build Coastguard Worker.. note::
35*61c4878aSAndroid Build Coastguard Worker   Here keys are generated locally for demonstration purposes only. In
36*61c4878aSAndroid Build Coastguard Worker   production, you must use a proper key management service (such as
37*61c4878aSAndroid Build Coastguard Worker   `Google Cloud KMS <https://cloud.google.com/security-key-management>`_)
38*61c4878aSAndroid Build Coastguard Worker   to generate, control access to, and log usage of software signing keys.
39*61c4878aSAndroid Build Coastguard Worker
40*61c4878aSAndroid Build Coastguard Worker.. code-block:: bash
41*61c4878aSAndroid Build Coastguard Worker
42*61c4878aSAndroid Build Coastguard Worker   $ mkdir keys
43*61c4878aSAndroid Build Coastguard Worker   $ pw update generate-key keys/root_key
44*61c4878aSAndroid Build Coastguard Worker   $ pw update generate-key keys/targets_key
45*61c4878aSAndroid Build Coastguard Worker   $ tree
46*61c4878aSAndroid Build Coastguard Worker   .
47*61c4878aSAndroid Build Coastguard Worker   └── keys
48*61c4878aSAndroid Build Coastguard Worker       ├── root_key
49*61c4878aSAndroid Build Coastguard Worker       ├── root_key.pub
50*61c4878aSAndroid Build Coastguard Worker       ├── targets_key
51*61c4878aSAndroid Build Coastguard Worker       └── targets_key.pub
52*61c4878aSAndroid Build Coastguard Worker
53*61c4878aSAndroid Build Coastguard Worker3. Now that we have the keys, let's find them an owner by creating the root
54*61c4878aSAndroid Build Coastguard Worker   metadata.
55*61c4878aSAndroid Build Coastguard Worker
56*61c4878aSAndroid Build Coastguard Worker.. code-block:: bash
57*61c4878aSAndroid Build Coastguard Worker
58*61c4878aSAndroid Build Coastguard Worker   # Assign a single key to each "root" and "targets" roles.
59*61c4878aSAndroid Build Coastguard Worker   $ pw update create-root-metadata --append-root-key keys/root_key.pub \
60*61c4878aSAndroid Build Coastguard Worker      --append-targets-key keys/targets_key.pub -o root_metadata.pb
61*61c4878aSAndroid Build Coastguard Worker
62*61c4878aSAndroid Build Coastguard Worker   # Sign the root metadata with the root key to make it official.
63*61c4878aSAndroid Build Coastguard Worker   $ pw update sign-root-metadata --root-metadata root_metadata.pb \
64*61c4878aSAndroid Build Coastguard Worker      --root-key keys/root_key
65*61c4878aSAndroid Build Coastguard Worker
66*61c4878aSAndroid Build Coastguard Worker   # Review the generated root metadata (output omitted for brevity).
67*61c4878aSAndroid Build Coastguard Worker   $ pw update inspect-root-metadata root_metadata.pb
68*61c4878aSAndroid Build Coastguard Worker
69*61c4878aSAndroid Build Coastguard Worker4. Now we are ready to create a bundle.
70*61c4878aSAndroid Build Coastguard Worker
71*61c4878aSAndroid Build Coastguard Worker.. code-block:: bash
72*61c4878aSAndroid Build Coastguard Worker
73*61c4878aSAndroid Build Coastguard Worker   # Start with an empty bundle.
74*61c4878aSAndroid Build Coastguard Worker   $ pw update create-empty-bundle my_bundle.pb
75*61c4878aSAndroid Build Coastguard Worker
76*61c4878aSAndroid Build Coastguard Worker   # Add root metadata.
77*61c4878aSAndroid Build Coastguard Worker   $ pw update add-root-metadata-to-bundle \
78*61c4878aSAndroid Build Coastguard Worker      --append-root-metadata root_metadata.pb --bundle my_bundle.pb
79*61c4878aSAndroid Build Coastguard Worker
80*61c4878aSAndroid Build Coastguard Worker   # Add some files.
81*61c4878aSAndroid Build Coastguard Worker   $ mkdir target_files
82*61c4878aSAndroid Build Coastguard Worker   $ echo "application bytes" > target_files/application.bin
83*61c4878aSAndroid Build Coastguard Worker   $ echo "rtos bytes" > target_files/rtos.bin
84*61c4878aSAndroid Build Coastguard Worker   $ pw update add-file-to-bundle --bundle my_bundle.pb --file target_files/application.bin
85*61c4878aSAndroid Build Coastguard Worker   $ pw update add-file-to-bundle --bundle my_bundle.pb --file target_files/rtos.bin
86*61c4878aSAndroid Build Coastguard Worker   $ tree
87*61c4878aSAndroid Build Coastguard Worker      .
88*61c4878aSAndroid Build Coastguard Worker      ├── keys
89*61c4878aSAndroid Build Coastguard Worker      │   ├── root_key
90*61c4878aSAndroid Build Coastguard Worker      │   ├── root_key.pub
91*61c4878aSAndroid Build Coastguard Worker      │   ├── targets_key
92*61c4878aSAndroid Build Coastguard Worker      │   └── targets_key.pub
93*61c4878aSAndroid Build Coastguard Worker      ├── my_bundle.pb
94*61c4878aSAndroid Build Coastguard Worker      ├── root_metadata.pb
95*61c4878aSAndroid Build Coastguard Worker      └── target_files
96*61c4878aSAndroid Build Coastguard Worker          ├── application.bin
97*61c4878aSAndroid Build Coastguard Worker          └── rtos.bin
98*61c4878aSAndroid Build Coastguard Worker
99*61c4878aSAndroid Build Coastguard Worker   # Sign our bundle with the "targets" key.
100*61c4878aSAndroid Build Coastguard Worker   $ pw update sign-bundle --bundle my_bundle.pb --key keys/targets_key
101*61c4878aSAndroid Build Coastguard Worker
102*61c4878aSAndroid Build Coastguard Worker   # Review and admire our work (output omitted).
103*61c4878aSAndroid Build Coastguard Worker   $> pw update inspect-bundle my_bundle.pb
104*61c4878aSAndroid Build Coastguard Worker
105*61c4878aSAndroid Build Coastguard Worker5. Finally we can verify the integrity of our bundle.
106*61c4878aSAndroid Build Coastguard Worker
107*61c4878aSAndroid Build Coastguard Worker.. note::
108*61c4878aSAndroid Build Coastguard Worker   Here we are using ``python3 -m pw_software_update.verify`` because the
109*61c4878aSAndroid Build Coastguard Worker   ``pw verify-bundle`` command is WIP.
110*61c4878aSAndroid Build Coastguard Worker
111*61c4878aSAndroid Build Coastguard Worker.. code-block:: bash
112*61c4878aSAndroid Build Coastguard Worker
113*61c4878aSAndroid Build Coastguard Worker   $ python3 -m pw_software_update.verify --incoming my_bundle.pb
114*61c4878aSAndroid Build Coastguard Worker      Verifying: my_bundle.pb
115*61c4878aSAndroid Build Coastguard Worker      (self-verification)
116*61c4878aSAndroid Build Coastguard Worker      Checking content of the trusted root metadata
117*61c4878aSAndroid Build Coastguard Worker             Checking role type
118*61c4878aSAndroid Build Coastguard Worker             Checking keys database
119*61c4878aSAndroid Build Coastguard Worker             Checking root signature requirement
120*61c4878aSAndroid Build Coastguard Worker             Checking targets signature requirement
121*61c4878aSAndroid Build Coastguard Worker             Checking for key sharing
122*61c4878aSAndroid Build Coastguard Worker      Verifying incoming root metadata
123*61c4878aSAndroid Build Coastguard Worker             Checking signatures against current root
124*61c4878aSAndroid Build Coastguard Worker             Total=1, threshold=1
125*61c4878aSAndroid Build Coastguard Worker             Verified: 1
126*61c4878aSAndroid Build Coastguard Worker             Checking content
127*61c4878aSAndroid Build Coastguard Worker             Checking role type
128*61c4878aSAndroid Build Coastguard Worker             Checking keys database
129*61c4878aSAndroid Build Coastguard Worker             Checking root signature requirement
130*61c4878aSAndroid Build Coastguard Worker             Checking targets signature requirement
131*61c4878aSAndroid Build Coastguard Worker             Checking for key sharing
132*61c4878aSAndroid Build Coastguard Worker             Checking signatures against current root
133*61c4878aSAndroid Build Coastguard Worker             Total=1, threshold=1
134*61c4878aSAndroid Build Coastguard Worker             Verified: 1
135*61c4878aSAndroid Build Coastguard Worker             Checking for version rollback
136*61c4878aSAndroid Build Coastguard Worker             Targets key rotation: False
137*61c4878aSAndroid Build Coastguard Worker      Upgrading trust to the incoming root metadata
138*61c4878aSAndroid Build Coastguard Worker      Verifying targets metadata
139*61c4878aSAndroid Build Coastguard Worker             Checking signatures: total=1, threshold=1
140*61c4878aSAndroid Build Coastguard Worker             Verified signatures: 1
141*61c4878aSAndroid Build Coastguard Worker             Checking content
142*61c4878aSAndroid Build Coastguard Worker             Checking role type
143*61c4878aSAndroid Build Coastguard Worker      Checking targets metadata for version rollback
144*61c4878aSAndroid Build Coastguard Worker      Verifying target file: "application"
145*61c4878aSAndroid Build Coastguard Worker      Verifying target file: "rtos"
146*61c4878aSAndroid Build Coastguard Worker      Verification passed.
147*61c4878aSAndroid Build Coastguard Worker
148*61c4878aSAndroid Build Coastguard Worker����
149*61c4878aSAndroid Build Coastguard WorkerCongratulations on creating your first ``pw_software_update`` bundle!
150*61c4878aSAndroid Build Coastguard Worker����
151*61c4878aSAndroid Build Coastguard Worker
152*61c4878aSAndroid Build Coastguard WorkerTo learn more, see :ref:`module-pw_software_update-design`.
153