Skip to contentSkip to conversation

binman: Add support for symlinking images

PATCH In review Neha Malcom Francis 2 participants 3 messages Oct 17, 2022 – Oct 22, 2022

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 binman: Add support for symlinking images

Adding support to symlink an image packaged using binman.

---

Changes in v2:
- added testing for symlink support
- moved from tools.Run('ln',...) to os.symlink()

 tools/binman/binman.rst           |  3 +++
 tools/binman/ftest.py             |  9 +++++++++
 tools/binman/image.py             |  6 ++++++
 tools/binman/test/259_symlink.dts | 16 ++++++++++++++++
 4 files changed, 34 insertions(+)
 create mode 100644 tools/binman/test/259_symlink.dts
tools/binman/binman.rst +3 -0
index 4ee6f41f35..d8a3d776f4 100644
@@ -780,6 +780,9 @@ align-default:
     This means that each section must specify its own default alignment, if
     required.
 
+symlink:
+    Adds a symlink to the image with string given in the symlink property.
+
 Examples of the above options can be found in the tests. See the
 tools/binman/test directory.
 
tools/binman/ftest.py +9 -0
index 261107b335..232ac2cf18 100644
@@ -5995,6 +5995,15 @@ fdt         fdtmap                Extract the devicetree blob from the fdtmap
         self.assertIn('Expected __bss_size symbol in vpl/u-boot-vpl',
                       str(e.exception))
 
+    def testSymlink(self):
+        """Test that image files can be named"""
+        retcode = self._DoTestFile('259_symlink.dts', debug=True, map=True)
+        self.assertEqual(0, retcode)
+        image = control.images['test_image']
+        fname = tools.get_output_filename('test_image.bin')
+        sname = tools.get_output_filename('symlink_to_test.bin')
+        self.assertTrue(os.path.islink(sname))
+        self.assertEqual(os.readlink(sname), fname)
 
 if __name__ == "__main__":
     unittest.main()
tools/binman/image.py +6 -0
index afc4b4d643..6d4bff5843 100644
@@ -38,6 +38,7 @@ class Image(section.Entry_section):
             repacked later
         test_section_timeout: Use a zero timeout for section multi-threading
             (for testing)
+        symlink: Name of symlink to image
 
     Args:
         copy_to_orig: Copy offset/size to orig_offset/orig_size after reading
@@ -97,6 +98,7 @@ class Image(section.Entry_section):
         if filename:
             self._filename = filename
         self.allow_repack = fdt_util.GetBool(self._node, 'allow-repack')
+        self._symlink = fdt_util.GetString(self._node, 'symlink')
 
     @classmethod
     def FromFile(cls, fname):
@@ -180,6 +182,10 @@ class Image(section.Entry_section):
             data = self.GetPaddedData()
             fd.write(data)
         tout.info("Wrote %#x bytes" % len(data))
+        # Create symlink to file if symlink given
+        if self._symlink is not None:
+            sname = tools.get_output_filename(self._symlink)
+            os.symlink(fname, sname)
 
     def WriteMap(self):
         """Write a map of the image to a .map file
tools/binman/test/259_symlink.dts new file +16 -0
new file mode 100644
index 0000000000..2ee1f7f05e
@@ -0,0 +1,16 @@
+/dts-v1/;
+
+/ {
+	#address-cells = <1>;
+	#size-cells = <1>;
+
+	binman {
+		multiple-images;
+		test_image {
+			filename = "test_image.bin";
+			symlink = "symlink_to_test.bin";
+			u-boot {
+			};
+		};
+	};
+};
Signature · 1 line
2.34.1
Reviewed-by on v2 1/1
#1 lore raw
Quoted 10 lines · Neha Malcom Francis

Adding support to symlink an image packaged using binman.

---

Changes in v2:
- added testing for symlink support
- moved from tools.Run('ln',...) to os.symlink()

Quoted 6 lines
 tools/binman/binman.rst           |  3 +++
 tools/binman/ftest.py             |  9 +++++++++
 tools/binman/image.py             |  6 ++++++
 tools/binman/test/259_symlink.dts | 16 ++++++++++++++++
 4 files changed, 34 insertions(+)
 create mode 100644 tools/binman/test/259_symlink.dts
Reviewed-by
#2 lore raw
Quoted 10 lines · Neha Malcom Francis

Adding support to symlink an image packaged using binman.

---

Changes in v2:
- added testing for symlink support
- moved from tools.Run('ln',...) to os.symlink()

Quoted 6 lines
 tools/binman/binman.rst           |  3 +++
 tools/binman/ftest.py             |  9 +++++++++
 tools/binman/image.py             |  6 ++++++
 tools/binman/test/259_symlink.dts | 16 ++++++++++++++++
 4 files changed, 34 insertions(+)
 create mode 100644 tools/binman/test/259_symlink.dts

Applied to u-boot-dm, thanks!