Merge lp:~tony-mansson/linaro-image-tools/snowball-support into lp:linaro-image-tools/11.11
- snowball-support
- Merge into trunk
Status: | Merged |
---|---|
Merged at revision: | 339 |
Proposed branch: | lp:~tony-mansson/linaro-image-tools/snowball-support |
Merge into: | lp:linaro-image-tools/11.11 |
Diff against target: |
213 lines (+171/-0) 2 files modified
linaro_image_tools/media_create/boards.py (+132/-0) linaro_image_tools/media_create/tests/test_media_create.py (+39/-0) |
To merge this branch: | bzr merge lp:~tony-mansson/linaro-image-tools/snowball-support |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
linaro-image-tools maintainers | Pending | ||
Review via email: mp+60924@code.launchpad.net |
Commit message
Description of the change
This is initial support for snowball
Loïc Minier (lool) wrote : | # |
Loïc Minier (lool) wrote : | # |
It would be nice to have more descriptive names for the flags rather than "flag"
Loïc Minier (lool) wrote : | # |
The dev/BoardConfig names should be tweaked a bit; perhaps "SnowballSdConfig" and "SnowballEmmcCo
LOADER_START_S should be renamed to SNOWBALL_
Mattias Backman (mabac) wrote : | # |
In f2f meeting Friday last week Loïc and Tony agreed that the options --mmc and '--dev snowball' cannot be used together. Code to block that should be added.
Mattias Backman (mabac) wrote : | # |
> It would be nice to have more descriptive names for the flags rather than
> "flag"
Here's the spec. http://
create_toc() writes the toc as:
data = struct.
Seems like 'flags' in the toc according to the spec is set to 0 while 'flag' is written to the toc fields align and load_address.
Mattias Backman (mabac) wrote : | # |
I suggest we consider this superseeded by https:/
Preview Diff
1 | === modified file 'linaro_image_tools/media_create/boards.py' |
2 | --- linaro_image_tools/media_create/boards.py 2011-04-26 16:37:19 +0000 |
3 | +++ linaro_image_tools/media_create/boards.py 2011-05-13 14:11:44 +0000 |
4 | @@ -495,6 +495,136 @@ |
5 | make_boot_script(boot_env, boot_script_path) |
6 | |
7 | |
8 | +class SnowballSdcardConfig(Ux500Config): |
9 | + '''Use only with --mmc option. Creates the standard vfat and ext2 |
10 | + partitions for kernel and rootfs on an SD card. |
11 | + Note that the Snowball board needs a loader partition on the |
12 | + internal eMMC flash to boot. That partition is created with |
13 | + the SnowballConfigImage configuration.''' |
14 | + |
15 | + @classmethod |
16 | + def _make_boot_files(cls, boot_env, chroot_dir, boot_dir, |
17 | + boot_device_or_file, k_img_data, i_img_data, |
18 | + d_img_data): |
19 | + make_uImage(cls.load_addr, k_img_data, boot_dir) |
20 | + boot_script_path = os.path.join(boot_dir, cls.boot_script) |
21 | + make_boot_script(boot_env, boot_script_path) |
22 | + |
23 | + |
24 | +class SnowballImageConfig(SnowballSdcardConfig): |
25 | + '''Use only with --image option. Creates a raw image which contains an |
26 | + additional (raw) loader partition, containing some boot stages |
27 | + and u-boot.''' |
28 | + # Boot ROM looks for a boot table of contents (TOC) at 0x20000 |
29 | + # Actually, it first looks at address 0, but that's where l-m-c |
30 | + # puts the MBR, so the boot loader skips that address. |
31 | + LOADER_START_S = (128 * 1024) / SECTOR_SIZE |
32 | + |
33 | + @classmethod |
34 | + def get_sfdisk_cmd(cls, should_align_boot_part=None): |
35 | + """Return the sfdisk command to partition the media. |
36 | + |
37 | + :param should_align_boot_part: Ignored. |
38 | + |
39 | + The Snowball partitioning scheme depends on whether the target is |
40 | + a raw image or an SD card. Both targets have the normal |
41 | + FAT 32 boot partition and EXT? root partition. |
42 | + The raw image prepends these two partitions with a raw loader partition, |
43 | + containing HW-dependent boot stages up to and including u-boot. |
44 | + This is done since the boot rom always boots off the internal memory; |
45 | + there simply is no point to having a loader partition on SD card. |
46 | + """ |
47 | + # boot ROM expects bootloader at 0x20000, which is sector 0x100 |
48 | + # with the usual SECTOR_SIZE of 0x200. |
49 | + # (sector 0 is MBR / partition table) |
50 | + loader_start, loader_end, loader_len = align_partition( |
51 | + SnowballImageConfig.LOADER_START_S, |
52 | + LOADER_MIN_SIZE_S, 1, PART_ALIGN_S) |
53 | + |
54 | + boot_start, boot_end, boot_len = align_partition( |
55 | + loader_end + 1, BOOT_MIN_SIZE_S, PART_ALIGN_S, PART_ALIGN_S) |
56 | + # we ignore _root_end / _root_len and return an sfdisk command to |
57 | + # instruct the use of all remaining space; XXX if we had some root size |
58 | + # config, we could do something more sensible |
59 | + root_start, _root_end, _root_len = align_partition( |
60 | + boot_end + 1, ROOT_MIN_SIZE_S, PART_ALIGN_S, PART_ALIGN_S) |
61 | + |
62 | + return '%s,%s,0xDA\n%s,%s,0x0C,*\n%s,,,-' % ( |
63 | + loader_start, loader_len, boot_start, boot_len, root_start) |
64 | + |
65 | + |
66 | + @classmethod |
67 | + def _make_boot_files(cls, boot_env, chroot_dir, boot_dir, |
68 | + boot_device_or_file, k_img_data, i_img_data, |
69 | + d_img_data): |
70 | + make_uImage(cls.load_addr, k_img_data, boot_dir) |
71 | + boot_script_path = os.path.join(boot_dir, cls.boot_script) |
72 | + make_boot_script(boot_env, boot_script_path) |
73 | + toc_filename = 'toc.bin' |
74 | + # Adresses are relative the toc at 0x20000 |
75 | + files = [('ISSW', 'boot_image_issw.bin', -1, 0, 0), |
76 | + ('X-LOADER', 'boot_image_x-loader.bin', -1, 0, 0), |
77 | + ('MEM_INIT', 'mem_init.bin', 0, 0x160000, 0), |
78 | + ('PWR_MGT', 'power_management.bin', 0, 0x170000, 0), |
79 | + ('NORMAL', 'u-boot.bin', 0, 0xBA0000, 0), |
80 | + ('UBOOT_ENV', 'u-boot-env.bin', 0, 0x00C1F000, 0)] |
81 | + config_files_path = os.path.join(chroot_dir, 'boot') |
82 | + new_files = get_file_info(config_files_path, files) |
83 | + with open(toc_filename, 'wb') as toc: |
84 | + create_toc(toc, new_files) |
85 | + install_snowball_boot_loader(toc_filename, new_files, |
86 | + boot_device_or_file, cls.LOADER_START_S) |
87 | + os.remove(toc_filename) |
88 | + |
89 | + |
90 | + |
91 | +def install_snowball_boot_loader(toc_file_name, files, |
92 | + boot_device_or_file, start_sector): |
93 | + ''' Copies TOC and boot files into the boot partition. |
94 | + A sector size of 1 is used for some files, as they do not |
95 | + necessarily start on an even address. ''' |
96 | + _dd(toc_file_name, boot_device_or_file, seek=start_sector) |
97 | + for item in files: |
98 | + section, filename, dummy_flag, offset, size = item |
99 | + if (offset % SECTOR_SIZE) != 0: |
100 | + seek_bytes = start_sector * SECTOR_SIZE + offset |
101 | + _dd(filename, boot_device_or_file, block_size=1, seek=seek_bytes) |
102 | + else: |
103 | + seek_sectors = start_sector + offset/SECTOR_SIZE |
104 | + _dd(filename, boot_device_or_file, seek=seek_sectors) |
105 | + |
106 | + |
107 | +def create_toc(f, files): |
108 | + ''' Writes a table of contents of the boot binaries. |
109 | + Boot rom searches this table to find the binaries.''' |
110 | + for item in files: |
111 | + section, filename, flag, address, size = item |
112 | + data = struct.pack('<IIIii12s', |
113 | + address, |
114 | + size, |
115 | + 0, flag, flag, |
116 | + section) |
117 | + f.write(data) |
118 | + |
119 | + |
120 | +def get_file_info(bin_dir, files): |
121 | + ''' Fills in the offsets of files that are located in |
122 | + non-absolute memory locations depending on their sizes.' |
123 | + Also fills in file sizes''' |
124 | + toc_size = 512 |
125 | + ofs = toc_size |
126 | + for i in range(len(files)): |
127 | + section, filename, flag, address, sz = files[i] |
128 | + filename = os.path.join(bin_dir, filename) |
129 | + if address != 0: |
130 | + ofs = address |
131 | + size = os.path.getsize(filename) |
132 | + files[i] = section, filename, flag, ofs, size |
133 | + ofs += size |
134 | + return files |
135 | + |
136 | + |
137 | + |
138 | class Mx5Config(BoardConfig): |
139 | serial_tty = 'ttymxc0' |
140 | extra_serial_opts = 'console=tty0 console=%s,115200n8' % serial_tty |
141 | @@ -687,6 +817,8 @@ |
142 | 'panda': PandaConfig, |
143 | 'vexpress': VexpressConfig, |
144 | 'ux500': Ux500Config, |
145 | + 'snowball_sdcard': SnowballSdcardConfig, |
146 | + 'snowball_image': SnowballImageConfig, |
147 | 'efikamx': EfikamxConfig, |
148 | 'efikasb': EfikasbConfig, |
149 | 'mx51evk': Mx51evkConfig, |
150 | |
151 | === modified file 'linaro_image_tools/media_create/tests/test_media_create.py' |
152 | --- linaro_image_tools/media_create/tests/test_media_create.py 2011-05-10 15:05:57 +0000 |
153 | +++ linaro_image_tools/media_create/tests/test_media_create.py 2011-05-13 14:11:44 +0000 |
154 | @@ -213,6 +213,18 @@ |
155 | expected = ['make_uImage', 'make_uInitrd', 'make_boot_script'] |
156 | self.assertEqual(expected, self.funcs_calls) |
157 | |
158 | + def test_snowball_sdcard_steps(self): |
159 | + self.make_boot_files(boards.SnowballSdcardConfig) |
160 | + expected = ['make_uImage', 'make_boot_script'] |
161 | + self.assertEqual(expected, self.funcs_calls) |
162 | + |
163 | + def test_snowball_image_steps(self): |
164 | + self.make_boot_files(boards.SnowballImageConfig) |
165 | + expected = ['make_uImage', 'make_boot_script', |
166 | + 'get_file_info', 'create_toc', |
167 | + 'install_snowball_boot_loader'] |
168 | + self.assertEqual(expected, self.funcs_calls) |
169 | + |
170 | def test_panda_steps(self): |
171 | self.mock_set_appropriate_serial_tty(boards.PandaConfig) |
172 | self.make_boot_files(boards.PandaConfig) |
173 | @@ -330,6 +342,16 @@ |
174 | '1,8191,0xDA\n8192,106496,0x0C,*\n114688,,,-', |
175 | boards.Mx5Config.get_sfdisk_cmd()) |
176 | |
177 | + def test_snowball_sdcard(self): |
178 | + self.assertEqual( |
179 | + '63,106432,0x0C,*\n106496,,,-', |
180 | + boards.SnowballSdcardConfig.get_sfdisk_cmd()) |
181 | + |
182 | + def test_snowball_image(self): |
183 | + self.assertEqual( |
184 | + '256,7936,0xDA\n8192,106496,0x0C,*\n114688,,,-', |
185 | + boards.SnowballImageConfig.get_sfdisk_cmd()) |
186 | + |
187 | def test_smdkv310(self): |
188 | self.assertEquals( |
189 | '1,8191,0xDA\n8192,106496,0x0C,*\n114688,,,-', |
190 | @@ -393,6 +415,23 @@ |
191 | 'bootm 0x00100000 0x08000000'} |
192 | self.assertEqual(expected, boot_commands) |
193 | |
194 | + def test_snowball_image(self): |
195 | + boot_commands = board_configs['snowball_image']._get_boot_env( |
196 | + is_live=False, is_lowmem=False, consoles=[], |
197 | + rootfs_uuid="deadbeef", d_img_data=None) |
198 | + expected = { |
199 | + 'bootargs': 'console=tty0 console=ttyAMA2,115200n8 ' |
200 | + 'root=UUID=deadbeef rootwait ro earlyprintk ' |
201 | + 'rootdelay=1 fixrtc nocompcache mem=96M@0 ' |
202 | + 'mem_modem=32M@96M mem=44M@128M pmem=22M@172M ' |
203 | + 'mem=30M@194M mem_mali=32M@224M pmem_hwb=54M@256M ' |
204 | + 'hwmem=48M@302M mem=152M@360M', |
205 | + 'bootcmd': 'fatload mmc 1:1 0x00100000 uImage; ' |
206 | + 'fatload mmc 1:1 0x08000000 uInitrd; ' |
207 | + 'bootm 0x00100000 0x08000000'} |
208 | + self.assertEqual(expected, boot_commands) |
209 | + |
210 | + |
211 | def test_panda(self): |
212 | # XXX: To fix bug 697824 we have to change class attributes of our |
213 | # OMAP board configs, and some tests do that so to make sure they |
We should move to some file.txt format which lists the "magic" values like filenames to read from, and all the other TOC contents; something like: x-loader. bin -1 0 0 t.bin 0 0x170000 0
foo.txt:
# name, relative file path, address, flag?, flag?
ISSW boot_image_issw.bin -1 0 0
X-LOADER boot_image_
MEM_INIT mem_init.bin 0 0x160000 0
PWR_MGT power_managemen
NORMAL u-boot.bin 0 0xBA0000 0
UBOOT_ENV u-boot-env.bin 0 0x00C1F000 0
then we'd add a linaro-media-create --snowball- toc-contents flag which would read that file