1- use crate :: os:: {
2- error:: { Error , Result } ,
3- mpsc, TcpStream , UefiOS , PACKET_SIZE ,
1+ use crate :: {
2+ os:: {
3+ error:: { Error , Result } ,
4+ mpsc, TcpStream , UefiOS , PACKET_SIZE ,
5+ } ,
6+ MIN_MEMORY ,
47} ;
58use alloc:: { boxed:: Box , collections:: BTreeMap , rc:: Rc , string:: ToString , vec:: Vec } ;
69use core:: { cell:: RefCell , mem, net:: SocketAddrV4 } ;
710use futures:: future:: { select, Either } ;
811use log:: info;
912use lz4_flex:: decompress;
10- use pixie_shared:: { ChunkHash , Image , TcpRequest , UdpRequest , BODY_LEN , CHUNKS_PORT , HEADER_LEN } ;
13+ use pixie_shared:: {
14+ ChunkHash , Image , TcpRequest , UdpRequest , BODY_LEN , CHUNKS_PORT , HEADER_LEN , MAX_CHUNK_SIZE ,
15+ } ;
1116use uefi:: proto:: console:: text:: Color ;
1217
1318struct PartialChunk {
@@ -232,6 +237,9 @@ pub async fn flash(os: UefiOS, server_addr: SocketAddrV4) -> Result<()> {
232237 let task1 = async {
233238 let mut tx = tx;
234239 let mut last_seen = Vec :: new ( ) ;
240+ let total_mem = os. get_total_mem ( ) ;
241+ let max_chunks = ( total_mem. saturating_sub ( MIN_MEMORY ) as usize / MAX_CHUNK_SIZE ) . max ( 128 ) ;
242+ log:: debug!( "Total memory: {total_mem}. Max chunks in memory: {max_chunks}" ) ;
235243 while !chunks_info. is_empty ( ) {
236244 let recv = Box :: pin ( socket. recv ( & mut buf) ) ;
237245 let sleep = Box :: pin ( os. sleep_us ( 100_000 ) ) ;
@@ -247,7 +255,7 @@ pub async fn flash(os: UefiOS, server_addr: SocketAddrV4) -> Result<()> {
247255 }
248256
249257 assert_eq ! ( last_seen. len( ) , received. len( ) ) ;
250- if last_seen. len ( ) > 128 {
258+ if last_seen. len ( ) > max_chunks {
251259 let hash = last_seen. remove ( 0 ) ;
252260 received
253261 . remove ( & hash)
0 commit comments