1
- use super :: { Config , Device , Error , config:: * } ;
1
+ use super :: { Config , Device , Error , config:: * , ser :: set_bootargs } ;
2
2
use embedded_hal:: digital:: OutputPin ;
3
3
use embedded_io:: { Read , Write } ;
4
4
use embedded_sdmmc:: {
@@ -80,29 +80,26 @@ pub fn load_from_sdcard<
80
80
return Err ( ( ) ) ;
81
81
} ;
82
82
83
- // Load firmware.
84
- let firmware_path = config. configs . firmware . as_ref ( ) . map ( |s| s. as_str ( ) ) . unwrap_or_else ( || {
85
- writeln ! ( d. tx, "warning: /config.toml: cannot find firmware path on key `configs.firmware`, using default configuration (/zImage)." ) . ok ( ) ;
86
- "ZIMAGE"
87
- } ) ;
88
- let ( file_dir, file_name) = locate_file_by_path ( & mut d. tx , "firmware" , firmware_path) ;
89
- let Ok ( firmware) = open_file_by_path ( & mut volume_mgr, root_dir, file_dir, file_name) else {
83
+ // Load device tree blob.
84
+ let Some ( opaque) = config. configs . opaque else {
85
+ writeln ! ( d. tx, "warning: /config.toml: cannot find opaque file path on key `configs.opaque`, using default configuration (zeroing `a1` for non-existing opaque file)." ) . ok ( ) ;
86
+ volume_mgr. close_dir ( root_dir) . unwrap ( ) ;
87
+ return Ok ( 0x0 ) ;
88
+ } ;
89
+ let dtb_path = opaque. as_str ( ) ;
90
+ let ( file_dir, file_name) = locate_file_by_path ( & mut d. tx , "dtb" , dtb_path) ;
91
+ let Ok ( dtb) = open_file_by_path ( & mut volume_mgr, root_dir, file_dir, file_name) else {
90
92
writeln ! (
91
93
d. tx,
92
- "error: /config.toml: file not found for firmware path {}." ,
93
- firmware_path
94
+ "error: /config.toml: file not found for dtb path {}." ,
95
+ dtb_path
94
96
)
95
97
. ok ( ) ;
96
98
return Err ( ( ) ) ;
97
99
} ;
98
- writeln ! (
99
- d. tx,
100
- "info: /config.toml: firmware located on {}." ,
101
- firmware_path
102
- )
103
- . ok ( ) ;
104
- let result =
105
- load_file_into_memory ( & mut volume_mgr, firmware, FIRMWARE_ADDRESS , FIRMWARE_LENGTH ) ;
100
+ writeln ! ( d. tx, "info: /config.toml: dtb located on {}." , dtb_path) . ok ( ) ;
101
+ // Load `bl808.dtb`.
102
+ let result = load_file_into_memory ( & mut volume_mgr, dtb, OPAQUE_ADDRESS , OPAQUE_LENGTH ) ;
106
103
match result {
107
104
Ok ( bytes) => {
108
105
writeln ! (
@@ -113,7 +110,7 @@ pub fn load_from_sdcard<
113
110
. ok ( ) ;
114
111
}
115
112
Err ( Error :: FileLength ( size) ) => {
116
- writeln ! ( d. tx, "error: /config.toml: file size for firmware {} is {} bytes, but maximum supported firmware size on the current platform (BL808) is 32,704 KiB." , firmware_path , size) . ok ( ) ;
113
+ writeln ! ( d. tx, "error: /config.toml: file size for dtb {} is {} bytes, but maximum supported dtb size on the current platform (BL808) is 64 KiB." , dtb_path , size) . ok ( ) ;
117
114
return Err ( ( ) ) ;
118
115
}
119
116
Err ( Error :: BlockDevice ( e) ) => {
@@ -125,41 +122,64 @@ pub fn load_from_sdcard<
125
122
. ok ( ) ;
126
123
return Err ( ( ) ) ;
127
124
}
125
+ Err ( _) => { }
126
+ }
127
+ // Patch bootargs to dtb.
128
+ if let Some ( bootargs) = config. configs . bootargs {
129
+ writeln ! ( d. tx, "debug: /config.toml: bootargs load start." ) . ok ( ) ;
130
+ let result = set_bootargs ( & bootargs) ;
131
+ writeln ! (
132
+ d. tx,
133
+ "debug: /config.toml: bootargs `{}` load from dtb." ,
134
+ bootargs
135
+ )
136
+ . ok ( ) ;
137
+ match result {
138
+ Ok ( ( ) ) => {
139
+ writeln ! ( d. tx, "info: /config.toml: bootargs set to `{}`." , bootargs) . ok ( ) ;
140
+ }
141
+ Err ( Error :: InvalideMagic ( _magic) ) => {
142
+ writeln ! ( d. tx, "warning: /config.toml: bootargs is unused, as `config.opaque` does not include an opaque information file in DTB format.
143
+ note: /config.toml: `config.bootargs` is set to `console=ttyS0,115200n8 root=/dev/mmcblk0p2 rw rootwait quiet` in the configuration." ) . ok ( ) ;
144
+ }
145
+ Err ( _) => {
146
+ writeln ! (
147
+ d. tx,
148
+ "error: /config.toml: failed to set bootargs on value `{}`." ,
149
+ bootargs
150
+ )
151
+ . ok ( ) ;
152
+ }
153
+ }
154
+ } else {
155
+ writeln ! ( d. tx, "warning: /config.toml: cannot find bootargs on key `configs.bootargs`, using default bootargs in DTB." ) . ok ( ) ;
128
156
}
129
157
130
158
let root_dir = volume_mgr. open_root_dir ( volume0) . map_err ( |_| ( ) ) ?;
131
159
132
- // Load device tree blob.
133
- let Some ( opaque) = config. configs . opaque else {
134
- writeln ! ( d. tx, "warning: /config.toml: cannot find opaque file path on key `configs.opaque`, using default configuration (zeroing `a1` for non-existing opaque file)." ) . ok ( ) ;
135
- volume_mgr. close_dir ( root_dir) . unwrap ( ) ;
136
- return Ok ( 0x0 ) ;
137
- } ;
138
- let dtb_path = opaque. as_str ( ) ;
139
- let ( file_dir, file_name) = locate_file_by_path ( & mut d. tx , "dtb" , dtb_path) ;
140
- let Ok ( dtb) = open_file_by_path ( & mut volume_mgr, root_dir, file_dir, file_name) else {
160
+ // Load firmware.
161
+ let firmware_path = config. configs . firmware . as_ref ( ) . map ( |s| s. as_str ( ) ) . unwrap_or_else ( || {
162
+ writeln ! ( d. tx, "warning: /config.toml: cannot find firmware path on key `configs.firmware`, using default configuration (/zImage)." ) . ok ( ) ;
163
+ "ZIMAGE"
164
+ } ) ;
165
+ let ( file_dir, file_name) = locate_file_by_path ( & mut d. tx , "firmware" , firmware_path) ;
166
+ let Ok ( firmware) = open_file_by_path ( & mut volume_mgr, root_dir, file_dir, file_name) else {
141
167
writeln ! (
142
168
d. tx,
143
- "error: /config.toml: file not found for dtb path {}." ,
144
- dtb_path
169
+ "error: /config.toml: file not found for firmware path {}." ,
170
+ firmware_path
145
171
)
146
172
. ok ( ) ;
147
173
return Err ( ( ) ) ;
148
174
} ;
149
- writeln ! ( d. tx, "info: /config.toml: dtb located on {}." , dtb_path) . ok ( ) ;
150
- // TODO: apply bootargs to dtb.
151
- if is_dtb_format ( & mut volume_mgr, dtb) {
152
- if let Some ( bootargs) = config. configs . bootargs {
153
- writeln ! ( d. tx, "info: /config.toml: bootargs set to `{}`." , bootargs) . ok ( ) ;
154
- } else {
155
- writeln ! ( d. tx, "warning: /config.toml: cannot find bootargs on key `configs.bootargs`, using default bootargs in DTB." ) . ok ( ) ;
156
- }
157
- } else {
158
- writeln ! ( d. tx, "warning: /config.toml: bootargs is unused, as `config.opaque` does not include an opaque information file in DTB format.
159
- note: /config.toml: `config.bootargs` is set to `console=ttyS0,115200n8 root=/dev/mmcblk0p2 rw rootwait quiet` in the configuration." ) . ok ( ) ;
160
- }
161
- // Load `bl808.dtb`.
162
- let result = load_file_into_memory ( & mut volume_mgr, dtb, OPAQUE_ADDRESS , OPAQUE_LENGTH ) ;
175
+ writeln ! (
176
+ d. tx,
177
+ "info: /config.toml: firmware located on {}." ,
178
+ firmware_path
179
+ )
180
+ . ok ( ) ;
181
+ let result =
182
+ load_file_into_memory ( & mut volume_mgr, firmware, FIRMWARE_ADDRESS , FIRMWARE_LENGTH ) ;
163
183
match result {
164
184
Ok ( bytes) => {
165
185
writeln ! (
@@ -170,7 +190,7 @@ pub fn load_from_sdcard<
170
190
. ok ( ) ;
171
191
}
172
192
Err ( Error :: FileLength ( size) ) => {
173
- writeln ! ( d. tx, "error: /config.toml: file size for dtb {} is {} bytes, but maximum supported dtb size on the current platform (BL808) is 64 KiB." , dtb_path , size) . ok ( ) ;
193
+ writeln ! ( d. tx, "error: /config.toml: file size for firmware {} is {} bytes, but maximum supported firmware size on the current platform (BL808) is 32,704 KiB." , firmware_path , size) . ok ( ) ;
174
194
return Err ( ( ) ) ;
175
195
}
176
196
Err ( Error :: BlockDevice ( e) ) => {
@@ -182,7 +202,9 @@ pub fn load_from_sdcard<
182
202
. ok ( ) ;
183
203
return Err ( ( ) ) ;
184
204
}
205
+ Err ( _) => { }
185
206
}
207
+
186
208
Ok ( OPAQUE_ADDRESS )
187
209
}
188
210
0 commit comments