public void ShouldFindProperty()
        {
            var fdt   = new FlattenedDeviceTree(File.ReadAllBytes(Utilities.GetBinaryLocation("xilinx_zynq_iic.dtb")));
            var model = fdt.Root.Properties.First(x => x.Name == "model").GetDataAsString();

            Assert.AreEqual("Enclustra MARS ZX3", model);
        }
        public void ShouldFindAllNodes()
        {
            var expectedNodeNames = new [] {
                "memory",
                "chosen",
                "soc",
                "amba@0",
                "intc@f8f01000",
                "pl310@f8f02000",
                "uart@e0001000",
                "timer@0xf8001000",
                "swdt@f8005000",
                "eth@e000b000",
                "phy@3",
                "slcr@f8000000",
                "i2c@e0004000",
                "touch@38",
                "usb@e0002000",
                "devcfg@f8007000",
                "tft@6C000000"
            };

            var fdt         = new FlattenedDeviceTree(File.ReadAllBytes(Utilities.GetBinaryLocation("xilinx_zynq_iic.dtb")));
            var descendants = fdt.Root.Descendants;

            CollectionAssert.AreEquivalent(expectedNodeNames, descendants.Select(x => x.Name));
        }
        public void ShouldReadHeader()
        {
            var fdt = new FlattenedDeviceTree(File.ReadAllBytes(Utilities.GetBinaryLocation("xilinx_zynq_iic.dtb")));

            Assert.AreEqual(17, fdt.Version);
            Assert.AreEqual(16, fdt.LastCompatibleVersion);
        }
        public void ShouldRewriteProperTree()
        {
            var originalBlob = File.ReadAllBytes(Utilities.GetBinaryLocation("xilinx_zynq_iic.dtb"));
            var fdt          = new FlattenedDeviceTree(originalBlob);
            var result       = fdt.GetBinaryBlob();

            CollectionAssert.AreEqual(originalBlob, result);
        }
Exemplo n.º 5
0
        public static void LoadFdt(this SystemBus sysbus, string file, long address, string bootargs = null, bool append = true, string excludedNodes="")
        {
            var fdtBlob = File.ReadAllBytes(file);
            if(bootargs == null)
            {
                sysbus.WriteBytes(fdtBlob, address, true);
                return;
            }
            var fdt = new FlattenedDeviceTree(fdtBlob);
            var chosenNode = fdt.Root.Subnodes.FirstOrDefault(x => x.Name == "chosen");
            if(chosenNode == null)
            {
                chosenNode = new TreeNode { Name = "chosen" };
                fdt.Root.Subnodes.Add(chosenNode);
            }
            var bootargsProperty = chosenNode.Properties.FirstOrDefault(x => x.Name == "bootargs");
            if(bootargsProperty == null)
            {
                bootargsProperty = new Property("bootargs", new byte[] { 0 });
                chosenNode.Properties.Add(bootargsProperty);
            }
            var oldBootargs = bootargsProperty.GetDataAsString();
            if(append)
            {
                bootargs = oldBootargs + bootargs;
            }
            if(oldBootargs != bootargs)
            {
                sysbus.DebugLog("Bootargs altered from '{0}' to '{1}'.", oldBootargs, bootargs);
            }
            bootargsProperty.PutDataAsString(bootargs);

            var excludedNodeNames = excludedNodes.Split(new [] {' '}, StringSplitOptions.RemoveEmptyEntries);
            byte[] disabledValue = Encoding.ASCII.GetBytes ("disabled");
            foreach(var deviceName in excludedNodeNames)
            {
                TreeNode node = fdt.Root.Descendants.FirstOrDefault(x => x.Name == deviceName);
                if(node == null)
                {
                    throw new RecoverableException(String.Format("Device {0} not found.", deviceName));
                }
                else
                {
                    Property statusProperty = node.Properties.FirstOrDefault (x => x.Name == "status");
                    if (statusProperty != null) {
                        node.Properties.Remove (statusProperty);
                    }
                    statusProperty = new Property ("status", disabledValue);
                    node.Properties.Add (statusProperty);
                }
            }

            fdtBlob = fdt.GetBinaryBlob();
            sysbus.WriteBytes(fdtBlob, address, true);
        }
        public static void LoadFdt(this SystemBus sysbus, string file, long address, string bootargs = null, bool append = true, string excludedNodes = "")
        {
            var fdtBlob = File.ReadAllBytes(file);

            if (bootargs == null)
            {
                sysbus.WriteBytes(fdtBlob, address, true);
                return;
            }
            var fdt        = new FlattenedDeviceTree(fdtBlob);
            var chosenNode = fdt.Root.Subnodes.FirstOrDefault(x => x.Name == "chosen");

            if (chosenNode == null)
            {
                chosenNode = new TreeNode {
                    Name = "chosen"
                };
                fdt.Root.Subnodes.Add(chosenNode);
            }
            var bootargsProperty = chosenNode.Properties.FirstOrDefault(x => x.Name == "bootargs");

            if (bootargsProperty == null)
            {
                bootargsProperty = new Property("bootargs", new byte[] { 0 });
                chosenNode.Properties.Add(bootargsProperty);
            }
            var oldBootargs = bootargsProperty.GetDataAsString();

            if (append)
            {
                bootargs = oldBootargs + bootargs;
            }
            if (oldBootargs != bootargs)
            {
                sysbus.DebugLog("Bootargs altered from '{0}' to '{1}'.", oldBootargs, bootargs);
            }
            bootargsProperty.PutDataAsString(bootargs);

            var excludedNodeNames = excludedNodes.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

            byte[] disabledValue = Encoding.ASCII.GetBytes("disabled");
            foreach (var deviceName in excludedNodeNames)
            {
                TreeNode node = fdt.Root.Descendants.FirstOrDefault(x => x.Name == deviceName);
                if (node == null)
                {
                    throw new RecoverableException(String.Format("Device {0} not found.", deviceName));
                }
                else
                {
                    Property statusProperty = node.Properties.FirstOrDefault(x => x.Name == "status");
                    if (statusProperty != null)
                    {
                        node.Properties.Remove(statusProperty);
                    }
                    statusProperty = new Property("status", disabledValue);
                    node.Properties.Add(statusProperty);
                }
            }

            fdtBlob = fdt.GetBinaryBlob();
            sysbus.WriteBytes(fdtBlob, address, true);
        }
        public void ShouldReadReservationBlocks()
        {
            var fdt = new FlattenedDeviceTree(File.ReadAllBytes(Utilities.GetBinaryLocation("xilinx_zynq_iic.dtb")));

            Assert.AreEqual(0, fdt.ReservationBlocks.Count);
        }