tar working
This commit is contained in:
parent
47dd3676bb
commit
dd825149d9
2
Makefile
2
Makefile
@ -26,6 +26,8 @@ LIBS =
|
|||||||
|
|
||||||
LD_FLAGS += $(addprefix -L,$(EXTRA_LIB_DIR))
|
LD_FLAGS += $(addprefix -L,$(EXTRA_LIB_DIR))
|
||||||
|
|
||||||
|
LD_FLAGS += -lm
|
||||||
|
|
||||||
ifneq "$(findstring $(MAKECMDGOALS), build_unit_test exec_unit_test coverage)" ""
|
ifneq "$(findstring $(MAKECMDGOALS), build_unit_test exec_unit_test coverage)" ""
|
||||||
INCLUDES += test/inc
|
INCLUDES += test/inc
|
||||||
C_FLAGS += --coverage
|
C_FLAGS += --coverage
|
||||||
|
90
inc/gpio.h
90
inc/gpio.h
@ -1,90 +0,0 @@
|
|||||||
/*****************************************************************************
|
|
||||||
Copyright 2016 Broadcom Limited. All rights reserved.
|
|
||||||
|
|
||||||
This program is the proprietary software of Broadcom Limited and/or its
|
|
||||||
licensors, and may only be used, duplicated, modified or distributed pursuant
|
|
||||||
to the terms and conditions of a separate, written license agreement executed
|
|
||||||
between you and Broadcom (an "Authorized License").
|
|
||||||
|
|
||||||
Except as set forth in an Authorized License, Broadcom grants no license
|
|
||||||
(express or implied), right to use, or waiver of any kind with respect to the
|
|
||||||
Software, and Broadcom expressly reserves all rights in and to the Software
|
|
||||||
and all intellectual property rights therein. IF YOU HAVE NO AUTHORIZED
|
|
||||||
LICENSE, THEN YOU HAVE NO RIGHT TO USE THIS SOFTWARE IN ANY WAY, AND SHOULD
|
|
||||||
IMMEDIATELY NOTIFY BROADCOM AND DISCONTINUE ALL USE OF THE SOFTWARE.
|
|
||||||
|
|
||||||
Except as expressly set forth in the Authorized License,
|
|
||||||
1. This program, including its structure, sequence and organization,
|
|
||||||
constitutes the valuable trade secrets of Broadcom, and you shall use all
|
|
||||||
reasonable efforts to protect the confidentiality thereof, and to use this
|
|
||||||
information only in connection with your use of Broadcom integrated
|
|
||||||
circuit products.
|
|
||||||
|
|
||||||
2. TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS"
|
|
||||||
AND WITH ALL FAULTS AND BROADCOM MAKES NO PROMISES, REPRESENTATIONS OR
|
|
||||||
WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH RESPECT
|
|
||||||
TO THE SOFTWARE. BROADCOM SPECIFICALLY DISCLAIMS ANY AND ALL IMPLIED
|
|
||||||
WARRANTIES OF TITLE, MERCHANTABILITY, NONINFRINGEMENT, FITNESS FOR A
|
|
||||||
PARTICULAR PURPOSE, LACK OF VIRUSES, ACCURACY OR COMPLETENESS,
|
|
||||||
QUIET ENJOYMENT, QUIET POSSESSION OR CORRESPONDENCE TO DESCRIPTION.
|
|
||||||
YOU ASSUME THE ENTIRE RISK ARISING OUT OF USE OR PERFORMANCE OF THE
|
|
||||||
SOFTWARE.
|
|
||||||
|
|
||||||
3. TO THE MAXIMUM EXTENT PERMITTED BY LAW, IN NO EVENT SHALL BROADCOM OR ITS
|
|
||||||
LICENSORS BE LIABLE FOR (i) CONSEQUENTIAL, INCIDENTAL, SPECIAL, INDIRECT,
|
|
||||||
OR EXEMPLARY DAMAGES WHATSOEVER ARISING OUT OF OR IN ANY WAY RELATING TO
|
|
||||||
YOUR USE OF OR INABILITY TO USE THE SOFTWARE EVEN IF BROADCOM HAS BEEN
|
|
||||||
ADVISED OF THE POSSIBILITY OF SUCH DAMAGES; OR (ii) ANY AMOUNT IN EXCESS
|
|
||||||
OF THE AMOUNT ACTUALLY PAID FOR THE SOFTWARE ITSELF OR U.S. $1, WHICHEVER
|
|
||||||
IS GREATER. THESE LIMITATIONS SHALL APPLY NOTWITHSTANDING ANY FAILURE OF
|
|
||||||
ESSENTIAL PURPOSE OF ANY LIMITED REMEDY.
|
|
||||||
******************************************************************************/
|
|
||||||
#ifndef GPIO_H
|
|
||||||
#define GPIO_H
|
|
||||||
|
|
||||||
#define GPIO_ENABLE 0x1
|
|
||||||
#define GPIO_DISABLE 0x0
|
|
||||||
|
|
||||||
#define GPIO_DRV_EN 0x1
|
|
||||||
#define GPIO_DRV_DIS 0x0
|
|
||||||
|
|
||||||
#define GPIO_SET_1 0x1
|
|
||||||
#define GPIO_SET_0 0x0
|
|
||||||
|
|
||||||
typedef enum {
|
|
||||||
GIO_GROUP_0,
|
|
||||||
GIO_GROUP_1,
|
|
||||||
GIO_GROUP_2,
|
|
||||||
} gio_group;
|
|
||||||
|
|
||||||
typedef enum {
|
|
||||||
FLASH_CS_FUNC_CS,
|
|
||||||
FLASH_CS_FUNC_GPIO,
|
|
||||||
} flash_cs_mux;
|
|
||||||
|
|
||||||
typedef enum {
|
|
||||||
GPIO_PIN_0 = 0x1 << 0,
|
|
||||||
GPIO_PIN_1 = 0x1 << 1,
|
|
||||||
GPIO_PIN_2 = 0x1 << 2,
|
|
||||||
GPIO_PIN_3 = 0x1 << 3,
|
|
||||||
} gpio_pin;
|
|
||||||
|
|
||||||
#define GPIO_PIN_ALL (GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3)
|
|
||||||
|
|
||||||
typedef enum {
|
|
||||||
STRAP_PIN_QSPI,
|
|
||||||
} strap_pin;
|
|
||||||
|
|
||||||
|
|
||||||
/* prototypes */
|
|
||||||
extern void gpio_config_output(gio_group grp, int pin);
|
|
||||||
extern void gpio_config_input(gio_group grp, int pin);
|
|
||||||
extern void gpio_set(gio_group grp, int pin, int val);
|
|
||||||
extern int gpio_get(gio_group grp, int pin);
|
|
||||||
|
|
||||||
extern void gpio_flash_cs_din_en(int enable);
|
|
||||||
extern void gpio_flash_cs_dout_en(int enable);
|
|
||||||
extern void gpio_flash_cs_oe_en(int enable);
|
|
||||||
extern void gpio_flash_mux_sel(flash_cs_mux mux);
|
|
||||||
|
|
||||||
#endif /* GPIO_H */
|
|
89
inc/io.h
89
inc/io.h
@ -1,89 +0,0 @@
|
|||||||
/*****************************************************************************
|
|
||||||
Copyright 2016 Broadcom Limited. All rights reserved.
|
|
||||||
|
|
||||||
This program is the proprietary software of Broadcom Limited and/or its
|
|
||||||
licensors, and may only be used, duplicated, modified or distributed pursuant
|
|
||||||
to the terms and conditions of a separate, written license agreement executed
|
|
||||||
between you and Broadcom (an "Authorized License").
|
|
||||||
|
|
||||||
Except as set forth in an Authorized License, Broadcom grants no license
|
|
||||||
(express or implied), right to use, or waiver of any kind with respect to the
|
|
||||||
Software, and Broadcom expressly reserves all rights in and to the Software
|
|
||||||
and all intellectual property rights therein. IF YOU HAVE NO AUTHORIZED
|
|
||||||
LICENSE, THEN YOU HAVE NO RIGHT TO USE THIS SOFTWARE IN ANY WAY, AND SHOULD
|
|
||||||
IMMEDIATELY NOTIFY BROADCOM AND DISCONTINUE ALL USE OF THE SOFTWARE.
|
|
||||||
|
|
||||||
Except as expressly set forth in the Authorized License,
|
|
||||||
1. This program, including its structure, sequence and organization,
|
|
||||||
constitutes the valuable trade secrets of Broadcom, and you shall use all
|
|
||||||
reasonable efforts to protect the confidentiality thereof, and to use this
|
|
||||||
information only in connection with your use of Broadcom integrated
|
|
||||||
circuit products.
|
|
||||||
|
|
||||||
2. TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS"
|
|
||||||
AND WITH ALL FAULTS AND BROADCOM MAKES NO PROMISES, REPRESENTATIONS OR
|
|
||||||
WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH RESPECT
|
|
||||||
TO THE SOFTWARE. BROADCOM SPECIFICALLY DISCLAIMS ANY AND ALL IMPLIED
|
|
||||||
WARRANTIES OF TITLE, MERCHANTABILITY, NONINFRINGEMENT, FITNESS FOR A
|
|
||||||
PARTICULAR PURPOSE, LACK OF VIRUSES, ACCURACY OR COMPLETENESS,
|
|
||||||
QUIET ENJOYMENT, QUIET POSSESSION OR CORRESPONDENCE TO DESCRIPTION.
|
|
||||||
YOU ASSUME THE ENTIRE RISK ARISING OUT OF USE OR PERFORMANCE OF THE
|
|
||||||
SOFTWARE.
|
|
||||||
|
|
||||||
3. TO THE MAXIMUM EXTENT PERMITTED BY LAW, IN NO EVENT SHALL BROADCOM OR ITS
|
|
||||||
LICENSORS BE LIABLE FOR (i) CONSEQUENTIAL, INCIDENTAL, SPECIAL, INDIRECT,
|
|
||||||
OR EXEMPLARY DAMAGES WHATSOEVER ARISING OUT OF OR IN ANY WAY RELATING TO
|
|
||||||
YOUR USE OF OR INABILITY TO USE THE SOFTWARE EVEN IF BROADCOM HAS BEEN
|
|
||||||
ADVISED OF THE POSSIBILITY OF SUCH DAMAGES; OR (ii) ANY AMOUNT IN EXCESS
|
|
||||||
OF THE AMOUNT ACTUALLY PAID FOR THE SOFTWARE ITSELF OR U.S. $1, WHICHEVER
|
|
||||||
IS GREATER. THESE LIMITATIONS SHALL APPLY NOTWITHSTANDING ANY FAILURE OF
|
|
||||||
ESSENTIAL PURPOSE OF ANY LIMITED REMEDY.
|
|
||||||
******************************************************************************/
|
|
||||||
#ifndef IO_H
|
|
||||||
#define IO_H
|
|
||||||
|
|
||||||
/* Includes */
|
|
||||||
#include <stdint.h>
|
|
||||||
|
|
||||||
/* macros */
|
|
||||||
|
|
||||||
/* 64 bit */
|
|
||||||
/*---------------TBD----------------------*/
|
|
||||||
#define read64(addr) 0 /*--TBD--*/
|
|
||||||
#define write64(addr, msw, lsw)
|
|
||||||
|
|
||||||
/* 32 bit */
|
|
||||||
#define readl(addr) \
|
|
||||||
(*((const volatile uint32_t *) (addr)))
|
|
||||||
|
|
||||||
#define writel(addr, val) \
|
|
||||||
(*((volatile uint32_t *) (addr)) = (uint32_t)(val))
|
|
||||||
|
|
||||||
/* 16 bit */
|
|
||||||
|
|
||||||
#define readw(addr) \
|
|
||||||
(*((const volatile uint16_t *) (addr)))
|
|
||||||
|
|
||||||
#define writew(addr, val) \
|
|
||||||
(*((volatile uint16_t *) (addr)) = (uint16_t)(val))
|
|
||||||
|
|
||||||
|
|
||||||
/* 8-bit */
|
|
||||||
#define readb(addr) \
|
|
||||||
(*((const volatile uint8_t *) (addr)))
|
|
||||||
|
|
||||||
#define writeb(addr, val) \
|
|
||||||
(*((volatile uint8_t *) (addr)) = (uint8_t)(val))
|
|
||||||
|
|
||||||
|
|
||||||
/* Wrappers */
|
|
||||||
#define reg_read64(addr) read64(addr)
|
|
||||||
#define reg_write64(addr, msw, lsw) write64(addr, msw, lsw)
|
|
||||||
#define reg_read32(addr) readl(addr)
|
|
||||||
#define reg_write32(addr, val) writel(addr, val)
|
|
||||||
#define reg_read16(addr) readw(addr)
|
|
||||||
#define reg_write16(addr, val) writew(addr, val)
|
|
||||||
#define reg_read8(addr) readb(addr)
|
|
||||||
#define reg_write8(addr, val) writeb(addr, val)
|
|
||||||
|
|
||||||
#endif /* IO_H */
|
|
198819
inc/sysmap.h
198819
inc/sysmap.h
File diff suppressed because it is too large
Load Diff
131
src/main.c
131
src/main.c
@ -1,9 +1,136 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <tar.h>
|
||||||
|
#include <assert.h>
|
||||||
|
|
||||||
|
#define ASCII_TO_NUMBER(num) ((num) - 48) //Converts an ascii digit to the corresponding number
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
#define TAR_FILE "test.tar"
|
||||||
|
#define BLOCK_SIZE 512
|
||||||
|
#define TAR_FILE_HEADER 512
|
||||||
|
struct tar_file_header {
|
||||||
|
char filename[100];
|
||||||
|
char mode[8];
|
||||||
|
char uid[8];
|
||||||
|
char gid[8];
|
||||||
|
char file_size[12];
|
||||||
|
char last_modification[12];
|
||||||
|
char checksum[8];
|
||||||
|
char type_flag;
|
||||||
|
char linked_file_name[100];
|
||||||
|
char ustar_indicator[6];
|
||||||
|
char ustar_version[2];
|
||||||
|
char owner_user_name[32];
|
||||||
|
char owner_group_name[32];
|
||||||
|
char device_major_number[8];
|
||||||
|
char device_minor_number[8];
|
||||||
|
char filename_prefix[155];
|
||||||
|
char padding[12];
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Decode a TAR octal number.
|
||||||
|
* Ignores everything after the first NUL or space character.
|
||||||
|
* @param data A pointer to a size-byte-long octal-encoded
|
||||||
|
* @param size The size of the field pointer to by the data pointer
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
static uint64_t decode_tar_octal(char* data, size_t size)
|
||||||
{
|
{
|
||||||
printf("Hello world.\n");
|
unsigned char *current_ptr = (unsigned char *) data + size;
|
||||||
|
uint64_t sum = 0;
|
||||||
|
uint64_t current_multiplier = 1;
|
||||||
|
|
||||||
|
// Skip everything after the last NUL/space character
|
||||||
|
// In some TAR archives the size field has non-trailing NULs/spaces, so
|
||||||
|
// thisis neccessary.
|
||||||
|
unsigned char* check_ptr = current_ptr; //This is used to check where the last NUL/space char is
|
||||||
|
for(; check_ptr >= (unsigned char *) data; --check_ptr) {
|
||||||
|
if((*check_ptr) == 0 || (*check_ptr) == ' ') {
|
||||||
|
current_ptr = check_ptr - 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for(; current_ptr >= (unsigned char *) data; --current_ptr) {
|
||||||
|
sum += ASCII_TO_NUMBER(*current_ptr) * current_multiplier;
|
||||||
|
current_multiplier *= 8;
|
||||||
|
}
|
||||||
|
return sum;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool check_checksum(struct tar_file_header *tar_header)
|
||||||
|
{
|
||||||
|
assert(tar_header != NULL);
|
||||||
|
|
||||||
|
char original_checksum[8];
|
||||||
|
memcpy(original_checksum, tar_header->checksum, 8);
|
||||||
|
memset(tar_header->checksum, ' ', 8);
|
||||||
|
|
||||||
|
int64_t unsigned_sum = 0;
|
||||||
|
int64_t signed_sum = 0;
|
||||||
|
unsigned char *uc_tar = (unsigned char *)tar_header;
|
||||||
|
signed char *sc_tar = (signed char *)tar_header;
|
||||||
|
for(int i = 0; i < TAR_FILE_HEADER; i++) {
|
||||||
|
unsigned_sum += uc_tar[i];
|
||||||
|
signed_sum += sc_tar[i];
|
||||||
|
}
|
||||||
|
//Copy back the checksum
|
||||||
|
memcpy(tar_header->checksum, original_checksum, 8);
|
||||||
|
//Decode the original checksum
|
||||||
|
uint64_t reference_checksum = decode_tar_octal(original_checksum, sizeof(original_checksum));
|
||||||
|
return (reference_checksum == unsigned_sum || reference_checksum == signed_sum);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
int fd;
|
||||||
|
|
||||||
|
fd = open(TAR_FILE, O_RDONLY);
|
||||||
|
if(fd < 0) {
|
||||||
|
fprintf(stderr, "Unable to open %s\r\n", TAR_FILE);
|
||||||
|
return fd;
|
||||||
|
}
|
||||||
|
|
||||||
|
int res;
|
||||||
|
char block[BLOCK_SIZE];
|
||||||
|
uint64_t read_count = 0, next_tar_header = 0, file_size, tmp, loop_count = 1;
|
||||||
|
do {
|
||||||
|
res = read(fd, block, sizeof(block));
|
||||||
|
if(next_tar_header == read_count) {
|
||||||
|
struct tar_file_header tar_header;
|
||||||
|
if(res != sizeof(tar_header)) {
|
||||||
|
fprintf(stderr, "tar header size wrong\r\n");
|
||||||
|
close(fd);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
memcpy(&tar_header, block, sizeof(tar_header));
|
||||||
|
if(!check_checksum(&tar_header)) {
|
||||||
|
fprintf(stderr, "checksum missmatch\r\n");
|
||||||
|
close(fd);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
file_size = decode_tar_octal(tar_header.file_size, sizeof(tar_header.file_size));
|
||||||
|
printf("%s - size: %lu\r\n", tar_header.filename, file_size);
|
||||||
|
next_tar_header = (file_size / BLOCK_SIZE + 1) * BLOCK_SIZE + loop_count * BLOCK_SIZE;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
for(int i = 0; i < BLOCK_SIZE; i++) {
|
||||||
|
if(block[i] == '\0') {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
printf("%c", block[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
read_count += res;
|
||||||
|
loop_count++;
|
||||||
|
tmp = next_tar_header + ((file_size / BLOCK_SIZE + 1) * BLOCK_SIZE);
|
||||||
|
} while(tmp >= read_count);
|
||||||
|
|
||||||
|
close(fd);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user