66use smoltcp:: iface:: SocketHandle ;
77use smoltcp:: wire:: IpAddress ;
88
9+ use crate :: device:: UnifiedBlockDevice ;
10+
911/// Timeout configuration for network operations.
1012#[ derive( Clone , Copy ) ]
1113pub struct Timeouts {
@@ -38,16 +40,61 @@ impl Timeouts {
3840 }
3941}
4042
41- /// Configuration for the download operation .
43+ /// Full download configuration .
4244#[ derive( Clone ) ]
4345pub struct DownloadConfig < ' a > {
4446 /// URL to download
4547 pub url : & ' a str ,
48+ /// Write to disk?
49+ pub write_to_disk : bool ,
50+ /// Target start sector for ISO
51+ pub target_start_sector : u64 ,
52+ /// Sector for manifest (raw write)
53+ pub manifest_sector : u64 ,
54+ /// ESP start LBA (for FAT32 manifest)
55+ pub esp_start_lba : u64 ,
56+ /// Partition UUID
57+ pub partition_uuid : [ u8 ; 16 ] ,
58+ /// ISO name for manifest
59+ pub iso_name : & ' a str ,
60+ /// Expected ISO size (0 = unknown)
61+ pub expected_size : u64 ,
4662}
4763
4864impl < ' a > DownloadConfig < ' a > {
49- pub fn new ( url : & ' a str ) -> Self {
50- Self { url }
65+ /// Simple config for download-only (no disk write).
66+ pub fn download_only ( url : & ' a str ) -> Self {
67+ Self {
68+ url,
69+ write_to_disk : false ,
70+ target_start_sector : 0 ,
71+ manifest_sector : 0 ,
72+ esp_start_lba : 0 ,
73+ partition_uuid : [ 0u8 ; 16 ] ,
74+ iso_name : "" ,
75+ expected_size : 0 ,
76+ }
77+ }
78+
79+ /// Full config for download + disk write + manifest.
80+ pub fn full (
81+ url : & ' a str ,
82+ target_start_sector : u64 ,
83+ manifest_sector : u64 ,
84+ esp_start_lba : u64 ,
85+ partition_uuid : [ u8 ; 16 ] ,
86+ iso_name : & ' a str ,
87+ ) -> Self {
88+ Self {
89+ url,
90+ write_to_disk : true ,
91+ target_start_sector,
92+ manifest_sector,
93+ esp_start_lba,
94+ partition_uuid,
95+ iso_name,
96+ expected_size : 0 ,
97+ }
5198 }
5299}
53100
@@ -57,14 +104,16 @@ pub struct Context<'a> {
57104 pub timeouts : Timeouts ,
58105 /// TSC frequency
59106 pub tsc_freq : u64 ,
60- /// Download URL
61- pub url : & ' a str ,
107+ /// Full configuration
108+ pub config : DownloadConfig < ' a > ,
62109 /// DHCP socket handle
63110 pub dhcp_handle : Option < SocketHandle > ,
64111 /// DNS socket handle
65112 pub dns_handle : Option < SocketHandle > ,
66113 /// TCP socket handle
67114 pub tcp_handle : Option < SocketHandle > ,
115+ /// Block device for disk writes
116+ pub blk_device : Option < UnifiedBlockDevice > ,
68117 /// Resolved IP address (from DNS)
69118 pub resolved_ip : Option < IpAddress > ,
70119 /// Resolved port
@@ -73,30 +122,57 @@ pub struct Context<'a> {
73122 pub url_path : & ' a str ,
74123 /// Host portion of URL
75124 pub url_host : & ' a str ,
76- /// Content-Length from HTTP response (if known)
125+ /// Content-Length from HTTP response
77126 pub content_length : Option < u64 > ,
78- /// Total bytes downloaded so far
127+ /// Total bytes downloaded
79128 pub bytes_downloaded : u64 ,
129+ /// Total bytes written to disk
130+ pub bytes_written : u64 ,
131+ /// Current write sector
132+ pub current_write_sector : u64 ,
133+ /// DNS servers from DHCP
134+ pub dns_servers : [ Option < IpAddress > ; 3 ] ,
80135}
81136
82137impl < ' a > Context < ' a > {
83138 /// Create new context.
84- pub fn new ( url : & ' a str , tsc_freq : u64 ) -> Self {
139+ pub fn new ( config : DownloadConfig < ' a > , tsc_freq : u64 ) -> Self {
140+ let start_sector = config. target_start_sector ;
85141 Self {
86142 timeouts : Timeouts :: new ( tsc_freq) ,
87143 tsc_freq,
88- url ,
144+ config ,
89145 dhcp_handle : None ,
90146 dns_handle : None ,
91147 tcp_handle : None ,
148+ blk_device : None ,
92149 resolved_ip : None ,
93150 resolved_port : 80 ,
94151 url_path : "" ,
95152 url_host : "" ,
96153 content_length : None ,
97154 bytes_downloaded : 0 ,
155+ bytes_written : 0 ,
156+ current_write_sector : start_sector,
157+ dns_servers : [ None ; 3 ] ,
98158 }
99159 }
160+
161+ /// Set block device for disk writes.
162+ pub fn with_block_device ( mut self , device : UnifiedBlockDevice ) -> Self {
163+ self . blk_device = Some ( device) ;
164+ self
165+ }
166+
167+ /// Get URL from config.
168+ pub fn url ( & self ) -> & str {
169+ self . config . url
170+ }
171+
172+ /// Check if disk write is enabled.
173+ pub fn should_write_to_disk ( & self ) -> bool {
174+ self . config . write_to_disk && self . blk_device . is_some ( )
175+ }
100176}
101177
102178/// Read TSC (Time Stamp Counter).
0 commit comments