Skip to content

Commit 1aac70e

Browse files
author
Sven Van Asbroeck
committed
Allow bare minimum platform device core and driver to be easily tested
Provide a forked `defconfig` and devicetree, so the platform device core and driver can be easily tested on QEMU, or a Raspberri Pi Zero. Although called "bcm2835-rng-rust", this is not a functional hwrng driver, just a bare minimum platform_device. All it will do is log a message to dmesg: [ ] rust_kernel: Rust platform_device probed and show up in sysfs: /sys/bus/platform/driver/bcm2835-rng-rust/ (the driver) /sys/bus/platform/devices/bcm2835-rng-rust/ (the device) How to run on QEMU ================== Download a Raspbian image. I used `2021-03-04-raspios-buster-armhf-lite.img`. It will consist of two partitions. Discover their offsets using: ```sh $ fdisk -l 2021-03-04-raspios-buster-armhf-lite.img Device Boot Start End Sectors Size Id Type 2021-03-04-raspios-buster-armhf-lite.img1 8192 532479 524288 256M c W95 FAT32 (LBA) 2021-03-04-raspios-buster-armhf-lite.img2 532480 3645439 3112960 1.5G 83 Linux ``` Mount the second partition on your PC: (note how the offset is multiplied by 512) ```sh $ mount -o loop,offset=$((512*532480)) 2021-03-04-raspios-buster-armhf-lite.img /mnt Comment out everything in /etc/ld.so.preload - otherwise the Raspbian rootfs cannot support a mainline kernel: $ vi /etc/ld.so.preload # comment everything out $ umount /mnt ``` Build the kernel for arm 32-bit: ```sh $ make bcm2835_rust_defconfig # defconfig forked so `bcm2835-rng-rust` binds to our driver $ make zImage dtbs modules ``` Start QEMU: ```sh # to boot mainline, make sure that /etc/ld.so.preload is commented out # in the Raspbian image. qemu-system-arm \ -M raspi2 \ -append "rw earlyprintk loglevel=8 console=ttyAMA0,115200 dwc_otg.lpm_enable=0 root=/dev/mmcblk0p2 rootwait" \ -cpu arm1176 \ -dtb bcm2836-rpi-2-b-rust.dts \ -hda ./2021-03-04-raspios-buster-armhf-lite.img \ -kernel zImage \ -m 1G \ -smp 4 \ -nographic \ ; How to run on a Raspberry Pi Zero(W) ==================================== Follow the instructions for QEMU above. Deploy the Raspbian image to SD card. Copy zImage and bcm2835-rpi-zero-w-rust.dtb to Raspbian's first (boot) partition: ``` zImage -> boot partition: kernel.img bcm2835-rpi-zero-w-rust.dtb -> boot partition: bcm2708-rpi-0-w.dtb ``` If you'd like wifi to keep working, also copy the kernel modules you built to Raspbian's second partition: ```sh $ make modules_install INSTALL_MOD_PATH=<somewhere> $ cp -rfa <somewhere> <Raspbian Partition> # should end up in /lib/modules/5.12.0-rc4+/ ``` Signed-off-by: Sven Van Asbroeck <[email protected]>
1 parent ad2b5af commit 1aac70e

File tree

4 files changed

+494
-1
lines changed

4 files changed

+494
-1
lines changed

arch/arm/boot/dts/Makefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,15 @@ dtb-$(CONFIG_ARCH_BCM2835) += \
8484
bcm2835-rpi-a-plus.dtb \
8585
bcm2835-rpi-cm1-io1.dtb \
8686
bcm2836-rpi-2-b.dtb \
87+
bcm2836-rpi-2-b-rust.dtb \
8788
bcm2837-rpi-3-a-plus.dtb \
8889
bcm2837-rpi-3-b.dtb \
8990
bcm2837-rpi-3-b-plus.dtb \
9091
bcm2837-rpi-cm3-io3.dtb \
9192
bcm2711-rpi-4-b.dtb \
9293
bcm2835-rpi-zero.dtb \
93-
bcm2835-rpi-zero-w.dtb
94+
bcm2835-rpi-zero-w.dtb \
95+
bcm2835-rpi-zero-w-rust.dtb
9496
dtb-$(CONFIG_ARCH_BCM_5301X) += \
9597
bcm4708-asus-rt-ac56u.dtb \
9698
bcm4708-asus-rt-ac68u.dtb \
Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
// SPDX-License-Identifier: GPL-2.0+
2+
/*
3+
* Copyright (C) 2017 Stefan Wahren <[email protected]>
4+
*/
5+
6+
/dts-v1/;
7+
#include "bcm2835.dtsi"
8+
#include "bcm2835-rpi.dtsi"
9+
#include "bcm283x-rpi-usb-otg.dtsi"
10+
11+
/ {
12+
compatible = "raspberrypi,model-zero-w", "brcm,bcm2835";
13+
model = "Raspberry Pi Zero W";
14+
15+
bcm2835-rng-rust {
16+
compatible = "brcm,bcm2835-rng";
17+
status = "okay";
18+
};
19+
20+
memory@0 {
21+
device_type = "memory";
22+
reg = <0 0x20000000>;
23+
};
24+
25+
chosen {
26+
/* 8250 auxiliary UART instead of pl011 */
27+
stdout-path = "serial1:115200n8";
28+
};
29+
30+
leds {
31+
act {
32+
gpios = <&gpio 47 GPIO_ACTIVE_LOW>;
33+
};
34+
};
35+
36+
wifi_pwrseq: wifi-pwrseq {
37+
compatible = "mmc-pwrseq-simple";
38+
reset-gpios = <&gpio 41 GPIO_ACTIVE_LOW>;
39+
};
40+
};
41+
42+
&gpio {
43+
/*
44+
* This is based on the official GPU firmware DT blob.
45+
*
46+
* Legend:
47+
* "NC" = not connected (no rail from the SoC)
48+
* "FOO" = GPIO line named "FOO" on the schematic
49+
* "FOO_N" = GPIO line named "FOO" on schematic, active low
50+
*/
51+
gpio-line-names = "ID_SDA",
52+
"ID_SCL",
53+
"SDA1",
54+
"SCL1",
55+
"GPIO_GCLK",
56+
"GPIO5",
57+
"GPIO6",
58+
"SPI_CE1_N",
59+
"SPI_CE0_N",
60+
"SPI_MISO",
61+
"SPI_MOSI",
62+
"SPI_SCLK",
63+
"GPIO12",
64+
"GPIO13",
65+
/* Serial port */
66+
"TXD0",
67+
"RXD0",
68+
"GPIO16",
69+
"GPIO17",
70+
"GPIO18",
71+
"GPIO19",
72+
"GPIO20",
73+
"GPIO21",
74+
"GPIO22",
75+
"GPIO23",
76+
"GPIO24",
77+
"GPIO25",
78+
"GPIO26",
79+
"GPIO27",
80+
"SDA0",
81+
"SCL0",
82+
"NC", /* GPIO30 */
83+
"NC", /* GPIO31 */
84+
"NC", /* GPIO32 */
85+
"NC", /* GPIO33 */
86+
"NC", /* GPIO34 */
87+
"NC", /* GPIO35 */
88+
"NC", /* GPIO36 */
89+
"NC", /* GPIO37 */
90+
"NC", /* GPIO38 */
91+
"NC", /* GPIO39 */
92+
"CAM_GPIO1", /* GPIO40 */
93+
"WL_ON", /* GPIO41 */
94+
"NC", /* GPIO42 */
95+
"WIFI_CLK", /* GPIO43 */
96+
"CAM_GPIO0", /* GPIO44 */
97+
"BT_ON", /* GPIO45 */
98+
"HDMI_HPD_N",
99+
"STATUS_LED_N",
100+
/* Used by SD Card */
101+
"SD_CLK_R",
102+
"SD_CMD_R",
103+
"SD_DATA0_R",
104+
"SD_DATA1_R",
105+
"SD_DATA2_R",
106+
"SD_DATA3_R";
107+
108+
pinctrl-0 = <&gpioout &alt0>;
109+
};
110+
111+
&hdmi {
112+
hpd-gpios = <&gpio 46 GPIO_ACTIVE_LOW>;
113+
power-domains = <&power RPI_POWER_DOMAIN_HDMI>;
114+
status = "okay";
115+
};
116+
117+
&sdhci {
118+
#address-cells = <1>;
119+
#size-cells = <0>;
120+
pinctrl-names = "default";
121+
pinctrl-0 = <&emmc_gpio34 &gpclk2_gpio43>;
122+
bus-width = <4>;
123+
mmc-pwrseq = <&wifi_pwrseq>;
124+
non-removable;
125+
status = "okay";
126+
127+
brcmf: wifi@1 {
128+
reg = <1>;
129+
compatible = "brcm,bcm4329-fmac";
130+
};
131+
};
132+
133+
&sdhost {
134+
pinctrl-names = "default";
135+
pinctrl-0 = <&sdhost_gpio48>;
136+
bus-width = <4>;
137+
status = "okay";
138+
};
139+
140+
&uart0 {
141+
pinctrl-names = "default";
142+
pinctrl-0 = <&uart0_gpio32 &uart0_ctsrts_gpio30>;
143+
status = "okay";
144+
145+
bluetooth {
146+
compatible = "brcm,bcm43438-bt";
147+
max-speed = <2000000>;
148+
shutdown-gpios = <&gpio 45 GPIO_ACTIVE_HIGH>;
149+
};
150+
};
151+
152+
&uart1 {
153+
pinctrl-names = "default";
154+
pinctrl-0 = <&uart1_gpio14>;
155+
status = "okay";
156+
};
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
/dts-v1/;
3+
#include "bcm2836.dtsi"
4+
#include "bcm2836-rpi.dtsi"
5+
#include "bcm283x-rpi-smsc9514.dtsi"
6+
#include "bcm283x-rpi-usb-host.dtsi"
7+
8+
/ {
9+
compatible = "raspberrypi,2-model-b", "brcm,bcm2836";
10+
model = "Raspberry Pi 2 Model B";
11+
12+
memory@0 {
13+
device_type = "memory";
14+
reg = <0 0x40000000>;
15+
};
16+
17+
bcm2835-rng-rust {
18+
compatible = "brcm,bcm2835-rng";
19+
status = "okay";
20+
};
21+
22+
leds {
23+
act {
24+
gpios = <&gpio 47 GPIO_ACTIVE_HIGH>;
25+
};
26+
27+
pwr {
28+
label = "PWR";
29+
gpios = <&gpio 35 GPIO_ACTIVE_HIGH>;
30+
default-state = "keep";
31+
linux,default-trigger = "default-on";
32+
};
33+
};
34+
};
35+
36+
&gpio {
37+
/*
38+
* Taken from rpi_SCH_2b_1p2_reduced.pdf and
39+
* the official GPU firmware DT blob.
40+
*
41+
* Legend:
42+
* "NC" = not connected (no rail from the SoC)
43+
* "FOO" = GPIO line named "FOO" on the schematic
44+
* "FOO_N" = GPIO line named "FOO" on schematic, active low
45+
*/
46+
gpio-line-names = "ID_SDA",
47+
"ID_SCL",
48+
"SDA1",
49+
"SCL1",
50+
"GPIO_GCLK",
51+
"GPIO5",
52+
"GPIO6",
53+
"SPI_CE1_N",
54+
"SPI_CE0_N",
55+
"SPI_MISO",
56+
"SPI_MOSI",
57+
"SPI_SCLK",
58+
"GPIO12",
59+
"GPIO13",
60+
/* Serial port */
61+
"TXD0",
62+
"RXD0",
63+
"GPIO16",
64+
"GPIO17",
65+
"GPIO18",
66+
"GPIO19",
67+
"GPIO20",
68+
"GPIO21",
69+
"GPIO22",
70+
"GPIO23",
71+
"GPIO24",
72+
"GPIO25",
73+
"GPIO26",
74+
"GPIO27",
75+
"SDA0",
76+
"SCL0",
77+
"", /* GPIO30 */
78+
"LAN_RUN",
79+
"CAM_GPIO1",
80+
"", /* GPIO33 */
81+
"", /* GPIO34 */
82+
"PWR_LOW_N",
83+
"", /* GPIO36 */
84+
"", /* GPIO37 */
85+
"USB_LIMIT",
86+
"", /* GPIO39 */
87+
"PWM0_OUT",
88+
"CAM_GPIO0",
89+
"SMPS_SCL",
90+
"SMPS_SDA",
91+
"ETHCLK",
92+
"PWM1_OUT",
93+
"HDMI_HPD_N",
94+
"STATUS_LED",
95+
/* Used by SD Card */
96+
"SD_CLK_R",
97+
"SD_CMD_R",
98+
"SD_DATA0_R",
99+
"SD_DATA1_R",
100+
"SD_DATA2_R",
101+
"SD_DATA3_R";
102+
103+
pinctrl-0 = <&gpioout &alt0 &i2s_alt0>;
104+
105+
/* I2S interface */
106+
i2s_alt0: i2s_alt0 {
107+
brcm,pins = <18 19 20 21>;
108+
brcm,function = <BCM2835_FSEL_ALT0>;
109+
};
110+
};
111+
112+
&hdmi {
113+
hpd-gpios = <&gpio 46 GPIO_ACTIVE_LOW>;
114+
power-domains = <&power RPI_POWER_DOMAIN_HDMI>;
115+
status = "okay";
116+
};
117+
118+
&pwm {
119+
pinctrl-names = "default";
120+
pinctrl-0 = <&pwm0_gpio40 &pwm1_gpio45>;
121+
status = "okay";
122+
};
123+
124+
&sdhost {
125+
pinctrl-names = "default";
126+
pinctrl-0 = <&sdhost_gpio48>;
127+
bus-width = <4>;
128+
status = "okay";
129+
};
130+
131+
&uart0 {
132+
pinctrl-names = "default";
133+
pinctrl-0 = <&uart0_gpio14>;
134+
status = "okay";
135+
};

0 commit comments

Comments
 (0)