avionic design with actual uboot and tooling
submodule of avionic design uboot bootloader and with included tools to get you started , read readme.md and readme-tk1-loader.md
This commit is contained in:
8
u-boot/fs/zfs/Makefile
Normal file
8
u-boot/fs/zfs/Makefile
Normal file
@@ -0,0 +1,8 @@
|
||||
#
|
||||
# (C) Copyright 2012
|
||||
# Jorgen Lundman <lundman at lundman.net>
|
||||
#
|
||||
# SPDX-License-Identifier: GPL-2.0+
|
||||
#
|
||||
|
||||
obj-y := dev.o zfs.o zfs_fletcher.o zfs_sha256.o zfs_lzjb.o
|
||||
111
u-boot/fs/zfs/dev.c
Normal file
111
u-boot/fs/zfs/dev.c
Normal file
@@ -0,0 +1,111 @@
|
||||
/*
|
||||
*
|
||||
* based on code of fs/reiserfs/dev.c by
|
||||
*
|
||||
* (C) Copyright 2003 - 2004
|
||||
* Sysgo AG, <www.elinos.com>, Pavel Bartusek <pba@sysgo.com>
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-2.0+
|
||||
*/
|
||||
|
||||
|
||||
#include <common.h>
|
||||
#include <config.h>
|
||||
#include <zfs_common.h>
|
||||
|
||||
static struct blk_desc *zfs_blk_desc;
|
||||
static disk_partition_t *part_info;
|
||||
|
||||
void zfs_set_blk_dev(struct blk_desc *rbdd, disk_partition_t *info)
|
||||
{
|
||||
zfs_blk_desc = rbdd;
|
||||
part_info = info;
|
||||
}
|
||||
|
||||
/* err */
|
||||
int zfs_devread(int sector, int byte_offset, int byte_len, char *buf)
|
||||
{
|
||||
short sec_buffer[SECTOR_SIZE/sizeof(short)];
|
||||
char *sec_buf = (char *)sec_buffer;
|
||||
unsigned block_len;
|
||||
|
||||
/*
|
||||
* Check partition boundaries
|
||||
*/
|
||||
if ((sector < 0) ||
|
||||
((sector + ((byte_offset + byte_len - 1) >> SECTOR_BITS)) >=
|
||||
part_info->size)) {
|
||||
/* errnum = ERR_OUTSIDE_PART; */
|
||||
printf(" ** zfs_devread() read outside partition sector %d\n", sector);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Get the read to the beginning of a partition.
|
||||
*/
|
||||
sector += byte_offset >> SECTOR_BITS;
|
||||
byte_offset &= SECTOR_SIZE - 1;
|
||||
|
||||
debug(" <%d, %d, %d>\n", sector, byte_offset, byte_len);
|
||||
|
||||
if (zfs_blk_desc == NULL) {
|
||||
printf("** Invalid Block Device Descriptor (NULL)\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (byte_offset != 0) {
|
||||
/* read first part which isn't aligned with start of sector */
|
||||
if (zfs_blk_desc->block_read(zfs_blk_desc,
|
||||
part_info->start + sector, 1,
|
||||
(void *)sec_buf) != 1) {
|
||||
printf(" ** zfs_devread() read error **\n");
|
||||
return 1;
|
||||
}
|
||||
memcpy(buf, sec_buf + byte_offset,
|
||||
min(SECTOR_SIZE - byte_offset, byte_len));
|
||||
buf += min(SECTOR_SIZE - byte_offset, byte_len);
|
||||
byte_len -= min(SECTOR_SIZE - byte_offset, byte_len);
|
||||
sector++;
|
||||
}
|
||||
|
||||
if (byte_len == 0)
|
||||
return 0;
|
||||
|
||||
/* read sector aligned part */
|
||||
block_len = byte_len & ~(SECTOR_SIZE - 1);
|
||||
|
||||
if (block_len == 0) {
|
||||
u8 p[SECTOR_SIZE];
|
||||
|
||||
block_len = SECTOR_SIZE;
|
||||
zfs_blk_desc->block_read(zfs_blk_desc,
|
||||
part_info->start + sector,
|
||||
1, (void *)p);
|
||||
memcpy(buf, p, byte_len);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (zfs_blk_desc->block_read(zfs_blk_desc, part_info->start + sector,
|
||||
block_len / SECTOR_SIZE,
|
||||
(void *)buf) != block_len / SECTOR_SIZE) {
|
||||
printf(" ** zfs_devread() read error - block\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
block_len = byte_len & ~(SECTOR_SIZE - 1);
|
||||
buf += block_len;
|
||||
byte_len -= block_len;
|
||||
sector += block_len / SECTOR_SIZE;
|
||||
|
||||
if (byte_len != 0) {
|
||||
/* read rest of data which are not in whole sector */
|
||||
if (zfs_blk_desc->block_read(zfs_blk_desc,
|
||||
part_info->start + sector,
|
||||
1, (void *)sec_buf) != 1) {
|
||||
printf(" ** zfs_devread() read error - last part\n");
|
||||
return 1;
|
||||
}
|
||||
memcpy(buf, sec_buf, byte_len);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
2341
u-boot/fs/zfs/zfs.c
Normal file
2341
u-boot/fs/zfs/zfs.c
Normal file
File diff suppressed because it is too large
Load Diff
75
u-boot/fs/zfs/zfs_fletcher.c
Normal file
75
u-boot/fs/zfs/zfs_fletcher.c
Normal file
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
* GRUB -- GRand Unified Bootloader
|
||||
* Copyright (C) 1999,2000,2001,2002,2003,2004 Free Software Foundation, Inc.
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-2.0+
|
||||
*/
|
||||
/*
|
||||
* Copyright 2007 Sun Microsystems, Inc. All rights reserved.
|
||||
* Use is subject to license terms.
|
||||
*/
|
||||
|
||||
#include <common.h>
|
||||
#include <malloc.h>
|
||||
#include <linux/stat.h>
|
||||
#include <linux/time.h>
|
||||
#include <linux/ctype.h>
|
||||
#include <asm/byteorder.h>
|
||||
#include "zfs_common.h"
|
||||
|
||||
#include <zfs/zfs.h>
|
||||
#include <zfs/zio.h>
|
||||
#include <zfs/dnode.h>
|
||||
#include <zfs/uberblock_impl.h>
|
||||
#include <zfs/vdev_impl.h>
|
||||
#include <zfs/zio_checksum.h>
|
||||
#include <zfs/zap_impl.h>
|
||||
#include <zfs/zap_leaf.h>
|
||||
#include <zfs/zfs_znode.h>
|
||||
#include <zfs/dmu.h>
|
||||
#include <zfs/dmu_objset.h>
|
||||
#include <zfs/dsl_dir.h>
|
||||
#include <zfs/dsl_dataset.h>
|
||||
|
||||
void
|
||||
fletcher_2_endian(const void *buf, uint64_t size,
|
||||
zfs_endian_t endian,
|
||||
zio_cksum_t *zcp)
|
||||
{
|
||||
const uint64_t *ip = buf;
|
||||
const uint64_t *ipend = ip + (size / sizeof(uint64_t));
|
||||
uint64_t a0, b0, a1, b1;
|
||||
|
||||
for (a0 = b0 = a1 = b1 = 0; ip < ipend; ip += 2) {
|
||||
a0 += zfs_to_cpu64(ip[0], endian);
|
||||
a1 += zfs_to_cpu64(ip[1], endian);
|
||||
b0 += a0;
|
||||
b1 += a1;
|
||||
}
|
||||
|
||||
zcp->zc_word[0] = cpu_to_zfs64(a0, endian);
|
||||
zcp->zc_word[1] = cpu_to_zfs64(a1, endian);
|
||||
zcp->zc_word[2] = cpu_to_zfs64(b0, endian);
|
||||
zcp->zc_word[3] = cpu_to_zfs64(b1, endian);
|
||||
}
|
||||
|
||||
void
|
||||
fletcher_4_endian(const void *buf, uint64_t size, zfs_endian_t endian,
|
||||
zio_cksum_t *zcp)
|
||||
{
|
||||
const uint32_t *ip = buf;
|
||||
const uint32_t *ipend = ip + (size / sizeof(uint32_t));
|
||||
uint64_t a, b, c, d;
|
||||
|
||||
for (a = b = c = d = 0; ip < ipend; ip++) {
|
||||
a += zfs_to_cpu32(ip[0], endian);
|
||||
b += a;
|
||||
c += b;
|
||||
d += c;
|
||||
}
|
||||
|
||||
zcp->zc_word[0] = cpu_to_zfs64(a, endian);
|
||||
zcp->zc_word[1] = cpu_to_zfs64(b, endian);
|
||||
zcp->zc_word[2] = cpu_to_zfs64(c, endian);
|
||||
zcp->zc_word[3] = cpu_to_zfs64(d, endian);
|
||||
}
|
||||
85
u-boot/fs/zfs/zfs_lzjb.c
Normal file
85
u-boot/fs/zfs/zfs_lzjb.c
Normal file
@@ -0,0 +1,85 @@
|
||||
/*
|
||||
* GRUB -- GRand Unified Bootloader
|
||||
* Copyright (C) 1999,2000,2001,2002,2003,2004 Free Software Foundation, Inc.
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-2.0+
|
||||
*/
|
||||
/*
|
||||
* Copyright 2007 Sun Microsystems, Inc. All rights reserved.
|
||||
* Use is subject to license terms.
|
||||
*/
|
||||
|
||||
#include <common.h>
|
||||
#include <malloc.h>
|
||||
#include <linux/stat.h>
|
||||
#include <linux/time.h>
|
||||
#include <linux/ctype.h>
|
||||
#include <asm/byteorder.h>
|
||||
#include "zfs_common.h"
|
||||
|
||||
#include <zfs/zfs.h>
|
||||
#include <zfs/zio.h>
|
||||
#include <zfs/dnode.h>
|
||||
#include <zfs/uberblock_impl.h>
|
||||
#include <zfs/vdev_impl.h>
|
||||
#include <zfs/zio_checksum.h>
|
||||
#include <zfs/zap_impl.h>
|
||||
#include <zfs/zap_leaf.h>
|
||||
#include <zfs/zfs_znode.h>
|
||||
#include <zfs/dmu.h>
|
||||
#include <zfs/dmu_objset.h>
|
||||
#include <zfs/dsl_dir.h>
|
||||
#include <zfs/dsl_dataset.h>
|
||||
|
||||
#define MATCH_BITS 6
|
||||
#define MATCH_MIN 3
|
||||
#define OFFSET_MASK ((1 << (16 - MATCH_BITS)) - 1)
|
||||
|
||||
/*
|
||||
* Decompression Entry - lzjb
|
||||
*/
|
||||
#ifndef NBBY
|
||||
#define NBBY 8
|
||||
#endif
|
||||
|
||||
int
|
||||
lzjb_decompress(void *s_start, void *d_start, uint32_t s_len,
|
||||
uint32_t d_len)
|
||||
{
|
||||
uint8_t *src = s_start;
|
||||
uint8_t *dst = d_start;
|
||||
uint8_t *d_end = (uint8_t *) d_start + d_len;
|
||||
uint8_t *s_end = (uint8_t *) s_start + s_len;
|
||||
uint8_t *cpy, copymap = 0;
|
||||
int copymask = 1 << (NBBY - 1);
|
||||
|
||||
while (dst < d_end && src < s_end) {
|
||||
if ((copymask <<= 1) == (1 << NBBY)) {
|
||||
copymask = 1;
|
||||
copymap = *src++;
|
||||
}
|
||||
if (src >= s_end) {
|
||||
printf("lzjb decompression failed\n");
|
||||
return ZFS_ERR_BAD_FS;
|
||||
}
|
||||
if (copymap & copymask) {
|
||||
int mlen = (src[0] >> (NBBY - MATCH_BITS)) + MATCH_MIN;
|
||||
int offset = ((src[0] << NBBY) | src[1]) & OFFSET_MASK;
|
||||
src += 2;
|
||||
cpy = dst - offset;
|
||||
if (src > s_end || cpy < (uint8_t *) d_start) {
|
||||
printf("lzjb decompression failed\n");
|
||||
return ZFS_ERR_BAD_FS;
|
||||
}
|
||||
while (--mlen >= 0 && dst < d_end)
|
||||
*dst++ = *cpy++;
|
||||
} else {
|
||||
*dst++ = *src++;
|
||||
}
|
||||
}
|
||||
if (dst < d_end) {
|
||||
printf("lzjb decompression failed\n");
|
||||
return ZFS_ERR_BAD_FS;
|
||||
}
|
||||
return ZFS_ERR_NONE;
|
||||
}
|
||||
136
u-boot/fs/zfs/zfs_sha256.c
Normal file
136
u-boot/fs/zfs/zfs_sha256.c
Normal file
@@ -0,0 +1,136 @@
|
||||
/*
|
||||
* GRUB -- GRand Unified Bootloader
|
||||
* Copyright (C) 1999,2000,2001,2002,2003,2004 Free Software Foundation, Inc.
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-2.0+
|
||||
*/
|
||||
/*
|
||||
* Copyright 2007 Sun Microsystems, Inc. All rights reserved.
|
||||
* Use is subject to license terms.
|
||||
*/
|
||||
|
||||
#include <common.h>
|
||||
#include <malloc.h>
|
||||
#include <linux/stat.h>
|
||||
#include <linux/time.h>
|
||||
#include <linux/ctype.h>
|
||||
#include <asm/byteorder.h>
|
||||
#include "zfs_common.h"
|
||||
|
||||
#include <zfs/zfs.h>
|
||||
#include <zfs/zio.h>
|
||||
#include <zfs/dnode.h>
|
||||
#include <zfs/uberblock_impl.h>
|
||||
#include <zfs/vdev_impl.h>
|
||||
#include <zfs/zio_checksum.h>
|
||||
#include <zfs/zap_impl.h>
|
||||
#include <zfs/zap_leaf.h>
|
||||
#include <zfs/zfs_znode.h>
|
||||
#include <zfs/dmu.h>
|
||||
#include <zfs/dmu_objset.h>
|
||||
#include <zfs/dsl_dir.h>
|
||||
#include <zfs/dsl_dataset.h>
|
||||
|
||||
/*
|
||||
* SHA-256 checksum, as specified in FIPS 180-2, available at:
|
||||
* http://csrc.nist.gov/cryptval
|
||||
*
|
||||
* This is a very compact implementation of SHA-256.
|
||||
* It is designed to be simple and portable, not to be fast.
|
||||
*/
|
||||
|
||||
/*
|
||||
* The literal definitions according to FIPS180-2 would be:
|
||||
*
|
||||
* Ch(x, y, z) (((x) & (y)) ^ ((~(x)) & (z)))
|
||||
* Maj(x, y, z) (((x) & (y)) | ((x) & (z)) | ((y) & (z)))
|
||||
*
|
||||
* We use logical equivalents which require one less op.
|
||||
*/
|
||||
#define Ch(x, y, z) ((z) ^ ((x) & ((y) ^ (z))))
|
||||
#define Maj(x, y, z) (((x) & (y)) ^ ((z) & ((x) ^ (y))))
|
||||
#define Rot32(x, s) (((x) >> s) | ((x) << (32 - s)))
|
||||
#define SIGMA0(x) (Rot32(x, 2) ^ Rot32(x, 13) ^ Rot32(x, 22))
|
||||
#define SIGMA1(x) (Rot32(x, 6) ^ Rot32(x, 11) ^ Rot32(x, 25))
|
||||
#define sigma0(x) (Rot32(x, 7) ^ Rot32(x, 18) ^ ((x) >> 3))
|
||||
#define sigma1(x) (Rot32(x, 17) ^ Rot32(x, 19) ^ ((x) >> 10))
|
||||
|
||||
static const uint32_t SHA256_K[64] = {
|
||||
0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5,
|
||||
0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
|
||||
0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,
|
||||
0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
|
||||
0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc,
|
||||
0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
|
||||
0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7,
|
||||
0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
|
||||
0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,
|
||||
0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
|
||||
0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3,
|
||||
0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
|
||||
0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5,
|
||||
0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
|
||||
0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
|
||||
0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2
|
||||
};
|
||||
|
||||
static void
|
||||
SHA256Transform(uint32_t *H, const uint8_t *cp)
|
||||
{
|
||||
uint32_t a, b, c, d, e, f, g, h, t, T1, T2, W[64];
|
||||
|
||||
for (t = 0; t < 16; t++, cp += 4)
|
||||
W[t] = (cp[0] << 24) | (cp[1] << 16) | (cp[2] << 8) | cp[3];
|
||||
|
||||
for (t = 16; t < 64; t++)
|
||||
W[t] = sigma1(W[t - 2]) + W[t - 7] +
|
||||
sigma0(W[t - 15]) + W[t - 16];
|
||||
|
||||
a = H[0]; b = H[1]; c = H[2]; d = H[3];
|
||||
e = H[4]; f = H[5]; g = H[6]; h = H[7];
|
||||
|
||||
for (t = 0; t < 64; t++) {
|
||||
T1 = h + SIGMA1(e) + Ch(e, f, g) + SHA256_K[t] + W[t];
|
||||
T2 = SIGMA0(a) + Maj(a, b, c);
|
||||
h = g; g = f; f = e; e = d + T1;
|
||||
d = c; c = b; b = a; a = T1 + T2;
|
||||
}
|
||||
|
||||
H[0] += a; H[1] += b; H[2] += c; H[3] += d;
|
||||
H[4] += e; H[5] += f; H[6] += g; H[7] += h;
|
||||
}
|
||||
|
||||
void
|
||||
zio_checksum_SHA256(const void *buf, uint64_t size,
|
||||
zfs_endian_t endian, zio_cksum_t *zcp)
|
||||
{
|
||||
uint32_t H[8] = { 0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a,
|
||||
0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19 };
|
||||
uint8_t pad[128];
|
||||
unsigned padsize = size & 63;
|
||||
unsigned i;
|
||||
|
||||
for (i = 0; i < size - padsize; i += 64)
|
||||
SHA256Transform(H, (uint8_t *)buf + i);
|
||||
|
||||
for (i = 0; i < padsize; i++)
|
||||
pad[i] = ((uint8_t *)buf)[i];
|
||||
|
||||
for (pad[padsize++] = 0x80; (padsize & 63) != 56; padsize++)
|
||||
pad[padsize] = 0;
|
||||
|
||||
for (i = 0; i < 8; i++)
|
||||
pad[padsize++] = (size << 3) >> (56 - 8 * i);
|
||||
|
||||
for (i = 0; i < padsize; i += 64)
|
||||
SHA256Transform(H, pad + i);
|
||||
|
||||
zcp->zc_word[0] = cpu_to_zfs64((uint64_t)H[0] << 32 | H[1],
|
||||
endian);
|
||||
zcp->zc_word[1] = cpu_to_zfs64((uint64_t)H[2] << 32 | H[3],
|
||||
endian);
|
||||
zcp->zc_word[2] = cpu_to_zfs64((uint64_t)H[4] << 32 | H[5],
|
||||
endian);
|
||||
zcp->zc_word[3] = cpu_to_zfs64((uint64_t)H[6] << 32 | H[7],
|
||||
endian);
|
||||
}
|
||||
Reference in New Issue
Block a user