summaryrefslogtreecommitdiff
path: root/docs/06-Optional-rootfs-build.txt
blob: 913861f170af848ed81b2ec6aaafe2bdbd60fe2f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
Optional Root filesystem build and use instructions
===================================================

A   Introduction

    This note describes ways to build Linux user-land
    filesystems of varying complexity for use with the
    virtualizer. Note that there are several ways to create
    filesystems and this note doesn't cover all possibilities.

    The default virtualizer release contains an empty filesystem
    stub located at "bootwrapper/payload/fsimg"

    A build using this stub doesn't contain a functional
    filesytem that the Linux kernel image can use. fsimg can be
    replaced with a suitable initramfs root filesystem image but
    with the following constraints:

    1.  Compressed or uncompressed cpio archives are supported.

    2.  The image size is limited to ~200 MB. In the default virtualizer
        build setup, the filesystem image size is limited to 32 MB.

    In section B. we illustrate a method to create a compressed
    cpio archive filesystem image that can be used by replacing
    "bootwrapper/payload/fsimg" file. We will also illustrate
    what parts of the Virtualizer software need modification to
    use a cpio archive of size > 32 MB as the root filesystem.

    The size restriction mentioned in A.2 implies that only very 'lean'
    filesystems such as busybox <http://www.busybox.net/> may be used.
    While busybox presents a minimal but robust command line environment,
    quite often a more conventional desktop like environment with window
    management on top of an X server is required in order to run web
    browsers etc.

    In section C. we illustrate a method to use a larger (~2GB) filesystem
    image that can be used with the ARM FastModels MMC emulation. Note that
    the MMC emulations only supports images that are just under 2GB in size.

    Note that if the MMC route is used, the "bootwrapper/payload/fsimg"
    filesystem image needs to be replaced by an empty file. This is to
    prevent Linux from using the cpio archive based initramfs as the root
    filesystem before it can detect the MMC based root filesystem.

B   Building and using a cpio archive as a initramfs root filesystem

    The following steps assume that a pre-built root filesystem is already
    available in a compressed form in the file rootfs.tar.gz.

    1. Uncompress the filesystem:

       sudo tar -zxf rootfs.tar.gz

    2. Ensure that the filesystem contains '/init'. It is used by Linux
       as the default init process when an initramfs filesystem is used.
       It can be the actual file or a symlink to another 'init' binary.
       Alternatively, use the 'rdinit=<absolute path to init application>'
       e.g. 'rdinit=/sbin/init' to specify which init binary should be
       used by Linux in the absence of '/init'.

       The kernel command line can be edited in 'bootwrapper/Makefile'. The
       BOOTARGS variable points to the kernel command line string.

    3. Create a compressed cpio archive from the uncompressed filesystem:

       pushd binary/boot/filesystem.dir
       sudo sh -c 'find . | cpio --quiet -H newc -o | gzip -3 -n > ../../../rootfs.cpio.gz'
       popd

    4. Copy the compressed cpio archive to "bootwrapper/payload/fsimg"

    5. If the size of the resulting cpio archive is > 32 MB then follow the
       steps mentioned below. The following diagram illustrates how the
       payload software (Linux in this case), initramfs filesystem &
       Virtualizer images are placed relative to each other in physical memory.

       Base of memory @ $(LOBASE)00000 ->     ----------------------
                                              |                    |
                                              |                    |
       Linux Kernel start @ 0x80008000 ->     |--------------------|
                                              |                    |
                                              |                    |
                                              |                    |
                                              |                    |
                                              |                    |
                                              |                    |
       Filesystem start @ 0x8df00000   ->     |--------------------|
                                              |                    |
                                              |                    |
                                              |                    |
       Virtualizer start @ $(HIBASE)00000  -> |--------------------|
                                              |                    |
                                              |                    |
                                              |--------------------|

       a. Increase the size of the FILESYSTEM region in the scatter file
          template bootwrapper/boot.map.template to be not less than the
          size of the cpio archive created in step 3. It is set to 32MB
          (0x2000000) by default.

       b. The variable HIBASE contains the value of the MB where the
          Virtualizer software (bootwrapper/img.axf) is loaded. Increase
          its value to prevent any overlap between the memory spaces used
          by the filesystem and the Virtualizer. An overlap will be flagged
          as a linker error while building the Virtualizer software.

          HIBASE can be changed as an environment variable at the time of
          building the Virtualizer software or in each of the following
          makefiles:

          a. "bootwrapper/Makefile"
          b. "bootwrapper/big-little/Makefile"

          If following the latter approach please ensure that both the
          makefiles contain the same value of HIBASE. The default value of
          $(HIBASE) is 0x8ff.

          The start address of the root filesystem is contained in the
          variable FSADDR. The default value of $(FSADDR) = 0x8df00000.

          The following equation illustrates the relationship between
          FSADDR and HIBASE mentioned earlier

          $(FSADDR)  + size of FILESYSTEM = $(HIBASE)00000
          0x8df00000 + 0x2000000          =     0x8ff00000

       c. Increase the kernel parameter value mem=nn[KMG] of the Linux kernel
	  in bootwrapper/Makefile so that Linux is aware that the size of
          physical memory is enough to include the root filesystem image. The
          default value is 255M.

	  BOOTARGS=mem=255M ...

          The following equation should be used as a reference for determining
          the amount of physical memory made visible to Linux.

          $(LOBASE)00000 + "size of memory" > $(FSADDR) + size of FILESYSTEM

	  where $(LOBASE) is start of physical memory in the platform in MB.
          Its default value is 0x800 which corresponds to the start of physical
          on the FastModels platform at 0x80000000.

    7. Build a Linux kernel image for use with the virtualizer by following
       the steps in "docs/03-Linux-kernel-build.txt".

    8. Build the Virtualizer by following the steps in "docs/01-Usage.txt".

    9. Launch the ARM FastModel by following the steps in "docs/01-Usage.txt".

C   Building and using a root filesystem with ARM FastModels MMC emulation

    1. Build a Linux kernel image for use with the virtualizer by following
       the steps in "docs/03-Linux-kernel-build.txt". Please ensure that the
       kernel is built with MMC support.

    2. A suitable root filesystem can be built using the pre-built root
       filesystem as mentioned under B.

       a. Create the mmc.dat file.
       $ dd if=/dev/zero of=mmc.dat bs=1M count=512

       b. Add /dev/loop<x> as ./mmc.dat and verify which /dev/loop<x> you got.
       $ sudo losetup -f ./mmc.dat
       $ sudo losetup -a

       c. Create an ext<2,3,4> filesystem on mmc.dat
       $ mke2fs -F ./mmc.dat

       d. Create a mountpoint to mount the image on.
       $ sudo mkdir /mnt/devel
       $ sudo mount /dev/loop<x> /mnt/devel

       e. Extract the contents of 'rootfs.tar.gz' into the image
       $ sudo tar zxvf rootfs.tar.gz --preserve \
         --strip-components=3 -C /mnt/devel

       g. Unmount the image and detach mmc.dat with the loop device
       $ sudo umount /mnt/devel
       $ sudo losetup -d /dev/loop<x>

    3. Modify the kernel command line to support the MMC image. This is done
       by indicating the filesystem location to the kernel via the kernel
       command-line arguments. Append 'root=/dev/mmcblk0' (for a single
       partition MMC image) to the argument list. To make this modification,
       edit the file bootwrapper/Makefile and change the BOOTARGS
       specification from:

       BOOTARGS=mem=255M console=ttyAMA0,115200 migration_cost=500
       cachepolicy=writealloc

       to

       BOOTARGS=root=/dev/mmcblk0 mem=255M console=ttyAMA0,115200
       migration_cost=500 cachepolicy=writealloc

    4. Build the Virtualizer by following the steps in "docs/01-Usage.txt".
       Please ensure that the 'bootwrapper/payload/fsimg' filesystem image
       is replaced by an empty file.

    5. The ARM FastModel mxscript needs modification to get the FastModel
       to use the mmc.img file created in step C above with the MMC emulation.
       To make this change uncomment the 'string mmcimage=' line and provide
       the complete path to the mmc.img file generated in step 2 above.

    6. Launch the ARM FastModel by following the steps in "docs/01-Usage.txt".

D   Known limitations

    None.