From e54044c5a84431c224a6b41767a3b587f62add8d Mon Sep 17 00:00:00 2001 From: nathael Pajani Date: Tue, 8 Jul 2014 21:25:38 +0200 Subject: [PATCH] Many small modifications for integration into Debian --- LICENCE => LICENSE | 0 Makefile | 6 +++--- README | 14 ++++++++------ isp_commands.c | 18 ++++++++++++++---- isp_commands.h | 20 +++++++++++++++----- isp_utils.c | 16 +++++++++++++--- isp_utils.h | 16 +++++++++++++--- isp_wrapper.c | 16 +++++++++++++--- lpcisp.c | 24 +++++++++++++++++------- lpcprog.1 | 19 +++++++++++-------- lpcprog.c | 22 ++++++++++++++++------ lpctools_parts.def | 4 ++++ parts.c | 18 ++++++++++++++---- parts.h | 18 ++++++++++++++---- prog_commands.c | 16 +++++++++++++--- prog_commands.h | 16 +++++++++++++--- 16 files changed, 181 insertions(+), 62 deletions(-) rename LICENCE => LICENSE (100%) diff --git a/LICENCE b/LICENSE similarity index 100% rename from LICENCE rename to LICENSE diff --git a/Makefile b/Makefile index c1a0004..46c70c2 100644 --- a/Makefile +++ b/Makefile @@ -24,18 +24,18 @@ LPCPROG_OBJS = ${OBJDIR}/lpcprog.o \ lpcisp: $(LPCISP_OBJS) @echo "Linking $@ ..." - @$(CC) $(CFLAGS) $(LPCISP_OBJS) -o $@ + @$(CC) $(LDFLAGS) $(LPCISP_OBJS) -o $@ @echo Done. lpcprog: $(LPCPROG_OBJS) @echo "Linking $@ ..." - @$(CC) $(CFLAGS) $(LPCPROG_OBJS) -o $@ + @$(CC) $(LDFLAGS) $(LPCPROG_OBJS) -o $@ @echo Done. ${OBJDIR}/%.o: %.c @mkdir -p $(dir $@) @echo "-- compiling" $< - @$(CC) -MMD -MP -MF ${OBJDIR}/$*.d $(CFLAGS) $< -c -o $@ + @$(CC) -MMD -MP -MF ${OBJDIR}/$*.d $(CPPFLAGS) $(CFLAGS) $< -c -o $@ clean: diff --git a/README b/README index ffc635d..5bb8319 100644 --- a/README +++ b/README @@ -1,24 +1,24 @@ LPCTools is an interface to NXP LPC Microcontrollers ISP (In-System Programming) serial interface. -It is split in two programms: lpcisp and lpcprog +It is split in two programs: lpcisp and lpcprog * lpcisp: -This tool gives access to each of the usefull isp commands on LPC +This tool gives access to each of the useful isp commands on LPC devices. It does not provide wrappers for flashing a device. * lpcprog: This tool does not give access to each isp command, instead it provides wrappers for flashing a device. -Both programms were originally written by Nathael Pajani - because existing programms were published +Both programs were originally written by Nathael Pajani + because existing programs were published under non-free licences, did not allow comercial use, or did not provide source code. -This programm is released under the terms of the GNU GPLv3 licence +This program is released under the terms of the GNU GPLv3 licence as can be found on the GNU website : -or in the included LICENCE file. +or in the included LICENSE file. ******************** @@ -28,5 +28,7 @@ Allow flashing of parts with flash sectors of different sizes (LPC1764 has 16 small 4k sectors and two big 32k sectors). --> Need to change parts definition format. +Prevent unwanted writting of Code Read Protection values. + Add the definition of all LPC parts ? diff --git a/isp_commands.c b/isp_commands.c index 34c4c28..00a4578 100644 --- a/isp_commands.c +++ b/isp_commands.c @@ -3,10 +3,20 @@ * LPC ISP Commands * * - * Written by Nathael Pajani + * Copyright (C) 2012 Nathael Pajani * - * This programm is released under the terms of the GNU GPLv3 licence - * as can be found on the GNU website : + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . * *********************************************************************/ @@ -634,7 +644,7 @@ int isp_send_cmd_go(uint32_t addr, char mode) } ret = isp_ret_code(buf, NULL, 0); if (ret != 0) { - printf("Error when trying to execute programm at 0x%08x in '%c' mode.\n", addr, mode); + printf("Error when trying to execute program at 0x%08x in '%c' mode.\n", addr, mode); return -1; } diff --git a/isp_commands.h b/isp_commands.h index 095b89a..42e3224 100644 --- a/isp_commands.h +++ b/isp_commands.h @@ -3,10 +3,20 @@ * LPC ISP Commands * * - * Written by Nathael Pajani + * Copyright (C) 2012 Nathael Pajani * - * This programm is released under the terms of the GNU GPLv3 licence - * as can be found on the GNU website : + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . * *********************************************************************/ @@ -93,12 +103,12 @@ int isp_cmd_copy_ram_to_flash(int arg_count, char** args); /* * go * aruments : address mode - * execute programm at 'address' (> 0x200) in 'mode' ('arm' or 'thumb') + * execute program at 'address' (> 0x200) in 'mode' ('arm' or 'thumb') */ int isp_cmd_go(int arg_count, char** args); /* * perform go operation - * start user programm at 'addr' in 'mode' + * start user program at 'addr' in 'mode' * mode is 'T' for thumb or 'A' for arm. */ int isp_send_cmd_go(uint32_t addr, char mode); diff --git a/isp_utils.c b/isp_utils.c index 8f844ed..b850eb9 100644 --- a/isp_utils.c +++ b/isp_utils.c @@ -3,10 +3,20 @@ * LPC ISP - Utility functions * * - * Written by Nathael Pajani + * Copyright (C) 2012 Nathael Pajani * - * This programm is released under the terms of the GNU GPLv3 licence - * as can be found on the GNU website : + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . * *********************************************************************/ diff --git a/isp_utils.h b/isp_utils.h index 155c63d..729c9f3 100644 --- a/isp_utils.h +++ b/isp_utils.h @@ -3,10 +3,20 @@ * LPC ISP - Utility functions * * - * Written by Nathael Pajani + * Copyright (C) 2012 Nathael Pajani * - * This programm is released under the terms of the GNU GPLv3 licence - * as can be found on the GNU website : + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . * *********************************************************************/ diff --git a/isp_wrapper.c b/isp_wrapper.c index 3d534a5..42dd99d 100644 --- a/isp_wrapper.c +++ b/isp_wrapper.c @@ -3,10 +3,20 @@ * LPC ISP Commands * * - * Written by Nathael Pajani + * Copyright (C) 2012 Nathael Pajani * - * This programm is released under the terms of the GNU GPLv3 licence - * as can be found on the GNU website : + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . * *********************************************************************/ diff --git a/lpcisp.c b/lpcisp.c index 5a317d9..db347fd 100644 --- a/lpcisp.c +++ b/lpcisp.c @@ -2,13 +2,23 @@ * * ISP (In-System Programming) tool for NXP LPC Microcontrollers * - * This tool gives access to each of the usefull isp commands on LPC + * This tool gives access to each of the useful isp commands on LPC * devices. It does not provide wrappers for flashing a device. * - * Written by Nathael Pajani + * Copyright (C) 2012 Nathael Pajani * - * This programm is released under the terms of the GNU GPLv3 licence - * as can be found on the GNU website : + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . * *********************************************************************/ @@ -34,7 +44,7 @@ #include "isp_commands.h" #define PROG_NAME "LPC ISP" -#define VERSION "1.04" +#define VERSION "1.05" /* short explanation on exit values: * @@ -50,7 +60,7 @@ void help(char *prog_name) fprintf(stderr, "Usage: %s [options] device [-s | --synchronize]\n" \ " %s [options] device command [command arguments]\n" \ " Default baudrate is B115200\n" \ - " is the (host) serial line used to programm the device\n" \ + " is the (host) serial line used to program the device\n" \ " is one of:\n" \ " \t unlock, write-to-ram, read-memory, prepare-for-write, copy-ram-to-flash, go, erase,\n" \ " \t blank-check, read-part-id, read-boot-version, compare and read-uid.\n" \ @@ -61,7 +71,7 @@ void help(char *prog_name) " \t prepare-for-write first last : prepare sectors from 'first' to 'last' for write operation\n" \ " \t copy-ram-to-flash flash_addr ram_addr count : copy count bytes (256, 512, 1024 or 4096)\n" \ " \t from 'ram_addr' to 'flash_addr'\n" \ - " \t go address mode : execute programm at 'address' (> 0x200) in 'mode' ('arm' or 'thumb')\n" \ + " \t go address mode : execute program at 'address' (> 0x200) in 'mode' ('arm' or 'thumb')\n" \ " \t erase first last : erase flash starting from 'first' sector up to (including) 'last' sector \n" \ " \t blank-check first last : check flash starting from 'first' sector to 'last' sector is blank\n" \ " \t read-part-id \n" \ diff --git a/lpcprog.1 b/lpcprog.1 index 97ed7d1..1ca70ed 100644 --- a/lpcprog.1 +++ b/lpcprog.1 @@ -1,4 +1,4 @@ -.TH LPCPROG "1" "August 2013" "LPC Tools 1.04" "User development Tools" +.TH LPCPROG "1" "August 2013" "LPC Tools 1.05" "User development Tools" .SH NAME lpcprog \- NXP's LPC micro-controllers flasher .SH SYNOPSIS @@ -25,7 +25,7 @@ FILES section for more information on default parts desription files and order o precedence. .TP \fB\-d\fR, \fB\-\-device\fR=\fIDEV\fR -Use DEV as host serial line to programm the target. Full path must be provided. +Use DEV as host serial line to program the target. Full path must be provided. Device node files are usually located in /dev/ directory. .TP \fB\-c\fR, \fB\-\-command\fR=\fICOMMAND\fR @@ -33,7 +33,7 @@ Command to execute. COMMAND must be one of \fBid\fR, \fBdump\fR, \fBflash\fR, \fBblank\fR or \fBgo\fR. See COMMANDS section for commands description. .TP -\fB\-b\fR, --baudrate=BAUD +\fB\-b\fR, \fB\-\-baudrate\fR=\fIBAUD\fR Use BAUD as the baudrate for communication with the target device. Defaults to 115200. .TP @@ -75,14 +75,14 @@ Erase the whole flash. .TP \fBgo\fR Unsupported Yet. Reset the target using hardware reset button or power cycle the -device to start the programm. +device to start the program. .SH "PARTS DESCRIPTION FILES" Default parts description files are /etc/lpctools_parts.def or ./lpctools_parts.def The parts description file is parsed for LPC device description for dump, blank, and flash commands. If none of the defaults exist and no existing file is supplied using \fB\-p\fR option, these command cannot execute. If the part description is not found in the first found file, the command will not execute either. -If no \fB\-p\fR option is provided, the programm looks for lpctools_parts.def in the +If no \fB\-p\fR option is provided, the program looks for lpctools_parts.def in the current directory first, and then in the /etc/ directory. .PP The content of parts description files is a list of LPC parts description. @@ -91,7 +91,7 @@ Refer to the default file found in the /etc/ directory for more information on t line format. .SH "USER CODE" A valid User Code is requiered by the LPC bootloader to start the internal user -programm. User Code is considered valid if the reserved exception vector location 7 +program. User Code is considered valid if the reserved exception vector location 7 (offset 0x 0000 001C in the vector table) contains the 2’s complement of the check-sum of table entries 0 through 6. This causes the checksum of the first 8 table entries to be 0. @@ -99,17 +99,20 @@ table entries to be 0. If the signature is not valid the LPC enters ISP mode. .PP The default behavior of \fBlpcprog\fR is to compute a valid code for the 7th -exception vector and modify the programmed binary data to include this valid code. +exception vector and modify the programed binary data to include this valid code. You can prevent this by using \fB\-n\fR option. .SH "ISP MODE AND CODE READ PROTECTION" Code Read Protection is a mechanism that allows "the user" to enable different levels of "security" in the system so that access to the on-chip flash and use of -the ISP can be restricted. When needed, CRP is invoked by programming a specific +the ISP can be restricted. When needed, CRP is invoked by programing a specific pattern in flash location at 0x0000 02FC. IAP commands are not affected by the code read protection. .PP If your device Does not enter ISP state, or if some commands do not succeed, it may be because the CRP mechanism is in use on your device. +.PP +Code Read Protection will not be implemented as it goes against the license of this +tool and against the free software philosophy. .SH AUTHOR Written by Nathael Pajani. .SH "REPORTING BUGS" diff --git a/lpcprog.c b/lpcprog.c index 137323a..07cc2df 100644 --- a/lpcprog.c +++ b/lpcprog.c @@ -6,10 +6,20 @@ * provides wrappers for flashing a device. * * - * Written by Nathael Pajani + * Copyright (C) 2012 Nathael Pajani * - * This programm is released under the terms of the GNU GPLv3 licence - * as can be found on the GNU website : + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . * *********************************************************************/ @@ -37,7 +47,7 @@ #include "parts.h" #define PROG_NAME "LPC ISP Prog tool" -#define VERSION "1.04" +#define VERSION "1.05" void help(char *prog_name) @@ -53,11 +63,11 @@ void help(char *prog_name) " \t flash file_name : put 'file' to flash, erasing requiered sectors\n" \ " \t blank : erase whole flash\n" \ " \t id : get all id information\n" \ - " \t go : execute programm from reset handler in thumb mode and open terminal\n" \ + " \t go : execute program from reset handler in thumb mode and open terminal\n" \ " Available options:\n" \ " \t -p | --parts=file : Parts description file (see defaults)\n" \ " \t -c | --command=cmd : \n" \ - " \t -d | --device=dev_path : Host serial line used to programm the device\n" \ + " \t -d | --device=dev_path : Host serial line used to program the device\n" \ " \t -b | --baudrate=N : Use this baudrate (Same baudrate must be used across whole session)\n" \ " \t -t | --trace : turn on trace output of serial communication\n" \ " \t -f | --freq=N : Oscilator frequency of target device\n" \ diff --git a/lpctools_parts.def b/lpctools_parts.def index 571fc69..85215fc 100644 --- a/lpctools_parts.def +++ b/lpctools_parts.def @@ -1,4 +1,8 @@ # Parts definition file +# +# Note that the version of this file found in /etc should not be modified to ease programm update. +# Instead place a copy in your project directory or specify an alternative using the appropriate option. +# # Lines starting whith # are comments # All values but the last one MUST be immediately followed by a coma (',') and can be precedeed by # any number of whitespaces. diff --git a/parts.c b/parts.c index d224595..ce114ea 100644 --- a/parts.c +++ b/parts.c @@ -3,10 +3,20 @@ * LPC Parts identification * * - * Written by Nathael Pajani + * Copyright (C) 2012 Nathael Pajani * - * This programm is released under the terms of the GNU GPLv3 licence - * as can be found on the GNU website : + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . * *********************************************************************/ @@ -22,7 +32,7 @@ /* When looking for parts description in a file ee do allocate (malloc) two memory * chunks which we will never free. - * The user should free part_desc->name and part_desc when they are no more usefull + * The user should free part_desc->name and part_desc when they are no more useful */ struct part_desc* find_part_in_file(uint64_t dev_id, char* parts_file_name) { diff --git a/parts.h b/parts.h index 2dc07d3..ede171d 100644 --- a/parts.h +++ b/parts.h @@ -3,10 +3,20 @@ * LPC Parts identification * * - * Written by Nathael Pajani + * Copyright (C) 2012 Nathael Pajani * - * This programm is released under the terms of the GNU GPLv3 licence - * as can be found on the GNU website : + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . * *********************************************************************/ @@ -37,7 +47,7 @@ struct part_desc { /* When looking for parts description in a file ee do allocate (malloc) two memory * chunks which we will never free. - * The user should free part_desc->name and part_desc when they are no more usefull + * The user should free part_desc->name and part_desc when they are no more useful */ struct part_desc* find_part_in_file(uint64_t dev_id, char* conf_file_name); diff --git a/prog_commands.c b/prog_commands.c index 0e3ebde..664f0ae 100644 --- a/prog_commands.c +++ b/prog_commands.c @@ -3,10 +3,20 @@ * LPC ISP Commands for flash tool * * - * Written by Nathael Pajani + * Copyright (C) 2012 Nathael Pajani * - * This programm is released under the terms of the GNU GPLv3 licence - * as can be found on the GNU website : + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . * *********************************************************************/ diff --git a/prog_commands.h b/prog_commands.h index f611aee..fcd06f1 100644 --- a/prog_commands.h +++ b/prog_commands.h @@ -3,10 +3,20 @@ * LPC ISP Commands for flash tool * * - * Written by Nathael Pajani + * Copyright (C) 2012 Nathael Pajani * - * This programm is released under the terms of the GNU GPLv3 licence - * as can be found on the GNU website : + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . * *********************************************************************/ -- 2.43.0