[FE training-materials-updates] Kernel labs: add back nfsroot/root

Michael Opdenacker michael.opdenacker at free-electrons.com
Tue Feb 4 11:27:39 CET 2014


Repository : git://git.free-electrons.com/training-materials.git

On branch  : master
Link       : http://git.free-electrons.com/training-materials/commit/?id=7bcacce03a4c714b6c2cea5cae59560f35323996

>---------------------------------------------------------------

commit 7bcacce03a4c714b6c2cea5cae59560f35323996
Author: Michael Opdenacker <michael.opdenacker at free-electrons.com>
Date:   Tue Feb 4 11:25:52 2014 +0100

    Kernel labs: add back nfsroot/root
    
    - This way we separate the rootfs generated by Buildroot
      from the code and makefile templates.
    
    - Another advantage is that the individual files
      are tracked by git now.
    
    Signed-off-by: Michael Opdenacker <michael.opdenacker at free-electrons.com>


>---------------------------------------------------------------

7bcacce03a4c714b6c2cea5cae59560f35323996
 .../linux/modules/nfsroot/root/debugging/Makefile  |    7 ++
 .../modules/nfsroot/root/debugging/drvbroken.c     |   73 ++++++++++++++++++++
 lab-data/linux/modules/nfsroot/root/hello/Makefile |    7 ++
 .../modules/nfsroot/root/hello/hello_version.c     |    8 +++
 .../linux/modules/nfsroot/root/nunchuk/Makefile    |    7 ++
 .../linux/modules/nfsroot/root/nunchuk/nunchuk.c   |    8 +++
 .../linux/modules/nfsroot/root/serial/Makefile     |    7 ++
 .../linux/modules/nfsroot/root/serial/feserial.c   |   42 +++++++++++
 .../nfsroot/root/serial/serial-get-counter.c       |   30 ++++++++
 .../nfsroot/root/serial/serial-reset-counter.c     |   29 ++++++++
 10 files changed, 218 insertions(+)

diff --git a/lab-data/linux/modules/nfsroot/root/debugging/Makefile b/lab-data/linux/modules/nfsroot/root/debugging/Makefile
new file mode 100644
index 0000000..ba9c779
--- /dev/null
+++ b/lab-data/linux/modules/nfsroot/root/debugging/Makefile
@@ -0,0 +1,7 @@
+ifneq ($(KERNELRELEASE),)
+obj-m := drvbroken.o
+else
+KDIR := $(HOME)/felabs/linux/src/linux
+all:
+	$(MAKE) -C $(KDIR) M=$$PWD
+endif
diff --git a/lab-data/linux/modules/nfsroot/root/debugging/drvbroken.c b/lab-data/linux/modules/nfsroot/root/debugging/drvbroken.c
new file mode 100644
index 0000000..9d615b5
--- /dev/null
+++ b/lab-data/linux/modules/nfsroot/root/debugging/drvbroken.c
@@ -0,0 +1,73 @@
+/* Voluntarily broken driver
+ * Copyright Thomas Petazzoni <thomas.petazzoni at free-electrons.com>
+ * License: GNU General Public License 2.0 or later
+ * Permission to break this driver even further!
+ */
+#include <linux/module.h>
+#include <linux/errno.h>
+#include <linux/fs.h>
+#include <linux/cdev.h>
+
+static dev_t broken_dev;
+static int broken_first_minor = 0;
+static int broken_count = 1;
+static struct cdev *broken_cdev;
+
+static ssize_t
+broken_write(struct file *file, const char __user * buf, size_t count,
+	     loff_t *ppos)
+{
+	printk(KERN_INFO "Writing %d bytes from %p to the device\n",
+	      count, buf);
+	return 0;
+}
+
+static ssize_t
+broken_read(struct file *file, char __user * buf, size_t count, loff_t * ppos)
+{
+	printk(KERN_INFO "Writing %d bytes to %p from the device\n",
+	count, buf);
+	return 0;
+}
+
+static const struct file_operations broken_fops = {
+	.owner = THIS_MODULE,
+	.read = broken_read,
+	.write = broken_write,
+};
+
+int __init broken_init(void)
+{
+	if (alloc_chrdev_region(&broken_dev, broken_first_minor, 1, "broken") <
+	    0) {
+		printk(KERN_ERR "broken: unable to find free device numbers\n");
+		return -EIO;
+	}
+
+	cdev_init(broken_cdev, &broken_fops);
+
+	if (cdev_add(broken_cdev, broken_dev, 1) < 0) {
+		printk(KERN_ERR "broken: unable to add a character device\n");
+		unregister_chrdev_region(broken_dev, broken_count);
+		return -EIO;
+	}
+
+	printk(KERN_INFO "Loaded the broken driver: major = %d, minor = %d\n",
+	       MAJOR(broken_dev), MINOR(broken_dev));
+
+	return 0;
+}
+
+void __exit broken_exit(void)
+{
+	cdev_del(broken_cdev);
+	unregister_chrdev_region(broken_dev, broken_count);
+	printk(KERN_INFO "Unloaded the broken driver!\n");
+}
+
+module_init(broken_init);
+module_exit(broken_exit);
+
+MODULE_AUTHOR("Thomas Petazzoni");
+MODULE_DESCRIPTION("Broken device");
+MODULE_LICENSE("GPL");
diff --git a/lab-data/linux/modules/nfsroot/root/hello/Makefile b/lab-data/linux/modules/nfsroot/root/hello/Makefile
new file mode 100644
index 0000000..3d3a43a
--- /dev/null
+++ b/lab-data/linux/modules/nfsroot/root/hello/Makefile
@@ -0,0 +1,7 @@
+ifneq ($(KERNELRELEASE),)
+obj-m := hello_version.o
+else
+KDIR := $(HOME)/felabs/linux/src/linux
+all:
+	$(MAKE) -C $(KDIR) M=$$PWD
+endif
diff --git a/lab-data/linux/modules/nfsroot/root/hello/hello_version.c b/lab-data/linux/modules/nfsroot/root/hello/hello_version.c
new file mode 100644
index 0000000..4fe61cf
--- /dev/null
+++ b/lab-data/linux/modules/nfsroot/root/hello/hello_version.c
@@ -0,0 +1,8 @@
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/i2c.h>
+
+/* Add your code here */
+
+MODULE_LICENSE("GPL");
+
diff --git a/lab-data/linux/modules/nfsroot/root/nunchuk/Makefile b/lab-data/linux/modules/nfsroot/root/nunchuk/Makefile
new file mode 100644
index 0000000..a71b495
--- /dev/null
+++ b/lab-data/linux/modules/nfsroot/root/nunchuk/Makefile
@@ -0,0 +1,7 @@
+ifneq ($(KERNELRELEASE),)
+obj-m := nunchuk.o
+else
+KDIR := $(HOME)/felabs/linux/src/linux
+all:
+	$(MAKE) -C $(KDIR) M=$$PWD
+endif
diff --git a/lab-data/linux/modules/nfsroot/root/nunchuk/nunchuk.c b/lab-data/linux/modules/nfsroot/root/nunchuk/nunchuk.c
new file mode 100644
index 0000000..4fe61cf
--- /dev/null
+++ b/lab-data/linux/modules/nfsroot/root/nunchuk/nunchuk.c
@@ -0,0 +1,8 @@
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/i2c.h>
+
+/* Add your code here */
+
+MODULE_LICENSE("GPL");
+
diff --git a/lab-data/linux/modules/nfsroot/root/serial/Makefile b/lab-data/linux/modules/nfsroot/root/serial/Makefile
new file mode 100644
index 0000000..0d54f08
--- /dev/null
+++ b/lab-data/linux/modules/nfsroot/root/serial/Makefile
@@ -0,0 +1,7 @@
+ifneq ($(KERNELRELEASE),)
+obj-m := feserial.o
+else
+KDIR := $(HOME)/felabs/linux/src/linux
+all:
+	$(MAKE) -C $(KDIR) M=$$PWD
+endif
diff --git a/lab-data/linux/modules/nfsroot/root/serial/feserial.c b/lab-data/linux/modules/nfsroot/root/serial/feserial.c
new file mode 100644
index 0000000..91583ee
--- /dev/null
+++ b/lab-data/linux/modules/nfsroot/root/serial/feserial.c
@@ -0,0 +1,42 @@
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/platform_device.h>
+
+/* Add your code here */
+
+static int feserial_probe(struct platform_device *pdev)
+{
+	pr_info("Called feserial_probe\n");
+	return 0;
+}
+
+static int feserial_remove(struct platform_device *pdev)
+{
+	pr_info("Called feserial_remove\n");
+        return 0;
+}
+
+static struct platform_driver feserial_driver = {
+        .driver = {
+                .name = "feserial",
+                .owner = THIS_MODULE,
+        },
+        .probe = feserial_probe,
+        .remove = feserial_remove,
+};
+
+static int __init feserial_init(void)
+{
+        return platform_driver_register(&feserial_driver);
+}
+
+static void __exit feserial_exit(void)
+{
+        platform_driver_unregister(&feserial_driver);
+}
+
+module_init(feserial_init);
+module_exit(feserial_exit);
+
+MODULE_LICENSE("GPL");
+
diff --git a/lab-data/linux/modules/nfsroot/root/serial/serial-get-counter.c b/lab-data/linux/modules/nfsroot/root/serial/serial-get-counter.c
new file mode 100644
index 0000000..07590dc
--- /dev/null
+++ b/lab-data/linux/modules/nfsroot/root/serial/serial-get-counter.c
@@ -0,0 +1,30 @@
+#include <stdio.h>
+#include <sys/ioctl.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <stdlib.h>
+
+#define SERIAL_RESET_COUNTER 0
+#define SERIAL_GET_COUNTER 1
+
+int main(void)
+{
+    unsigned int val;
+    int fd, ret;
+
+    fd = open("/dev/serial", O_RDWR);
+    if (fd < 0) {
+        fprintf(stderr, "Unable to open /dev/serial\n");
+        exit (1);
+    }
+
+    ret = ioctl(fd, SERIAL_GET_COUNTER, & val);
+    if (ret < 0) {
+        fprintf(stderr, "Unable to get counter\n");
+        exit (1);
+    }
+
+    printf("Counter value: %d\n", val);
+    return 0;
+}
diff --git a/lab-data/linux/modules/nfsroot/root/serial/serial-reset-counter.c b/lab-data/linux/modules/nfsroot/root/serial/serial-reset-counter.c
new file mode 100644
index 0000000..cb268db
--- /dev/null
+++ b/lab-data/linux/modules/nfsroot/root/serial/serial-reset-counter.c
@@ -0,0 +1,29 @@
+#include <stdio.h>
+#include <sys/ioctl.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <stdlib.h>
+
+#define SERIAL_RESET_COUNTER 0
+#define SERIAL_GET_COUNTER 1
+
+int main(void)
+{
+    int fd, ret;
+
+    fd = open("/dev/serial", O_RDWR);
+    if (fd < 0) {
+        fprintf(stderr, "Unable to open /dev/serial\n");
+        exit (1);
+    }
+
+    ret = ioctl(fd, SERIAL_RESET_COUNTER);
+    if (ret < 0) {
+        fprintf(stderr, "Unable to reset counter\n");
+        exit (1);
+    }
+
+    printf("Counter reset\n");
+    return 0;
+}



More information about the training-materials-updates mailing list