@@ -16,10 +16,18 @@ use crate::{
16
16
pub fn write_t1_simple < ObjectID : FsVerityHashValue > (
17
17
mut t1 : Type1Entry < ObjectID > ,
18
18
bootdir : & Path ,
19
+ boot_subdir : Option < & str > ,
19
20
root_id : & ObjectID ,
20
21
cmdline_extra : & [ & str ] ,
21
22
repo : & Repository < ObjectID > ,
22
23
) -> Result < ( ) > {
24
+ let bootdir = if let Some ( subdir) = boot_subdir {
25
+ let subdir_path = Path :: new ( subdir) ;
26
+ bootdir. join ( subdir_path. strip_prefix ( "/" ) . unwrap_or ( subdir_path) )
27
+ } else {
28
+ bootdir. to_path_buf ( )
29
+ } ;
30
+
23
31
t1. entry
24
32
. adjust_cmdline ( Some ( & root_id. to_hex ( ) ) , cmdline_extra) ;
25
33
@@ -63,35 +71,78 @@ pub fn write_t2_simple<ObjectID: FsVerityHashValue>(
63
71
Ok ( ( ) )
64
72
}
65
73
74
+ /// Writes boot entry to the boot partition
75
+ ///
76
+ /// # Arguments
77
+ ///
78
+ /// * repo - The composefs repository
79
+ /// * entry - Boot entry variant to be written
80
+ /// * root_id - The content hash of the generated EROFS image id
81
+ /// * boot_partition - Path to the boot partition/directory
82
+ /// * boot_subdir - If `Some(path)`, the path is prepended to `initrd` and `linux` keys in the BLS entry
83
+ ///
84
+ /// For example, if `boot_partition = "/boot"` and `boot_subdir = Some("1")` ,
85
+ /// the BLS entry will contain
86
+ ///
87
+ /// ```text
88
+ /// linux /boot/1/<entry_id>/linux
89
+ /// initrd /boot/1/<entry_id>/initrd
90
+ /// ```
91
+ ///
92
+ /// If `boot_partition = "/boot"` and `boot_subdir = None` , the BLS entry will contain
93
+ ///
94
+ /// ```text
95
+ /// linux /<entry_id>/linux
96
+ /// initrd /<entry_id>/initrd
97
+ /// ```
98
+ ///
99
+ /// * entry_id - In case of a BLS entry, the name of file to be generated in `loader/entries`
100
+ /// * cmdline_extra - Extra kernel command line arguments
101
+ ///
66
102
pub fn write_boot_simple < ObjectID : FsVerityHashValue > (
67
103
repo : & Repository < ObjectID > ,
68
104
entry : BootEntry < ObjectID > ,
69
105
root_id : & ObjectID ,
70
- bootdir : & Path ,
106
+ boot_partition : & Path ,
107
+ boot_subdir : Option < & str > ,
71
108
entry_id : Option < & str > ,
72
109
cmdline_extra : & [ & str ] ,
73
110
) -> Result < ( ) > {
74
111
match entry {
75
112
BootEntry :: Type1 ( mut t1) => {
76
113
if let Some ( name) = entry_id {
77
- t1. relocate ( name) ;
114
+ t1. relocate ( boot_subdir , name) ;
78
115
}
79
- write_t1_simple ( t1, bootdir, root_id, cmdline_extra, repo) ?;
116
+ write_t1_simple (
117
+ t1,
118
+ boot_partition,
119
+ boot_subdir,
120
+ root_id,
121
+ cmdline_extra,
122
+ repo,
123
+ ) ?;
80
124
}
81
125
BootEntry :: Type2 ( mut t2) => {
82
126
if let Some ( name) = entry_id {
83
127
t2. rename ( name) ;
84
128
}
85
129
ensure ! ( cmdline_extra. is_empty( ) , "Can't add --cmdline args to UKIs" ) ;
86
- write_t2_simple ( t2, bootdir , root_id, repo) ?;
130
+ write_t2_simple ( t2, boot_partition , root_id, repo) ?;
87
131
}
88
132
BootEntry :: UsrLibModulesUki ( _entry) => todo ! ( ) ,
89
133
BootEntry :: UsrLibModulesVmLinuz ( entry) => {
90
134
let mut t1 = entry. into_type1 ( entry_id) ;
91
135
if let Some ( name) = entry_id {
92
- t1. relocate ( name) ? ;
136
+ t1. relocate ( boot_subdir , name) ;
93
137
}
94
- write_t1_simple ( t1, bootdir, root_id, cmdline_extra, repo) ?;
138
+ write_t1_simple (
139
+ t1,
140
+ boot_partition,
141
+ boot_subdir,
142
+ root_id,
143
+ cmdline_extra,
144
+ repo,
145
+ ) ?;
95
146
}
96
147
} ;
97
148
0 commit comments