blob: 4620172169d1855cc8db2a7e15c4fb6747ebdec2 [file] [log] [blame]
Chris Frantz903bcec2021-11-09 16:43:29 -08001# Copyright lowRISC contributors.
2# Licensed under the Apache License, Version 2.0, see LICENSE for details.
3# SPDX-License-Identifier: Apache-2.0
4
Alexander Williams04969982022-06-10 09:09:01 -07005load("@rules_rust//rust:defs.bzl", "rust_doc", "rust_library", "rust_test")
Chris Frantza9413192022-08-04 21:03:00 -07006load("//rules:ujson.bzl", "ujson_rust")
Chris Frantz903bcec2021-11-09 16:43:29 -08007
8package(default_visibility = ["//visibility:public"])
9
Chris Frantza9413192022-08-04 21:03:00 -070010ujson_rust(
11 name = "e2e_command",
Chris Frantz3f699692022-09-30 12:42:22 -070012 srcs = ["//sw/device/lib/testing/json:command"],
Chris Frantza9413192022-08-04 21:03:00 -070013 defines = ["opentitanlib=crate"],
14)
15
Chris Frantzb0db1f52022-10-04 17:55:11 -070016ujson_rust(
17 name = "gpio",
18 srcs = ["//sw/device/lib/testing/json:gpio"],
19 defines = ["opentitanlib=crate"],
20)
21
22ujson_rust(
23 name = "pinmux_config",
24 srcs = ["//sw/device/lib/testing/json:pinmux_config"],
25 defines = ["opentitanlib=crate"],
26)
27
Chris Frantzd220d022023-03-02 15:14:21 +000028ujson_rust(
29 name = "spi_passthru",
30 srcs = ["//sw/device/lib/testing/json:spi_passthru"],
31 defines = ["opentitanlib=crate"],
32)
33
Chris Frantz53b4a1e2022-07-29 14:21:19 -070034filegroup(
35 name = "config",
36 srcs = glob(["src/app/config/*.json"]),
37)
38
Chris Frantz903bcec2021-11-09 16:43:29 -080039rust_library(
40 name = "opentitanlib",
41 srcs = [
42 "src/app/command.rs",
Chris Frantz53b4a1e2022-07-29 14:21:19 -070043 "src/app/config/mod.rs",
44 "src/app/config/structs.rs",
Chris Frantz903bcec2021-11-09 16:43:29 -080045 "src/app/mod.rs",
Jes B. Klinke3f055912022-02-11 10:49:35 -080046 "src/backend/cw310.rs",
47 "src/backend/hyperdebug.rs",
48 "src/backend/mod.rs",
Jes B. Klinke426665c2022-02-18 12:01:26 -080049 "src/backend/proxy.rs",
Michał Mazureke60214b2022-03-31 17:10:53 +020050 "src/backend/ti50emulator.rs",
Jes B. Klinke3f055912022-02-11 10:49:35 -080051 "src/backend/ultradebug.rs",
52 "src/backend/verilator.rs",
Chris Frantzcfc6ac62022-04-27 19:46:45 -070053 "src/bootstrap/eeprom.rs",
Chris Frantz0b548fa2021-11-22 14:08:11 -080054 "src/bootstrap/legacy.rs",
Chris Frantz903bcec2021-11-09 16:43:29 -080055 "src/bootstrap/mod.rs",
56 "src/bootstrap/primitive.rs",
Jes B. Klinkea948fc32022-01-25 15:44:27 -080057 "src/bootstrap/rescue.rs",
Chris Frantz50931152022-09-01 00:52:57 +000058 "src/chip/alert.rs",
59 "src/chip/boolean.rs",
60 "src/chip/mod.rs",
Alphan Ulusoy968524e2022-01-10 16:20:20 -050061 "src/crypto/mod.rs",
Jon Flatley2f90f922022-01-11 15:08:04 -050062 "src/crypto/rsa.rs",
Alphan Ulusoy968524e2022-01-10 16:20:20 -050063 "src/crypto/sha256.rs",
Chris Frantzb1c57102022-10-20 14:43:33 -070064 "src/dif/lc_ctrl.rs",
Dan McArdlece675582023-01-03 15:30:06 -050065 "src/dif/rstmgr.rs",
Chris Frantzb1c57102022-10-20 14:43:33 -070066 "src/dif/mod.rs",
Jon Flatley66769952022-01-25 10:50:21 -050067 "src/image/image.rs",
68 "src/image/manifest.rs",
69 "src/image/manifest_def.rs",
70 "src/image/mod.rs",
Timothy Trippel841959f2022-03-21 17:01:00 -070071 "src/io/emu.rs",
Chris Frantz903bcec2021-11-09 16:43:29 -080072 "src/io/gpio.rs",
Drew Macraefeec67e2022-01-26 13:05:12 -080073 "src/io/i2c.rs",
Chris Frantz903bcec2021-11-09 16:43:29 -080074 "src/io/mod.rs",
75 "src/io/spi.rs",
76 "src/io/uart.rs",
77 "src/lib.rs",
Jon Flatley3a344e92022-08-18 16:30:54 -040078 "src/otp/alert_handler.rs",
79 "src/otp/alert_handler_regs.rs",
Jon Flatley48f64de2022-01-06 09:53:40 -050080 "src/otp/lc_state.rs",
81 "src/otp/mod.rs",
Jon Flatley48f64de2022-01-06 09:53:40 -050082 "src/otp/otp_img.rs",
Chris Frantza4008df2022-04-14 18:15:50 -070083 "src/proxy/errors.rs",
Jes B. Klinke9f70b8c2022-02-18 12:07:22 -080084 "src/proxy/handler.rs",
Michał Mazurek50a75882022-02-15 21:22:31 +010085 "src/proxy/mod.rs",
86 "src/proxy/protocol.rs",
Timothy Trippel841959f2022-03-21 17:01:00 -070087 "src/proxy/socket_server.rs",
88 "src/spiflash/flash.rs",
89 "src/spiflash/mod.rs",
90 "src/spiflash/sfdp.rs",
Miles Daidc380052022-07-21 12:56:51 -040091 "src/test_utils/bootstrap.rs",
Chris Frantza9413192022-08-04 21:03:00 -070092 "src/test_utils/e2e_command.rs",
Chris Frantzac63faf2022-10-20 14:35:54 -070093 "src/test_utils/epmp.rs",
Chris Frantzb0db1f52022-10-04 17:55:11 -070094 "src/test_utils/gpio.rs",
Chris Frantzd220d022023-03-02 15:14:21 +000095 "src/test_utils/spi_passthru.rs",
Miles Daidc380052022-07-21 12:56:51 -040096 "src/test_utils/init.rs",
97 "src/test_utils/load_bitstream.rs",
98 "src/test_utils/mod.rs",
Chris Frantz54ec4572022-08-04 21:01:05 -070099 "src/test_utils/rpc.rs",
Chris Frantz32156692022-06-21 22:03:26 -0700100 "src/test_utils/status.rs",
Brian Granaghan4012e162022-12-07 20:26:27 +0000101 "src/tpm/access.rs",
Jes B. Klinkecae4c4c2022-05-24 16:33:02 -0700102 "src/tpm/driver.rs",
103 "src/tpm/mod.rs",
Brian Granaghan4012e162022-12-07 20:26:27 +0000104 "src/tpm/status.rs",
Jes B. Klinke6aad69a2022-02-15 10:36:40 -0800105 "src/transport/common/mod.rs",
Chris Frantz37ce1ee2023-02-28 00:28:48 +0000106 "src/transport/common/fpga.rs",
Jes B. Klinke6aad69a2022-02-15 10:36:40 -0800107 "src/transport/common/uart.rs",
Chris Frantz903bcec2021-11-09 16:43:29 -0800108 "src/transport/cw310/gpio.rs",
109 "src/transport/cw310/mod.rs",
110 "src/transport/cw310/spi.rs",
Chris Frantz903bcec2021-11-09 16:43:29 -0800111 "src/transport/cw310/usb.rs",
Jes B. Klinke6aad69a2022-02-15 10:36:40 -0800112 "src/transport/errors.rs",
Jes B. Klinkec571bde2022-02-02 14:51:54 -0800113 "src/transport/hyperdebug/c2d2.rs",
Jes B. Klinke3a7f9422023-01-19 12:43:34 -0800114 "src/transport/hyperdebug/dfu.rs",
Jes B. Klinke4a932b22021-10-06 14:31:17 -0700115 "src/transport/hyperdebug/gpio.rs",
Drew Macraefeec67e2022-01-26 13:05:12 -0800116 "src/transport/hyperdebug/i2c.rs",
Jes B. Klinke4a932b22021-10-06 14:31:17 -0700117 "src/transport/hyperdebug/mod.rs",
118 "src/transport/hyperdebug/spi.rs",
Chris Frantz903bcec2021-11-09 16:43:29 -0800119 "src/transport/mod.rs",
Michał Mazurek42d224b2022-06-13 14:38:47 +0200120 "src/transport/proxy/emu.rs",
Jes B. Klinke426665c2022-02-18 12:01:26 -0800121 "src/transport/proxy/gpio.rs",
122 "src/transport/proxy/i2c.rs",
123 "src/transport/proxy/mod.rs",
124 "src/transport/proxy/spi.rs",
125 "src/transport/proxy/uart.rs",
Michał Mazureke60214b2022-03-31 17:10:53 +0200126 "src/transport/ti50emulator/emu.rs",
127 "src/transport/ti50emulator/gpio.rs",
128 "src/transport/ti50emulator/i2c.rs",
129 "src/transport/ti50emulator/mod.rs",
130 "src/transport/ti50emulator/spi.rs",
131 "src/transport/ti50emulator/uart.rs",
Chris Frantz903bcec2021-11-09 16:43:29 -0800132 "src/transport/ultradebug/gpio.rs",
133 "src/transport/ultradebug/mod.rs",
134 "src/transport/ultradebug/mpsse.rs",
135 "src/transport/ultradebug/spi.rs",
136 "src/transport/ultradebug/uart.rs",
137 "src/transport/verilator/mod.rs",
Chris Frantz5fafe012022-09-26 17:57:10 -0700138 "src/transport/verilator/gpio.rs",
Chris Frantz2fb6d642022-05-11 13:30:05 -0700139 "src/transport/verilator/stdout.rs",
Chris Frantz903bcec2021-11-09 16:43:29 -0800140 "src/transport/verilator/subprocess.rs",
141 "src/transport/verilator/transport.rs",
142 "src/transport/verilator/uart.rs",
Chris Frantz6c93ea72022-04-11 11:54:51 -0700143 "src/uart/console.rs",
144 "src/uart/mod.rs",
Alphan Ulusoy011a9082022-01-05 10:32:47 -0500145 "src/util/bigint.rs",
Chris Frantz903bcec2021-11-09 16:43:29 -0800146 "src/util/bitfield.rs",
147 "src/util/file.rs",
Chris Frantz903bcec2021-11-09 16:43:29 -0800148 "src/util/mod.rs",
Jes B. Klinke356f07b2023-02-16 14:13:22 -0800149 "src/util/nix.rs",
Jon Flatley68e7dfd2022-01-31 11:26:57 -0500150 "src/util/num_de.rs",
Chris Frantz903bcec2021-11-09 16:43:29 -0800151 "src/util/parse_int.rs",
Jon Flatley48f64de2022-01-06 09:53:40 -0500152 "src/util/present.rs",
Chris Frantzd799b322022-04-13 12:02:04 -0700153 "src/util/rom_detect.rs",
Chris Frantzce4e1f02022-08-22 21:39:39 -0700154 "src/util/unknown.rs",
Jes B. Klinkece2fecc2021-11-05 09:40:38 -0700155 "src/util/usb.rs",
Alphan Ulusoy906e2602022-09-12 06:17:47 -0400156 "src/util/usr_access.rs",
Chris Frantz903bcec2021-11-09 16:43:29 -0800157 "src/util/voltage.rs",
Chris Frantz50931152022-09-01 00:52:57 +0000158 ] + select({
159 "//sw/device:is_english_breakfast": [],
160 "//conditions:default": [
161 "src/chip/earlgrey.rs",
Chris Frantzb0db1f52022-10-04 17:55:11 -0700162 "src/test_utils/pinmux_config.rs",
Chris Frantz50931152022-09-01 00:52:57 +0000163 ],
164 }),
Chris Frantz53b4a1e2022-07-29 14:21:19 -0700165 compile_data = [
166 ":config",
Chris Frantzb0db1f52022-10-04 17:55:11 -0700167 ":gpio",
Chris Frantza9413192022-08-04 21:03:00 -0700168 ":e2e_command",
Chris Frantzb0db1f52022-10-04 17:55:11 -0700169 ":pinmux_config",
Chris Frantzd220d022023-03-02 15:14:21 +0000170 ":spi_passthru",
Jes B. Klinke3a7f9422023-01-19 12:43:34 -0800171 "@hyperdebug_firmware//file",
Chris Frantz53b4a1e2022-07-29 14:21:19 -0700172 ],
Jes B. Klinke3a7f9422023-01-19 12:43:34 -0800173 crate_features = [
174 "include_hyperdebug_firmware",
175 ] + select({
Chris Frantz50931152022-09-01 00:52:57 +0000176 "//sw/device:is_english_breakfast": ["english_breakfast"],
177 "//conditions:default": [],
178 }),
Chris Frantz903bcec2021-11-09 16:43:29 -0800179 proc_macro_deps = [
180 "//sw/host/opentitanlib/opentitantool_derive",
Chris Frantz95594022023-02-13 17:59:54 +0000181 "@crate_index//:serde_derive",
182 "@lowrisc_serde_annotate//annotate_derive:annotate_derive",
Chris Frantz903bcec2021-11-09 16:43:29 -0800183 ],
Chris Frantza9413192022-08-04 21:03:00 -0700184 rustc_env = {
185 "e2e_command": "$(location :e2e_command)",
Chris Frantzb0db1f52022-10-04 17:55:11 -0700186 "gpio": "$(location :gpio)",
187 "pinmux_config": "$(location :pinmux_config)",
Chris Frantzd220d022023-03-02 15:14:21 +0000188 "spi_passthru": "$(location :spi_passthru)",
Jes B. Klinke3a7f9422023-01-19 12:43:34 -0800189 "hyperdebug_firmware": "$(location @hyperdebug_firmware//file)",
Chris Frantza9413192022-08-04 21:03:00 -0700190 },
Chris Frantz903bcec2021-11-09 16:43:29 -0800191 deps = [
Chris Frantz50931152022-09-01 00:52:57 +0000192 "//sw/host/opentitanlib/bindgen",
Chris Frantz1a6f7002023-02-14 20:14:11 +0000193 "@crate_index//:anyhow",
Chris Frantzda46e842023-03-06 19:22:49 +0000194 "@crate_index//:arrayvec",
Chris Frantz1a6f7002023-02-14 20:14:11 +0000195 "@crate_index//:bitflags",
196 "@crate_index//:bitvec",
197 "@crate_index//:byteorder",
198 "@crate_index//:chrono",
199 "@crate_index//:crc",
200 "@crate_index//:deser-hjson",
201 "@crate_index//:directories",
202 "@crate_index//:env_logger",
203 "@crate_index//:erased-serde",
204 "@crate_index//:hex",
205 "@crate_index//:humantime",
206 "@crate_index//:humantime-serde",
207 "@crate_index//:indicatif",
208 "@crate_index//:lazy_static",
209 "@crate_index//:log",
210 "@crate_index//:memoffset",
211 "@crate_index//:mio",
212 "@crate_index//:mio-signals",
213 "@crate_index//:nix",
214 "@crate_index//:num-bigint-dig",
215 "@crate_index//:num-traits",
216 "@crate_index//:num_enum",
217 "@crate_index//:rand",
218 "@crate_index//:raw_tty",
219 "@crate_index//:regex",
220 "@crate_index//:rsa",
221 "@crate_index//:rusb",
222 "@crate_index//:serde",
223 "@crate_index//:serde_json",
224 "@crate_index//:serialport",
225 "@crate_index//:sha2",
226 "@crate_index//:shellwords",
227 "@crate_index//:structopt",
228 "@crate_index//:thiserror",
229 "@crate_index//:typetag",
230 "@crate_index//:zerocopy",
Chris Frantz95594022023-02-13 17:59:54 +0000231 "@lowrisc_safe_ftdi//:safe_ftdi",
232 "@lowrisc_serde_annotate//:serde_annotate",
Miguel Young de la Sota4e08b952022-04-11 11:26:30 -0400233 ],
Chris Frantz903bcec2021-11-09 16:43:29 -0800234)
235
236rust_test(
237 name = "opentitanlib_test",
238 compile_data = [
Chris Frantz617a4062022-08-15 22:01:20 -0700239 ":e2e_command",
Chris Frantzb0db1f52022-10-04 17:55:11 -0700240 ":gpio",
241 ":pinmux_config",
Jes B. Klinke3a7f9422023-01-19 12:43:34 -0800242 "@hyperdebug_firmware//file",
Chris Frantz903bcec2021-11-09 16:43:29 -0800243 "src/bootstrap/simple.bin",
244 "src/spiflash/SFDP_MX66L1G.bin",
245 ],
246 crate = ":opentitanlib",
247 data = [
Jon Flatley66769952022-01-25 10:50:21 -0500248 "src/image/testdata/hello.txt",
249 "src/image/testdata/manifest.hjson",
Jon Flatleyd9a7c022022-05-24 10:44:29 -0400250 "src/image/testdata/manifest_missing.hjson",
Jon Flatleye6b98b82022-04-26 11:23:24 -0400251 "src/image/testdata/test_image.bin",
Jon Flatley66769952022-01-25 10:50:21 -0500252 "src/image/testdata/world.txt",
Jon Flatleyabf1af62022-01-28 13:38:00 -0500253 "src/otp/testdata/lc_ctrl_state.hjson",
254 "src/otp/testdata/otp_ctrl_img_dev.hjson",
255 "src/otp/testdata/otp_ctrl_mmap.hjson",
256 "src/otp/testdata/output.vmem",
Chris Frantz903bcec2021-11-09 16:43:29 -0800257 ],
Chris Frantz617a4062022-08-15 22:01:20 -0700258 rustc_env = {
259 "e2e_command": "$(location :e2e_command)",
Chris Frantzb0db1f52022-10-04 17:55:11 -0700260 "gpio": "$(location :gpio)",
261 "pinmux_config": "$(location :pinmux_config)",
Chris Frantz617a4062022-08-15 22:01:20 -0700262 },
Chris Frantz903bcec2021-11-09 16:43:29 -0800263)
Alexander Williams04969982022-06-10 09:09:01 -0700264
265rust_doc(
266 name = "opentitanlib_doc",
267 crate = ":opentitanlib",
268)