Skip to contentSkip to conversation

Patch: new board Socrates Cyclone 5

Buildroot Michał Łyszczek 4 participants 10 messages Jul 30, 2017 – Aug 1, 2017

lore
Share & tools
lore
#0 lore raw

Hi,

This is my first contribution so please correct me if I did something wrong.

I attach patch with new board support - EVB SoCrates based on Altera's Cyclone 5. I had to add a single binary file - preloader.bin. This is uboot based SPL from Altera. Problem with altera is that boot images must be signed with mkpimage tool, that is bundled with Quartus and it is not possible to sign SPL from buildroot. Yes, supposedly there is option in config to create signed SPL, but it doesn't work for none of my Altera's board, hence this binary SPL. Good side is that this SPL loads uboot that is made during compilation, so there is still place for customization and patching if someone needs it.

Signature · 16 lines
Best Regards
?yszczek Micha?
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Added-new-board-EVB-SoCrates-based-on-Altera-Cyclone.patch
Type: text/x-patch
Size: 47132 bytes
Desc: not available
URL: <http://lists.busybox.net/pipermail/buildroot/attachments/20170730/da0e1e48/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 488 bytes
Desc: OpenPGP digital signature
URL: <http://lists.busybox.net/pipermail/buildroot/attachments/20170730/da0e1e48/attachment.asc>
#1 lore raw

Hello,

(Lionel, Jan: see below, there is a question for you.)

Quoted 1 line · Micha? ?yszczek

This is my first contribution so please correct me if I did something wrong.

Could you please resend your patch with "git send-email" so that it is sent as the e-mail body and not as attachment? This will make reviewing the patch a lot easier.

Quoted 9 lines

I attach patch with new board support - EVB SoCrates based on Altera's Cyclone 5. I had to add a single binary file - preloader.bin. This is uboot based SPL from Altera. Problem with altera is that boot images must be signed with mkpimage tool, that is bundled with Quartus and it is not possible to sign SPL from buildroot. Yes, supposedly there is option in config to create signed SPL, but it doesn't work for none of my Altera's board, hence this binary SPL. Good side is that this SPL loads uboot that is made during compilation, so there is still place for customization and patching if someone needs it.

I've added in Cc: Jan and Lionel who added and improved the BR2_TARGET_UBOOT_ALTERA_SOCFPGA_IMAGE_CRC. Hopefully they will have some ideas.

Best regards,

Thomas

Signature · 3 lines
Thomas Petazzoni, CTO, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com
#2 lore raw
Quoted 1 line · Thomas Petazzoni

Hello,

Hi!

Quoted 19 lines

(Lionel, Jan: see below, there is a question for you.)

Quoted 1 line · Micha? ?yszczek

This is my first contribution so please correct me if I did something wrong.

Could you please resend your patch with "git send-email" so that it is sent as the e-mail body and not as attachment? This will make reviewing the patch a lot easier.

Quoted 9 lines

I attach patch with new board support - EVB SoCrates based on Altera's Cyclone 5. I had to add a single binary file - preloader.bin. This is uboot based SPL from Altera. Problem with altera is that boot images must be signed with mkpimage tool, that is bundled with Quartus and it is not possible to sign SPL from buildroot. Yes, supposedly there is option in config to create signed SPL, but it doesn't work for none of my Altera's board, hence this binary SPL. Good side is that this SPL loads uboot that is made during compilation, so there is still place for customization and patching if someone needs it.

What do you mean by "signed" with mkpimage? As far as I know mkpimage can't sign anything, it just puts a simple header before the BIN file and then adds a CRC at the end. Simply looking at the help message of Altera's own mkpimage:

Quoted 28 lines

mkpimage version 16.0 (build 211)

Description: This tool creates an Altera BootROM-compatible image of Second Stage Boot Loader (SSBL). The input and output files are in binary format. It can also decode and check the validity of previously generated image.

Usage:
Create quad image:
mkpimage [options] -hv <num> -o <outfile> <infile> <infile> <infile> <infile>
Create single image:
mkpimage [options] -hv <num> -o <outfile> <infile>
Decode single/quad image:

     mkpimage -d [-a <num>] <infile>

Options:
-a (--alignment) <num> : Address alignment in kilobytes for output image
(64, 128, 256, etc.), default to 64 for header version 0 and 256 for header version 1, override if the NAND flash has a different block size. If outputting a single image, value of '0' is permitted to specify no flash block padding (needed for SSBL image encryption).
-d (--decode) : Flag to decode the header information from
input file and display it
-f (--force) : Flag to force decoding even if the input file
is an unpadded image
-h (--help) : Display this help message and exit
-hv (--header-version) <num> : Header version to be created (Arria/Cyclone V =

Quoted 6 lines
                                0, Arria 10 = 1)

-o (--output) <outfile> : Output file, relative and absolute path
supported
-off (--offset) <num> : Program entry offset relative to start of
header (0x40), default to 0x14. Used for header version 1 only

Buildroot uses barebox's reimplementation in package/mkpimage to have the same functionality. They should generate a valid image for Altera bootloaders (both Arria/Cyclone V and 10).

Now on top of that I know that the Arria 10 supports booting signed and even encrypted images, however I'm not sure if the Cyclone V has this functionality. If it does and your board is configured only to accept signed code maybe that's your problem?

Can I access this preloader.bin somewhere? I could check if there's anything obviously special about it.

Quoted 11 lines

I've added in Cc: Jan and Lionel who added and improved the BR2_TARGET_UBOOT_ALTERA_SOCFPGA_IMAGE_CRC. Hopefully they will have some ideas.

Best regards,

Thomas
--
Thomas Petazzoni, CTO, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com

Signature · 8 lines
Lionel Flandrin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://lists.busybox.net/pipermail/buildroot/attachments/20170801/68f68ca7/attachment.asc>
#3 lore raw

Hello,

Quoted 2 lines · Lionel Flandrin

Can I access this preloader.bin somewhere? I could check if there's anything obviously special about it.

The preloader.bin is part of the patch that Micha? sent:

https://patchwork.ozlabs.org/patch/795350/

And the very reason why I opened up this thread is because it's not great to have pre-built bootloader images in the Buildroot tree.

Best regards,

Thomas

Signature · 3 lines
Thomas Petazzoni, CTO, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com
#4 lore raw
Quoted 10 lines · Thomas Petazzoni

Hello,

Quoted 2 lines · Lionel Flandrin

Can I access this preloader.bin somewhere? I could check if there's anything obviously special about it.

The preloader.bin is part of the patch that Micha? sent:

https://patchwork.ozlabs.org/patch/795350/

Ah, I missed that, thank you for pointing it out.

It's definitely a mkpimage file. A simple way to validate that is to check offset 0x40:

@0x40: [41 53 30 31]     Magic ("AS01")
@0x44: [00]              Version (v0 for Cyclone V)
@0x45: [00]              Flags
@0x46: [48 25]           Program length in words, so 38176B
@0x48: [00 00]           Not used ("spare")
@0x4a: [62 01]           Header checksum

Then at the end of the file you have a 4 byte CRC which I haven't bothered to validate.

So nothing out of the ordinary as far as I can tell. In particular I can't see anything ressembling a cryptographic signature at the beginning or end of the file. Looks like a regular u-boot SPL to me.

I can't really say more about it, I don't have a Cyclone V board at the moment. My advice would be to validate that the SPL generated by u-boot does contain a valid mkpimage header. Since there are no standard extensions (Altera uses ".bin" for everything) it's easy to use the wrong file by mistake. I think buildroot's file should end in ".crc" (the ".bin" generated by u-boot is the raw u-boot binary and can't be used as-is).

There's also the possibility of an error during flashing (truncated file or something similar). If the mkpimage CRC is invalid the ROM will bail out. So make sure you give the correct file size to your flasher.

If everything else fails it should be possible to debug the boot sequence with the JTAG, see if the CPU jumps into the SPL code at some point. If it does then clearly it's the SPL that's bogus, otherwise it's the boot ROM refusing to load it for some reason.

Here are some docs regarding "bare metal" debugging:
https://rocketboards.org/foswiki/view/Documentation/UsingDS5HeadlessDebuggerWithAlteraSoCs

Quoted 2 lines

And the very reason why I opened up this thread is because it's not great to have pre-built bootloader images in the Buildroot tree.

I agree completely.

Quoted 3 lines

Best regards,

Thomas

Signature · 8 lines
Lionel Flandrin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://lists.busybox.net/pipermail/buildroot/attachments/20170801/97ffc01a/attachment.asc>
#5 lore raw
Quoted 27 lines · On Tue, 1 Aug 2017 12:02:48 +0200 Lionel Flandrin <[email protected]> wrote:
Quoted 10 lines · Thomas Petazzoni

Hello,

Quoted 2 lines · Lionel Flandrin

Can I access this preloader.bin somewhere? I could check if there's anything obviously special about it.

The preloader.bin is part of the patch that Micha? sent:

https://patchwork.ozlabs.org/patch/795350/

Ah, I missed that, thank you for pointing it out.

It's definitely a mkpimage file. A simple way to validate that is to check offset 0x40:

@0x40: [41 53 30 31]     Magic ("AS01")
@0x44: [00]              Version (v0 for Cyclone V)
@0x45: [00]              Flags
@0x46: [48 25]           Program length in words, so 38176B
@0x48: [00 00]           Not used ("spare")
@0x4a: [62 01]           Header checksum

Then at the end of the file you have a 4 byte CRC which I haven't bothered to validate.

Quoted 6 lines

So nothing out of the ordinary as far as I can tell. In particular I can't see anything ressembling a cryptographic signature at the beginning or end of the file. Looks like a regular u-boot SPL to me.

I can't really say more about it, I don't have a Cyclone V board at the moment. My advice would be to validate that the SPL generated by

Hi, I've got a Socrates Cyclone V available and so I am able to test. If there are any patches to test, I can probably help.

Regards
Jan

[...]

Quoted 10 lines
Quoted 3 lines

And the very reason why I opened up this thread is because it's not great to have pre-built bootloader images in the Buildroot tree.

I agree completely.

Quoted 3 lines

Best regards,

Thomas

Signature · 4 lines
   Jan Viktorin                  E-mail: Viktorin at RehiveTech.com
   System Architect              Web:    www.RehiveTech.com
   RehiveTech
   Brno, Czech Republic
#6 lore raw

Hello,

Quoted 31 lines · Jan Viktorin
Quoted 31 lines · Thomas Petazzoni
Quoted 10 lines

Hello,

Quoted 2 lines · Lionel Flandrin

Can I access this preloader.bin somewhere? I could check if there's anything obviously special about it.

The preloader.bin is part of the patch that Micha? sent:

https://patchwork.ozlabs.org/patch/795350/

Ah, I missed that, thank you for pointing it out.

It's definitely a mkpimage file. A simple way to validate that is to check offset 0x40:

@0x40: [41 53 30 31]     Magic ("AS01")
@0x44: [00]              Version (v0 for Cyclone V)
@0x45: [00]              Flags
@0x46: [48 25]           Program length in words, so 38176B
@0x48: [00 00]           Not used ("spare")
@0x4a: [62 01]           Header checksum

Then at the end of the file you have a 4 byte CRC which I haven't bothered to validate.

So nothing out of the ordinary as far as I can tell. In particular I can't see anything ressembling a cryptographic signature at the beginning or end of the file. Looks like a regular u-boot SPL to me.

Quoted 5 lines
Quoted 2 lines

I can't really say more about it, I don't have a Cyclone V board at the moment. My advice would be to validate that the SPL generated by

Hi, I've got a Socrates Cyclone V available and so I am able to test. If there are any patches to test, I can probably help.

Micha? original patch is at
https://patchwork.ozlabs.org/patch/795350/, but I dislike having the prebuilt preloader.bin in the Buildroot tree. So if you can get that to work without having a pre-built binary in U-Boot, that'd be great.

Thanks!

Thomas

Signature · 3 lines
Thomas Petazzoni, CTO, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com
#7 lore raw

W dniu 01.08.2017 o 13:21, Thomas Petazzoni pisze:

Quoted 41 lines

Hello,

Quoted 31 lines · Jan Viktorin
Quoted 31 lines · Thomas Petazzoni
Quoted 10 lines

Hello,

Quoted 2 lines · Lionel Flandrin

Can I access this preloader.bin somewhere? I could check if there's anything obviously special about it.

The preloader.bin is part of the patch that Micha? sent:

https://patchwork.ozlabs.org/patch/795350/

Ah, I missed that, thank you for pointing it out.

It's definitely a mkpimage file. A simple way to validate that is to check offset 0x40:

@0x40: [41 53 30 31]     Magic ("AS01")
@0x44: [00]              Version (v0 for Cyclone V)
@0x45: [00]              Flags
@0x46: [48 25]           Program length in words, so 38176B
@0x48: [00 00]           Not used ("spare")
@0x4a: [62 01]           Header checksum

Then at the end of the file you have a 4 byte CRC which I haven't bothered to validate.

So nothing out of the ordinary as far as I can tell. In particular I can't see anything ressembling a cryptographic signature at the beginning or end of the file. Looks like a regular u-boot SPL to me.

Quoted 5 lines
Quoted 2 lines

I can't really say more about it, I don't have a Cyclone V board at the moment. My advice would be to validate that the SPL generated by

Hi, I've got a Socrates Cyclone V available and so I am able to test. If there are any patches to test, I can probably help.

Quoted 9 lines

Micha? original patch is at
https://patchwork.ozlabs.org/patch/795350/, but I dislike having the prebuilt preloader.bin in the Buildroot tree. So if you can get that to work without having a pre-built binary in U-Boot, that'd be great.

Thanks!

Thomas

Hi,

Sorry for confusion, by "signing" I meant using mkpimage to generate header and CRC - no crypto magic here.

I tried flashing with genereted spl.crc but it didn't work, and it looks like board never reaches SPL code - it hangs in boot rom (never reaches code from sd card).

I have investigated it more and tried to compile uboot from altera's git
(https://github.com/altera-opensource/u-boot-socfpga ; tag v2017.07)

And I did:

make socfpga_cyclone5_config
make

I've also created valid mkpimage (using official one from altera), when verifying mkpimage tool reports 4 valid images (all the same). In this scenario cyclone still didn't boot up and hangs in boot rom and never reaches spl code.

Jan Viktorin, you said you have socrates board, did you ever compile spl manually for this board? It looks like I must be missing something.

Any ideas?

Signature · 10 lines
Best Regards
?yszczek Micha?

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 488 bytes
Desc: OpenPGP digital signature
URL: <http://lists.busybox.net/pipermail/buildroot/attachments/20170801/fbd561ae/attachment.asc>
#8 lore raw

W dniu 01.08.2017 o 20:08, Micha? ?yszczek pisze:

Quoted 74 lines

W dniu 01.08.2017 o 13:21, Thomas Petazzoni pisze:

Quoted 41 lines

Hello,

Quoted 31 lines · Jan Viktorin
Quoted 31 lines · Thomas Petazzoni
Quoted 10 lines

Hello,

Quoted 2 lines · Lionel Flandrin

Can I access this preloader.bin somewhere? I could check if there's anything obviously special about it.

The preloader.bin is part of the patch that Micha? sent:

https://patchwork.ozlabs.org/patch/795350/

Ah, I missed that, thank you for pointing it out.

It's definitely a mkpimage file. A simple way to validate that is to check offset 0x40:

@0x40: [41 53 30 31]     Magic ("AS01")
@0x44: [00]              Version (v0 for Cyclone V)
@0x45: [00]              Flags
@0x46: [48 25]           Program length in words, so 38176B
@0x48: [00 00]           Not used ("spare")
@0x4a: [62 01]           Header checksum

Then at the end of the file you have a 4 byte CRC which I haven't bothered to validate.

So nothing out of the ordinary as far as I can tell. In particular I can't see anything ressembling a cryptographic signature at the beginning or end of the file. Looks like a regular u-boot SPL to me.

Quoted 5 lines
Quoted 2 lines

I can't really say more about it, I don't have a Cyclone V board at the moment. My advice would be to validate that the SPL generated by

Hi, I've got a Socrates Cyclone V available and so I am able to test. If there are any patches to test, I can probably help.

Quoted 9 lines

Micha? original patch is at
https://patchwork.ozlabs.org/patch/795350/, but I dislike having the prebuilt preloader.bin in the Buildroot tree. So if you can get that to work without having a pre-built binary in U-Boot, that'd be great.

Thanks!

Thomas

Hi,

Sorry for confusion, by "signing" I meant using mkpimage to generate header and CRC - no crypto magic here.

I tried flashing with genereted spl.crc but it didn't work, and it looks like board never reaches SPL code - it hangs in boot rom (never reaches code from sd card).

I have investigated it more and tried to compile uboot from altera's git
(https://github.com/altera-opensource/u-boot-socfpga ; tag v2017.07)

And I did:

make socfpga_cyclone5_config
make

I've also created valid mkpimage (using official one from altera), when verifying mkpimage tool reports 4 valid images (all the same). In this scenario cyclone still didn't boot up and hangs in boot rom and never reaches spl code.

Quoted 5 lines

Jan Viktorin, you said you have socrates board, did you ever compile spl manually for this board? It looks like I must be missing something.

Any ideas?

Ok, I know what I was missing. My brain. I used socfpga_cyclone5 config while I should have used socfpga_cyclone. So it looks like I can actually post a patch without any binary stuff.

Now question arises. Should I post completly new patch, or somehow modify previous one?

Signature · 11 lines
Z wyrazami szacunku
?yszczek Micha?
+48-727-564-419

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 488 bytes
Desc: OpenPGP digital signature
URL: <http://lists.busybox.net/pipermail/buildroot/attachments/20170801/c0e335e7/attachment.asc>
#9 lore raw

Hello,

Quoted 3 lines · Micha? ?yszczek

Ok, I know what I was missing. My brain. I used socfpga_cyclone5 config while I should have used socfpga_cyclone. So it looks like I can actually post a patch without any binary stuff.

Great!

Quoted 2 lines

Now question arises. Should I post completly new patch, or somehow modify previous one?

Post a completely new patch.

Thanks!

Thomas

Signature · 3 lines
Thomas Petazzoni, CTO, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com